From b236bcfe34a006fa61e6df0924ba6b4784870b09 Mon Sep 17 00:00:00 2001 From: Vinicius Date: Wed, 18 Nov 2026 15:36:29 -0300 Subject: [PATCH] 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> --- src/browser/PlaywrightScenarioBrowser.test.ts | 81 +++++++++++-------- src/browser/PlaywrightScenarioBrowser.ts | 4 +- 2 files changed, 50 insertions(+), 35 deletions(-) diff --git a/src/browser/PlaywrightScenarioBrowser.test.ts b/src/browser/PlaywrightScenarioBrowser.test.ts index 30bbd71c69..816fe61299 100644 --- a/src/browser/PlaywrightScenarioBrowser.test.ts +++ b/src/browser/PlaywrightScenarioBrowser.test.ts @@ -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", diff --git a/src/browser/PlaywrightScenarioBrowser.ts b/src/browser/PlaywrightScenarioBrowser.ts index abc8262f77..1a43e0e9f6 100644 --- a/src/browser/PlaywrightScenarioBrowser.ts +++ b/src/browser/PlaywrightScenarioBrowser.ts @@ -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",