Repository navigation
fix(env): preserve system tool PATH precedence #3447
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
Merged
fengmk2
merged 3 commits into
voidzero-dev:main
from
liangmiQwQ:liang/codex/system-first-path
Nov 19, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/snapshots.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| [[case]] | ||
| name = "system_pm_preserves_node_and_path" | ||
| vp = "global" | ||
| skip-platforms = ["windows"] | ||
| prewarm-package-managers = false | ||
| steps = [["node", "verify.mjs", "system-pm"]] | ||
|
|
||
| [[case]] | ||
| name = "managed_shim_preserves_system_node_path" | ||
| vp = "global" | ||
| skip-platforms = ["windows"] | ||
| prewarm-package-managers = false | ||
| steps = [["node", "verify.mjs", "shim"]] | ||
|
|
||
| [[case]] | ||
| name = "explicit_pm_preserves_system_node_path" | ||
| vp = "global" | ||
| skip-platforms = ["windows"] | ||
| prewarm-package-managers = false | ||
| steps = [["node", "verify.mjs", "explicit-pm"]] |
7 changes: 7 additions & 0 deletions
7
.../fixtures/system_first_path/snapshots/explicit_pm_preserves_system_node_path.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # explicit_pm_preserves_system_node_path | ||
|
|
||
| ## `node verify.mjs explicit-pm` | ||
|
|
||
| ``` | ||
| explicit-pm: selected Node and original PATH precedence preserved | ||
| ``` |
7 changes: 7 additions & 0 deletions
7
...fixtures/system_first_path/snapshots/managed_shim_preserves_system_node_path.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # managed_shim_preserves_system_node_path | ||
|
|
||
| ## `node verify.mjs shim` | ||
|
|
||
| ``` | ||
| shim: selected Node and original PATH precedence preserved | ||
| ``` |
7 changes: 7 additions & 0 deletions
7
...shots/fixtures/system_first_path/snapshots/system_pm_preserves_node_and_path.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # system_pm_preserves_node_and_path | ||
|
|
||
| ## `node verify.mjs system-pm` | ||
|
|
||
| ``` | ||
| system-pm: selected Node and original PATH precedence preserved | ||
| ``` |
83 changes: 83 additions & 0 deletions
83
crates/vp_cli_snapshots/tests/cli_snapshots/fixtures/system_first_path/verify.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| import assert from 'node:assert/strict'; | ||
| import { spawnSync } from 'node:child_process'; | ||
| import { chmodSync, mkdirSync, writeFileSync, symlinkSync } from 'node:fs'; | ||
| import { delimiter, join } from 'node:path'; | ||
|
|
||
| const scenario = process.argv[2]; | ||
| const root = process.cwd(); | ||
| const first = join(root, 'first-bin'); | ||
| const nodeBin = join(root, 'node-bin'); | ||
| const pmBin = join(root, 'pm-bin'); | ||
| for (const dir of [first, nodeBin, pmBin]) { | ||
| mkdirSync(dir, { recursive: true }); | ||
| } | ||
| function executable(path, content) { | ||
| writeFileSync(path, content); | ||
| chmodSync(path, 0o755); | ||
| } | ||
| // Each later directory supplies a competing tool to expose accidental PATH promotion. | ||
| symlinkSync(process.execPath, join(nodeBin, 'node')); | ||
| executable(join(first, 'path-probe'), '#!/bin/sh\necho preferred\n'); | ||
| executable(join(nodeBin, 'path-probe'), '#!/bin/sh\necho shadowed-by-node\n'); | ||
| executable(join(pmBin, 'npm'), '#!/bin/sh\necho system-npm\n'); | ||
| executable(join(pmBin, 'path-probe'), '#!/bin/sh\necho shadowed-by-pm\n'); | ||
| executable(join(pmBin, 'node'), '#!/bin/sh\necho shadowed-by-pm\nexit 1\n'); | ||
| const manager = '#!/bin/sh\nif [ "${1-}" = "--version" ]; then echo 10.18.0; else node probe.mjs; fi\n'; | ||
| executable(join(pmBin, 'pnpm'), manager); | ||
| writeFileSync( | ||
| 'package.json', | ||
| JSON.stringify({ name: 'system-first-path', private: true, packageManager: 'pnpm@10.18.0' }), | ||
| ); | ||
| writeFileSync( | ||
| 'probe.mjs', | ||
| ` | ||
| import assert from 'node:assert/strict'; | ||
| import { execFileSync } from 'node:child_process'; | ||
| assert.equal(execFileSync('path-probe', { encoding: 'utf8' }).trim(), 'preferred'); | ||
| assert.match(execFileSync('node', ['--version'], { encoding: 'utf8' }), /^v/); | ||
| console.log('selected Node and original PATH precedence preserved'); | ||
| `, | ||
| ); | ||
| const env = { | ||
| ...process.env, | ||
| PATH: [first, nodeBin, pmBin, process.env.PATH].join(delimiter), | ||
| // Start a fresh shell selection instead of inheriting the runner's Node selection. | ||
| VP_PATH_INJECTED_TOOLS: '', | ||
| }; | ||
| function run(args) { | ||
| const result = spawnSync('vp', args, { env, encoding: 'utf8' }); | ||
| assert.equal(result.status, 0, `${args.join(' ')}\n${result.stdout}\n${result.stderr}`); | ||
| return result.stdout; | ||
| } | ||
| run(['env', 'off', 'node']); | ||
| run(['env', 'off', 'pm']); | ||
| if (scenario === 'system-pm') { | ||
| assert.match(run(['install']), /selected Node and original PATH precedence preserved/); | ||
| run(['env', 'on', 'node']); | ||
| assert.match(run(['install']), /selected Node and original PATH precedence preserved/); | ||
| assert.match( | ||
| run(['env', 'exec', '--node', process.versions.node, 'pnpm', 'install']), | ||
| /selected Node and original PATH precedence preserved/, | ||
| ); | ||
| } else { | ||
| const managed = join(process.env.VP_HOME, 'package_manager/pnpm/10.18.0/pnpm/bin'); | ||
| mkdirSync(managed, { recursive: true }); | ||
| for (const tool of ['pnpm', 'pnpx']) { | ||
| executable(join(managed, tool), manager); | ||
| } | ||
| run(['env', 'on', 'pnpm']); | ||
| if (scenario === 'shim') { | ||
| const result = spawnSync(join(process.env.VP_HOME, 'bin/pnpm'), ['install'], { | ||
| env, | ||
| encoding: 'utf8', | ||
| }); | ||
| assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`); | ||
| assert.match(result.stdout, /selected Node and original PATH precedence preserved/); | ||
| } else { | ||
| assert.match( | ||
| run(['env', 'exec', '--package-manager', 'pnpm@10.18.0', 'pnpm', 'install']), | ||
| /selected Node and original PATH precedence preserved/, | ||
| ); | ||
| } | ||
| } | ||
| console.log(`${scenario}: selected Node and original PATH precedence preserved`); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.