From f94168ac6812bf112ad0de1eb402cb9573a0c60e Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 24 Nov 2026 13:43:09 +0100 Subject: [PATCH 1/4] test: deleting a baseline's simulator removes its launchd overrides folder (#1780) --- src/drivers/ios/index-seed-sources.test.ts | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/src/drivers/ios/index-seed-sources.test.ts b/src/drivers/ios/index-seed-sources.test.ts index d923e9e0f..e00b4a0b3 100644 --- a/src/drivers/ios/index-seed-sources.test.ts +++ b/src/drivers/ios/index-seed-sources.test.ts @@ -14,6 +14,9 @@ import { driverData, waitForCalls, FaultyFilesystem, + overridesFolder, + overridesPath, + overridesPlist, plantManagedDevice, simctl, } from "./test-slim.js"; @@ -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>) => { + 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>) => { + 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>, + database: Awaited>, + ) => { + 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>) => { + const [listed] = await driver.listSources(); + await expect(driver.destroySource(listed?.id ?? "")).rejects.toBeInstanceOf( + DriverCrashError, + ); + }, + }, + ]; + const outcomes: Record = {}; + 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); From 26dd52e37afa064b89832a6fff7617488dce1b84 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 24 Nov 2026 13:43:23 +0100 Subject: [PATCH 2/4] fix(ios): deleting a baseline's simulator removes its launchd overrides folder (#1780) --- src/drivers/ios/AGENTS.md | 2 +- src/drivers/ios/seeds.ts | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/drivers/ios/AGENTS.md b/src/drivers/ios/AGENTS.md index e32c479ca..ae55d6cf4 100644 --- a/src/drivers/ios/AGENTS.md +++ b/src/drivers/ios/AGENTS.md @@ -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`. +- The overrides folder lives outside the device set (`launchdOverridesRoot`), so `destroy` and every seed deletion remove it themselves 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. diff --git a/src/drivers/ios/seeds.ts b/src/drivers/ios/seeds.ts index 8a88cfd39..74b7a99b6 100644 --- a/src/drivers/ios/seeds.ts +++ b/src/drivers/ios/seeds.ts @@ -466,6 +466,8 @@ export class Seeds { async #deleteSeedSimulator(udid: string): Promise { 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. */ From e475e76a026f0744186e4e5ee89c627c82129fa7 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 24 Nov 2026 13:43:48 +0100 Subject: [PATCH 3/4] docs(ios): fit the manual's size cap (#1780) --- src/drivers/ios/AGENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/ios/AGENTS.md b/src/drivers/ios/AGENTS.md index ae55d6cf4..988a01d3a 100644 --- a/src/drivers/ios/AGENTS.md +++ b/src/drivers/ios/AGENTS.md @@ -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` and every seed deletion remove it themselves after `simctl delete`. +- The overrides folder is outside the device set (`launchdOverridesRoot`): `destroy` and each seed deletion remove it 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. From d60f79eaae0ac0cf8bdfd1860381e83ee4ab9575 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 24 Nov 2026 13:43:55 +0100 Subject: [PATCH 4/4] docs(ios): fit the manual's size cap (#1780) --- src/drivers/ios/AGENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/ios/AGENTS.md b/src/drivers/ios/AGENTS.md index 988a01d3a..7b9746474 100644 --- a/src/drivers/ios/AGENTS.md +++ b/src/drivers/ios/AGENTS.md @@ -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 is outside the device set (`launchdOverridesRoot`): `destroy` and each seed deletion remove it 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.