From 93ae5fd41f700ec405a5fc0e0b7dddf862e386a3 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 2 Oct 2026 19:06:41 +0200 Subject: [PATCH 1/3] =?UTF-8?q?test:=20reproduce=20#263=20=E2=80=94=20a=20?= =?UTF-8?q?removal=20of=20a=20recorded=20version=20that=20is=20no=20longer?= =?UTF-8?q?=20installed=20says=20another=20one=20is=20installed=20now?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/component-installer.test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/core/component-installer.test.ts b/src/core/component-installer.test.ts index 36c1138a8..232d15a8a 100644 --- a/src/core/component-installer.test.ts +++ b/src/core/component-installer.test.ts @@ -1397,6 +1397,32 @@ describe("ComponentInstaller.remove", () => { expect(harness.registry.snapshot.components).toHaveLength(1); }); + it("refuses a record whose version is no longer installed saying none is installed, and a record whose version was installed again saying that one is not Simlock's, in a removal and a dry run alike", async () => { + // 26.5 is on the machine with another receipt; 25.0 is not on the machine at all. + const harness = await createHarness(); + for (const version of ["25.0", "26.5"]) { + await harness.registry.recordComponent({ + installedAt: 1_000, + platform: "ios", + receipt: { install: "1", version }, + version, + }); + } + + for (const dryRun of [false, true]) { + await expect(harness.installer.remove(removeIos("25.0", { dryRun }))).rejects.toMatchObject({ + message: "No ios 25.0 is installed now, so there is nothing to remove", + name: "ComponentNotOwnedError", + }); + await expect(harness.installer.remove(removeIos("26.5", { dryRun }))).rejects.toMatchObject({ + message: + "The ios 26.5 installed now is not the one Simlock installed, so Simlock will not remove it", + name: "ComponentNotOwnedError", + }); + } + expect(removals(harness.ios)).toEqual([]); + }); + it.each(["provisioning", "ready", "leased", "reclaiming", "quarantined", "shutdown"] as const)( "refuses a component a %s registry device uses with ComponentInUseError naming the count, and never calls removeComponent", async (state) => { From d980630daa8781c16f10c5a57f5ee1b10bf0f868 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 2 Oct 2026 19:12:48 +0200 Subject: [PATCH 2/3] fix(core): a removal of a recorded version that is no longer installed says none is installed --- src/core/component-installer.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/component-installer.ts b/src/core/component-installer.ts index b4152f306..68d8c5a79 100644 --- a/src/core/component-installer.ts +++ b/src/core/component-installer.ts @@ -388,9 +388,16 @@ export class ComponentInstaller { `Simlock has no record of installing ${platform} ${version}, so it will not remove it`, ); } - const listed = (await this.#listDriver(driver)).find((entry) => - sameReceipt(entry.receipt, record.receipt), - ); + const components = await this.#listDriver(driver); + // A record outlives a removal that failed after the driver deleted the component (ADR 0010 + // §5): with no such version on the machine, the refusal must not name one. + if (!components.some((entry) => entry.listing.version === version)) { + throw new ComponentNotOwnedError( + platform, + `No ${platform} ${version} is installed now, so there is nothing to remove`, + ); + } + const listed = components.find((entry) => sameReceipt(entry.receipt, record.receipt)); if (listed === undefined) { throw new ComponentNotOwnedError( platform, From 3f833b9f1ea5545bc674af4564679764b0cf6d32 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 2 Oct 2026 19:22:10 +0200 Subject: [PATCH 3/3] fix(core): only a removal that matches no receipt asks whether the version is installed --- src/core/component-installer.test.ts | 17 +++++++++++++++++ src/core/component-installer.ts | 16 ++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/core/component-installer.test.ts b/src/core/component-installer.test.ts index 232d15a8a..435b1db91 100644 --- a/src/core/component-installer.test.ts +++ b/src/core/component-installer.test.ts @@ -1423,6 +1423,23 @@ describe("ComponentInstaller.remove", () => { expect(removals(harness.ios)).toEqual([]); }); + it("removes a component whose receipt matches the record even when the listing names its version differently", async () => { + // The driver lists 26.5 with the receipt Simlock recorded under 26.5.0. + const harness = await createHarness(); + const receipt = { preinstalled: "26.5" }; + await harness.registry.recordComponent({ + installedAt: 1_000, + platform: "ios", + receipt, + version: "26.5.0", + }); + + await expect(harness.installer.remove(removeIos("26.5.0"))).resolves.toMatchObject({ + outcome: "removed", + }); + expect(removals(harness.ios)).toEqual([receipt]); + }); + it.each(["provisioning", "ready", "leased", "reclaiming", "quarantined", "shutdown"] as const)( "refuses a component a %s registry device uses with ComponentInUseError naming the count, and never calls removeComponent", async (state) => { diff --git a/src/core/component-installer.ts b/src/core/component-installer.ts index 68d8c5a79..692dfa4c3 100644 --- a/src/core/component-installer.ts +++ b/src/core/component-installer.ts @@ -389,16 +389,16 @@ export class ComponentInstaller { ); } const components = await this.#listDriver(driver); - // A record outlives a removal that failed after the driver deleted the component (ADR 0010 - // §5): with no such version on the machine, the refusal must not name one. - if (!components.some((entry) => entry.listing.version === version)) { - throw new ComponentNotOwnedError( - platform, - `No ${platform} ${version} is installed now, so there is nothing to remove`, - ); - } const listed = components.find((entry) => sameReceipt(entry.receipt, record.receipt)); if (listed === undefined) { + // A record outlives a removal that failed after the driver deleted the component (ADR 0010 + // §5): with no such version on the machine, the refusal must not name one. + if (!components.some((entry) => entry.listing.version === version)) { + throw new ComponentNotOwnedError( + platform, + `No ${platform} ${version} is installed now, so there is nothing to remove`, + ); + } throw new ComponentNotOwnedError( platform, `The ${platform} ${version} installed now is not the one Simlock installed, so Simlock ` +