-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(hook-env): preserve PATH reordering done after activation #8190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Test that PATH reordering done after `mise activate` is preserved by hook-env. | ||
| # This simulates the scenario where ~/.zlogin (which runs after ~/.zshrc on login | ||
| # shells) reorders PATH entries — e.g., moving a tool to the front for priority. | ||
| # | ||
| # Regression test for https://github.com/jdx/mise/discussions/8188 | ||
| # and https://github.com/jdx/mise/issues/8168 | ||
|
|
||
| # Save the mise binary path before we override PATH | ||
| MISE_BIN="$(which mise)" | ||
|
|
||
| # Simulate the PATH captured during mise activate in ~/.zshrc | ||
| # The original order has system-bin first, mytool/bin last | ||
| export __MISE_ORIG_PATH="$HOME/system-bin:/usr/local/bin:/usr/bin:/bin:$HOME/mytool/bin" | ||
|
|
||
| # Create test directories and executables | ||
| mkdir -p "$HOME/mytool/bin" | ||
| mkdir -p "$HOME/system-bin" | ||
|
|
||
| # Simulate ~/.zlogin moving ~/mytool/bin to the FRONT of PATH | ||
| # (this is what users do to override system binaries) | ||
| export PATH="$HOME/mytool/bin:$HOME/system-bin:/usr/local/bin:/usr/bin:/bin" | ||
|
|
||
| cat >mise.toml <<'EOF' | ||
| EOF | ||
|
|
||
| # Run hook-env using the saved binary path | ||
| eval "$("$MISE_BIN" hook-env -s bash)" | ||
|
|
||
| echo "DEBUG: PATH=$PATH" | ||
|
|
||
| # ~/mytool/bin should still be BEFORE ~/system-bin because the user | ||
| # reordered it to the front after activation | ||
| MYTOOL_POS=$(echo "$PATH" | tr ':' '\n' | grep -n "mytool/bin" | head -1 | cut -d: -f1) | ||
| SYSTEM_POS=$(echo "$PATH" | tr ':' '\n' | grep -n "system-bin" | head -1 | cut -d: -f1) | ||
|
Comment on lines
+35
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The You can use |
||
|
|
||
| echo "DEBUG: mytool/bin at position $MYTOOL_POS, system-bin at position $SYSTEM_POS" | ||
|
|
||
| if [[ -z $MYTOOL_POS ]]; then | ||
| echo "FAIL: mytool/bin not found in PATH" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ -z $SYSTEM_POS ]]; then | ||
| echo "FAIL: system-bin not found in PATH" | ||
| exit 1 | ||
| fi | ||
|
|
||
| if [[ $MYTOOL_POS -lt $SYSTEM_POS ]]; then | ||
| echo "SUCCESS: mytool/bin stays before system-bin (reorder preserved)" | ||
| else | ||
| echo "FAIL: mytool/bin ($MYTOOL_POS) was moved after system-bin ($SYSTEM_POS)" | ||
| echo "hook-env restored the original __MISE_ORIG_PATH order instead of the current order" | ||
| exit 1 | ||
| fi | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whichis non-POSIX and is flagged by ShellCheck (SC2230). Sincehk.pklrunsshellcheckovere2e/**, this will break linting in CI. Prefercommand -v mise(and fail with a clear message if it’s not found) when capturing the absolute path before overridingPATH.