-
Notifications
You must be signed in to change notification settings - Fork 5k
ci(windows): stash multi-line env vars around Enter-VsDevShell #34355
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
4
commits into
main
Choose a base branch
from
farm/1854e8ed/vs-shell-multiline-env
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.
+73
−0
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
063ae25
ci(windows): stash multi-line env vars around Enter-VsDevShell
robobun 1bd8104
test: cover vs-shell.ps1 multi-line env stash on Windows
robobun a6a36e2
[autofix.ci] apply automated fixes
autofix-ci[bot] 9456e26
test: drop per-test timeout (runner.node.mjs already passes --timeout)
robobun 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,60 @@ | ||
| // Regression guard for scripts/vs-shell.ps1: Enter-VsDevShell parses | ||
| // `cmd /c set` output line by line, so a multi-line env value (e.g. the | ||
| // commit message in BUILDKITE_MESSAGE) used to leak each `KEY=VALUE`-shaped | ||
| // body line as its own env var. A body line like `BUN_JSC_foo=bar baz` then | ||
| // aborted every spawned Bun process on the Windows test lanes. | ||
| import { expect, test } from "bun:test"; | ||
| import { bunEnv, bunExe, isWindows } from "harness"; | ||
| import { existsSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
|
|
||
| const vswhere = "C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vswhere.exe"; | ||
|
|
||
| test.skipIf(!isWindows || !existsSync(vswhere))( | ||
| "vs-shell.ps1 shields multi-line env vars from Enter-VsDevShell", | ||
| async () => { | ||
| const repoRoot = join(import.meta.dir, "..", ".."); | ||
| const vsShell = join(repoRoot, "scripts", "vs-shell.ps1"); | ||
| const probe = ["line1", "VS_SHELL_LEAKED=oops", "BUN_JSC_notARealOption=1 some trailing text", "line4"].join("\n"); | ||
|
|
||
| const dump = | ||
| "process.stdout.write(JSON.stringify({" + | ||
| "probe:process.env.VS_SHELL_PROBE," + | ||
| "leaked:process.env.VS_SHELL_LEAKED," + | ||
| "jsc:process.env.BUN_JSC_notARealOption," + | ||
| "vs:process.env.VSINSTALLDIR" + | ||
| "}))"; | ||
|
|
||
| const env: Record<string, string | undefined> = { ...bunEnv, VS_SHELL_PROBE: probe }; | ||
| // The Windows test runner already sits inside vs-shell.ps1, so VSINSTALLDIR | ||
| // is set; unset it so the child re-runs the loader and hits the stash path. | ||
| delete env.VSINSTALLDIR; | ||
|
|
||
| await using proc = Bun.spawn({ | ||
| cmd: ["pwsh", "-NoProfile", "-File", vsShell, bunExe(), "-e", dump], | ||
| env, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
|
|
||
| // vs-shell.ps1 writes status lines before `$ <cmd>`; the JSON is the last line. | ||
| const jsonLine = stdout.trimEnd().split("\n").pop() ?? ""; | ||
| let result: { probe: unknown; leaked: unknown; jsc: unknown; vs: unknown }; | ||
| try { | ||
| result = JSON.parse(jsonLine); | ||
| } catch { | ||
| throw new Error(`expected JSON on last line, got:\n--- stdout ---\n${stdout}\n--- stderr ---\n${stderr}`); | ||
| } | ||
|
|
||
| expect(result).toEqual({ | ||
| probe, // round-tripped intact, newlines preserved | ||
| leaked: undefined, // body line did not become its own var | ||
| jsc: undefined, // body line did not become its own var | ||
| vs: expect.any(String), // VS env was still loaded | ||
| }); | ||
| expect(stderr).not.toContain("invalid JSC environment variable"); | ||
| expect(exitCode).toBe(0); | ||
| }, | ||
| 60_000, | ||
| ); | ||
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.