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
43 changes: 43 additions & 0 deletions src/core/component-installer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,49 @@ 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("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) => {
Expand Down
13 changes: 10 additions & 3 deletions src/core/component-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,17 @@ 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);
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 ` +
Expand Down
Loading