#!/usr/bin/env bash

# Test that `mise lock` (unfiltered) prunes stale version entries when the
# resolved version changes. This matches the behavior of filtered runs.

export MISE_LOCKFILE=1

rm -f mise.toml mise.lock

echo "=== Setup: lock dummy at 1.0.0 ==="
cat <<'EOF' >mise.toml
[tools]
dummy = "1.0.0"
EOF

mise install dummy@1.0.0
mise lock --platform linux-x64
assert_contains "cat mise.lock" 'version = "1.0.0"'
assert_not_contains "cat mise.lock" 'version = "1.1.0"'

echo "=== Change config to 1.1.0 and re-lock (unfiltered) ==="
cat <<'EOF' >mise.toml
[tools]
dummy = "1.1.0"
EOF

mise install dummy@1.1.0

# Unfiltered lock run (no tool specified)
mise lock --platform linux-x64

# Should have the new version
assert_contains "cat mise.lock" 'version = "1.1.0"'
# Should NOT have the old version (this was the bug: both would be present)
assert_not_contains "cat mise.lock" 'version = "1.0.0"'

echo "=== Cleanup ==="
rm -f mise.toml mise.lock
