#!/usr/bin/env zsh
set -euo pipefail
orig_path="$PATH"

cat <<EOF >.mise.toml
[tools]
node = "20.0.0"
EOF

mkdir 18
cat <<EOF >18/.mise.toml
[tools]
node = "18.0.0"
EOF

assert_path() {
  local expected="${1//$HOME/\~}"
  local actual="${PATH/%$orig_path/}"
  actual="${actual//$HOME/\~}"
  actual="${actual/%:/}"
  if [[ "$actual" != "$expected" ]]; then
    echo "Invalid PATH:  $actual"
    echo "Expected PATH: $expected"
    exit 1
  fi
}

mise install node@20.0.0 node@18.0.0
# shellcheck disable=SC1090
eval "$(mise activate zsh --status)" && _mise_hook

#mise install
test "$(node -v)" = "v20.0.0"

cd 18 && _mise_hook
#mise install
test "$(node -v)" = "v18.0.0"

cd .. && _mise_hook
test "$(node -v)" = "v20.0.0"

mise shell node@18.0.0 && _mise_hook
test "$(node -v)" = "v18.0.0"

mise deactivate
assert_path ""
