From 96267880c3dec7715f8e71293ed2bc13c9eacf24 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Sat, 21 Nov 2026 06:06:46 -0500 Subject: [PATCH] test(process): consolidate selected child environment proofs (#13074) --- .../process-global/apktoolEnvironment.test.ts | 48 +++++++-------- .../nativeModuleResolverEnvironment.test.ts | 58 +++++++++---------- 2 files changed, 51 insertions(+), 55 deletions(-) diff --git a/tests/process-global/apktoolEnvironment.test.ts b/tests/process-global/apktoolEnvironment.test.ts index 294155f207..643a2954f7 100644 --- a/tests/process-global/apktoolEnvironment.test.ts +++ b/tests/process-global/apktoolEnvironment.test.ts @@ -16,37 +16,35 @@ afterEach(() => { // These executable probes validate the real CLI and process environment boundary; // they do not establish native Apktool decoding behavior. -it.skipIf(process.platform === "win32").each([ - { name: "missing", selected: {}, expected: "absent" }, - { - name: "unset", - selected: { REA_APKTOOL_ENV_PROFILE: undefined }, - expected: "absent", - }, - { - name: "empty", - selected: { REA_APKTOOL_ENV_PROFILE: "" }, - expected: "empty", - }, - { - name: "selected", - selected: { REA_APKTOOL_ENV_PROFILE: "selected-profile" }, - expected: "selected-profile", - }, -])( - "preserves $name Apktool settings after the ambient environment changes", - async ({ selected, expected }) => { +it.skipIf(process.platform === "win32")( + "preserves selected Apktool settings after the ambient environment changes", + async () => { const root = await createTestTempDirectory( "rea-apktool-selected-environment-", ); const command = join(root, "apktool"); await writeFile( command, - '#!/bin/sh\nprofile=${REA_APKTOOL_ENV_PROFILE-absent}\n[ -n "$profile" ] || profile=empty\nprintf "2.11.1+%s\\n" "$profile"\n', + [ + "#!/bin/sh", + 'printf "2.11.1+%s.%s.%s.%s\\n" "${REA_APKTOOL_MISSING-absent}" "${REA_APKTOOL_UNSET-absent}" "empty-${REA_APKTOOL_EMPTY-absent}" "${REA_APKTOOL_SELECTED-absent}"', + "", + ].join("\n"), { mode: 0o755 }, ); - const cli = createCli({ REA_APKTOOL_COMMAND: command, ...selected }); - vi.stubEnv("REA_APKTOOL_ENV_PROFILE", "late-ambient-profile"); + const cli = createCli({ + REA_APKTOOL_COMMAND: command, + REA_APKTOOL_UNSET: undefined, + REA_APKTOOL_EMPTY: "", + REA_APKTOOL_SELECTED: "selected-profile", + }); + for (const key of [ + "REA_APKTOOL_MISSING", + "REA_APKTOOL_UNSET", + "REA_APKTOOL_EMPTY", + "REA_APKTOOL_SELECTED", + ]) + vi.stubEnv(key, "late-ambient-profile"); let stdout = ""; await cli.serve(["inspect-apktool-client", "--json"], { env: {}, @@ -57,7 +55,9 @@ it.skipIf(process.platform === "win32").each([ }); const evidence = parseEvidence(JSON.parse(stdout)); expect(evidence.normalized_result).toMatchObject({ - client: { apktool_version: `2.11.1+${expected}` }, + client: { + apktool_version: "2.11.1+absent.absent.empty-.selected-profile", + }, }); expect(evidence.environment).toBeNull(); }, diff --git a/tests/process-global/nativeModuleResolverEnvironment.test.ts b/tests/process-global/nativeModuleResolverEnvironment.test.ts index 6a941bea21..14368dcd4f 100644 --- a/tests/process-global/nativeModuleResolverEnvironment.test.ts +++ b/tests/process-global/nativeModuleResolverEnvironment.test.ts @@ -10,53 +10,49 @@ afterEach(() => vi.unstubAllEnvs()); // Playwright starts the actual selected executable, which records its environment // and exits before the browser handshake. This proves launch inheritance only. -it.skipIf(process.platform === "win32").each([ - { name: "missing", selected: {}, expected: "absent" }, - { - name: "unset", - selected: { REA_MODULE_ENV_PROFILE: undefined }, - expected: "absent", - }, - { name: "empty", selected: { REA_MODULE_ENV_PROFILE: "" }, expected: "" }, - { - name: "selected", - selected: { REA_MODULE_ENV_PROFILE: "selected-profile" }, - expected: "selected-profile", - }, -])( - "preserves $name module-resolver settings in the real Playwright child", - async ({ selected, expected }) => { +it.skipIf(process.platform === "win32")( + "preserves selected environment values in the real Playwright child", + async () => { const root = await createTestTempDirectory( "rea-module-resolver-environment-", ); - const command = join(root, "browser"), - receipt = join(root, "receipt"); + const command = join(root, "browser"); + const receipt = join(root, "receipt"); const quotedReceipt = `'${receipt.replaceAll("'", "'\\''")}'`; + const keys = [ + "REA_MODULE_MISSING", + "REA_MODULE_UNSET", + "REA_MODULE_EMPTY", + "REA_MODULE_SELECTED", + ]; + const fields = keys.map((key) => `"\${${key}-absent}"`).join(" "); await writeFile( command, - '#!/bin/sh\nprintf "%s\\n%s" "$$" "${REA_MODULE_ENV_PROFILE-absent}" > ' + - quotedReceipt + - "\nexit 0\n", + `#!/bin/sh\nprintf "%s\\n" "$$" ${fields} > ${quotedReceipt}\nexit 0\n`, { mode: 0o755 }, ); - const environment = { REA_BROWSER_EXECUTABLE: command, ...selected }; + + const environment: Record = { + REA_BROWSER_EXECUTABLE: command, + REA_MODULE_UNSET: undefined, + REA_MODULE_EMPTY: "", + REA_MODULE_SELECTED: "selected-profile", + }; const resolver = new NativeModuleResolver(environment); onTestFinished(() => resolver.close()); - // Constructor selection is immutable even when the original caller map changes. - Object.assign(environment, { - REA_MODULE_ENV_PROFILE: "later-caller-profile", - }); - vi.stubEnv("REA_MODULE_ENV_PROFILE", "late-ambient-profile"); + for (const key of keys) { + environment[key] = "later-caller-profile"; + vi.stubEnv(key, "late-ambient-profile"); + } const result = await resolver.resolve({ importerUrl: "https://app.test/main.js", importMap: null, specifiers: ["./dep.js"], }); expect(result.ok).toBe(false); - const observed = await readFile(receipt, "utf8"); - const separator = observed.indexOf("\n"); - expect(observed.slice(separator + 1)).toBe(expected); - const pid = Number(observed.slice(0, separator)); + const [rawPid, ...values] = (await readFile(receipt, "utf8")).split("\n"); + expect(values).toEqual(["absent", "absent", "", "selected-profile", ""]); + const pid = Number(rawPid); expect(Number.isSafeInteger(pid) && pid > 0).toBe(true); expect(await observeProcessStartIdentity(pid)).toBeUndefined(); },