#!/usr/bin/env bash
# history.describe_command reads personal dotfile diffs, so only trusted
# system/global configuration and the explicit environment variable may set it.

require_cmd git

echo 'value=baseline' >~/tracked.conf
assert_succeed "mise bootstrap dotfiles track ~/tracked.conf"

cat <<EOF >.mise.toml
[settings]
history.describe_command = "touch $HOME/project-describe-ran"
EOF
assert_succeed "mise install"
assert_contains "mise trust --show" ": trusted"

echo 'value=project' >~/tracked.conf
assert_succeed "mise bootstrap dotfiles watch --once"
assert "mise bootstrap dotfiles history --json | jq -r '.[0].description_source'" "computed"
assert_fail "test -e ~/project-describe-ran"

cat <<EOF >>"$MISE_CONFIG_DIR/config.toml"

[settings]
history.describe_command = "cat > $HOME/global-describe-input"
EOF
echo 'value=global' >~/tracked.conf
assert_succeed "mise bootstrap dotfiles watch --once"
assert_succeed "test -s ~/global-describe-input"
assert_contains "cat ~/global-describe-input" 'value=global'

echo 'value=environment' >~/tracked.conf
assert_succeed "MISE_HISTORY_DESCRIBE_COMMAND='cat > $HOME/env-describe-input' mise bootstrap dotfiles watch --once"
assert_succeed "test -s ~/env-describe-input"
assert_contains "cat ~/env-describe-input" 'value=environment'
