Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/tool-server/test/boot-device-hotboot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -173,14 +173,17 @@ 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);
}
);

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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions packages/tool-server/test/setup/clear-argent-env.ts
Original file line number Diff line number Diff line change
@@ -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];
}
}
7 changes: 4 additions & 3 deletions packages/tool-server/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down