From 90d006dd4a5ec37b841bb2d929a47342a6d1a45c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ignacy=20=C5=81=C4=85tka?= Date: Mon, 3 Aug 2026 16:02:29 +0200 Subject: [PATCH] test(tool-server): stop unit tests inheriting the developer's ARGENT_* overrides MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `selectGpuMode` reads ARGENT_EMULATOR_GPU_MODE before falling back to the platform default, so a shell exporting `ARGENT_EMULATOR_GPU_MODE=host` — the documented escape hatch for hosts where swiftshader is too slow — made the six platform-parameterised `-gpu` assertions in boot-device-hotboot resolve `host` instead of `swiftshader`/`auto` and fail. The same class bites elsewhere: ARGENT_EMULATOR_NO_WINDOW fails four more in that file, ARGENT_SIMULATOR_NO_WINDOW fails the Simulator.app attach assertion in boot-device, and ARGENT_PORT/ARGENT_HOST fail both bind-failure-telemetry tests. Clear the whole ARGENT_* prefix from a suite-wide setup file so assertions test the shipped defaults. Tests that exercise an override already set it themselves. Also reorder the four `it.each(PLATFORMS)` titles, whose `%s` placeholders ran against the [platform, gpu] tuple and rendered as "-gpu linux on swiftshader". --- .../test/boot-device-hotboot.test.ts | 11 ++++++---- .../test/setup/clear-argent-env.ts | 21 +++++++++++++++++++ packages/tool-server/vitest.config.ts | 7 ++++--- 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 packages/tool-server/test/setup/clear-argent-env.ts diff --git a/packages/tool-server/test/boot-device-hotboot.test.ts b/packages/tool-server/test/boot-device-hotboot.test.ts index ec766b583..b3dd3e2b9 100644 --- a/packages/tool-server/test/boot-device-hotboot.test.ts +++ b/packages/tool-server/test/boot-device-hotboot.test.ts @@ -142,7 +142,7 @@ function mockHappyBootChain(newSerial = "emulator-5554") { describe("boot-device Android — hot-boot with cold-boot fallback", () => { it.each(PLATFORMS)( - "picks the hot-boot spawn args + `-gpu %s` on %s when default_boot probes Loadable", + "on %s picks the hot-boot spawn args + `-gpu %s` when default_boot probes Loadable", async (platform, expectedGpu) => { setPlatform(platform); hasSnapshotMock.mockResolvedValue(true); @@ -173,6 +173,9 @@ describe("boot-device Android — hot-boot with cold-boot fallback", () => { // `swiftshader` for universal compatibility (sidesteps the host GL // stack, which silently fails on Optimus / dual-GPU / Wayland-with- // NVIDIA setups); every other host uses `auto`. See `selectGpuMode`. + // These are the no-override defaults, so they only hold with + // `ARGENT_EMULATOR_GPU_MODE` unset — `test/setup/clear-argent-env.ts` + // strips it from the runner's environment for the whole suite. const gpuIdx = hotArgs.indexOf("-gpu"); expect(gpuIdx).toBeGreaterThanOrEqual(0); expect(hotArgs[gpuIdx + 1]).toBe(expectedGpu); @@ -180,7 +183,7 @@ describe("boot-device Android — hot-boot with cold-boot fallback", () => { ); it.each(PLATFORMS)( - "hands `-gpu %s` to both probe and hot-boot spawn on %s", + "on %s hands `-gpu %s` to both probe and hot-boot spawn", async (platform, expectedGpu) => { // Sibling test of the assertion above, focused on parity: the probe // argv and the spawn argv must agree on every renderer-affecting flag, @@ -332,7 +335,7 @@ describe("boot-device Android — hot-boot with cold-boot fallback", () => { }); it.each(PLATFORMS)( - "ignores empty/whitespace ARGENT_EMULATOR_GPU_MODE, falls through to `%s` default on %s", + "on %s ignores empty/whitespace ARGENT_EMULATOR_GPU_MODE, falls through to the `%s` default", async (platform, expectedGpu) => { // `export FOO=` foot-gun: fall through to platform default, don't crash. setPlatform(platform); @@ -376,7 +379,7 @@ describe("boot-device Android — hot-boot with cold-boot fallback", () => { }); it.each(PLATFORMS)( - "skips hot-boot and cold-boots with `-gpu %s` on %s when no snapshot exists", + "on %s skips hot-boot and cold-boots with `-gpu %s` when no snapshot exists", async (platform, expectedGpu) => { setPlatform(platform); hasSnapshotMock.mockResolvedValue(false); diff --git a/packages/tool-server/test/setup/clear-argent-env.ts b/packages/tool-server/test/setup/clear-argent-env.ts new file mode 100644 index 000000000..16407ddfb --- /dev/null +++ b/packages/tool-server/test/setup/clear-argent-env.ts @@ -0,0 +1,21 @@ +// Unit tests assert argent's shipped defaults, so they must not inherit the +// tool-server configuration the developer running them keeps in their shell. +// Every ARGENT_* variable is a user-facing override that changes asserted +// behavior: `ARGENT_EMULATOR_GPU_MODE` replaces the `-gpu` value boot-device +// resolves per platform, `ARGENT_EMULATOR_NO_WINDOW` / `ARGENT_SIMULATOR_NO_WINDOW` +// add `-no-window` and suppress the Simulator.app attach, and `ARGENT_PORT` / +// `ARGENT_HOST` retarget the bind that the startup-telemetry tests inspect. An +// exported override turns those assertions into a property of the machine +// rather than of the code, and the failure reads as a source regression. +// +// Clearing the whole prefix (rather than a hand-maintained list) also covers +// overrides added to src later without a second edit here. A test that +// exercises an override sets it itself, so nothing depends on the ambient value. +// +// This runs before the test module graph is imported, so module-level env reads +// observe the cleared state too. +for (const name of Object.keys(process.env)) { + if (name.startsWith("ARGENT_")) { + delete process.env[name]; + } +} diff --git a/packages/tool-server/vitest.config.ts b/packages/tool-server/vitest.config.ts index 8c4a381a2..2d1e59d12 100644 --- a/packages/tool-server/vitest.config.ts +++ b/packages/tool-server/vitest.config.ts @@ -5,9 +5,10 @@ export default defineConfig({ test: { include: ["test/**/*.test.ts"], globals: true, - // Suite-wide guard against unit tests incidentally shelling out to real - // `xcrun simctl` / adb (see the setup file's comment). - setupFiles: ["test/setup/stub-status-bar.ts"], + // Suite-wide guards, each documented in its own file: strip the developer's + // ARGENT_* overrides so assertions test the shipped defaults, and stop unit + // tests incidentally shelling out to real `xcrun simctl` / adb. + setupFiles: ["test/setup/clear-argent-env.ts", "test/setup/stub-status-bar.ts"], }, resolve: { alias: {