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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/drivers/ios/AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Resolve and boot:
- Named services (ADR 0083): `exclude` beats `include` beats a category; `simlock-managed.json` records the names, so one dropped from both is written back on. A baseline saved before it keeps a dropped name off; `include` it.
- Slim `except` (ADR 0066): an excepted category's labels are written `false`; an unknown name is `BAD_REQUEST`; a kept label not read back throws `KeptCategoriesError`.
- A recovery boot writes no slim overrides and reads nothing back. DeviceHub clipboard isolation is configured before preparation and recovery boots; ready default-set simulators reboot under the lease claim before a grant. Active leases at upgrade keep clipboard sync until a later boot or lease end.
- The overrides folder lives outside the device set (`launchdOverridesRoot`), so `destroy` removes it itself after `simctl delete`.
- `launchdOverridesRoot` is outside the device set: `destroy` and each seed deletion remove their folder after `simctl delete`.
- After every boot and before the readback, `runAfterBoot` (`boot-courtesies.ts`) runs the volume step, then the window step. Each only reports its failure (`onSilenceFailed`, `onWindowFailed`).
- Volume (`ios.simulator.audio: false`): apps play at volume 0. A baseline source is not silenced.
- Window (`ios.simulator.headless: false`): DeviceHub is opened in the background and leaves started devices running when it quits. Only a non-zero exit of that open means it is missing: Simulator.app is then opened, detached.
Expand Down
121 changes: 121 additions & 0 deletions src/drivers/ios/index-seed-sources.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ import {
driverData,
waitForCalls,
FaultyFilesystem,
overridesFolder,
overridesPath,
overridesPlist,
plantManagedDevice,
simctl,
} from "./test-slim.js";
Expand Down Expand Up @@ -740,6 +743,124 @@ describe("IosSimctlDriver", () => {
});
});

it("deleting a baseline's simulator removes its launchd overrides folder, through destroySource, the leftover sweep and a failed save, and a failed delete keeps it", async () => {
const baselineUdid = "00000000-0000-0000-0000-0000000000bb";
const kind = { deviceTypeId: driverData.deviceTypeId, kind: "baseline" as const };
const cases = [
{
name: "destroySource",
plant: { ...kind, runtimeId: driverData.runtimeId, udid: baselineUdid },
steps: [
{ match: listInvocation, result: { code: 0, stderr: "", stdout: listFixture } },
{ match: sourcesSimctl("shutdown", baselineUdid) },
{ match: sourcesSimctl("delete", baselineUdid) },
],
act: async (driver: Awaited<ReturnType<typeof createDriver>>) => {
const [listed] = await driver.listSources();
await driver.destroySource(listed?.id ?? "");
},
},
{
name: "the sweep of another process's making row",
plant: {
...kind,
maker: "earlier-process",
runtimeId: driverData.runtimeId,
state: "making" as const,
udid: baselineUdid,
},
steps: [
{ match: sourcesSimctl("shutdown", baselineUdid) },
{ match: sourcesSimctl("delete", baselineUdid) },
],
act: async (driver: Awaited<ReturnType<typeof createDriver>>) => {
await driver.listSources();
},
},
{
name: "a save that fails after the clone",
plant: undefined,
steps: [
{ match: listInvocation, result: { code: 0, stderr: "", stdout: listFixture } },
{ match: simctl("shutdown", driverData.udid) },
{
match: simctl(
"clone",
driverData.udid,
"simlock-baseline-device-1",
`${deviceRoot}/sources`,
),
result: { code: 0, stderr: "", stdout: `${baselineUdid}\n` },
},
{ match: sourcesSimctl("shutdown", baselineUdid) },
{ match: sourcesSimctl("delete", baselineUdid) },
],
act: async (
driver: Awaited<ReturnType<typeof createDriver>>,
database: Awaited<ReturnType<typeof memorySourceDatabase>>,
) => {
database.exec(
"CREATE TRIGGER refuse_ready BEFORE UPDATE OF state ON ios_source_data BEGIN SELECT RAISE(ABORT, 'source row locked'); END",
);
await expect(
driver.saveSource({
address: driverData.udid,
deviceId: driverData.udid,
driverData,
physical: false,
}),
).rejects.toMatchObject({ message: expect.stringContaining("source row locked") });
},
},
{
name: "destroySource whose delete fails",
plant: { ...kind, runtimeId: driverData.runtimeId, udid: baselineUdid },
steps: [
{ match: listInvocation, result: { code: 0, stderr: "", stdout: listFixture } },
{ match: sourcesSimctl("shutdown", baselineUdid) },
{
match: sourcesSimctl("delete", baselineUdid),
result: { code: 1, stderr: "busy", stdout: "" },
},
],
act: async (driver: Awaited<ReturnType<typeof createDriver>>) => {
const [listed] = await driver.listSources();
await expect(driver.destroySource(listed?.id ?? "")).rejects.toBeInstanceOf(
DriverCrashError,
);
},
},
];
const outcomes: Record<string, { deleted: boolean; folderKept: boolean }> = {};
for (const { name, plant, steps, act } of cases) {
const filesystem = new MemoryFilesystem();
await plantManagedDevice(filesystem);
const database = await memorySourceDatabase();
if (plant !== undefined) plantSource(database, plant);
// why: the save copies the lease's folder to the clone; a planted baseline already has its own.
const from = plant === undefined ? driverData.udid : baselineUdid;
await filesystem.mkdirp(overridesFolder(from));
await filesystem.writeFileAtomic(overridesPath(from), overridesPlist({ "a.b": true }));
const runner = new ScriptedProcessRunner(steps);
const driver = await createDriver(runner, new FakeClock(), filesystem, database);

await act(driver, database);

outcomes[name] = {
deleted: runner.calls.some(
(call) => call.args.at(-2) === "delete" && call.args.at(-1) === baselineUdid,
),
folderKept: await filesystem.exists(overridesFolder(baselineUdid)),
};
}
expect(outcomes).toEqual({
destroySource: { deleted: true, folderKept: false },
"the sweep of another process's making row": { deleted: true, folderKept: false },
"a save that fails after the clone": { deleted: true, folderKept: false },
"destroySource whose delete fails": { deleted: true, folderKept: true },
});
});

it("destroySource refuses an id that names no source, without running simctl", async () => {
const runner = new ScriptedProcessRunner([]);
const driver = await createDriver(runner);
Expand Down
2 changes: 2 additions & 0 deletions src/drivers/ios/seeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@ export class Seeds {
async #deleteSeedSimulator(udid: string): Promise<void> {
await this.#simctl.bestEffortShutdown(udid, this.#sourcesSet);
await this.#deleteIn(udid, this.#sourcesSet);
// why: the overrides folder lives outside the device set, so `simctl delete` leaves it; a failed delete throws before this and keeps it.
await this.#slimBoot.removeOverrides(udid);
}

/** why: ADR 0076 §1: the throwaway lives in the device set and is deleted only through the `making` row that names it (ADR 0001 §6), with its log folder, which `simctl delete` leaves behind. */
Expand Down
Loading