fix(browser): match the win32 environment snapshot spelling for SystemRoot (#8387)

Browser scenario launches forward a caller-selected environment through
snapshotEnvironment, which uppercases every name on win32. The launch
allowlist read the mixed-case "SystemRoot" spelling, so the lookup was
always undefined on Windows and the launched browser never received the
variable the allowlist intends to forward; the effective launch
environment was only HOME/LANG/PATH/TEMP/TMP.

Node's Windows spawn path re-adds a small set of system variables from
the parent environment, which has masked the missing entry so far, but
that behavior is outside REA's contract. The Electron active-provider
allowlist already reads "SYSTEMROOT" (uppercase) for the same snapshot,
so match that spelling here and keep the launched browser environment
dependent only on REA's own allowlist.

Co-authored-by: Vinicius Henrique Menezes Moreira <29902685+SwintexD@users.noreply.github.com>
Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-18 13:36:29 -05:00
1 parent 0b95fa7d69
commit b236bcfe34
2 files changed
+50 -35

No files matched your search

+47 -34
View File
@@ -18,6 +18,7 @@ import { DEFAULT_CDP_COMMAND_TIMEOUT_MS } from "../domain/browserDeadline.js";
import { browserScenarioSchema } from "../domain/browserScenario.js";
import { PLAYWRIGHT_CLEANUP_CONFIRMATION_TIMEOUT_MS } from "./PlaywrightExecutionBoundary.js";
import { absoluteCallerPath } from "../filesystem/callerPath.js";
import { snapshotEnvironment } from "../process/snapshotEnvironment.js";
import {
attachedScenarioLeaseKey,
failBrowserScenarioOperation,
@@ -50,41 +51,53 @@ it("locks one attached browser across loopback spellings of one endpoint", () =>
);
});
it("passes the selected environment to the actual browser launch boundary", async () => {
vi.stubEnv("LANG", "ambient-language");
const selected = {
LANG: "selected-language",
PATH: "/selected/bin",
REA_PRIVATE_VALUE: "not-a-launch-setting",
};
let launchedEnvironment: unknown;
const scenario = browserScenarioSchema.parse({
browser: { mode: "launch", executable_path: process.execPath },
start_url: { url: "https://example.test" },
actions: [
{ step_id: "settle", action: "wait_for_timeout", duration_ms: 1 },
],
});
await expect(
openPlaywrightScenarioBrowser(scenario, selected, {
launcher: {
connectOverCDP: async () => {
throw new Error("Unexpected connection");
},
launchPersistentContext: async (_profile, options) => {
launchedEnvironment = options?.env;
throw new Error("launch boundary reached");
},
it.each([
{ platform: "win32", systemRootKey: "SYSTEMROOT" },
{ platform: "linux", systemRootKey: "SystemRoot" },
] as const)(
"passes the selected environment to the $platform browser launch boundary",
async ({ platform, systemRootKey }) => {
vi.stubEnv("LANG", "ambient-language");
const selected = snapshotEnvironment(
{
LANG: "selected-language",
PATH: "/selected/bin",
SystemRoot: "C:/WINDOWS",
REA_PRIVATE_VALUE: "not-a-launch-setting",
},
}),
).rejects.toMatchObject({
diagnostics: { startup_error: "launch boundary reached" },
});
expect(launchedEnvironment).toEqual({
LANG: "selected-language",
PATH: "/selected/bin",
});
});
platform,
);
let launchedEnvironment: unknown;
const scenario = browserScenarioSchema.parse({
browser: { mode: "launch", executable_path: process.execPath },
start_url: { url: "https://example.test" },
actions: [
{ step_id: "settle", action: "wait_for_timeout", duration_ms: 1 },
],
});
await expect(
openPlaywrightScenarioBrowser(scenario, selected, {
platform,
launcher: {
connectOverCDP: async () => {
throw new Error("Unexpected connection");
},
launchPersistentContext: async (_profile, options) => {
launchedEnvironment = options?.env;
throw new Error("launch boundary reached");
},
},
}),
).rejects.toMatchObject({
diagnostics: { startup_error: "launch boundary reached" },
});
expect(launchedEnvironment).toEqual({
LANG: "selected-language",
PATH: "/selected/bin",
[systemRootKey]: "C:/WINDOWS",
});
},
);
it.skipIf(process.platform === "win32")(
"passes the caller-selected symlink-parent executable to the launch boundary",
+3 -1
View File
@@ -359,7 +359,9 @@ const allowedBrowserEnvironment = (
"LANG",
"LD_LIBRARY_PATH",
"PATH",
"SystemRoot",
// Snapshot environments uppercase names on win32; match that spelling so
// the launched browser receives the Windows system root it needs.
platform === "win32" ? "SYSTEMROOT" : "SystemRoot",
"TEMP",
"TMP",
"TMPDIR",