-
Notifications
You must be signed in to change notification settings - Fork 4.3k
child_process: honor runtime process.env.PATH in sync spawn variants #29239
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
Open
robobun
wants to merge
9
commits into
main
Choose a base branch
from
farm/b23657e5/fix-execfilesync-stale-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+74
−2
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
610c6f6
child_process: honor runtime process.env.PATH in sync spawn variants
robobun 4e7847f
[autofix.ci] apply automated fixes
autofix-ci[bot] b15270b
test: address review — stdout/exitCode assertion order, drop flaky st…
robobun 37e7ce2
test: hoist node:fs/node:path to top-level imports
robobun b1f7876
[autofix.ci] apply automated fixes
autofix-ci[bot] 669ab20
child_process: normalize PATH casing on Windows in normalized env
robobun 2063f63
ci: retrigger — aarch64-build-cpp infra flake (exit 255)
robobun 5d1f4f4
test: pipe fixture stderr for diagnostics on failure
robobun d97d351
[autofix.ci] apply automated fixes
autofix-ci[bot] 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| // Regression test for https://github.com/oven-sh/bun/issues/29237 | ||
| // child_process sync variants (execFileSync, spawnSync, execSync) must | ||
| // resolve commands using the *current* process.env.PATH when options.env | ||
| // is omitted — not a stale snapshot captured at Bun startup. | ||
|
|
||
| import { expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe, isWindows, tempDir } from "harness"; | ||
| import { chmodSync } from "node:fs"; | ||
| import path from "node:path"; | ||
|
|
||
| test.skipIf(isWindows)("execFileSync/spawnSync/execSync honor runtime mutations to process.env.PATH", async () => { | ||
| using dir = tempDir("issue-29237", { | ||
| // Fake `marker` binary — whichever PATH entry wins gets called. | ||
| "fake/marker": '#!/bin/sh\necho "FAKE_CALLED"\n', | ||
| "fixture.js": ` | ||
| const { execFileSync, spawnSync, execSync } = require("node:child_process"); | ||
| const path = require("node:path"); | ||
|
|
||
| // Prepend our fake-binary dir to PATH at runtime. | ||
| const fakeDir = path.join(__dirname, "fake"); | ||
| process.env.PATH = fakeDir + path.delimiter + process.env.PATH; | ||
|
|
||
| // 1. execFileSync without explicit env — must use mutated PATH. | ||
| const a = execFileSync("marker", { encoding: "utf8" }).trim(); | ||
| console.log("execFileSync:", a); | ||
|
|
||
| // 2. spawnSync without explicit env. | ||
| const b = spawnSync("marker", [], { encoding: "utf8" }); | ||
| console.log("spawnSync:", (b.stdout || "").trim()); | ||
|
|
||
| // 3. execSync without explicit env. | ||
| const c = execSync("marker", { encoding: "utf8" }).trim(); | ||
| console.log("execSync:", c); | ||
|
|
||
| // 4. execFileSync *with* explicit env — sanity check, already worked. | ||
| const d = execFileSync("marker", { encoding: "utf8", env: process.env }).trim(); | ||
| console.log("execFileSync+env:", d); | ||
| `, | ||
| }); | ||
|
|
||
| // chmod the fake binary so it's executable — tempDir writes 0644 by default. | ||
| chmodSync(path.join(String(dir), "fake", "marker"), 0o755); | ||
|
|
||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "fixture.js"], | ||
| env: bunEnv, | ||
robobun marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| cwd: String(dir), | ||
| stderr: "pipe", | ||
| }); | ||
|
|
||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
|
|
||
| // Surface any subprocess stderr on assertion failure for diagnosis. | ||
| if (exitCode !== 0) console.error("fixture stderr:", stderr); | ||
|
|
||
| // Assert stdout first for better failure messages, then exit code. | ||
| expect(stdout).toBe( | ||
| "execFileSync: FAKE_CALLED\n" + | ||
| "spawnSync: FAKE_CALLED\n" + | ||
| "execSync: FAKE_CALLED\n" + | ||
| "execFileSync+env: FAKE_CALLED\n", | ||
| ); | ||
| expect(exitCode).toBe(0); | ||
| }); | ||
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.