Skip to content
19 changes: 9 additions & 10 deletions src/core/device-root.test.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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();

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion src/core/instance-identity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/core/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down Expand Up @@ -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 });
}
Expand Down
5 changes: 4 additions & 1 deletion src/drivers/ios/devicectl-passthrough.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { resolve } from "node:path";

import { describe, expect, it } from "vitest";

import { PassthroughRefusedError } from "../../core/index.js";
import { FakeClock, MemoryFilesystem, ScriptedProcessRunner } from "../../ports/index.js";
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";
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/ios/index-component-install.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]);
}
});

Expand Down
28 changes: 16 additions & 12 deletions src/drivers/ios/index-device-set.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { join } from "node:path";
import { describe, it, expect } from "vitest";
import {
OWNED_ROOT_MARKER_FILE,
Expand All @@ -16,10 +17,13 @@ import { memorySourceDatabase } from "./testing.js";
import {
driverData,
deviceRoot,
sourcesSetPath,
simctlArgs,
deviceHubEdit,
plantManagedDevice,
instanceId,
simlockDeviceRoot,
unownedSourcesSet,
} from "./test-slim.js";
import {
PHYSICAL_DEVICE,
Expand Down Expand Up @@ -58,14 +62,14 @@ 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" },
`${coreSimulatorRoot}/Devices`,
join(coreSimulatorRoot, "Devices"),
false,
"/home/.simlock/devices/ios-sources",
unownedSourcesSet,
true,
],
] as const)(
Expand Down Expand Up @@ -222,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)}`,
);
Expand All @@ -243,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 <udid>\`, or, for a seed in the sources set, \`xcrun simctl --set ${ownRoot}/sources delete <udid>\`.`,
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 <udid>\`, or, for a seed in the sources set, \`xcrun simctl --set ${join(ownRoot, "sources")} delete <udid>\`.`,
path: ownRoot,
reason: "device-set-changed",
},
Expand All @@ -257,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 <udid>\`, or, for a seed in the sources set, \`xcrun simctl --set ${ownRoot}/sources delete <udid>\`.`,
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 <udid>\`, or, for a seed in the sources set, \`xcrun simctl --set ${join(ownRoot, "sources")} delete <udid>\`.`,
path: ownRoot,
reason: "device-set-changed",
},
Expand Down Expand Up @@ -359,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) => {
Expand Down Expand Up @@ -397,7 +401,7 @@ describe("IosSimctlDriver device set", () => {
[
"simctl",
"--set",
scoped ? `${deviceRoot}/sources` : "/home/.simlock/devices/ios-sources",
scoped ? sourcesSetPath : unownedSourcesSet,
"clone",
seedUdid,
driverData.name,
Expand Down Expand Up @@ -433,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" });
Expand Down Expand Up @@ -503,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({
Expand Down
4 changes: 2 additions & 2 deletions src/drivers/ios/index-list-components.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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]);
}
});

Expand Down
4 changes: 2 additions & 2 deletions src/drivers/ios/index-passthrough.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]);
}
});

Expand Down
17 changes: 13 additions & 4 deletions src/drivers/ios/index-provenance-root.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
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";
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,
simlockDeviceRoot,
plantManagedDevice,
instanceId,
} from "./test-slim.js";
import {
PHYSICAL_DEVICE,
UNSCOPED_LEGACY_CALLS,
Expand Down Expand Up @@ -47,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]);
}
});

Expand Down Expand Up @@ -115,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
Expand Down Expand Up @@ -216,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);
Expand Down
3 changes: 2 additions & 1 deletion src/drivers/ios/index-remove-component.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { promiseState } from "../../test-support/promise-state.js";
import { memorySourceDatabase, plantSource } from "./testing.js";
import {
deviceRoot,
sourcesSetPath,
simctl,
driverData,
waitForCalls,
Expand Down Expand Up @@ -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]);
}
});

Expand Down
14 changes: 7 additions & 7 deletions src/drivers/ios/index-save-source-lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IosSimctlDriver } from "./index.js";
import { memorySourceDatabase } from "./testing.js";
import {
deviceRoot,
sourcesSetPath,
driverData,
simctl,
plantManagedDevice,
Expand Down Expand Up @@ -55,22 +56,21 @@ 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]);
}
});

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();
Expand All @@ -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 } },
{
Expand Down Expand Up @@ -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([
Expand Down
Loading
Loading