From 35e9ff6bb9920eb52c095906132d1e3d3c1d07c1 Mon Sep 17 00:00:00 2001 From: Xavier Date: Sat, 31 Oct 2026 07:44:03 -0300 Subject: [PATCH 1/5] test(e2e): find the Android SDK on Windows in the slow Android tests The slow Android smoke, stream and warm-pool tests looked for the SDK under ANDROID_HOME, ANDROID_SDK_ROOT or ~/Library/Android/sdk only, and for adb/emulator without .exe, so on Windows they skipped and read as a pass. They now ask the driver's own locateSdk through a new e2e/helpers/android-sdk.ts, which also runs a .bat tool (avdmanager) through cmd.exe with its arguments quoted. The stream test's host pgrep check runs on macOS and Linux only. Co-Authored-By: Claude Opus 5.5 --- e2e/helpers/android-sdk.test.ts | 95 +++++++++++++++++++++++++++++++++ e2e/helpers/android-sdk.ts | 71 ++++++++++++++++++++++++ e2e/slow-android-smoke.test.ts | 47 ++++++---------- e2e/slow-android-stream.test.ts | 26 ++++----- e2e/slow-warm-pool.test.ts | 32 +++++------ src/drivers/android/AGENTS.md | 2 +- src/drivers/android/index.ts | 2 + 7 files changed, 208 insertions(+), 67 deletions(-) create mode 100644 e2e/helpers/android-sdk.test.ts create mode 100644 e2e/helpers/android-sdk.ts diff --git a/e2e/helpers/android-sdk.test.ts b/e2e/helpers/android-sdk.test.ts new file mode 100644 index 000000000..1cfb57e5f --- /dev/null +++ b/e2e/helpers/android-sdk.test.ts @@ -0,0 +1,95 @@ +import { describe, expect, it } from "vitest"; + +import { MemoryFilesystem } from "../../src/ports/index.js"; +import { findAndroidSdk, sdkToolInvocation } from "./android-sdk.js"; + +const SDK = "/Local/Android/Sdk"; +const WINDOWS_TOOLS = [ + "cmdline-tools/latest/bin/avdmanager.bat", + "cmdline-tools/latest/bin/sdkmanager.bat", + "emulator/emulator.exe", + "platform-tools/adb.exe", +]; + +async function sdkWith(tools: readonly string[]): Promise { + const filesystem = new MemoryFilesystem(); + await filesystem.mkdirp(SDK); + for (const tool of tools) { + const path = `${SDK}/${tool}`; + await filesystem.mkdirp(path.slice(0, path.lastIndexOf("/"))); + await filesystem.writeFileAtomic(path, ""); + } + return filesystem; +} + +// why: the lookup's search order and tool names are proven in src/drivers/android/prerequisites.test.ts; +// these prove only what this helper adds: a skip on anything short of a complete SDK, and how a +// `.bat` tool is run. +describe("findAndroidSdk", () => { + it("finds a Windows SDK under %LOCALAPPDATA% with its .exe and .bat tools", async () => { + const sdk = await findAndroidSdk( + { LOCALAPPDATA: "/Local" }, + "/Users/me", + await sdkWith(WINDOWS_TOOLS), + "win32", + ); + + expect(sdk).toEqual({ + adb: "/Local/Android/Sdk/platform-tools/adb.exe", + avdmanager: "/Local/Android/Sdk/cmdline-tools/latest/bin/avdmanager.bat", + emulator: "/Local/Android/Sdk/emulator/emulator.exe", + root: "/Local/Android/Sdk", + sdkmanager: "/Local/Android/Sdk/cmdline-tools/latest/bin/sdkmanager.bat", + }); + }); + + it.each([ + [ + "an SDK missing its emulator (incomplete)", + WINDOWS_TOOLS.filter((t) => !t.startsWith("emulator/")), + ], + [ + "an SDK of extensionless tools on Windows (incomplete)", + WINDOWS_TOOLS.map((t) => t.replace(/\.(bat|exe)$/, "")), + ], + ])("is undefined for %s", async (_case, tools) => { + await expect( + findAndroidSdk({ ANDROID_HOME: SDK }, "/Users/me", await sdkWith(tools), "win32"), + ).resolves.toBeUndefined(); + }); + + it("is undefined when no searched root exists (absent)", async () => { + await expect( + findAndroidSdk({ ANDROID_HOME: "/nowhere" }, "/Users/me", new MemoryFilesystem(), "darwin"), + ).resolves.toBeUndefined(); + }); +}); + +describe("sdkToolInvocation", () => { + it("runs a .bat on Windows through a shell with the tool and every argument quoted", () => { + expect( + sdkToolInvocation("C:/Program Files/Sdk/avdmanager.bat", ["list", "avd"], "win32"), + ).toEqual({ + args: ['"list"', '"avd"'], + file: '"C:/Program Files/Sdk/avdmanager.bat"', + shell: true, + }); + }); + + it.each([ + ["an .exe on Windows", "C:/Sdk/adb.exe", "win32"], + ["a tool on macOS", "/Sdk/cmdline-tools/latest/bin/avdmanager", "darwin"], + ] as const)("runs %s directly, without a shell", (_case, tool, platform) => { + expect(sdkToolInvocation(tool, ["list", "avd"], platform)).toEqual({ + args: ["list", "avd"], + file: tool, + shell: false, + }); + }); + + it.each(["%PATH%", 'a"b', "a!b"])("refuses to pass %s to a .bat through cmd.exe", (arg) => { + expect(() => sdkToolInvocation("C:/Sdk/avdmanager.bat", [arg], "win32")).toThrow( + `cannot pass ${JSON.stringify(arg)} to a .bat through cmd.exe`, + ); + }); +}); diff --git a/e2e/helpers/android-sdk.ts b/e2e/helpers/android-sdk.ts new file mode 100644 index 000000000..29477880e --- /dev/null +++ b/e2e/helpers/android-sdk.ts @@ -0,0 +1,71 @@ +import { execFile } from "node:child_process"; +import { homedir } from "node:os"; +import { promisify } from "node:util"; + +import { type AndroidSdkPaths, locateSdk } from "../../src/drivers/android/index.js"; +import { type Filesystem, NodeFilesystem } from "../../src/ports/index.js"; + +const execFileAsync = promisify(execFile); + +/** + * why: the slow Android tests skip exactly when the real driver could not start, so they ask the + * driver's own `locateSdk` (which knows `%LOCALAPPDATA%` and the `.exe`/`.bat` tools on Windows) + * rather than a lookup of their own that silently skips on a host it does not know. + */ +export async function findAndroidSdk( + env: Readonly>, + homeDirectory: string, + filesystem: Filesystem, + platform: NodeJS.Platform, +): Promise { + const location = await locateSdk(env, homeDirectory, filesystem, platform); + return location.kind === "complete" ? location.paths : undefined; +} + +export const ANDROID_SDK: AndroidSdkPaths | undefined = await findAndroidSdk( + process.env, + homedir(), + new NodeFilesystem(), + process.platform, +); + +export function requireAndroidSdk(): AndroidSdkPaths { + if (ANDROID_SDK === undefined) { + throw new Error("no complete Android SDK on this host: the test should have been skipped"); + } + return ANDROID_SDK; +} + +/** why: `%` and `!` expand and `"` ends the quoting inside cmd.exe, so no quoting makes them literal. */ +const CMD_UNSAFE = /["%!\r\n]/; + +/** + * why: Node refuses to run a `.bat` without a shell, so on Windows one goes through cmd.exe with + * the tool and every argument quoted, and an argument cmd.exe would still expand is refused. + */ +export function sdkToolInvocation( + tool: string, + args: readonly string[], + platform: NodeJS.Platform, +): { readonly file: string; readonly args: readonly string[]; readonly shell: boolean } { + if (platform !== "win32" || !tool.toLowerCase().endsWith(".bat")) { + return { args, file: tool, shell: false }; + } + const unsafe = [tool, ...args].find((part) => CMD_UNSAFE.test(part)); + if (unsafe !== undefined) { + throw new Error(`cannot pass ${JSON.stringify(unsafe)} to a .bat through cmd.exe`); + } + return { args: args.map((arg) => `"${arg}"`), file: `"${tool}"`, shell: true }; +} + +export async function runSdkTool( + tool: string, + args: readonly string[], + options: { readonly timeout?: number } = {}, +): Promise<{ readonly stdout: string; readonly stderr: string }> { + const invocation = sdkToolInvocation(tool, args, process.platform); + return execFileAsync(invocation.file, invocation.args, { + shell: invocation.shell, + ...(options.timeout === undefined ? {} : { timeout: options.timeout }), + }); +} diff --git a/e2e/slow-android-smoke.test.ts b/e2e/slow-android-smoke.test.ts index ed46c3556..4892c9df3 100644 --- a/e2e/slow-android-smoke.test.ts +++ b/e2e/slow-android-smoke.test.ts @@ -1,25 +1,15 @@ -import { execFile } from "node:child_process"; import { existsSync } from "node:fs"; -import { homedir } from "node:os"; import { join } from "node:path"; -import { promisify } from "node:util"; import { describe, expect, it } from "vitest"; +import type { AndroidSdkPaths } from "../src/drivers/android/index.js"; +import { ANDROID_SDK, requireAndroidSdk, runSdkTool } from "./helpers/android-sdk.js"; import { withDaemon } from "./helpers/index.js"; import { DEVICE_READY_MS, waitFor } from "./helpers/wait.js"; -const execFileAsync = promisify(execFile); -const ANDROID_HOME = - process.env.ANDROID_HOME ?? - process.env.ANDROID_SDK_ROOT ?? - join(homedir(), "Library/Android/sdk"); -const hasAndroidSdk = - existsSync(ANDROID_HOME) && existsSync(join(ANDROID_HOME, "platform-tools", "adb")); - /** Simlock's emulators live on Simlock's own adb server, so that is the one to ask. */ -async function adbDevices(serverPort: number): Promise { - const adb = join(ANDROID_HOME, "platform-tools", "adb"); - const { stdout } = await execFileAsync(adb, ["-P", String(serverPort), "devices"]).catch(() => ({ +async function adbDevices(sdk: AndroidSdkPaths, serverPort: number): Promise { + const { stdout } = await runSdkTool(sdk.adb, ["-P", String(serverPort), "devices"]).catch(() => ({ stdout: "", })); return stdout @@ -30,12 +20,10 @@ async function adbDevices(serverPort: number): Promise { .map((line) => line.split(/\s+/)[0] as string); } -async function avdManagerList(): Promise { - const avdmanager = join(ANDROID_HOME, "cmdline-tools", "latest", "bin", "avdmanager"); - const binary = existsSync(avdmanager) - ? avdmanager - : join(ANDROID_HOME, "tools", "bin", "avdmanager"); - const { stdout } = await execFileAsync(binary, ["list", "avd"]).catch(() => ({ stdout: "" })); +async function avdManagerList(sdk: AndroidSdkPaths): Promise { + const { stdout } = await runSdkTool(sdk.avdmanager, ["list", "avd"]).catch(() => ({ + stdout: "", + })); return [...stdout.matchAll(/Name:\s*(\S+)/g)].map((match) => match[1] as string); } @@ -50,7 +38,7 @@ interface AndroidCatalogOutput { }[]; } -function checkCatalog(output: AndroidCatalogOutput): void { +function checkCatalog(sdk: AndroidSdkPaths, output: AndroidCatalogOutput): void { const android = output.platforms.find((platform) => platform.platform === "android"); if (android === undefined) { throw new Error("simlock catalog reported no android platform -- SDK discovery failed"); @@ -64,13 +52,7 @@ function checkCatalog(output: AndroidCatalogOutput): void { expect(images.length, "expected the installed system images to be listed").toBeGreaterThan(0); for (const image of images) { expect(android.runtimes).toContain(image.runtime); - const path = join( - ANDROID_HOME, - "system-images", - `android-${image.runtime}`, - image.tag, - image.abi, - ); + const path = join(sdk.root, "system-images", `android-${image.runtime}`, image.tag, image.abi); expect(existsSync(path), `listed image ${JSON.stringify(image)} is not installed`).toBe(true); } @@ -81,7 +63,7 @@ function checkCatalog(output: AndroidCatalogOutput): void { // Real emulator boots are slow and this SDK layout is host-specific, so this lane is // gated on an actually-discoverable Android SDK rather than just `process.platform`. -describe.skipIf(!hasAndroidSdk)( +describe.skipIf(ANDROID_SDK === undefined)( "Android smoke (real emulator/adb)", { tags: ["slow", "android"] }, () => { @@ -89,6 +71,7 @@ describe.skipIf(!hasAndroidSdk)( "catalog lists Simlock's Pixel 9 first, a cold lease of Pixel 9 boots a real emulator with the library screen size, and a shut-down emulator reports erasableReadable:false with no crash or false provenance finding", { timeout: 420_000 }, async () => { + const sdk = requireAndroidSdk(); const env = await withDaemon({ driver: "real", // why: a learned warm kind would re-boot the emulator the idle shutdown just stopped. @@ -101,7 +84,7 @@ describe.skipIf(!hasAndroidSdk)( try { const catalog = await env.cli(["catalog", "--json", "--platform", "android"]); expect(catalog.code).toBe(0); - checkCatalog(catalog.json as AndroidCatalogOutput); + checkCatalog(sdk, catalog.json as AndroidCatalogOutput); const lease = await env.cli( [ @@ -151,7 +134,7 @@ describe.skipIf(!hasAndroidSdk)( // deliberately keeps opaque outside drivers/android (architecture.md #2) -- // the grant names simlock's own AVD, not the adb serial, so this only // asserts that *an* emulator is actually online, not which one by serial. - const onlineSerials = await adbDevices(adbServerPort); + const onlineSerials = await adbDevices(sdk, adbServerPort); expect( onlineSerials.length, "expected at least one booted emulator visible to Simlock's own adb server", @@ -163,7 +146,7 @@ describe.skipIf(!hasAndroidSdk)( existsSync(join(env.home, "devices", "android", `${avdName}.avd`)), "expected the AVD to live inside Simlock's own device root", ).toBe(true); - const avdNames = await avdManagerList(); + const avdNames = await avdManagerList(sdk); expect( avdNames.includes(avdName), "a Simlock AVD must not appear in the user's own AVD home", diff --git a/e2e/slow-android-stream.test.ts b/e2e/slow-android-stream.test.ts index ea11e7d13..9f4abc4e6 100644 --- a/e2e/slow-android-stream.test.ts +++ b/e2e/slow-android-stream.test.ts @@ -1,18 +1,9 @@ import { execFile } from "node:child_process"; -import { existsSync } from "node:fs"; -import { homedir } from "node:os"; -import { join } from "node:path"; import { describe, expect, it } from "vitest"; +import { ANDROID_SDK } from "./helpers/android-sdk.js"; import { DEVICE_READY_MS, deviceStreamUrl, waitFor, withHttpDaemon } from "./helpers/index.js"; -const ANDROID_HOME = - process.env.ANDROID_HOME ?? - process.env.ANDROID_SDK_ROOT ?? - join(homedir(), "Library/Android/sdk"); -const hasAndroidSdk = - existsSync(ANDROID_HOME) && existsSync(join(ANDROID_HOME, "platform-tools", "adb")); - const TAG = { alive: 0x06, description: 0x01, keyframe: 0x02, delta: 0x03, meta: 0x05 } as const; interface Frame { @@ -50,7 +41,7 @@ async function readFrames( return frames; } -describe.skipIf(!hasAndroidSdk)( +describe.skipIf(ANDROID_SDK === undefined)( "Android screen stream (real emulator)", { tags: ["slow", "android"] }, () => { @@ -221,10 +212,15 @@ describe.skipIf(!hasAndroidSdk)( expect(release.code, release.stderr).toBe(0); await Promise.race([draining, new Promise((resolve) => setTimeout(resolve, 15_000))]); expect(lastEnded, "the stream outlived its lease").toBe(true); - const hostShells = await new Promise((resolve) => { - execFile("pgrep", ["-fl", "[s]imlock-scrcpy-"], (_error, stdout) => resolve(stdout)); - }); - expect(hostShells, "a host adb shell for the capture outlived the lease").toBe(""); + // why: Windows has no pgrep, and src/ports has no way to list processes by command + // line (ProcessSupervisor reads one known pid), so this host-side check runs on macOS + // and Linux only; the device-side checks above still run everywhere. + if (process.platform !== "win32") { + const hostShells = await new Promise((resolve) => { + execFile("pgrep", ["-fl", "[s]imlock-scrcpy-"], (_error, stdout) => resolve(stdout)); + }); + expect(hostShells, "a host adb shell for the capture outlived the lease").toBe(""); + } } finally { await env .cli(["nuke", "--delete-devices", "--yes"], { timeout: 120_000 }) diff --git a/e2e/slow-warm-pool.test.ts b/e2e/slow-warm-pool.test.ts index bc88c3693..71799d979 100644 --- a/e2e/slow-warm-pool.test.ts +++ b/e2e/slow-warm-pool.test.ts @@ -1,11 +1,11 @@ import { execFile } from "node:child_process"; import { existsSync, readdirSync } from "node:fs"; import { readFile, writeFile } from "node:fs/promises"; -import { homedir } from "node:os"; import { join } from "node:path"; import { promisify } from "node:util"; import { describe, expect, it } from "vitest"; +import { ANDROID_SDK, requireAndroidSdk, runSdkTool } from "./helpers/android-sdk.js"; import { withDaemon, waitFor, type RecordedEvent, type TestEnv } from "./helpers/index.js"; import { iosDeviceSet, setDevices, sweepStaleDeviceSets } from "./helpers/ios-device-set.js"; @@ -22,10 +22,6 @@ const execFileAsync = promisify(execFile); * Run only through `scripts/slow-e2e.sh e2e/slow-warm-pool.test.ts`, never in CI. */ -const ANDROID_HOME = - process.env.ANDROID_HOME ?? - process.env.ANDROID_SDK_ROOT ?? - join(homedir(), "Library/Android/sdk"); /** The ABI an emulator runs natively on this host; an image of the other ABI is listed but cannot boot. */ const HOST_ABI = process.arch === "arm64" ? "arm64-v8a" : "x86_64"; @@ -110,16 +106,11 @@ async function installedIosRuntimes(): Promise { } } -/** Whether an emulator, adb and a system image of the host's ABI (`system-images///`) exist. */ +/** why: the daemon boots only an image of the host's ABI (`system-images///`) from the SDK it finds, so the image is looked for under that SDK's root. */ function installedAndroidImages(): boolean { - const root = join(ANDROID_HOME, "system-images"); - if ( - !existsSync(join(ANDROID_HOME, "emulator", "emulator")) || - !existsSync(join(ANDROID_HOME, "platform-tools", "adb")) || - !existsSync(root) - ) { - return false; - } + if (ANDROID_SDK === undefined) return false; + const root = join(ANDROID_SDK.root, "system-images"); + if (!existsSync(root)) return false; try { return readdirSync(root).some((api) => readdirSync(join(root, api)).some((tag) => existsSync(join(root, api, tag, HOST_ABI))), @@ -135,17 +126,20 @@ async function missingPlatform(): Promise { return "iOS is missing: no macOS host with an installed iOS runtime"; } if (!installedAndroidImages()) { - return `Android is missing: no emulator, adb and installed ${HOST_ABI} system image`; + return `Android is missing: no complete SDK with an installed ${HOST_ABI} system image`; } return undefined; } /** Simlock's emulators live on Simlock's own adb server, so that is the one to ask. */ async function onlineEmulators(adbServerPort: number): Promise { - const adb = join(ANDROID_HOME, "platform-tools", "adb"); - const { stdout } = await execFileAsync(adb, ["-P", String(adbServerPort), "devices"], { - timeout: QUERY_TIMEOUT, - }).catch((error: unknown) => { + const { stdout } = await runSdkTool( + requireAndroidSdk().adb, + ["-P", String(adbServerPort), "devices"], + { + timeout: QUERY_TIMEOUT, + }, + ).catch((error: unknown) => { // A timed-out adb is a hang to report, not "no emulator online". if ((error as { killed?: boolean }).killed === true) throw error; return { stdout: "" }; diff --git a/src/drivers/android/AGENTS.md b/src/drivers/android/AGENTS.md index 3d2c6a389..af82780f9 100644 --- a/src/drivers/android/AGENTS.md +++ b/src/drivers/android/AGENTS.md @@ -1,7 +1,7 @@ # Android driver Does: emulators in an owned AVD home behind Simlock's own adb server, and USB phones on the default adb server. -Entry: `index.ts` → `AndroidDriver.create(options)`; also `androidPrerequisites`, `hostAbiFor`, `ANDROID_PASSTHROUGH_TOOLS`. +Entry: `index.ts` → `AndroidDriver.create(options)`; also `androidPrerequisites`, `hostAbiFor`, `ANDROID_PASSTHROUGH_TOOLS`, and `locateSdk` (the slow e2e tests find the SDK through it). Uses: core, ports, `../installer-process.ts`. Never imports: bus, leasing, daemon. Parent: [drivers](../AGENTS.md). Flows: [device selection](../../../docs/internal/flows/device-selection.md). diff --git a/src/drivers/android/index.ts b/src/drivers/android/index.ts index 8782ae034..1fa0e1386 100644 --- a/src/drivers/android/index.ts +++ b/src/drivers/android/index.ts @@ -2865,6 +2865,8 @@ function portAllocatorFor(processRunner: ProcessRunner, adb: string): PortAlloca } export { androidDeviceDataTable } from "./device-data.js"; export { androidPrerequisites } from "./prerequisites.js"; +export { locateSdk } from "./sdk-paths.js"; +export type { AndroidSdkPaths } from "./sdk-paths.js"; function virtualReclaimStrategy(clean: "standard" | "full"): "snapshot" | "wipe" { return clean === "full" ? "wipe" : "snapshot"; From dcb5df1c42016c681f53f941c5a4466bd69eb56d Mon Sep 17 00:00:00 2001 From: Xavier Date: Wed, 4 Nov 2026 18:27:39 -0300 Subject: [PATCH 2/5] test(e2e): plant the crash-dump marker only on macOS in the Android smoke test The marker needs crashpad's database xattrs, which only macOS's `xattr` writes, so on Windows the smoke test failed there instead of checking the lease. Elsewhere the rest of the test runs without it. Co-Authored-By: Claude Opus 5.5 --- e2e/slow-android-smoke.test.ts | 56 ++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/e2e/slow-android-smoke.test.ts b/e2e/slow-android-smoke.test.ts index fb3c8ea92..fb21e393d 100644 --- a/e2e/slow-android-smoke.test.ts +++ b/e2e/slow-android-smoke.test.ts @@ -98,7 +98,7 @@ describe.skipIf(ANDROID_SDK === undefined)( { tags: ["slow", "android"] }, () => { it( - "catalog lists Simlock's Pixel 9 first, a cold lease of Pixel 9 boots a real emulator with the library screen size and leaves a dump in the user's shared crash database alone, and a released emulator is deleted from the root and from avdmanager with no crash or false provenance finding", + "catalog lists Simlock's Pixel 9 first, a cold lease of Pixel 9 boots a real emulator with the library screen size and, on macOS, leaves a dump in the user's shared crash database alone, and a released emulator is deleted from the root and from avdmanager with no crash or false provenance finding", { timeout: 420_000 }, async () => { const sdk = requireAndroidSdk(); @@ -111,26 +111,32 @@ describe.skipIf(ANDROID_SDK === undefined)( if (adbServerPort === undefined) { throw new Error("the real-SDK lane must allocate its own adb server port"); } - const completedDir = await sharedCrashCompletedDir(sdk); + // why: the planted dump needs crashpad's database xattrs, which only macOS's `xattr` writes; elsewhere the rest of the smoke test still runs. + const completedDir = + process.platform === "darwin" ? await sharedCrashCompletedDir(sdk) : undefined; // why: crashpad skips a report file without its database xattrs, so a plain file would never be read, let alone deleted. const dumpId = randomUUID(); - const planted = join(completedDir, `${dumpId}.dmp`); - const createdRoot = firstMissingAncestor(completedDir); + const planted = + completedDir === undefined ? undefined : join(completedDir, `${dumpId}.dmp`); + const createdRoot = + completedDir === undefined ? undefined : firstMissingAncestor(completedDir); try { - await mkdir(completedDir, { recursive: true }); - await writeFile(planted, "simlock slow-lane crash dump marker"); - await execFileAsync("xattr", [ - "-w", - "org.chromium.crashpad.database.uuid", - dumpId, - planted, - ]); - await execFileAsync("xattr", [ - "-w", - "org.chromium.crashpad.database.creation_time", - String(Math.floor(Date.now() / 1000)), - planted, - ]); + if (completedDir !== undefined && planted !== undefined) { + await mkdir(completedDir, { recursive: true }); + await writeFile(planted, "simlock slow-lane crash dump marker"); + await execFileAsync("xattr", [ + "-w", + "org.chromium.crashpad.database.uuid", + dumpId, + planted, + ]); + await execFileAsync("xattr", [ + "-w", + "org.chromium.crashpad.database.creation_time", + String(Math.floor(Date.now() / 1000)), + planted, + ]); + } const catalog = await env.cli(["catalog", "--json", "--platform", "android"]); expect(catalog.code).toBe(0); checkCatalog(sdk, catalog.json as AndroidCatalogOutput); @@ -176,10 +182,12 @@ describe.skipIf(ANDROID_SDK === undefined)( expect(density.stdout).toContain("Physical density: 420"); // why: the lease is up, so no dialog blocked the boot, and the launch must have left the user's shared crash database alone. - expect( - existsSync(planted), - "the lease deleted a dump in the user's shared crash db", - ).toBe(true); + if (planted !== undefined) { + expect( + existsSync(planted), + "the lease deleted a dump in the user's shared crash db", + ).toBe(true); + } const refused = await env.cli(["adb", "kill-server"]); expect(refused.code, "simlock adb kill-server must be refused, not run").toBe(2); @@ -264,7 +272,9 @@ describe.skipIf(ANDROID_SDK === undefined)( label: "daemon stop left the worker lock behind", }); } finally { - await rm(planted, { force: true }); + if (planted !== undefined) { + await rm(planted, { force: true }); + } if (createdRoot !== undefined) { await rm(createdRoot, { recursive: true, force: true }); } From 13d819a71f3bdb5dafc992250ad4331bea8f099f Mon Sep 17 00:00:00 2001 From: Xavier Date: Wed, 4 Nov 2026 18:39:57 -0300 Subject: [PATCH 3/5] test(e2e): run SDK tools through the ports runner and find the lock as the daemon does - `runSdkTool` runs through `NodeProcessRunner`, which owns how a `.bat` runs under cmd.exe, instead of a second copy of that rule. - `locateSdk` reaches the e2e helper through the Android driver's `testing.ts`, not its index; the helper becomes `test-android-sdk.ts`. - The smoke test finds the worker lock with `defaultWorkerLockPath`, so it runs on Windows too. Co-Authored-By: Claude Opus 5.5 --- e2e/helpers/android-sdk.ts | 71 ------------------- ...d-sdk.test.ts => test-android-sdk.test.ts} | 39 ++++------ e2e/helpers/test-android-sdk.ts | 57 +++++++++++++++ e2e/slow-android-smoke.test.ts | 13 ++-- e2e/slow-android-stream.test.ts | 2 +- e2e/slow-android-tunnel.test.ts | 2 +- e2e/slow-baseline.test.ts | 2 +- e2e/slow-warm-pool.test.ts | 2 +- src/drivers/android/AGENTS.md | 2 +- src/drivers/android/index.ts | 2 - src/drivers/android/testing.ts | 2 + 11 files changed, 88 insertions(+), 106 deletions(-) delete mode 100644 e2e/helpers/android-sdk.ts rename e2e/helpers/{android-sdk.test.ts => test-android-sdk.test.ts} (66%) create mode 100644 e2e/helpers/test-android-sdk.ts diff --git a/e2e/helpers/android-sdk.ts b/e2e/helpers/android-sdk.ts deleted file mode 100644 index 29477880e..000000000 --- a/e2e/helpers/android-sdk.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { execFile } from "node:child_process"; -import { homedir } from "node:os"; -import { promisify } from "node:util"; - -import { type AndroidSdkPaths, locateSdk } from "../../src/drivers/android/index.js"; -import { type Filesystem, NodeFilesystem } from "../../src/ports/index.js"; - -const execFileAsync = promisify(execFile); - -/** - * why: the slow Android tests skip exactly when the real driver could not start, so they ask the - * driver's own `locateSdk` (which knows `%LOCALAPPDATA%` and the `.exe`/`.bat` tools on Windows) - * rather than a lookup of their own that silently skips on a host it does not know. - */ -export async function findAndroidSdk( - env: Readonly>, - homeDirectory: string, - filesystem: Filesystem, - platform: NodeJS.Platform, -): Promise { - const location = await locateSdk(env, homeDirectory, filesystem, platform); - return location.kind === "complete" ? location.paths : undefined; -} - -export const ANDROID_SDK: AndroidSdkPaths | undefined = await findAndroidSdk( - process.env, - homedir(), - new NodeFilesystem(), - process.platform, -); - -export function requireAndroidSdk(): AndroidSdkPaths { - if (ANDROID_SDK === undefined) { - throw new Error("no complete Android SDK on this host: the test should have been skipped"); - } - return ANDROID_SDK; -} - -/** why: `%` and `!` expand and `"` ends the quoting inside cmd.exe, so no quoting makes them literal. */ -const CMD_UNSAFE = /["%!\r\n]/; - -/** - * why: Node refuses to run a `.bat` without a shell, so on Windows one goes through cmd.exe with - * the tool and every argument quoted, and an argument cmd.exe would still expand is refused. - */ -export function sdkToolInvocation( - tool: string, - args: readonly string[], - platform: NodeJS.Platform, -): { readonly file: string; readonly args: readonly string[]; readonly shell: boolean } { - if (platform !== "win32" || !tool.toLowerCase().endsWith(".bat")) { - return { args, file: tool, shell: false }; - } - const unsafe = [tool, ...args].find((part) => CMD_UNSAFE.test(part)); - if (unsafe !== undefined) { - throw new Error(`cannot pass ${JSON.stringify(unsafe)} to a .bat through cmd.exe`); - } - return { args: args.map((arg) => `"${arg}"`), file: `"${tool}"`, shell: true }; -} - -export async function runSdkTool( - tool: string, - args: readonly string[], - options: { readonly timeout?: number } = {}, -): Promise<{ readonly stdout: string; readonly stderr: string }> { - const invocation = sdkToolInvocation(tool, args, process.platform); - return execFileAsync(invocation.file, invocation.args, { - shell: invocation.shell, - ...(options.timeout === undefined ? {} : { timeout: options.timeout }), - }); -} diff --git a/e2e/helpers/android-sdk.test.ts b/e2e/helpers/test-android-sdk.test.ts similarity index 66% rename from e2e/helpers/android-sdk.test.ts rename to e2e/helpers/test-android-sdk.test.ts index 1cfb57e5f..31a4e8728 100644 --- a/e2e/helpers/android-sdk.test.ts +++ b/e2e/helpers/test-android-sdk.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from "vitest"; import { MemoryFilesystem } from "../../src/ports/index.js"; -import { findAndroidSdk, sdkToolInvocation } from "./android-sdk.js"; +import { findAndroidSdk, runSdkTool } from "./test-android-sdk.js"; const SDK = "/Local/Android/Sdk"; const WINDOWS_TOOLS = [ @@ -23,8 +23,8 @@ async function sdkWith(tools: readonly string[]): Promise { } // why: the lookup's search order and tool names are proven in src/drivers/android/prerequisites.test.ts; -// these prove only what this helper adds: a skip on anything short of a complete SDK, and how a -// `.bat` tool is run. +// these prove only what this helper adds: a skip on anything short of a complete SDK, and that a +// tool which fails or runs past its timeout rejects, as `execFile` did. describe("findAndroidSdk", () => { it("finds a Windows SDK under %LOCALAPPDATA% with its .exe and .bat tools", async () => { const sdk = await findAndroidSdk( @@ -65,31 +65,22 @@ describe("findAndroidSdk", () => { }); }); -describe("sdkToolInvocation", () => { - it("runs a .bat on Windows through a shell with the tool and every argument quoted", () => { - expect( - sdkToolInvocation("C:/Program Files/Sdk/avdmanager.bat", ["list", "avd"], "win32"), - ).toEqual({ - args: ['"list"', '"avd"'], - file: '"C:/Program Files/Sdk/avdmanager.bat"', - shell: true, - }); +describe("runSdkTool", () => { + it("answers a tool that exits 0 with its output", async () => { + await expect( + runSdkTool(process.execPath, ["-e", 'process.stdout.write("ok")']), + ).resolves.toMatchObject({ stdout: "ok" }); }); - it.each([ - ["an .exe on Windows", "C:/Sdk/adb.exe", "win32"], - ["a tool on macOS", "/Sdk/cmdline-tools/latest/bin/avdmanager", "darwin"], - ] as const)("runs %s directly, without a shell", (_case, tool, platform) => { - expect(sdkToolInvocation(tool, ["list", "avd"], platform)).toEqual({ - args: ["list", "avd"], - file: tool, - shell: false, + it("rejects a tool that exits non-zero, not killed", async () => { + await expect(runSdkTool(process.execPath, ["-e", "process.exit(3)"])).rejects.toMatchObject({ + killed: false, }); }); - it.each(["%PATH%", 'a"b', "a!b"])("refuses to pass %s to a .bat through cmd.exe", (arg) => { - expect(() => sdkToolInvocation("C:/Sdk/avdmanager.bat", [arg], "win32")).toThrow( - `cannot pass ${JSON.stringify(arg)} to a .bat through cmd.exe`, - ); + it("rejects a tool its timeout ended, killed", async () => { + await expect( + runSdkTool(process.execPath, ["-e", "setTimeout(() => {}, 60000)"], { timeout: 200 }), + ).rejects.toMatchObject({ killed: true }); }); }); diff --git a/e2e/helpers/test-android-sdk.ts b/e2e/helpers/test-android-sdk.ts new file mode 100644 index 000000000..b4258a79e --- /dev/null +++ b/e2e/helpers/test-android-sdk.ts @@ -0,0 +1,57 @@ +import { homedir } from "node:os"; + +import { type AndroidSdkPaths, locateSdk } from "../../src/drivers/android/testing.js"; +import { type Filesystem, NodeFilesystem, NodeProcessRunner } from "../../src/ports/index.js"; + +const runner = new NodeProcessRunner(); + +/** + * why: the slow Android tests skip exactly when the real driver could not start, so they ask the + * driver's own `locateSdk` (which knows `%LOCALAPPDATA%` and the `.exe`/`.bat` tools on Windows) + * rather than a lookup of their own that silently skips on a host it does not know. + */ +export async function findAndroidSdk( + env: Readonly>, + homeDirectory: string, + filesystem: Filesystem, + platform: NodeJS.Platform, +): Promise { + const location = await locateSdk(env, homeDirectory, filesystem, platform); + return location.kind === "complete" ? location.paths : undefined; +} + +export const ANDROID_SDK: AndroidSdkPaths | undefined = await findAndroidSdk( + process.env, + homedir(), + new NodeFilesystem(), + process.platform, +); + +export function requireAndroidSdk(): AndroidSdkPaths { + if (ANDROID_SDK === undefined) { + throw new Error("no complete Android SDK on this host: the test should have been skipped"); + } + return ANDROID_SDK; +} + +/** + * why: a `.bat` tool (`avdmanager` on Windows) runs through the ports' process runner, which owns + * how a batch file runs under cmd.exe and which arguments it refuses. As `execFile` did, a non-zero + * exit rejects, and a run its timeout ended rejects with `killed: true`. + */ +export async function runSdkTool( + tool: string, + args: readonly string[], + options: { readonly timeout?: number } = {}, +): Promise<{ readonly stdout: string; readonly stderr: string }> { + const result = await runner.run( + tool, + args, + options.timeout === undefined ? {} : { timeoutMs: options.timeout }, + ); + if (result.code === 0) return result; + throw Object.assign( + new Error(`${tool} ${args.join(" ")} exited ${String(result.code)}: ${result.stderr}`), + { killed: result.code === null }, + ); +} diff --git a/e2e/slow-android-smoke.test.ts b/e2e/slow-android-smoke.test.ts index fb21e393d..9e0046493 100644 --- a/e2e/slow-android-smoke.test.ts +++ b/e2e/slow-android-smoke.test.ts @@ -2,13 +2,14 @@ import { execFile } from "node:child_process"; import { existsSync } from "node:fs"; import { mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises"; import { randomUUID } from "node:crypto"; -import { userInfo } from "node:os"; +import { tmpdir, userInfo } from "node:os"; import { dirname, join } from "node:path"; import { promisify } from "node:util"; import { describe, expect, it } from "vitest"; -import type { AndroidSdkPaths } from "../src/drivers/android/index.js"; -import { ANDROID_SDK, requireAndroidSdk, runSdkTool } from "./helpers/android-sdk.js"; +import type { AndroidSdkPaths } from "../src/drivers/android/testing.js"; +import { defaultWorkerLockPath } from "../src/ports/index.js"; +import { ANDROID_SDK, requireAndroidSdk, runSdkTool } from "./helpers/test-android-sdk.js"; import { withDaemon } from "./helpers/index.js"; import { DEVICE_READY_MS, waitFor } from "./helpers/wait.js"; @@ -257,7 +258,11 @@ describe.skipIf(ANDROID_SDK === undefined)( expect(list.code).toBe(0); // why: ADR 0059: the worker with real drivers holds the machine's worker lock while it runs and frees it at its stop. - const lockFolder = join(`/tmp/simlock-${process.getuid?.() ?? 0}`, "worker.lock"); + const lockFolder = defaultWorkerLockPath( + process.platform, + process.getuid?.() ?? 0, + tmpdir(), + ); const owner = JSON.parse(await readFile(join(lockFolder, "owner.json"), "utf8")) as { folder: string; pid: number; diff --git a/e2e/slow-android-stream.test.ts b/e2e/slow-android-stream.test.ts index 9f4abc4e6..db9bfd2ab 100644 --- a/e2e/slow-android-stream.test.ts +++ b/e2e/slow-android-stream.test.ts @@ -1,7 +1,7 @@ import { execFile } from "node:child_process"; import { describe, expect, it } from "vitest"; -import { ANDROID_SDK } from "./helpers/android-sdk.js"; +import { ANDROID_SDK } from "./helpers/test-android-sdk.js"; import { DEVICE_READY_MS, deviceStreamUrl, waitFor, withHttpDaemon } from "./helpers/index.js"; const TAG = { alive: 0x06, description: 0x01, keyframe: 0x02, delta: 0x03, meta: 0x05 } as const; diff --git a/e2e/slow-android-tunnel.test.ts b/e2e/slow-android-tunnel.test.ts index 896dcd5bb..c6c984ce5 100644 --- a/e2e/slow-android-tunnel.test.ts +++ b/e2e/slow-android-tunnel.test.ts @@ -13,7 +13,7 @@ import { withSharedDaemon, type SharedTestEnv, } from "./helpers/index.js"; -import { ANDROID_SDK } from "./helpers/android-sdk.js"; +import { ANDROID_SDK } from "./helpers/test-android-sdk.js"; const BODY = "simlock-tunnel-ok"; diff --git a/e2e/slow-baseline.test.ts b/e2e/slow-baseline.test.ts index 5ac3fdb53..dea5c6834 100644 --- a/e2e/slow-baseline.test.ts +++ b/e2e/slow-baseline.test.ts @@ -4,7 +4,7 @@ import { join } from "node:path"; import { describe, expect, it } from "vitest"; import { IOS } from "./helpers/agent-device-targets.js"; -import { ANDROID_SDK } from "./helpers/android-sdk.js"; +import { ANDROID_SDK } from "./helpers/test-android-sdk.js"; import { withDaemon } from "./helpers/index.js"; import type { TestEnv } from "./helpers/env.js"; import { iosDeviceSet, setDevices, sweepStaleDeviceSets } from "./helpers/ios-device-set.js"; diff --git a/e2e/slow-warm-pool.test.ts b/e2e/slow-warm-pool.test.ts index 9d92f9e7a..80f49dc6c 100644 --- a/e2e/slow-warm-pool.test.ts +++ b/e2e/slow-warm-pool.test.ts @@ -5,7 +5,7 @@ import { join } from "node:path"; import { promisify } from "node:util"; import { describe, expect, it } from "vitest"; -import { ANDROID_SDK, requireAndroidSdk, runSdkTool } from "./helpers/android-sdk.js"; +import { ANDROID_SDK, requireAndroidSdk, runSdkTool } from "./helpers/test-android-sdk.js"; import { withDaemon, waitFor, type RecordedEvent, type TestEnv } from "./helpers/index.js"; import { iosDeviceSet, setDevices, sweepStaleDeviceSets } from "./helpers/ios-device-set.js"; diff --git a/src/drivers/android/AGENTS.md b/src/drivers/android/AGENTS.md index 2fad6ebde..8f4262ee8 100644 --- a/src/drivers/android/AGENTS.md +++ b/src/drivers/android/AGENTS.md @@ -1,7 +1,7 @@ # Android driver Does: emulators in an owned AVD home behind Simlock's own adb server, and USB phones on the default adb server. -Entry: `index.ts` → `AndroidDriver.create(options)`; also `androidPrerequisites`, `hostAbiFor`, `ANDROID_PASSTHROUGH_TOOLS`, and `locateSdk` (the slow e2e tests find the SDK through it). +Entry: `index.ts` → `AndroidDriver.create(options)`; also `androidPrerequisites`, `hostAbiFor`, `ANDROID_PASSTHROUGH_TOOLS`; tests also get `locateSdk` from `testing.ts` (the slow e2e tests find the SDK through it). Uses: core, ports, `../installer-process.ts`. Never imports: bus, leasing, daemon. Parent: [drivers](../AGENTS.md). Flows: [device selection](../../../docs/internal/flows/device-selection.md). diff --git a/src/drivers/android/index.ts b/src/drivers/android/index.ts index 6b5870089..2e520f11d 100644 --- a/src/drivers/android/index.ts +++ b/src/drivers/android/index.ts @@ -3567,8 +3567,6 @@ function portAllocatorFor(processRunner: ProcessRunner, adb: string): PortAlloca export { androidDeviceDataTable } from "./device-data.js"; export { androidSourceDataOwner } from "./source-data.js"; export { androidPrerequisites } from "./prerequisites.js"; -export { locateSdk } from "./sdk-paths.js"; -export type { AndroidSdkPaths } from "./sdk-paths.js"; function virtualReclaimStrategy(clean: "standard" | "full"): "snapshot" | "wipe" { return clean === "full" ? "wipe" : "snapshot"; diff --git a/src/drivers/android/testing.ts b/src/drivers/android/testing.ts index 3482e94bf..5f3b2c517 100644 --- a/src/drivers/android/testing.ts +++ b/src/drivers/android/testing.ts @@ -1,6 +1,8 @@ import { NodeSqliteOpener, type SqliteDatabase } from "../../ports/index.js"; import { androidSourceDataOwner } from "./source-data.js"; +export { locateSdk, type AndroidSdkPaths } from "./sdk-paths.js"; + export async function memoryAndroidSourceDatabase(): Promise { const database = await new NodeSqliteOpener().open(":memory:", { readOnly: false }); for (const migration of androidSourceDataOwner.migrations) database.exec(migration); From d833bd1b81c878bbd339e61003016883f4698a22 Mon Sep 17 00:00:00 2001 From: Xavier Date: Wed, 4 Nov 2026 18:48:06 -0300 Subject: [PATCH 4/5] test(e2e): move the smoke test's crash-dump steps into helpers Fallow's CRAP gate put the smoke test at 63.6 over its 30 limit once the macOS-only gate added its branches; `crashDumpTarget`, `plantCrashDump`, `crashDumpKept` and `removeCrashDump` hold them. Co-Authored-By: Claude Opus 5.5 --- e2e/slow-android-smoke.test.ts | 96 +++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 37 deletions(-) diff --git a/e2e/slow-android-smoke.test.ts b/e2e/slow-android-smoke.test.ts index 9e0046493..1f00ce792 100644 --- a/e2e/slow-android-smoke.test.ts +++ b/e2e/slow-android-smoke.test.ts @@ -51,6 +51,58 @@ function firstMissingAncestor(path: string): string | undefined { return missing; } +interface CrashDump { + readonly completedDir: string; + readonly createdRoot: string | undefined; + readonly id: string; + readonly planted: string; +} + +/** why: the planted dump needs crashpad's database xattrs, which only macOS's `xattr` writes; elsewhere there is no dump and the rest of the smoke test still runs. */ +async function crashDumpTarget(sdk: AndroidSdkPaths): Promise { + if (process.platform !== "darwin") return undefined; + const completedDir = await sharedCrashCompletedDir(sdk); + const id = randomUUID(); + return { + completedDir, + createdRoot: firstMissingAncestor(completedDir), + id, + planted: join(completedDir, `${id}.dmp`), + }; +} + +/** why: crashpad skips a report file without its database xattrs, so a plain file would never be read, let alone deleted. */ +async function plantCrashDump(dump: CrashDump | undefined): Promise { + if (dump === undefined) return; + await mkdir(dump.completedDir, { recursive: true }); + await writeFile(dump.planted, "simlock slow-lane crash dump marker"); + await execFileAsync("xattr", [ + "-w", + "org.chromium.crashpad.database.uuid", + dump.id, + dump.planted, + ]); + await execFileAsync("xattr", [ + "-w", + "org.chromium.crashpad.database.creation_time", + String(Math.floor(Date.now() / 1000)), + dump.planted, + ]); +} + +/** why: with no dump planted there is nothing the lease could have deleted. */ +function crashDumpKept(dump: CrashDump | undefined): boolean { + return dump === undefined || existsSync(dump.planted); +} + +async function removeCrashDump(dump: CrashDump | undefined): Promise { + if (dump === undefined) return; + await rm(dump.planted, { force: true }); + if (dump.createdRoot !== undefined) { + await rm(dump.createdRoot, { recursive: true, force: true }); + } +} + async function avdManagerList(sdk: AndroidSdkPaths): Promise { const { stdout } = await runSdkTool(sdk.avdmanager, ["list", "avd"]).catch(() => ({ stdout: "", @@ -112,32 +164,9 @@ describe.skipIf(ANDROID_SDK === undefined)( if (adbServerPort === undefined) { throw new Error("the real-SDK lane must allocate its own adb server port"); } - // why: the planted dump needs crashpad's database xattrs, which only macOS's `xattr` writes; elsewhere the rest of the smoke test still runs. - const completedDir = - process.platform === "darwin" ? await sharedCrashCompletedDir(sdk) : undefined; - // why: crashpad skips a report file without its database xattrs, so a plain file would never be read, let alone deleted. - const dumpId = randomUUID(); - const planted = - completedDir === undefined ? undefined : join(completedDir, `${dumpId}.dmp`); - const createdRoot = - completedDir === undefined ? undefined : firstMissingAncestor(completedDir); + const crashDump = await crashDumpTarget(sdk); try { - if (completedDir !== undefined && planted !== undefined) { - await mkdir(completedDir, { recursive: true }); - await writeFile(planted, "simlock slow-lane crash dump marker"); - await execFileAsync("xattr", [ - "-w", - "org.chromium.crashpad.database.uuid", - dumpId, - planted, - ]); - await execFileAsync("xattr", [ - "-w", - "org.chromium.crashpad.database.creation_time", - String(Math.floor(Date.now() / 1000)), - planted, - ]); - } + await plantCrashDump(crashDump); const catalog = await env.cli(["catalog", "--json", "--platform", "android"]); expect(catalog.code).toBe(0); checkCatalog(sdk, catalog.json as AndroidCatalogOutput); @@ -183,12 +212,10 @@ describe.skipIf(ANDROID_SDK === undefined)( expect(density.stdout).toContain("Physical density: 420"); // why: the lease is up, so no dialog blocked the boot, and the launch must have left the user's shared crash database alone. - if (planted !== undefined) { - expect( - existsSync(planted), - "the lease deleted a dump in the user's shared crash db", - ).toBe(true); - } + expect( + crashDumpKept(crashDump), + "the lease deleted a dump in the user's shared crash db", + ).toBe(true); const refused = await env.cli(["adb", "kill-server"]); expect(refused.code, "simlock adb kill-server must be refused, not run").toBe(2); @@ -277,12 +304,7 @@ describe.skipIf(ANDROID_SDK === undefined)( label: "daemon stop left the worker lock behind", }); } finally { - if (planted !== undefined) { - await rm(planted, { force: true }); - } - if (createdRoot !== undefined) { - await rm(createdRoot, { recursive: true, force: true }); - } + await removeCrashDump(crashDump); await env .cli(["nuke", "--delete-devices", "--yes"], { timeout: 120_000 }) .catch(() => undefined); From c898e9c6af80a5816324103ad2ae507171606e9c Mon Sep 17 00:00:00 2001 From: Xavier Date: Wed, 4 Nov 2026 18:57:23 -0300 Subject: [PATCH 5/5] test(e2e): runSdkTool runs a .bat under a path with spaces on Windows CodeRabbit: the helper's own Windows path had no test; this one runs a batch tool in a folder with spaces and checks an argument with spaces arrives intact. Co-Authored-By: Claude Opus 5.5 --- e2e/helpers/test-android-sdk.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/e2e/helpers/test-android-sdk.test.ts b/e2e/helpers/test-android-sdk.test.ts index 31a4e8728..72709392b 100644 --- a/e2e/helpers/test-android-sdk.test.ts +++ b/e2e/helpers/test-android-sdk.test.ts @@ -1,3 +1,7 @@ +import { mkdtemp, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; + import { describe, expect, it } from "vitest"; import { MemoryFilesystem } from "../../src/ports/index.js"; @@ -83,4 +87,26 @@ describe("runSdkTool", () => { runSdkTool(process.execPath, ["-e", "setTimeout(() => {}, 60000)"], { timeout: 200 }), ).rejects.toMatchObject({ killed: true }); }); + + // why: avdmanager on Windows is a .bat under the SDK root, which may hold spaces; the slow tests reach it only through this helper. + it.runIf(process.platform === "win32")( + "runs a .bat under a path with spaces and hands it an argument with spaces intact", + async () => { + const directory = await mkdtemp(join(tmpdir(), "simlock sdk ")); + const printer = join(directory, "print-args.cjs"); + const tool = join(directory, "avd manager.bat"); + await writeFile(printer, "console.log(JSON.stringify(process.argv.slice(2)));\n"); + await writeFile( + tool, + ["@echo off", `"${process.execPath}" "${printer}" %*`, ""].join("\r\n"), + ); + try { + const result = await runSdkTool(tool, ["list", "with space"]); + + expect(JSON.parse(result.stdout)).toEqual(["list", "with space"]); + } finally { + await rm(directory, { force: true, recursive: true }); + } + }, + ); });