From d173628afca91f7eb36a5353edff1f1fca2d21fa Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 16:17:35 +0100 Subject: [PATCH 1/6] test: the iOS driver's and core's unit tests run on the Windows job (#1708) --- src/test-support/windows-skipped.ts | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/src/test-support/windows-skipped.ts b/src/test-support/windows-skipped.ts index acd2836ee..7e60f1173 100644 --- a/src/test-support/windows-skipped.ts +++ b/src/test-support/windows-skipped.ts @@ -19,9 +19,6 @@ const WINDOWS_SKIPPED: readonly string[] = [ "src/cli/passthrough.test.ts", "src/cli/tunnel-forward-and-emulator.test.ts", "src/clock-hook.test.ts", - "src/core/device-root.test.ts", - "src/core/instance-identity.test.ts", - "src/core/registry.test.ts", "src/daemon/connection-host.test.ts", "src/daemon/device-data-tables.test.ts", "src/daemon/dispatcher-events.test.ts", @@ -79,30 +76,6 @@ const WINDOWS_SKIPPED: readonly string[] = [ "src/drivers/android/seeds-copies.test.ts", "src/drivers/android/seeds-library-and-fit.test.ts", "src/drivers/android/two-instances.test.ts", - "src/drivers/ios/boot-courtesies.test.ts", - "src/drivers/ios/boot-deadline.test.ts", - "src/drivers/ios/devicectl-passthrough.test.ts", - "src/drivers/ios/index-component-install.test.ts", - "src/drivers/ios/index-device-set.test.ts", - "src/drivers/ios/index-list-components.test.ts", - "src/drivers/ios/index-passthrough.test.ts", - "src/drivers/ios/index-provenance-root.test.ts", - "src/drivers/ios/index-remove-component.test.ts", - "src/drivers/ios/index-save-source-lifecycle.test.ts", - "src/drivers/ios/index-seed-provision.test.ts", - "src/drivers/ios/index-seed-record.test.ts", - "src/drivers/ios/index-seed-sources.test.ts", - "src/drivers/ios/index-seed-swap.test.ts", - "src/drivers/ios/index-seed-throwaway.test.ts", - "src/drivers/ios/index-simulator-audio.test.ts", - "src/drivers/ios/index-slim-mode.test.ts", - "src/drivers/ios/index-slim-resolve-advisories.test.ts", - "src/drivers/ios/index.test.ts", - "src/drivers/ios/physical-files-and-limits.test.ts", - "src/drivers/ios/physical-presence.test.ts", - "src/drivers/ios/physical.test.ts", - "src/drivers/ios/slim-except.test.ts", - "src/drivers/ios/slim-named-services.test.ts", "src/fast-track.test.ts", "src/gateway/boundary.test.ts", "src/gateway/dispatcher-reads.test.ts", From a4f16b9af90992f3680cef218311ab4e869e2298 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 16:18:20 +0100 Subject: [PATCH 2/6] fix(ios): test helpers build the overrides paths with node:path (#1708) --- src/drivers/ios/test-slim.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/drivers/ios/test-slim.ts b/src/drivers/ios/test-slim.ts index 2bd7ecd93..6f8b308f4 100644 --- a/src/drivers/ios/test-slim.ts +++ b/src/drivers/ios/test-slim.ts @@ -1,3 +1,5 @@ +import { join } from "node:path"; + import { expect, vi, type Mock } from "vitest"; import { @@ -115,7 +117,7 @@ export async function createSlimDriver( export const overridesRoot = "/private/var/tmp"; export function overridesFolder(udid: string): string { - return `${overridesRoot}/com.apple.CoreSimulator.SimDevice.${udid}`; + return join(overridesRoot, `com.apple.CoreSimulator.SimDevice.${udid}`); } export function overridesPath(udid: string): string { @@ -264,7 +266,7 @@ export const prepareSlim = { mode: "slim", purpose: "prepare" } as const; // why: DeviceHub's preferences are edited as an export, a PlistBuddy edit of it and an import back // through cfprefsd (`defaults`); the export sits in the launchd overrides root. -const deviceHubStaging = "/private/var/tmp/devicehub-preferences.plist"; +const deviceHubStaging = join(overridesRoot, "devicehub-preferences.plist"); export function deviceHubEdit(command: string) { return [ From e226dc79570cd0518c07ed7442f2e3ef3c1ccc4d Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 16:32:38 +0100 Subject: [PATCH 3/6] fix(core): the owned-root, registry and identity tests expect Windows paths, close state.db, skip the mode check there (#1708) --- src/core/device-root.test.ts | 19 +++++++++---------- src/core/instance-identity.test.ts | 3 ++- src/core/registry.test.ts | 8 ++++++-- src/drivers/ios/devicectl-passthrough.test.ts | 5 ++++- src/drivers/ios/test-physical.ts | 4 +++- src/drivers/ios/test-slim.ts | 5 +++-- 6 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/core/device-root.test.ts b/src/core/device-root.test.ts index 761f2d272..e0ee41047 100644 --- a/src/core/device-root.test.ts +++ b/src/core/device-root.test.ts @@ -1,6 +1,6 @@ import { mkdtemp, rm, symlink } from "node:fs/promises"; import { tmpdir } from "node:os"; -import { join } from "node:path"; +import { join, resolve } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; @@ -14,9 +14,10 @@ import type { Platform } from "./domain.js"; import { ensureOwnedRoot, OWNED_ROOT_MARKER_FILE, OwnedRootError } from "./index.js"; const instanceId = "instance-a"; -const parent = "/home/agent/.simlock/devices"; -const root = `${parent}/ios`; -const markerPath = `${root}/${OWNED_ROOT_MARKER_FILE}`; +// why: ensureOwnedRoot returns `resolve(path)`, which puts a drive letter on a Windows host. +const parent = resolve("/home/agent/.simlock/devices"); +const root = join(parent, "ios"); +const markerPath = join(root, OWNED_ROOT_MARKER_FILE); const uid = 501; const idGenerator = new CryptoIdGenerator(); @@ -111,7 +112,7 @@ describe("ensureOwnedRoot", () => { uid, }); - expect(staged).toEqual([`${parent}/.ios.4242.id-1.staging`]); + expect(staged).toEqual([join(parent, ".ios.4242.id-1.staging")]); }); it("publishes a root and its marker in the same instant", async () => { @@ -149,9 +150,7 @@ describe("ensureOwnedRoot", () => { it("returns the resolved path for a root written with relative segments", async () => { const filesystem = createFilesystem(); - await expect( - ensure(filesystem, { path: "/home/agent/.simlock/devices/android/../ios" }), - ).resolves.toBe(root); + await expect(ensure(filesystem, { path: `${parent}/android/../ios` })).resolves.toBe(root); }); it("reuses a root it already owns without rewriting its marker", async () => { @@ -265,14 +264,14 @@ describe("ensureOwnedRoot", () => { it("refuses an unmarked root that already holds something", async () => { const filesystem = createFilesystem(); await seedRoot(filesystem); - await filesystem.writeFileAtomic(`${root}/someone-elses-work.txt`, ""); + await filesystem.writeFileAtomic(join(root, "someone-elses-work.txt"), ""); await expect(refusal(filesystem)).resolves.toBe("non-empty-unowned-root"); }); it("refuses a path occupied by something that is not a directory", async () => { const filesystem = createFilesystem(); - await filesystem.mkdirp("/home/agent/.simlock/devices"); + await filesystem.mkdirp(parent); await filesystem.writeFileAtomic(root, "not a directory"); await expect(refusal(filesystem)).resolves.toBe("non-empty-unowned-root"); diff --git a/src/core/instance-identity.test.ts b/src/core/instance-identity.test.ts index dc84329a3..267a94c76 100644 --- a/src/core/instance-identity.test.ts +++ b/src/core/instance-identity.test.ts @@ -124,7 +124,8 @@ describe("loadInstanceId on a real filesystem", () => { await expect(filesystem.readdir(home)).resolves.toEqual(["instance.json"]); }); - it("creates instance.json owner-only", async () => { + // why: ADR 0087 section 3: Windows has no mode 0600, so `stat` reports another mode there. + it.skipIf(process.platform === "win32")("creates instance.json owner-only", async () => { // why: #685: `writeFileExclusive` links a temp file into place, and that temp file is written // without a mode, so the identity the daemon stamps into every device root lands world- // readable under the umask every real host starts from. A restrictive umask here would diff --git a/src/core/registry.test.ts b/src/core/registry.test.ts index 864bf97a0..98c7ab3e8 100644 --- a/src/core/registry.test.ts +++ b/src/core/registry.test.ts @@ -125,11 +125,13 @@ describe("Registry", () => { }); migrated.close(); - const reopened = await loadRegistry(await openState(registryOwner)); + const reopenedState = await openState(registryOwner); + const reopened = await loadRegistry(reopenedState); expect(reopened.leaseRequests().map((record) => record.request.baseline)).toEqual([ undefined, "checkout", ]); + reopenedState.close(); } finally { await rm(directory, { force: true, recursive: true }); } @@ -248,10 +250,12 @@ describe("Registry", () => { }); migrated.close(); - const reopened = await loadRegistry(await openState(registryOwner)); + const reopenedState = await openState(registryOwner); + const reopened = await loadRegistry(reopenedState); expect( reopened.snapshot.devices.map((device) => device.physical && device.hardwareSerial), ).toEqual([undefined, "R58Y61A60HN2"]); + reopenedState.close(); } finally { await rm(directory, { force: true, recursive: true }); } diff --git a/src/drivers/ios/devicectl-passthrough.test.ts b/src/drivers/ios/devicectl-passthrough.test.ts index 879cacb95..94f2a2b82 100644 --- a/src/drivers/ios/devicectl-passthrough.test.ts +++ b/src/drivers/ios/devicectl-passthrough.test.ts @@ -1,3 +1,5 @@ +import { resolve } from "node:path"; + import { describe, expect, it } from "vitest"; import { PassthroughRefusedError } from "../../core/index.js"; @@ -5,7 +7,8 @@ import { FakeClock, MemoryFilesystem, ScriptedProcessRunner } from "../../ports/ import { IosSimctlDriver } from "./index.js"; import { memorySourceDatabase } from "./testing.js"; -const deviceRoot = "/Devices"; +// why: the driver passes `resolve(root)` to simctl, which puts a drive letter on a Windows host. +const deviceRoot = resolve("/Devices"); const UDID = "00008110-001A2B3C4D5E"; const APP = "com.example.app"; const BUILD = "/builds/App.app"; diff --git a/src/drivers/ios/test-physical.ts b/src/drivers/ios/test-physical.ts index 6cf177be0..d592e5c86 100644 --- a/src/drivers/ios/test-physical.ts +++ b/src/drivers/ios/test-physical.ts @@ -1,3 +1,4 @@ +import { resolve } from "node:path"; import { readFileSync } from "node:fs"; import { expect } from "vitest"; import type { PhysicalInspection } from "../../core/index.js"; @@ -25,7 +26,8 @@ const appsFixture = JSON.parse( export const SIMLOCK_HOME = "/home/.simlock"; -export const DEVICE_ROOT = "/Devices"; +// why: the driver passes `resolve(root)` to simctl, which puts a drive letter on a Windows host. +export const DEVICE_ROOT = resolve("/Devices"); export const READ_LIMIT_MS = 30_000; diff --git a/src/drivers/ios/test-slim.ts b/src/drivers/ios/test-slim.ts index 6f8b308f4..dc009d831 100644 --- a/src/drivers/ios/test-slim.ts +++ b/src/drivers/ios/test-slim.ts @@ -1,4 +1,4 @@ -import { join } from "node:path"; +import { join, resolve } from "node:path"; import { expect, vi, type Mock } from "vitest"; @@ -20,7 +20,8 @@ import { memorySourceDatabase } from "./testing.js"; // why: the slim boot's fixtures, shared by the driver's two test files (index.test.ts is at its size limit). -export const deviceRoot = "/Devices"; +// why: the driver passes `resolve(root)` to simctl, which puts a drive letter on a Windows host. +export const deviceRoot = resolve("/Devices"); export const instanceId = "instance-1"; From fdf2b2c6dbac10f2657c07cdf659f4abbc4d32a7 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 16:45:32 +0100 Subject: [PATCH 4/6] fix(ios): test helpers build the sources set and devicectl json paths the way the driver does (#1708) --- src/drivers/ios/index-component-install.test.ts | 4 ++-- src/drivers/ios/index-device-set.test.ts | 7 ++++--- src/drivers/ios/index-list-components.test.ts | 4 ++-- src/drivers/ios/index-passthrough.test.ts | 4 ++-- src/drivers/ios/index-provenance-root.test.ts | 11 +++++++++-- src/drivers/ios/index-remove-component.test.ts | 3 ++- .../ios/index-save-source-lifecycle.test.ts | 14 +++++++------- .../ios/index-screen-tool-versions.test.ts | 4 ++-- src/drivers/ios/index-seed-provision.test.ts | 17 ++++++----------- src/drivers/ios/index-seed-record.test.ts | 11 +++++------ src/drivers/ios/index-seed-sources.test.ts | 3 ++- src/drivers/ios/index-seed-throwaway.test.ts | 5 +++-- src/drivers/ios/index-simulator-audio.test.ts | 3 ++- .../ios/index-slim-resolve-advisories.test.ts | 4 ++-- src/drivers/ios/index.test.ts | 4 ++-- src/drivers/ios/test-index.ts | 7 ++++--- src/drivers/ios/test-physical.ts | 9 +++++++-- src/drivers/ios/test-slim.ts | 4 +++- 18 files changed, 66 insertions(+), 52 deletions(-) diff --git a/src/drivers/ios/index-component-install.test.ts b/src/drivers/ios/index-component-install.test.ts index d8759b1fc..a33680dd8 100644 --- a/src/drivers/ios/index-component-install.test.ts +++ b/src/drivers/ios/index-component-install.test.ts @@ -3,7 +3,7 @@ import { RuntimeMissingError, DriverCrashError } from "../../core/index.js"; import { ScriptedProcessRunner, FakeClock, MemoryFilesystem } from "../../ports/index.js"; import { IosSimctlDriver } from "./index.js"; import { memorySourceDatabase } from "./testing.js"; -import { deviceRoot, simctl, instanceId } from "./test-slim.js"; +import { deviceRoot, sourcesSetPath, simctl, instanceId } from "./test-slim.js"; import { UNSCOPED_LEGACY_CALLS, createDriver, @@ -30,7 +30,7 @@ afterEach(() => { if (call.command !== "xcrun" || call.args[0] !== "simctl") continue; if (UNSCOPED_LEGACY_CALLS.has(call.args.join(" "))) continue; expect(call.args.slice(0, 2)).toEqual(["simctl", "--set"]); - expect([deviceRoot, `${deviceRoot}/sources`]).toContain(call.args[2]); + expect([deviceRoot, sourcesSetPath]).toContain(call.args[2]); } }); diff --git a/src/drivers/ios/index-device-set.test.ts b/src/drivers/ios/index-device-set.test.ts index 243f91a42..2cf2e5114 100644 --- a/src/drivers/ios/index-device-set.test.ts +++ b/src/drivers/ios/index-device-set.test.ts @@ -16,6 +16,7 @@ import { memorySourceDatabase } from "./testing.js"; import { driverData, deviceRoot, + sourcesSetPath, simctlArgs, deviceHubEdit, plantManagedDevice, @@ -58,8 +59,8 @@ describe("IosSimctlDriver device set", () => { } it.each([ - ["unset", {}, deviceRoot, true, `${deviceRoot}/sources`, false], - ["simlock", { deviceSet: "simlock" }, deviceRoot, true, `${deviceRoot}/sources`, false], + ["unset", {}, deviceRoot, true, sourcesSetPath, false], + ["simlock", { deviceSet: "simlock" }, deviceRoot, true, sourcesSetPath, false], [ "default", { deviceSet: "default" }, @@ -397,7 +398,7 @@ describe("IosSimctlDriver device set", () => { [ "simctl", "--set", - scoped ? `${deviceRoot}/sources` : "/home/.simlock/devices/ios-sources", + scoped ? sourcesSetPath : "/home/.simlock/devices/ios-sources", "clone", seedUdid, driverData.name, diff --git a/src/drivers/ios/index-list-components.test.ts b/src/drivers/ios/index-list-components.test.ts index df102be51..a61aa9506 100644 --- a/src/drivers/ios/index-list-components.test.ts +++ b/src/drivers/ios/index-list-components.test.ts @@ -1,7 +1,7 @@ import { afterEach, expect, it, describe } from "vitest"; import { DriverCrashError } from "../../core/index.js"; import { ScriptedProcessRunner } from "../../ports/index.js"; -import { deviceRoot } from "./test-slim.js"; +import { deviceRoot, sourcesSetPath } from "./test-slim.js"; import { Image, UNSCOPED_LEGACY_CALLS, @@ -33,7 +33,7 @@ afterEach(() => { if (call.command !== "xcrun" || call.args[0] !== "simctl") continue; if (UNSCOPED_LEGACY_CALLS.has(call.args.join(" "))) continue; expect(call.args.slice(0, 2)).toEqual(["simctl", "--set"]); - expect([deviceRoot, `${deviceRoot}/sources`]).toContain(call.args[2]); + expect([deviceRoot, sourcesSetPath]).toContain(call.args[2]); } }); diff --git a/src/drivers/ios/index-passthrough.test.ts b/src/drivers/ios/index-passthrough.test.ts index f34583dc9..ff781c2e5 100644 --- a/src/drivers/ios/index-passthrough.test.ts +++ b/src/drivers/ios/index-passthrough.test.ts @@ -10,7 +10,7 @@ import { } from "../../ports/index.js"; import { IosSimctlDriver } from "./index.js"; import { memorySourceDatabase } from "./testing.js"; -import { deviceRoot } from "./test-slim.js"; +import { deviceRoot, sourcesSetPath } from "./test-slim.js"; import { UNSCOPED_LEGACY_CALLS, createDriver, @@ -35,7 +35,7 @@ afterEach(() => { if (call.command !== "xcrun" || call.args[0] !== "simctl") continue; if (UNSCOPED_LEGACY_CALLS.has(call.args.join(" "))) continue; expect(call.args.slice(0, 2)).toEqual(["simctl", "--set"]); - expect([deviceRoot, `${deviceRoot}/sources`]).toContain(call.args[2]); + expect([deviceRoot, sourcesSetPath]).toContain(call.args[2]); } }); diff --git a/src/drivers/ios/index-provenance-root.test.ts b/src/drivers/ios/index-provenance-root.test.ts index 2248912ae..04bfa4fa1 100644 --- a/src/drivers/ios/index-provenance-root.test.ts +++ b/src/drivers/ios/index-provenance-root.test.ts @@ -4,7 +4,14 @@ import { OWNED_ROOT_MARKER_FILE, OwnedRootError } from "../../core/index.js"; import { ScriptedProcessRunner, MemoryFilesystem, FakeClock } from "../../ports/index.js"; import { IosSimctlDriver } from "./index.js"; import { memorySourceDatabase } from "./testing.js"; -import { deviceRoot, driverData, dataPath, plantManagedDevice, instanceId } from "./test-slim.js"; +import { + deviceRoot, + sourcesSetPath, + driverData, + dataPath, + plantManagedDevice, + instanceId, +} from "./test-slim.js"; import { PHYSICAL_DEVICE, UNSCOPED_LEGACY_CALLS, @@ -47,7 +54,7 @@ afterEach(() => { if (call.command !== "xcrun" || call.args[0] !== "simctl") continue; if (UNSCOPED_LEGACY_CALLS.has(call.args.join(" "))) continue; expect(call.args.slice(0, 2)).toEqual(["simctl", "--set"]); - expect([deviceRoot, `${deviceRoot}/sources`]).toContain(call.args[2]); + expect([deviceRoot, sourcesSetPath]).toContain(call.args[2]); } }); diff --git a/src/drivers/ios/index-remove-component.test.ts b/src/drivers/ios/index-remove-component.test.ts index 1aa5cf583..42e61c61a 100644 --- a/src/drivers/ios/index-remove-component.test.ts +++ b/src/drivers/ios/index-remove-component.test.ts @@ -5,6 +5,7 @@ import { promiseState } from "../../test-support/promise-state.js"; import { memorySourceDatabase, plantSource } from "./testing.js"; import { deviceRoot, + sourcesSetPath, simctl, driverData, waitForCalls, @@ -48,7 +49,7 @@ afterEach(() => { if (call.command !== "xcrun" || call.args[0] !== "simctl") continue; if (UNSCOPED_LEGACY_CALLS.has(call.args.join(" "))) continue; expect(call.args.slice(0, 2)).toEqual(["simctl", "--set"]); - expect([deviceRoot, `${deviceRoot}/sources`]).toContain(call.args[2]); + expect([deviceRoot, sourcesSetPath]).toContain(call.args[2]); } }); diff --git a/src/drivers/ios/index-save-source-lifecycle.test.ts b/src/drivers/ios/index-save-source-lifecycle.test.ts index e442cb6e7..00fbad041 100644 --- a/src/drivers/ios/index-save-source-lifecycle.test.ts +++ b/src/drivers/ios/index-save-source-lifecycle.test.ts @@ -6,6 +6,7 @@ import { IosSimctlDriver } from "./index.js"; import { memorySourceDatabase } from "./testing.js"; import { deviceRoot, + sourcesSetPath, driverData, simctl, plantManagedDevice, @@ -55,7 +56,7 @@ afterEach(() => { if (call.command !== "xcrun" || call.args[0] !== "simctl") continue; if (UNSCOPED_LEGACY_CALLS.has(call.args.join(" "))) continue; expect(call.args.slice(0, 2)).toEqual(["simctl", "--set"]); - expect([deviceRoot, `${deviceRoot}/sources`]).toContain(call.args[2]); + expect([deviceRoot, sourcesSetPath]).toContain(call.args[2]); } }); @@ -63,14 +64,13 @@ describe("IosSimctlDriver", () => { describe("saveSource", () => { const cloneUdid = "00000000-0000-0000-0000-0000000000bb"; const baselineName = "simlock-baseline-device-1"; - const sourcesSet = `${deviceRoot}/sources`; const device = { address: driverData.udid, deviceId: driverData.udid, driverData: { ...driverData, lineage: ["AAAAAAAA-1111-2222-3333-BBBBBBBBBBBB"] }, physical: false, } as const; - const cloneInvocation = simctl("clone", driverData.udid, baselineName, sourcesSet); + const cloneInvocation = simctl("clone", driverData.udid, baselineName, sourcesSetPath); it("keeps a shut-down copy of the device in the sources set as a ready baseline source with its disabled.plist, and a failing clone keeps no row", async () => { const database = await memorySourceDatabase(); @@ -82,9 +82,9 @@ describe("IosSimctlDriver", () => { overridesPath(driverData.udid), overridesPlist({ "a.b": true }), ); - await filesystem.mkdirp(`${sourcesSet}/${cloneUdid}/data`); - await filesystem.writeFileAtomic(`${sourcesSet}/${cloneUdid}/data/state`, "12345"); - await plantLaunchServices(filesystem, `${sourcesSet}/${cloneUdid}`); + await filesystem.mkdirp(`${sourcesSetPath}/${cloneUdid}/data`); + await filesystem.writeFileAtomic(`${sourcesSetPath}/${cloneUdid}/data/state`, "12345"); + await plantLaunchServices(filesystem, `${sourcesSetPath}/${cloneUdid}`); const runner = new ScriptedProcessRunner([ { match: listInvocation, result: { code: 0, stderr: "", stdout: listFixture } }, { @@ -116,7 +116,7 @@ describe("IosSimctlDriver", () => { expect(await filesystem.readFile(overridesPath(cloneUdid))).toBe( overridesPlist({ "a.b": true }), ); - expect(await launchServicesFiles(filesystem, `${sourcesSet}/${cloneUdid}`)).toEqual([ + expect(await launchServicesFiles(filesystem, `${sourcesSetPath}/${cloneUdid}`)).toEqual([ "com.apple.LaunchServices.unregisteredtypes-501.db", ]); await expect(driver.listSources()).resolves.toEqual([ diff --git a/src/drivers/ios/index-screen-tool-versions.test.ts b/src/drivers/ios/index-screen-tool-versions.test.ts index 0f4f00baf..8a71d544b 100644 --- a/src/drivers/ios/index-screen-tool-versions.test.ts +++ b/src/drivers/ios/index-screen-tool-versions.test.ts @@ -7,7 +7,7 @@ import { } from "../../ports/index.js"; import { IosSimctlDriver } from "./index.js"; import { memorySourceDatabase } from "./testing.js"; -import { deviceRoot, instanceId } from "./test-slim.js"; +import { deviceRoot, sourcesSetPath, instanceId } from "./test-slim.js"; import { UNSCOPED_LEGACY_CALLS, createDriver, scopedRunners } from "./test-index.js"; /** @@ -26,7 +26,7 @@ afterEach(() => { if (call.command !== "xcrun" || call.args[0] !== "simctl") continue; if (UNSCOPED_LEGACY_CALLS.has(call.args.join(" "))) continue; expect(call.args.slice(0, 2)).toEqual(["simctl", "--set"]); - expect([deviceRoot, `${deviceRoot}/sources`]).toContain(call.args[2]); + expect([deviceRoot, sourcesSetPath]).toContain(call.args[2]); } }); diff --git a/src/drivers/ios/index-seed-provision.test.ts b/src/drivers/ios/index-seed-provision.test.ts index 0d856ec74..0932cae3d 100644 --- a/src/drivers/ios/index-seed-provision.test.ts +++ b/src/drivers/ios/index-seed-provision.test.ts @@ -14,6 +14,7 @@ import { IosSimctlDriver } from "./index.js"; import { memorySourceDatabase } from "./testing.js"; import { deviceRoot, + sourcesSetPath, driverData, plantManagedDevice, waitForCalls, @@ -51,7 +52,7 @@ afterEach(() => { if (call.command !== "xcrun" || call.args[0] !== "simctl") continue; if (UNSCOPED_LEGACY_CALLS.has(call.args.join(" "))) continue; expect(call.args.slice(0, 2)).toEqual(["simctl", "--set"]); - expect([deviceRoot, `${deviceRoot}/sources`]).toContain(call.args[2]); + expect([deviceRoot, sourcesSetPath]).toContain(call.args[2]); } }); @@ -131,7 +132,7 @@ describe("IosSimctlDriver", () => { "the seed's row is making, with no simulator yet, when create runs", ).toEqual([{ state: "making", udid: null }]); expect( - filesystem.mkdirpModes.get(`${deviceRoot}/sources`), + filesystem.mkdirpModes.get(sourcesSetPath), "under deviceSet simlock the sources set is asked for private to the user", ).toBe(0o700); expect(runner.calls).toEqual([ @@ -142,7 +143,7 @@ describe("IosSimctlDriver", () => { { ...simctl("listapps", throwawayUdid), options: { timeoutMs: 30_000 } }, { ...simctl("shutdown", throwawayUdid), options: { timeoutMs: 30_000 } }, { - ...simctl("clone", throwawayUdid, "simlock-seed-device-1", `${deviceRoot}/sources`), + ...simctl("clone", throwawayUdid, "simlock-seed-device-1", sourcesSetPath), options: { timeoutMs: 330_000 }, }, { ...simctl("delete", throwawayUdid), options: { timeoutMs: 30_000 } }, @@ -254,12 +255,7 @@ describe("IosSimctlDriver", () => { { match: simctl("shutdown", driverData.udid) }, { hangs: true, - match: simctl( - "clone", - driverData.udid, - "simlock-baseline-device-1", - `${deviceRoot}/sources`, - ), + match: simctl("clone", driverData.udid, "simlock-baseline-device-1", sourcesSetPath), }, ], }, @@ -343,8 +339,7 @@ describe("IosSimctlDriver", () => { physical: false, }), deleteArgs: (udid: string) => sourcesSimctl("delete", udid).args, - hung: simctl("clone", driverData.udid, "simlock-baseline-device-1", `${deviceRoot}/sources`) - .args, + hung: simctl("clone", driverData.udid, "simlock-baseline-device-1", sourcesSetPath).args, isDefault: false, seeded: false, steps: [ diff --git a/src/drivers/ios/index-seed-record.test.ts b/src/drivers/ios/index-seed-record.test.ts index ee7e400a6..b37909aa6 100644 --- a/src/drivers/ios/index-seed-record.test.ts +++ b/src/drivers/ios/index-seed-record.test.ts @@ -7,7 +7,7 @@ import { type SqliteDatabase, } from "../../ports/index.js"; import { memorySourceDatabase, plantBytes } from "./testing.js"; -import { deviceRoot, driverData, plantManagedDevice, simctl } from "./test-slim.js"; +import { deviceRoot, driverData, sourcesSetPath, plantManagedDevice, simctl } from "./test-slim.js"; import { RecordingLogger, createDriver, @@ -28,8 +28,7 @@ afterEach(() => { const copyUdid = "CCCCCCCC-4444-5555-6666-DDDDDDDDDDDD"; const lineageUdid = throwawayUdid.toUpperCase(); -const sourcesSet = `${deviceRoot}/sources`; -const seedFolder = `${sourcesSet}/${seedUdid}`; +const seedFolder = `${sourcesSetPath}/${seedUdid}`; const SQLITE_HEADER = Buffer.from("SQLite format 3\u0000"); const MEBIBYTE = 1_048_576; @@ -128,7 +127,7 @@ async function saveBaseline(options: { { match: listInvocation, result: { code: 0, stderr: "", stdout: listFixture } }, { match: simctl("shutdown", driverData.udid) }, { - match: simctl("clone", driverData.udid, "simlock-baseline-device-1", sourcesSet), + match: simctl("clone", driverData.udid, "simlock-baseline-device-1", sourcesSetPath), result: { code: 0, stderr: "", stdout: `${baselineUdid}\n` }, }, ]); @@ -266,14 +265,14 @@ describe("IosSimctlDriver source records", () => { expect(walkFails.error).toMatchObject({ code: "EACCES" }); expect( walkFails.runner.calls.some( - (call) => call.args.join(" ") === `simctl --set ${sourcesSet} delete ${seedUdid}`, + (call) => call.args.join(" ") === `simctl --set ${sourcesSetPath} delete ${seedUdid}`, ), "the seed's clone is deleted", ).toBe(true); expect(walkFails.database.prepare("SELECT source_id FROM ios_source_data").all()).toEqual([]); expect(recorded(walkFails.database)).toEqual([]); - const baselineFolder = `${sourcesSet}/${baselineUdid}`; + const baselineFolder = `${sourcesSetPath}/${baselineUdid}`; const lease = driverData.udid.toUpperCase(); const fromUsedLease = await saveBaseline({ lineage: [lineageUdid], diff --git a/src/drivers/ios/index-seed-sources.test.ts b/src/drivers/ios/index-seed-sources.test.ts index d923e9e0f..925eb72c7 100644 --- a/src/drivers/ios/index-seed-sources.test.ts +++ b/src/drivers/ios/index-seed-sources.test.ts @@ -11,6 +11,7 @@ import { } from "./testing.js"; import { deviceRoot, + sourcesSetPath, driverData, waitForCalls, FaultyFilesystem, @@ -51,7 +52,7 @@ afterEach(() => { if (call.command !== "xcrun" || call.args[0] !== "simctl") continue; if (UNSCOPED_LEGACY_CALLS.has(call.args.join(" "))) continue; expect(call.args.slice(0, 2)).toEqual(["simctl", "--set"]); - expect([deviceRoot, `${deviceRoot}/sources`]).toContain(call.args[2]); + expect([deviceRoot, sourcesSetPath]).toContain(call.args[2]); } }); diff --git a/src/drivers/ios/index-seed-throwaway.test.ts b/src/drivers/ios/index-seed-throwaway.test.ts index 7bd5d6ffb..2e26a4bb5 100644 --- a/src/drivers/ios/index-seed-throwaway.test.ts +++ b/src/drivers/ios/index-seed-throwaway.test.ts @@ -5,6 +5,7 @@ import { memorySourceDatabase, plantSource } from "./testing.js"; import { deviceHubEdit, deviceRoot, + sourcesSetPath, driverData, instanceId, plantManagedDevice, @@ -53,7 +54,7 @@ const worlds: readonly World[] = [ devicesDir: deviceRoot, isDefault: false, label: "simlock set", - sourcesSet: `${deviceRoot}/sources`, + sourcesSet: sourcesSetPath, }, { config: { deviceSet: "default" }, @@ -413,7 +414,7 @@ describe("IosSimctlDriver seed throwaway", () => { it("baseline.save deletes the saved-from lease's log folder", async () => { const baselineName = "simlock-baseline-device-1"; const leaseLogs = `${logsRoot}/${driverData.udid}`; - const clone = simctl("clone", driverData.udid, baselineName, `${deviceRoot}/sources`); + const clone = simctl("clone", driverData.udid, baselineName, sourcesSetPath); const cloneUdid = "00000000-0000-0000-0000-0000000000cc"; const cases = [ { label: "present", plant: true, clone: "ok", logs: false, warnings: [] }, diff --git a/src/drivers/ios/index-simulator-audio.test.ts b/src/drivers/ios/index-simulator-audio.test.ts index 8e8f70f00..f6ebff1a1 100644 --- a/src/drivers/ios/index-simulator-audio.test.ts +++ b/src/drivers/ios/index-simulator-audio.test.ts @@ -10,6 +10,7 @@ import { type SilenceFailedFact, IosSimctlDriver } from "./index.js"; import { memorySourceDatabase } from "./testing.js"; import { deviceRoot, + sourcesSetPath, driverData, simctlArgs, simctl, @@ -36,7 +37,7 @@ afterEach(() => { if (call.command !== "xcrun" || call.args[0] !== "simctl") continue; if (UNSCOPED_LEGACY_CALLS.has(call.args.join(" "))) continue; expect(call.args.slice(0, 2)).toEqual(["simctl", "--set"]); - expect([deviceRoot, `${deviceRoot}/sources`]).toContain(call.args[2]); + expect([deviceRoot, sourcesSetPath]).toContain(call.args[2]); } }); diff --git a/src/drivers/ios/index-slim-resolve-advisories.test.ts b/src/drivers/ios/index-slim-resolve-advisories.test.ts index 856ea6ffb..b38f056c5 100644 --- a/src/drivers/ios/index-slim-resolve-advisories.test.ts +++ b/src/drivers/ios/index-slim-resolve-advisories.test.ts @@ -1,6 +1,6 @@ import { afterEach, expect, describe, it } from "vitest"; import { MemoryFilesystem, ScriptedProcessRunner, FakeClock } from "../../ports/index.js"; -import { deviceRoot, createSlimDriver } from "./test-slim.js"; +import { deviceRoot, sourcesSetPath, createSlimDriver } from "./test-slim.js"; import { IOS_RUNTIME_ASSET_ROOT, SizedFilesystem, @@ -30,7 +30,7 @@ afterEach(() => { if (call.command !== "xcrun" || call.args[0] !== "simctl") continue; if (UNSCOPED_LEGACY_CALLS.has(call.args.join(" "))) continue; expect(call.args.slice(0, 2)).toEqual(["simctl", "--set"]); - expect([deviceRoot, `${deviceRoot}/sources`]).toContain(call.args[2]); + expect([deviceRoot, sourcesSetPath]).toContain(call.args[2]); } }); diff --git a/src/drivers/ios/index.test.ts b/src/drivers/ios/index.test.ts index e23b9ed68..76f1cc33a 100644 --- a/src/drivers/ios/index.test.ts +++ b/src/drivers/ios/index.test.ts @@ -2,7 +2,7 @@ import { afterEach, expect, it, describe } from "vitest"; import { UnknownModelError, DriverCrashError, RuntimeMissingError } from "../../core/index.js"; import { ScriptedProcessRunner, MemoryFilesystem } from "../../ports/index.js"; import { SLIM_CATEGORIES } from "./index.js"; -import { deviceRoot, createSlimDriver } from "./test-slim.js"; +import { deviceRoot, sourcesSetPath, createSlimDriver } from "./test-slim.js"; import { UNSCOPED_LEGACY_CALLS, createDriver, @@ -73,7 +73,7 @@ afterEach(() => { if (call.command !== "xcrun" || call.args[0] !== "simctl") continue; if (UNSCOPED_LEGACY_CALLS.has(call.args.join(" "))) continue; expect(call.args.slice(0, 2)).toEqual(["simctl", "--set"]); - expect([deviceRoot, `${deviceRoot}/sources`]).toContain(call.args[2]); + expect([deviceRoot, sourcesSetPath]).toContain(call.args[2]); } }); diff --git a/src/drivers/ios/test-index.ts b/src/drivers/ios/test-index.ts index bf4990a75..893e8c0e3 100644 --- a/src/drivers/ios/test-index.ts +++ b/src/drivers/ios/test-index.ts @@ -13,6 +13,7 @@ import { plantReadySeed, memorySourceDatabase, type PlantedSource } from "./test import { simctl, deviceRoot, + sourcesSetPath, driverData, dataPath, instanceId, @@ -89,7 +90,7 @@ export function sourcesSimctl(...args: readonly string[]): { readonly command: string; readonly args: string[]; } { - return { args: ["simctl", "--set", `${deviceRoot}/sources`, ...args], command: "xcrun" }; + return { args: ["simctl", "--set", sourcesSetPath, ...args], command: "xcrun" }; } /** why: A database that already holds the seed of the kind `spec` names, so a test of the copy step starts at the clone. */ @@ -394,7 +395,7 @@ export function throwawaySeedSteps( { match: simctl("listapps", throwawayUdid) }, { match: simctl("shutdown", throwawayUdid) }, { - match: simctl("clone", throwawayUdid, name, `${deviceRoot}/sources`), + match: simctl("clone", throwawayUdid, name, sourcesSetPath), result: { code: 0, stderr: "", stdout: `${seed}\n` }, }, { match: simctl("delete", throwawayUdid) }, @@ -404,7 +405,7 @@ export function throwawaySeedSteps( /** why: `simctl clone` made the seed's folder in the sources set, which the scripted runner cannot do, and a make walks it before the seed turns ready. */ export async function plantSeedClone( filesystem: Filesystem, - sourcesSet: string = `${deviceRoot}/sources`, + sourcesSet: string = sourcesSetPath, udid: string = seedUdid, ): Promise { await filesystem.mkdirp(`${sourcesSet}/${udid}`); diff --git a/src/drivers/ios/test-physical.ts b/src/drivers/ios/test-physical.ts index d592e5c86..90b9ded3c 100644 --- a/src/drivers/ios/test-physical.ts +++ b/src/drivers/ios/test-physical.ts @@ -1,4 +1,4 @@ -import { resolve } from "node:path"; +import { join, resolve } from "node:path"; import { readFileSync } from "node:fs"; import { expect } from "vitest"; import type { PhysicalInspection } from "../../core/index.js"; @@ -26,6 +26,11 @@ const appsFixture = JSON.parse( export const SIMLOCK_HOME = "/home/.simlock"; +// why: the driver builds the json path with `join`, which uses backslashes on a Windows host. +const JSON_OUTPUT_PATH = new RegExp( + `^${join(SIMLOCK_HOME, "devicectl").replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}[\\\\/][^\\\\/]+$`, +); + // why: the driver passes `resolve(root)` to simctl, which puts a drive letter on a Windows host. export const DEVICE_ROOT = resolve("/Devices"); @@ -261,7 +266,7 @@ export class Lab { #read(argv: readonly string[], script: ReadScript): this { return this.add({ match: { - args: ["devicectl", ...argv, "--json-output", /^\/home\/\.simlock\/devicectl\/[^/]+$/], + args: ["devicectl", ...argv, "--json-output", JSON_OUTPUT_PATH], command: "xcrun", }, onSpawn: async (args) => { diff --git a/src/drivers/ios/test-slim.ts b/src/drivers/ios/test-slim.ts index dc009d831..9dcc060eb 100644 --- a/src/drivers/ios/test-slim.ts +++ b/src/drivers/ios/test-slim.ts @@ -23,6 +23,8 @@ import { memorySourceDatabase } from "./testing.js"; // why: the driver passes `resolve(root)` to simctl, which puts a drive letter on a Windows host. export const deviceRoot = resolve("/Devices"); +export const sourcesSetPath = join(deviceRoot, "sources"); + export const instanceId = "instance-1"; export const driverData = { @@ -122,7 +124,7 @@ export function overridesFolder(udid: string): string { } export function overridesPath(udid: string): string { - return `${overridesFolder(udid)}/disabled.plist`; + return join(overridesFolder(udid), "disabled.plist"); } /** why: ADR 0083 S2: the record of named services sits beside the overrides file. */ From db328ebbe74b34892a499f9658ad1909aface99d Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 17:02:12 +0100 Subject: [PATCH 5/6] fix(ios): fixtures spell derived paths the way the driver joins them, and the sized filesystem matches either style (#1708) --- src/drivers/ios/index-device-set.test.ts | 19 ++++++++++-------- src/drivers/ios/index-provenance-root.test.ts | 6 ++++-- src/drivers/ios/index-seed-provision.test.ts | 8 +++++--- src/drivers/ios/index-seed-record.test.ts | 20 +++++++++++++------ src/drivers/ios/index-seed-swap.test.ts | 9 ++++++++- src/drivers/ios/index-seed-throwaway.test.ts | 20 ++++++++++--------- .../ios/physical-files-and-limits.test.ts | 5 +++-- src/drivers/ios/test-index.ts | 12 ++++++++--- src/drivers/ios/test-slim.ts | 11 +++++++++- 9 files changed, 75 insertions(+), 35 deletions(-) diff --git a/src/drivers/ios/index-device-set.test.ts b/src/drivers/ios/index-device-set.test.ts index 2cf2e5114..9b0b50114 100644 --- a/src/drivers/ios/index-device-set.test.ts +++ b/src/drivers/ios/index-device-set.test.ts @@ -1,3 +1,4 @@ +import { join } from "node:path"; import { describe, it, expect } from "vitest"; import { OWNED_ROOT_MARKER_FILE, @@ -21,6 +22,8 @@ import { deviceHubEdit, plantManagedDevice, instanceId, + simlockDeviceRoot, + unownedSourcesSet, } from "./test-slim.js"; import { PHYSICAL_DEVICE, @@ -64,9 +67,9 @@ describe("IosSimctlDriver device set", () => { [ "default", { deviceSet: "default" }, - `${coreSimulatorRoot}/Devices`, + join(coreSimulatorRoot, "Devices"), false, - "/home/.simlock/devices/ios-sources", + unownedSourcesSet, true, ], ] as const)( @@ -223,8 +226,8 @@ describe("IosSimctlDriver device set", () => { ); it("an operator who switches with leftovers gets device-set-changed, and an unreadable folder gets unreadable", async () => { - const ownRoot = "/home/.simlock/devices/ios"; - const xcodeDevices = `${coreSimulatorRoot}/Devices`; + const ownRoot = simlockDeviceRoot; + const xcodeDevices = join(coreSimulatorRoot, "Devices"); const [first, second, third] = [1, 2, 3].map( (n) => `00000000-0000-0000-0000-00000000000${String(n)}`, ); @@ -360,7 +363,7 @@ describe("IosSimctlDriver device set", () => { it.each([ ["simlock", { deviceRoot, deviceSet: "simlock" }, deviceRoot], - ["default", { deviceSet: "default" }, `${coreSimulatorRoot}/Devices`], + ["default", { deviceSet: "default" }, join(coreSimulatorRoot, "Devices")], ] as const)( "a new simulator's marks name this instance under deviceSet %s", async (setting, config, devicesDir) => { @@ -398,7 +401,7 @@ describe("IosSimctlDriver device set", () => { [ "simctl", "--set", - scoped ? sourcesSetPath : "/home/.simlock/devices/ios-sources", + scoped ? sourcesSetPath : unownedSourcesSet, "clone", seedUdid, driverData.name, @@ -434,7 +437,7 @@ describe("IosSimctlDriver device set", () => { ); it("under deviceSet default listManaged reports only devices whose durable mark names this instance", async () => { - const devicesDir = `${coreSimulatorRoot}/Devices`; + const devicesDir = join(coreSimulatorRoot, "Devices"); const udid = (n: number) => `00000000-0000-0000-0000-00000000010${String(n)}`; const mark = (owner?: string) => JSON.stringify({ ...(owner === undefined ? {} : { instanceId: owner }), token: "t" }); @@ -504,7 +507,7 @@ describe("IosSimctlDriver device set", () => { }); it("under deviceSet default foreignDevices and the removal's unused count take only devices this instance's mark does not name", async () => { - const devicesDir = `${coreSimulatorRoot}/Devices`; + const devicesDir = join(coreSimulatorRoot, "Devices"); const udids = ["A", "B", "C"].map((n) => `0000000${n}-0000-0000-0000-000000000000`); const devices = (used: boolean) => JSON.stringify({ diff --git a/src/drivers/ios/index-provenance-root.test.ts b/src/drivers/ios/index-provenance-root.test.ts index 04bfa4fa1..2b013ef1a 100644 --- a/src/drivers/ios/index-provenance-root.test.ts +++ b/src/drivers/ios/index-provenance-root.test.ts @@ -1,4 +1,5 @@ import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; import { afterEach, expect, it, describe } from "vitest"; import { OWNED_ROOT_MARKER_FILE, OwnedRootError } from "../../core/index.js"; import { ScriptedProcessRunner, MemoryFilesystem, FakeClock } from "../../ports/index.js"; @@ -9,6 +10,7 @@ import { sourcesSetPath, driverData, dataPath, + simlockDeviceRoot, plantManagedDevice, instanceId, } from "./test-slim.js"; @@ -122,7 +124,7 @@ describe("IosSimctlDriver", () => { await driver.resolveSpec({ model: "iPhone 16", osVersion: "26.5", platform: "ios" }); await expect(driver.provision(spec)).rejects.toThrow( - `ENOENT: no such file or directory, open '${dataPath}'`, + `ENOENT: no such file or directory, open '/Devices/${driverData.udid}/data'`, ); // why: A durable mark standing alone is exactly what `Doctor` reads as a foreign erase, so @@ -223,7 +225,7 @@ describe("IosSimctlDriver", () => { simlockHome: "/home/.simlock", }); - expect(driver.deviceRoot).toBe("/home/.simlock/devices/ios"); + expect(driver.deviceRoot).toBe(resolve(simlockDeviceRoot)); await expect( filesystem.exists(`/home/.simlock/devices/ios/${OWNED_ROOT_MARKER_FILE}`), ).resolves.toBe(true); diff --git a/src/drivers/ios/index-seed-provision.test.ts b/src/drivers/ios/index-seed-provision.test.ts index 0932cae3d..d5bd0be31 100644 --- a/src/drivers/ios/index-seed-provision.test.ts +++ b/src/drivers/ios/index-seed-provision.test.ts @@ -1,3 +1,4 @@ +import { join } from "node:path"; import { afterEach, expect, it, vi, describe } from "vitest"; import { DriverCrashError } from "../../core/index.js"; import { @@ -20,6 +21,7 @@ import { waitForCalls, simctl, instanceId, + unownedSourcesSet, } from "./test-slim.js"; import { UNSCOPED_LEGACY_CALLS, @@ -309,11 +311,11 @@ describe("IosSimctlDriver", () => { hung: [ "simctl", "--set", - "/home/.simlock/devices/ios-sources", + unownedSourcesSet, "clone", seedUdid, driverData.name, - `${coreSimulatorRoot}/Devices`, + join(coreSimulatorRoot, "Devices"), ], isDefault: true, seeded: true, @@ -350,7 +352,7 @@ describe("IosSimctlDriver", () => { ])( "a create or clone that answers after its limit deletes the simulator it names in its own set ($call)", async ({ act, deleteArgs, hung, isDefault, seeded, steps }) => { - const devicesDir = `${coreSimulatorRoot}/Devices`; + const devicesDir = join(coreSimulatorRoot, "Devices"); const lateUdid = "00000000-0000-0000-0000-0000000000c1"; const list = isDefault ? { args: ["simctl", "list", "-j", "devicetypes", "runtimes"], command: "xcrun" } diff --git a/src/drivers/ios/index-seed-record.test.ts b/src/drivers/ios/index-seed-record.test.ts index b37909aa6..27b4ab93a 100644 --- a/src/drivers/ios/index-seed-record.test.ts +++ b/src/drivers/ios/index-seed-record.test.ts @@ -1,3 +1,4 @@ +import { join } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { FakeClock, @@ -7,7 +8,14 @@ import { type SqliteDatabase, } from "../../ports/index.js"; import { memorySourceDatabase, plantBytes } from "./testing.js"; -import { deviceRoot, driverData, sourcesSetPath, plantManagedDevice, simctl } from "./test-slim.js"; +import { + deviceRoot, + driverData, + inPosixForm, + sourcesSetPath, + plantManagedDevice, + simctl, +} from "./test-slim.js"; import { RecordingLogger, createDriver, @@ -69,7 +77,7 @@ async function provisionNewSeed(options: { const database = await memorySourceDatabase(); const filesystem = new UnreadableFiles(); await plantManagedDevice(filesystem); - await filesystem.mkdirp(`${logsRoot}/${throwawayUdid}`); + await filesystem.mkdirp(join(logsRoot, throwawayUdid)); await options.plant(filesystem); // why: `simctl clone` gives the copy what the seed holds, and the scripted runner cannot. await filesystem.mkdirp(seedFolder); @@ -186,14 +194,14 @@ describe("IosSimctlDriver source records", () => { await plantBytes(filesystem, `${seedFolder}/data/one.db-shm`, Buffer.from("index")); await plantBytes(filesystem, `${seedFolder}/data/two.db`, SQLITE_HEADER); await plantBytes(filesystem, `${seedFolder}/data/two.db-wal`, naming); - filesystem.defineSymlink(`${seedFolder}/data/Logs`, `${logsRoot}/${lineageUdid}`); + filesystem.defineSymlink(`${seedFolder}/data/Logs`, join(logsRoot, lineageUdid)); }, }); expect(seed.error).toBeUndefined(); - expect(seed.opener.checkpoints.sort()).toEqual([ - `${seedFolder}/data/one.db`, - `${seedFolder}/data/two.db`, + expect(seed.opener.checkpoints.map(inPosixForm).sort()).toEqual([ + inPosixForm(`${seedFolder}/data/one.db`), + inPosixForm(`${seedFolder}/data/two.db`), ]); expect(storedLineage(seed.database)).toEqual({ lineage: JSON.stringify([lineageUdid]), diff --git a/src/drivers/ios/index-seed-swap.test.ts b/src/drivers/ios/index-seed-swap.test.ts index 3acd83383..0f31376f5 100644 --- a/src/drivers/ios/index-seed-swap.test.ts +++ b/src/drivers/ios/index-seed-swap.test.ts @@ -1,3 +1,4 @@ +import { join } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { DriverCrashError } from "../../core/index.js"; import { FakeClock, MemoryFilesystem, ScriptedProcessRunner } from "../../ports/index.js"; @@ -23,6 +24,10 @@ afterEach(() => { const lineageUdid = "AAAAAAAA-1111-2222-3333-BBBBBBBBBBBB"; const copyUdid = "CCCCCCCC-4444-5555-6666-DDDDDDDDDDDD"; +function escapeRegExp(text: string): string { + return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); +} + describe("IosSimctlDriver copy swap", () => { it("a copy keeps its source's lineage, swaps the lineage's UDIDs in every recorded file and link for its own before its first boot and logs the swap", async () => { class TickingWrites extends MemoryFilesystem { @@ -146,7 +151,9 @@ describe("IosSimctlDriver copy swap", () => { label: "a result of another length", lineage: ["AAAAAAAA-1111-2222-3333-BBBBBBBBBBB"], crash: true, - error: new RegExp(`${file}.*length`), + error: new RegExp( + `${escapeRegExp(`${join(deviceRoot, copyUdid)}/data/Library/note.plist`)}.*length`, + ), }, ]; for (const attempt of cases) { diff --git a/src/drivers/ios/index-seed-throwaway.test.ts b/src/drivers/ios/index-seed-throwaway.test.ts index 2e26a4bb5..cfda7c40b 100644 --- a/src/drivers/ios/index-seed-throwaway.test.ts +++ b/src/drivers/ios/index-seed-throwaway.test.ts @@ -1,3 +1,4 @@ +import { join } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { FakeClock, MemoryFilesystem, ScriptedProcessRunner } from "../../ports/index.js"; import { IosSimctlDriver } from "./index.js"; @@ -10,6 +11,7 @@ import { instanceId, plantManagedDevice, simctl, + unownedSourcesSet, } from "./test-slim.js"; import { RecordingLogger, @@ -58,10 +60,10 @@ const worlds: readonly World[] = [ }, { config: { deviceSet: "default" }, - devicesDir: `${coreSimulatorRoot}/Devices`, + devicesDir: join(coreSimulatorRoot, "Devices"), isDefault: true, label: "default set", - sourcesSet: "/home/.simlock/devices/ios-sources", + sourcesSet: unownedSourcesSet, }, ]; @@ -126,7 +128,7 @@ describe("IosSimctlDriver seed throwaway", () => { if (!world.isDefault) await plantManagedDevice(filesystem); await filesystem.mkdirp(`${world.devicesDir}/${throwawayUdid}/data`); await filesystem.mkdirp(`${world.devicesDir}/${copyUdid}/data`); - await filesystem.mkdirp(`${logsRoot}/${throwawayUdid}`); + await filesystem.mkdirp(join(logsRoot, throwawayUdid)); const driver = await IosSimctlDriver.create({ clock: new FakeClock(), coreSimulatorRoot, @@ -149,7 +151,7 @@ describe("IosSimctlDriver seed throwaway", () => { database.prepare("SELECT state, udid, throwaway_udid FROM ios_source_data").all(), world.label, ).toEqual([{ state: "ready", throwaway_udid: throwawayUdid, udid: seedUdid }]); - await expect(filesystem.exists(`${logsRoot}/${throwawayUdid}`), world.label).resolves.toBe( + await expect(filesystem.exists(join(logsRoot, throwawayUdid)), world.label).resolves.toBe( false, ); } @@ -242,7 +244,7 @@ describe("IosSimctlDriver seed throwaway", () => { await plantManagedDevice(filesystem); await plantSeedClone(filesystem); await filesystem.mkdirp(`${deviceRoot}/${copyUdid}/data`); - if (failure.absent !== true) await filesystem.mkdirp(`${logsRoot}/${throwawayUdid}`); + if (failure.absent !== true) await filesystem.mkdirp(join(logsRoot, throwawayUdid)); const driver = await IosSimctlDriver.create({ clock: new FakeClock(), database, @@ -267,7 +269,7 @@ describe("IosSimctlDriver seed throwaway", () => { database.prepare("SELECT state, udid, throwaway_udid FROM ios_source_data").all(), failure.label, ).toEqual(failure.rows); - await expect(filesystem.exists(`${logsRoot}/${throwawayUdid}`), failure.label).resolves.toBe( + await expect(filesystem.exists(join(logsRoot, throwawayUdid)), failure.label).resolves.toBe( failure.logFolder, ); expect(logger.warnings, failure.label).toEqual(failure.warnings); @@ -388,7 +390,7 @@ describe("IosSimctlDriver seed throwaway", () => { scopedRunners.push(runner); const filesystem = new MemoryFilesystem(); await plantManagedDevice(filesystem); - await filesystem.mkdirp(`${logsRoot}/${throwawayUdid}`); + await filesystem.mkdirp(join(logsRoot, throwawayUdid)); const driver = await IosSimctlDriver.create({ clock: new FakeClock(), database, @@ -407,13 +409,13 @@ describe("IosSimctlDriver seed throwaway", () => { expect(database.prepare("SELECT COUNT(*) AS n FROM ios_source_data").get(), label).toEqual({ n: 0, }); - await expect(filesystem.exists(`${logsRoot}/${throwawayUdid}`), label).resolves.toBe(false); + await expect(filesystem.exists(join(logsRoot, throwawayUdid)), label).resolves.toBe(false); } }); it("baseline.save deletes the saved-from lease's log folder", async () => { const baselineName = "simlock-baseline-device-1"; - const leaseLogs = `${logsRoot}/${driverData.udid}`; + const leaseLogs = join(logsRoot, driverData.udid); const clone = simctl("clone", driverData.udid, baselineName, sourcesSetPath); const cloneUdid = "00000000-0000-0000-0000-0000000000cc"; const cases = [ diff --git a/src/drivers/ios/physical-files-and-limits.test.ts b/src/drivers/ios/physical-files-and-limits.test.ts index 1bfbf760d..24ad3d1e6 100644 --- a/src/drivers/ios/physical-files-and-limits.test.ts +++ b/src/drivers/ios/physical-files-and-limits.test.ts @@ -1,4 +1,5 @@ import { readFileSync } from "node:fs"; +import { dirname, join } from "node:path"; import { describe, it, expect } from "vitest"; import { promiseState } from "../../test-support/promise-state.js"; import { @@ -28,7 +29,7 @@ const simctlListFixture = readFileSync( "utf8", ); -const JSON_DIR = `${SIMLOCK_HOME}/devicectl`; +const JSON_DIR = join(SIMLOCK_HOME, "devicectl"); describe("IosSimctlDriver physical handler: files and limits", () => { it("every devicectl read passes --json-output naming a new file in /devicectl/ (the driver creates it, mode 0700), and the driver reads that file and then deletes it", async () => { @@ -40,7 +41,7 @@ describe("IosSimctlDriver physical handler: files and limits", () => { expect(lab.written).toHaveLength(3); expect(new Set(lab.written).size).toBe(3); for (const path of lab.written) { - expect(path).toMatch(/^\/home\/\.simlock\/devicectl\/[^/]+$/); + expect(dirname(path)).toBe(JSON_DIR); expect(await lab.filesystem.exists(path)).toBe(false); } const directory = await lab.filesystem.lstat(JSON_DIR); diff --git a/src/drivers/ios/test-index.ts b/src/drivers/ios/test-index.ts index 893e8c0e3..979ea48d1 100644 --- a/src/drivers/ios/test-index.ts +++ b/src/drivers/ios/test-index.ts @@ -1,3 +1,4 @@ +import { join } from "node:path"; import { readFileSync } from "node:fs"; import { type ScriptedProcessExpectation, @@ -18,6 +19,7 @@ import { dataPath, instanceId, printDisabled, + inPosixForm, } from "./test-slim.js"; export const listFixture = readFileSync( @@ -333,12 +335,16 @@ export const IOS_RUNTIME_ASSET_ROOT = * as a downloaded runtime bundle of several GiB would; it measures every other path as usual. */ export class SizedFilesystem extends MemoryFilesystem { - constructor(private readonly sizes: ReadonlyMap) { + readonly #sizes: ReadonlyMap; + + constructor(sizes: ReadonlyMap) { super(); + this.#sizes = new Map([...sizes].map(([path, size]) => [inPosixForm(path), size])); } + // why: the driver joins the bundle's path with `join`, so on a Windows host it asks with backslashes. override async directorySize(path: string): Promise { - return this.sizes.get(path) ?? super.directorySize(path); + return this.#sizes.get(inPosixForm(path)) ?? super.directorySize(path); } } @@ -368,7 +374,7 @@ export const prepareFull = { mode: "full", purpose: "prepare" } as const; export const throwawayUdid = "00000000-0000-0000-0000-0000000000bb"; -export const logsRoot = "/Logs/CoreSimulator"; +export const logsRoot = join("/Logs", "CoreSimulator"); /** why: the calls that make a seed from a throwaway under the `simlock` set, in order; a test starts its script with these, after the catalog read. */ type ScriptedStep = Pick; diff --git a/src/drivers/ios/test-slim.ts b/src/drivers/ios/test-slim.ts index 9dcc060eb..8179423c4 100644 --- a/src/drivers/ios/test-slim.ts +++ b/src/drivers/ios/test-slim.ts @@ -25,6 +25,15 @@ export const deviceRoot = resolve("/Devices"); export const sourcesSetPath = join(deviceRoot, "sources"); +// why: the driver joins these under `simlockHome` with `join`, so a Windows host spells them with backslashes. +export const simlockDeviceRoot = join("/home/.simlock", "devices", "ios"); +export const unownedSourcesSet = join("/home/.simlock", "devices", "ios-sources"); + +/** why: the in-memory filesystem names a path in `/` form without a drive letter, so a test compares in that form. */ +export function inPosixForm(path: string): string { + return path.replace(/^[A-Za-z]:(?=[\\/])/, "").replaceAll("\\", "/"); +} + export const instanceId = "instance-1"; export const driverData = { @@ -129,7 +138,7 @@ export function overridesPath(udid: string): string { /** why: ADR 0083 S2: the record of named services sits beside the overrides file. */ export function recordPath(udid: string): string { - return `${overridesFolder(udid)}/simlock-managed.json`; + return join(overridesFolder(udid), "simlock-managed.json"); } export function overridesPlist(entries: Readonly>): string { From e3e5a89f6018835ae62e85603f69e3da2c6a24c4 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 17:14:03 +0100 Subject: [PATCH 6/6] fix(ios): the last fixtures that spelled a joined path with a slash (#1708) --- src/drivers/ios/index-device-set.test.ts | 4 ++-- src/drivers/ios/index-seed-record.test.ts | 19 ++++++------------- src/drivers/ios/index-seed-throwaway.test.ts | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/drivers/ios/index-device-set.test.ts b/src/drivers/ios/index-device-set.test.ts index 9b0b50114..fa024bd59 100644 --- a/src/drivers/ios/index-device-set.test.ts +++ b/src/drivers/ios/index-device-set.test.ts @@ -247,7 +247,7 @@ describe("IosSimctlDriver device set", () => { await fs.writeFileAtomic(`${ownRoot}/${OWNED_ROOT_MARKER_FILE}`, "{}"); }, { - message: `Refusing the ios device set: Simlock's own set at ${ownRoot} still holds 2 simulator(s) (${first}, ${second}). Set drivers.ios.deviceSet back to simlock, run \`simlock nuke --delete-devices\` and \`simlock doctor --purge-orphans\`, then switch again. Delete any that remain with \`xcrun simctl --set ${ownRoot} delete \`, or, for a seed in the sources set, \`xcrun simctl --set ${ownRoot}/sources delete \`.`, + message: `Refusing the ios device set: Simlock's own set at ${ownRoot} still holds 2 simulator(s) (${first}, ${second}). Set drivers.ios.deviceSet back to simlock, run \`simlock nuke --delete-devices\` and \`simlock doctor --purge-orphans\`, then switch again. Delete any that remain with \`xcrun simctl --set ${ownRoot} delete \`, or, for a seed in the sources set, \`xcrun simctl --set ${join(ownRoot, "sources")} delete \`.`, path: ownRoot, reason: "device-set-changed", }, @@ -261,7 +261,7 @@ describe("IosSimctlDriver device set", () => { await fs.writeFileAtomic(`${ownRoot}/${OWNED_ROOT_MARKER_FILE}`, "{}"); }, { - message: `Refusing the ios device set: Simlock's own set at ${ownRoot} still holds 2 simulator(s) (${first}, ${third}). Set drivers.ios.deviceSet back to simlock, run \`simlock nuke --delete-devices\` and \`simlock doctor --purge-orphans\`, then switch again. Delete any that remain with \`xcrun simctl --set ${ownRoot} delete \`, or, for a seed in the sources set, \`xcrun simctl --set ${ownRoot}/sources delete \`.`, + message: `Refusing the ios device set: Simlock's own set at ${ownRoot} still holds 2 simulator(s) (${first}, ${third}). Set drivers.ios.deviceSet back to simlock, run \`simlock nuke --delete-devices\` and \`simlock doctor --purge-orphans\`, then switch again. Delete any that remain with \`xcrun simctl --set ${ownRoot} delete \`, or, for a seed in the sources set, \`xcrun simctl --set ${join(ownRoot, "sources")} delete \`.`, path: ownRoot, reason: "device-set-changed", }, diff --git a/src/drivers/ios/index-seed-record.test.ts b/src/drivers/ios/index-seed-record.test.ts index 27b4ab93a..bb3830f96 100644 --- a/src/drivers/ios/index-seed-record.test.ts +++ b/src/drivers/ios/index-seed-record.test.ts @@ -8,14 +8,7 @@ import { type SqliteDatabase, } from "../../ports/index.js"; import { memorySourceDatabase, plantBytes } from "./testing.js"; -import { - deviceRoot, - driverData, - inPosixForm, - sourcesSetPath, - plantManagedDevice, - simctl, -} from "./test-slim.js"; +import { deviceRoot, driverData, sourcesSetPath, plantManagedDevice, simctl } from "./test-slim.js"; import { RecordingLogger, createDriver, @@ -36,7 +29,7 @@ afterEach(() => { const copyUdid = "CCCCCCCC-4444-5555-6666-DDDDDDDDDDDD"; const lineageUdid = throwawayUdid.toUpperCase(); -const seedFolder = `${sourcesSetPath}/${seedUdid}`; +const seedFolder = join(sourcesSetPath, seedUdid); const SQLITE_HEADER = Buffer.from("SQLite format 3\u0000"); const MEBIBYTE = 1_048_576; @@ -199,9 +192,9 @@ describe("IosSimctlDriver source records", () => { }); expect(seed.error).toBeUndefined(); - expect(seed.opener.checkpoints.map(inPosixForm).sort()).toEqual([ - inPosixForm(`${seedFolder}/data/one.db`), - inPosixForm(`${seedFolder}/data/two.db`), + expect(seed.opener.checkpoints.sort()).toEqual([ + `${seedFolder}/data/one.db`, + `${seedFolder}/data/two.db`, ]); expect(storedLineage(seed.database)).toEqual({ lineage: JSON.stringify([lineageUdid]), @@ -280,7 +273,7 @@ describe("IosSimctlDriver source records", () => { expect(walkFails.database.prepare("SELECT source_id FROM ios_source_data").all()).toEqual([]); expect(recorded(walkFails.database)).toEqual([]); - const baselineFolder = `${sourcesSetPath}/${baselineUdid}`; + const baselineFolder = join(sourcesSetPath, baselineUdid); const lease = driverData.udid.toUpperCase(); const fromUsedLease = await saveBaseline({ lineage: [lineageUdid], diff --git a/src/drivers/ios/index-seed-throwaway.test.ts b/src/drivers/ios/index-seed-throwaway.test.ts index cfda7c40b..05a824659 100644 --- a/src/drivers/ios/index-seed-throwaway.test.ts +++ b/src/drivers/ios/index-seed-throwaway.test.ts @@ -221,7 +221,7 @@ describe("IosSimctlDriver seed throwaway", () => { filesystem: new BrokenLogRemoval(), rows: [{ state: "ready", throwaway_udid: throwawayUdid, udid: seedUdid }], logFolder: true, - warnings: [`could not delete log folder ${logsRoot}/${throwawayUdid}: denied`], + warnings: [`could not delete log folder ${join(logsRoot, throwawayUdid)}: denied`], }, { label: "log folder absent",