fix(env): drop stale install paths during reactivation#10162
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a fix to prevent stale mise-managed install paths from being preserved as user prefixes in the PATH environment variable, which could otherwise shadow the active tool version. It adds a helper function is_mise_install_path to identify paths within the mise installs directory (including canonicalized paths) and skip them during PATH restoration. An end-to-end test test_zsh_reactivate_drops_stale_install_path is also added to verify this behavior in zsh. There are no review comments, so no feedback is provided.
Greptile SummaryFixes a PATH-poisoning bug where a stale mise install path inherited from a parent shell (e.g. from an editor extension) was preserved as a user prefix ahead of the active project version during
Confidence Score: 5/5Safe to merge — the change is narrowly scoped to the non-aggressive activation branch, correctly handles symlinked data directories via a canonicalization fallback, and is covered by a targeted regression test. The No files require special attention. Important Files Changed
Reviews (3): Last reviewed commit: "fix(env): drop stale install paths durin..." | Re-trigger Greptile |
0d4eb22 to
1059761
Compare
1059761 to
a62adfc
Compare
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR fixes a bug where stale mise install paths persist in PATH during shell reactivation. The implementation filters mise install-paths during the non-aggressive PATH recomputation phase, and a new end-to-end test validates that reactivation correctly prioritizes project-specified tool versions over stale global paths. ChangesStale install path filtering and regression test
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
`mise x tool@X` / `run` / `env` correctly remap the direct command, but a stale mise-managed install dir left earlier on PATH (e.g. from a frozen env snapshot of a previously activated shell) stayed ahead of the bin dir mise injects, so PATH lookups inside the process tree (subshells, env shebangs, package-manager workers) still resolved the other version -- a split-brain where `node --version` says 22 while the tests actually run on 24. Filter mise-managed install dirs out of the inherited PATH when Toolset composes the child env, so the requested version wins for the whole process tree. Mirrors the hook-env reactivation fix (jdx#10162): share its is_mise_install_path helper (moved to path_env) and extend it to also cover shared/system install dirs (MISE_SHARED_INSTALL_DIRS + the system installs dir) that find_in_shared_installs resolves into. Addresses discussion jdx#10345. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`mise x tool@X` / `run` / `env` correctly remap the direct command, but a stale mise-managed install dir left earlier on PATH (e.g. from a frozen env snapshot of a previously activated shell) stayed ahead of the bin dir mise injects, so PATH lookups inside the process tree (subshells, env shebangs, package-manager workers) still resolved the other version -- a split-brain where `node --version` says 22 while the tests actually run on 24. Filter mise-managed install dirs out of the inherited PATH when Toolset composes the child env, so the requested version wins for the whole process tree. Mirrors the hook-env reactivation fix (jdx#10162): share its is_mise_install_path helper (moved to path_env) and extend it to also cover shared/system install dirs (MISE_SHARED_INSTALL_DIRS + the system installs dir) that find_in_shared_installs resolves into. Addresses discussion jdx#10345. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
hook-envreactivation, even when the inherited session diff did not claim them.installs/node/24/binfrom being preserved as a user prefix ahead of the active project version.Reproduction
The new
e2e/env/test_zsh_reactivate_drops_stale_install_pathtest sets globalnode = "24", enablespackage.jsonidiomatic versions, creates a project withdevEngines.runtime.version = "22.x", activates zsh, then simulates a parent/editor environment that prepends the inactive global Node install path before spawning a non-interactive zsh child.Before this change, the test fails with:
After this change, reactivation keeps
node@22.17.1first.Discussion context: #10095 (reply in thread)
Tests
mise run buildCARGO_TARGET_DIR=/home/risu/.cache/cargo-target/mise-409845c58888dcc6 e2e/run_test env/test_zsh_reactivate_drops_stale_install_pathCARGO_TARGET_DIR=/home/risu/.cache/cargo-target/mise-409845c58888dcc6 e2e/run_test env/test_path_reorder_after_activateCARGO_TARGET_DIR=/home/risu/.cache/cargo-target/mise-409845c58888dcc6 e2e/run_test env/test_path_interleaved_regressionCARGO_TARGET_DIR=/home/risu/.cache/cargo-target/mise-409845c58888dcc6 e2e/run_test cli/test_activate_multiple_zshgit diff --checkSummary by CodeRabbit
Bug Fixes
Tests