From e8994507f6c8ba1a53d717f34f43ad0c639d5cd3 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Mon, 9 Nov 2026 22:50:08 +0100 Subject: [PATCH 1/4] =?UTF-8?q?test:=20reproduce=20#1476=20=E2=80=94=20bas?= =?UTF-8?q?eline=20remove=20answers=20a=20plain=20error,=20not=20DEVICE=5F?= =?UTF-8?q?BUSY,=20while=20a=20copy=20is=20reclaiming?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/daemon/dispatcher.test.ts | 47 +++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/daemon/dispatcher.test.ts b/src/daemon/dispatcher.test.ts index 0fa32a088..9abfe23a3 100644 --- a/src/daemon/dispatcher.test.ts +++ b/src/daemon/dispatcher.test.ts @@ -1288,6 +1288,53 @@ describe("Dispatcher: baseline.remove", () => { }); }); +describe("Dispatcher: baseline.remove while a copy is reclaiming", () => { + it("refuses the remove with DEVICE_BUSY naming the reclaiming device, and removes the baseline once its reclaim ends", async () => { + const { clock, dispatcher, registry } = await buildDispatcher({ + driverOptions: { latencyMs: { shutdown: 1_000 } }, + }); + const admin = session({ role: "admin" }); + const operator = await dispatcher.dispatch( + "lease.request", + { model: "iPhone 17 Pro", osVersion: "26.5", platform: "ios" }, + session(), + ); + await dispatcher.dispatch( + "baseline.save", + { leaseId: operator.lease.id, name: "checkout" }, + admin, + ); + const copy = await dispatcher.dispatch( + "lease.request", + { baseline: "checkout", platform: "ios" }, + session(), + ); + const stateOf = (): string | undefined => + registry.snapshot.devices.find((device) => device.id === copy.device.id)?.state; + await dispatcher.dispatch("lease.release", { leaseId: copy.lease.id }, session()); + await vi.waitFor(() => expect(stateOf()).toBe("reclaiming")); + + const refusal = await dispatcher.dispatch("baseline.remove", { name: "checkout" }, admin).then( + () => undefined, + (rejected: unknown) => rejected, + ); + + expect(refusal).toMatchObject({ + code: "DEVICE_BUSY", + details: { id: copy.device.id, reason: "reclaiming" }, + }); + await vi.waitFor(() => { + clock.advance(1_000); + expect(stateOf()).toBe("deleted"); + }); + expect(await dispatcher.dispatch("baseline.remove", { name: "checkout" }, admin)).toEqual({ + deletedDevices: [], + name: "checkout", + versions: [1], + }); + }); +}); + describe("Dispatcher: doctor baseline sources", () => { it("lists a baseline's source with its name and version, a ready baseline source no row names as an orphan only doctor --purge-orphans deletes, and finds a stale baseline", async () => { const { dispatcher, driver, eventBus, registry } = await buildDispatcher(); From 658d748dbd607cf08a90ef28bd87ae6896a0e610 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 10 Nov 2026 08:48:06 +0100 Subject: [PATCH 2/4] fix(core): baseline remove while a copy is reclaiming answers DEVICE_BUSY (#1476) --- src/core/baselines.ts | 7 +++++-- src/daemon/dispatcher.ts | 6 ++++++ src/http/admin-declarations.ts | 2 +- website/src/content/docs/docs/reference/cli.mdx | 2 +- website/src/content/docs/docs/reference/errors.mdx | 2 +- website/src/content/docs/docs/worker/baselines.mdx | 3 ++- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/core/baselines.ts b/src/core/baselines.ts index 25eed2171..1d1d7a13f 100644 --- a/src/core/baselines.ts +++ b/src/core/baselines.ts @@ -8,6 +8,7 @@ import { NoDriverError } from "./driver-catalog.js"; import type { ReclaimCoordinator, SavedSource } from "./reclaim-coordinator.js"; import type { Registry, ReleasedLease } from "./registry.js"; import type { DeviceOperationClaim, DeviceOperationClaims } from "./device-operation-claims.js"; +import { DeviceBusyError } from "./physical-enrollment.js"; import type { ManagedDeviceLifecycle } from "./managed-device-lifecycle.js"; import type { SerializedDecision } from "./serialized-decision.js"; @@ -100,7 +101,7 @@ export interface BaselineServiceOptions { save: (released: ReleasedLease) => Promise, ): Promise; }; - readonly claims: Pick; + readonly claims: Pick; readonly decisions: SerializedDecision; readonly eventBus: Pick; readonly lifecycle: Pick; @@ -432,7 +433,9 @@ export class BaselineService { const claim = this.options.claims.tryClaim(device.id, "cleanup"); if (claim === undefined) { for (const held of claimed) held.claim.release(); - throw new Error(`Device ${device.id} made from baseline ${name} is busy`); + const reclaiming = + device.state === "reclaiming" || this.options.claims.claim(device.id)?.kind === "reclaim"; + throw new DeviceBusyError(device.id, reclaiming ? "reclaiming" : "busy"); } claimed.push({ claim, device }); } diff --git a/src/daemon/dispatcher.ts b/src/daemon/dispatcher.ts index 36b46b490..e7b5122cc 100644 --- a/src/daemon/dispatcher.ts +++ b/src/daemon/dispatcher.ts @@ -1065,6 +1065,12 @@ export class Dispatcher { if (error instanceof UnknownBaselineError) { throw new DispatchError("UNKNOWN_BASELINE", error.message, { name: error.baselineName }); } + if (error instanceof DeviceBusyError) { + throw new DispatchError("DEVICE_BUSY", error.message, { + id: error.id, + reason: error.reason, + }); + } throw error; } }; diff --git a/src/http/admin-declarations.ts b/src/http/admin-declarations.ts index 26e4222af..289467dd6 100644 --- a/src/http/admin-declarations.ts +++ b/src/http/admin-declarations.ts @@ -199,7 +199,7 @@ export const baselineRemoveRoute = declareRoute({ errors: { 400: ["BAD_REQUEST"], 404: ["UNKNOWN_BASELINE", "UNKNOWN_WORKER"], - 409: ["BASELINE_IN_USE", "WORKER_NOT_CONNECTED"], + 409: ["BASELINE_IN_USE", "DEVICE_BUSY", "WORKER_NOT_CONNECTED"], }, }); diff --git a/website/src/content/docs/docs/reference/cli.mdx b/website/src/content/docs/docs/reference/cli.mdx index a79899bdc..eede5e3d9 100644 --- a/website/src/content/docs/docs/reference/cli.mdx +++ b/website/src/content/docs/docs/reference/cli.mdx @@ -655,7 +655,7 @@ Remove baseline login v1? [y/N] y Removed baseline login v1. ``` -When idle devices were made from it, the line ends with ` Deleted 2 idle devices made from it.` An unknown name is `UNKNOWN_BASELINE`; a baseline a lease uses is refused with `BASELINE_IN_USE` and nothing is deleted. With `--worker wrk_a` the prompt and the line end in ` from wrk_a`. +When idle devices were made from it, the line ends with ` Deleted 2 idle devices made from it.` An unknown name is `UNKNOWN_BASELINE`; a baseline a lease uses is refused with `BASELINE_IN_USE` and nothing is deleted. A copy that is being cleaned up or held by another operation is refused with `DEVICE_BUSY`; run the command again once it ends. With `--worker wrk_a` the prompt and the line end in ` from wrk_a`. ## simlock device diff --git a/website/src/content/docs/docs/reference/errors.mdx b/website/src/content/docs/docs/reference/errors.mdx index 32de67421..e6babc6b4 100644 --- a/website/src/content/docs/docs/reference/errors.mdx +++ b/website/src/content/docs/docs/reference/errors.mdx @@ -74,7 +74,7 @@ In a script, check `code`, not the message: the wording of a message can change, | Code | Exit | HTTP | Meaning | What to do | | --- | --- | --- | --- | --- | | `DEVICE_NOT_ENROLLABLE` | 12 | 422 | `device add` of a device that cannot be enrolled. The reason is one of: not connected, network only, not trusted, Developer Mode off, OS too old, unsupported kind, locked, unreadable, a simulator or emulator, or enrolled on the other platform. | Fix what the message names (connect it by USB, trust this computer, turn on Developer Mode, unlock it) and run `device add` again. | -| `DEVICE_BUSY` | 11 | 409 | `device add` or `device remove` of a device that is leased, being cleaned, or held by another operation. | Try again once that ends. | +| `DEVICE_BUSY` | 11 | 409 | `device add`, `device remove` or `baseline remove` of a device that is leased, being cleaned, or held by another operation. | Try again once that ends. | | `UNKNOWN_DEVICE` | 12 | 404 | `device remove` of an ID that is not an enrolled device. | Check the ID with `simlock list --devices`. | ## Tunnels diff --git a/website/src/content/docs/docs/worker/baselines.mdx b/website/src/content/docs/docs/worker/baselines.mdx index d6d453e65..c477df398 100644 --- a/website/src/content/docs/docs/worker/baselines.mdx +++ b/website/src/content/docs/docs/worker/baselines.mdx @@ -85,7 +85,7 @@ Remove baseline login v1? [y/N] y Removed baseline login v1. ``` -This deletes every version of `login` and the idle copies made from it. If an agent is still using a copy, Simlock refuses with `BASELINE_IN_USE` and names the lease; remove it after that lease ends. Pass `--yes` to skip the question, for example in a script. +This deletes every version of `login` and the idle copies made from it. If an agent is still using a copy, Simlock refuses with `BASELINE_IN_USE` and names the lease; remove it after that lease ends. If a copy is still being cleaned up after its lease ended, Simlock refuses with `DEVICE_BUSY`; try again in a moment. Pass `--yes` to skip the question, for example in a script. `simlock nuke --delete-devices` removes every baseline on the worker. @@ -97,6 +97,7 @@ This deletes every version of `login` and the idle copies made from it. If an ag | `UNKNOWN_BASELINE` | No baseline on this worker has that name. | Check the name with `simlock baseline list`. | | `BASELINE_STALE` | The runtime or image the baseline needs is gone. | Install it again, or save a new version. | | `BASELINE_IN_USE` | `remove` was refused because a lease uses a copy. | Wait for that lease to end, then remove. | +| `DEVICE_BUSY` | `remove` was refused because a copy is being cleaned up or another operation holds it. | Try again in a moment. | | `FORBIDDEN` | The session does not have the admin role. | Run the command as an admin. | `simlock doctor` lists each baseline's files on disk under `sources`. Files that belong to no baseline are reported as orphans; only `simlock doctor --purge-orphans` deletes them. From 681eee2258b57bba61eea65d278a4ffde8cb3a4d Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 10 Nov 2026 08:57:37 +0100 Subject: [PATCH 3/4] fix(core): baseline remove's busy reason reads the device state; test the busy case; docs name DEVICE_BUSY (#1476) --- src/core/baselines.ts | 6 +- src/daemon/dispatcher.test.ts | 59 +++++++++++++++++++ .../content/docs/docs/reference/errors.mdx | 2 +- .../using-devices/programmatic-client.mdx | 2 +- 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/core/baselines.ts b/src/core/baselines.ts index 1d1d7a13f..69aef6550 100644 --- a/src/core/baselines.ts +++ b/src/core/baselines.ts @@ -101,7 +101,7 @@ export interface BaselineServiceOptions { save: (released: ReleasedLease) => Promise, ): Promise; }; - readonly claims: Pick; + readonly claims: Pick; readonly decisions: SerializedDecision; readonly eventBus: Pick; readonly lifecycle: Pick; @@ -433,9 +433,7 @@ export class BaselineService { const claim = this.options.claims.tryClaim(device.id, "cleanup"); if (claim === undefined) { for (const held of claimed) held.claim.release(); - const reclaiming = - device.state === "reclaiming" || this.options.claims.claim(device.id)?.kind === "reclaim"; - throw new DeviceBusyError(device.id, reclaiming ? "reclaiming" : "busy"); + throw new DeviceBusyError(device.id, device.state === "reclaiming" ? "reclaiming" : "busy"); } claimed.push({ claim, device }); } diff --git a/src/daemon/dispatcher.test.ts b/src/daemon/dispatcher.test.ts index 9abfe23a3..74136882e 100644 --- a/src/daemon/dispatcher.test.ts +++ b/src/daemon/dispatcher.test.ts @@ -1335,6 +1335,65 @@ describe("Dispatcher: baseline.remove while a copy is reclaiming", () => { }); }); +describe("Dispatcher: baseline.remove while a copy is being made", () => { + it("refuses the remove with DEVICE_BUSY and reason busy, naming the device, until the copy is leased", async () => { + const { clock, dispatcher, registry } = await buildDispatcher({ + driverOptions: { latencyMs: { makeReady: 1_000 } }, + }); + const admin = session({ role: "admin" }); + const finish = async (pending: Promise): Promise => { + let done = false; + void pending.then( + () => (done = true), + () => (done = true), + ); + await vi.waitFor(() => { + clock.advance(1_000); + expect(done).toBe(true); + }); + return pending; + }; + const operator = await finish( + dispatcher.dispatch( + "lease.request", + { model: "iPhone 17 Pro", osVersion: "26.5", platform: "ios" }, + session(), + ), + ); + await dispatcher.dispatch( + "baseline.save", + { leaseId: operator.lease.id, name: "checkout" }, + admin, + ); + const copyRequest = dispatcher.dispatch( + "lease.request", + { baseline: "checkout", platform: "ios" }, + session(), + ); + await vi.waitFor(() => + expect( + registry.snapshot.virtualDevices.some( + (device) => device.spec.baseline?.name === "checkout" && device.state !== "deleted", + ), + ).toBe(true), + ); + const making = registry.snapshot.virtualDevices.find( + (device) => device.spec.baseline?.name === "checkout" && device.state !== "deleted", + ); + + const refusal = await dispatcher.dispatch("baseline.remove", { name: "checkout" }, admin).then( + () => undefined, + (rejected: unknown) => rejected, + ); + + expect(refusal).toMatchObject({ + code: "DEVICE_BUSY", + details: { id: making?.id, reason: "busy" }, + }); + await finish(copyRequest); + }); +}); + describe("Dispatcher: doctor baseline sources", () => { it("lists a baseline's source with its name and version, a ready baseline source no row names as an orphan only doctor --purge-orphans deletes, and finds a stale baseline", async () => { const { dispatcher, driver, eventBus, registry } = await buildDispatcher(); diff --git a/website/src/content/docs/docs/reference/errors.mdx b/website/src/content/docs/docs/reference/errors.mdx index e6babc6b4..d617373a6 100644 --- a/website/src/content/docs/docs/reference/errors.mdx +++ b/website/src/content/docs/docs/reference/errors.mdx @@ -74,7 +74,7 @@ In a script, check `code`, not the message: the wording of a message can change, | Code | Exit | HTTP | Meaning | What to do | | --- | --- | --- | --- | --- | | `DEVICE_NOT_ENROLLABLE` | 12 | 422 | `device add` of a device that cannot be enrolled. The reason is one of: not connected, network only, not trusted, Developer Mode off, OS too old, unsupported kind, locked, unreadable, a simulator or emulator, or enrolled on the other platform. | Fix what the message names (connect it by USB, trust this computer, turn on Developer Mode, unlock it) and run `device add` again. | -| `DEVICE_BUSY` | 11 | 409 | `device add`, `device remove` or `baseline remove` of a device that is leased, being cleaned, or held by another operation. | Try again once that ends. | +| `DEVICE_BUSY` | 11 | 409 | `device add` or `device remove` of a device that is leased, being cleaned, or held by another operation. `baseline remove` of a baseline whose copy is being cleaned up or held by another operation (a leased copy gets `BASELINE_IN_USE`). | Try again once that ends. | | `UNKNOWN_DEVICE` | 12 | 404 | `device remove` of an ID that is not an enrolled device. | Check the ID with `simlock list --devices`. | ## Tunnels diff --git a/website/src/content/docs/docs/using-devices/programmatic-client.mdx b/website/src/content/docs/docs/using-devices/programmatic-client.mdx index a48712ecd..65f342863 100644 --- a/website/src/content/docs/docs/using-devices/programmatic-client.mdx +++ b/website/src/content/docs/docs/using-devices/programmatic-client.mdx @@ -202,7 +202,7 @@ Each of these does what the matching `simlock` command does: | `listBaselines()` | `simlock baseline list` | `{ baselines }`: the newest version of each name. On a gateway it covers every worker, each entry with its `workerId`. | | `removeBaseline({ name, workerId? })` | `simlock baseline remove` | `{ name, versions, deletedDevices }`. On a gateway, `workerId` is required and names the worker to remove it from. | -The baseline calls can throw `UNKNOWN_LEASE`, `BASELINE_SAVE_FAILED`, `UNKNOWN_BASELINE` and `BASELINE_IN_USE`; see [Baselines](/simlock/docs/worker/baselines). +The baseline calls can throw `UNKNOWN_LEASE`, `BASELINE_SAVE_FAILED`, `UNKNOWN_BASELINE` and `BASELINE_IN_USE`; `removeBaseline` can also throw `DEVICE_BUSY`; see [Baselines](/simlock/docs/worker/baselines). ### Update the daemon From 8b09309ace9c081e886ef189cbd23999ff9031a7 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Tue, 10 Nov 2026 09:19:31 +0100 Subject: [PATCH 4/4] fix(daemon): keep dispatcher files within the size limit; baseline remove tests move to dispatcher-baselines.test.ts (#1476) --- src/daemon/dispatcher-baselines.test.ts | 109 ++++++++++++++++++++++++ src/daemon/dispatcher.test.ts | 106 ----------------------- src/daemon/dispatcher.ts | 8 +- 3 files changed, 110 insertions(+), 113 deletions(-) create mode 100644 src/daemon/dispatcher-baselines.test.ts diff --git a/src/daemon/dispatcher-baselines.test.ts b/src/daemon/dispatcher-baselines.test.ts new file mode 100644 index 000000000..b6278b8fe --- /dev/null +++ b/src/daemon/dispatcher-baselines.test.ts @@ -0,0 +1,109 @@ +import { describe, expect, it, vi } from "vitest"; + +import { buildDispatcher, session } from "./test-dispatcher.js"; + +describe("Dispatcher: baseline.remove while a copy is reclaiming", () => { + it("refuses the remove with DEVICE_BUSY naming the reclaiming device, and removes the baseline once its reclaim ends", async () => { + const { clock, dispatcher, registry } = await buildDispatcher({ + driverOptions: { latencyMs: { shutdown: 1_000 } }, + }); + const admin = session({ role: "admin" }); + const operator = await dispatcher.dispatch( + "lease.request", + { model: "iPhone 17 Pro", osVersion: "26.5", platform: "ios" }, + session(), + ); + await dispatcher.dispatch( + "baseline.save", + { leaseId: operator.lease.id, name: "checkout" }, + admin, + ); + const copy = await dispatcher.dispatch( + "lease.request", + { baseline: "checkout", platform: "ios" }, + session(), + ); + const stateOf = (): string | undefined => + registry.snapshot.devices.find((device) => device.id === copy.device.id)?.state; + await dispatcher.dispatch("lease.release", { leaseId: copy.lease.id }, session()); + await vi.waitFor(() => expect(stateOf()).toBe("reclaiming")); + + const refusal = await dispatcher.dispatch("baseline.remove", { name: "checkout" }, admin).then( + () => undefined, + (rejected: unknown) => rejected, + ); + + expect(refusal).toMatchObject({ + code: "DEVICE_BUSY", + details: { id: copy.device.id, reason: "reclaiming" }, + }); + await vi.waitFor(() => { + clock.advance(1_000); + expect(stateOf()).toBe("deleted"); + }); + expect(await dispatcher.dispatch("baseline.remove", { name: "checkout" }, admin)).toEqual({ + deletedDevices: [], + name: "checkout", + versions: [1], + }); + }); +}); + +describe("Dispatcher: baseline.remove while a copy is being made", () => { + it("refuses the remove with DEVICE_BUSY and reason busy, naming the device, until the copy is leased", async () => { + const { clock, dispatcher, registry } = await buildDispatcher({ + driverOptions: { latencyMs: { makeReady: 1_000 } }, + }); + const admin = session({ role: "admin" }); + const finish = async (pending: Promise): Promise => { + let done = false; + void pending.then( + () => (done = true), + () => (done = true), + ); + await vi.waitFor(() => { + clock.advance(1_000); + expect(done).toBe(true); + }); + return pending; + }; + const operator = await finish( + dispatcher.dispatch( + "lease.request", + { model: "iPhone 17 Pro", osVersion: "26.5", platform: "ios" }, + session(), + ), + ); + await dispatcher.dispatch( + "baseline.save", + { leaseId: operator.lease.id, name: "checkout" }, + admin, + ); + const copyRequest = dispatcher.dispatch( + "lease.request", + { baseline: "checkout", platform: "ios" }, + session(), + ); + await vi.waitFor(() => + expect( + registry.snapshot.virtualDevices.some( + (device) => device.spec.baseline?.name === "checkout" && device.state !== "deleted", + ), + ).toBe(true), + ); + const making = registry.snapshot.virtualDevices.find( + (device) => device.spec.baseline?.name === "checkout" && device.state !== "deleted", + ); + + const refusal = await dispatcher.dispatch("baseline.remove", { name: "checkout" }, admin).then( + () => undefined, + (rejected: unknown) => rejected, + ); + + expect(refusal).toMatchObject({ + code: "DEVICE_BUSY", + details: { id: making?.id, reason: "busy" }, + }); + await finish(copyRequest); + }); +}); diff --git a/src/daemon/dispatcher.test.ts b/src/daemon/dispatcher.test.ts index 74136882e..0fa32a088 100644 --- a/src/daemon/dispatcher.test.ts +++ b/src/daemon/dispatcher.test.ts @@ -1288,112 +1288,6 @@ describe("Dispatcher: baseline.remove", () => { }); }); -describe("Dispatcher: baseline.remove while a copy is reclaiming", () => { - it("refuses the remove with DEVICE_BUSY naming the reclaiming device, and removes the baseline once its reclaim ends", async () => { - const { clock, dispatcher, registry } = await buildDispatcher({ - driverOptions: { latencyMs: { shutdown: 1_000 } }, - }); - const admin = session({ role: "admin" }); - const operator = await dispatcher.dispatch( - "lease.request", - { model: "iPhone 17 Pro", osVersion: "26.5", platform: "ios" }, - session(), - ); - await dispatcher.dispatch( - "baseline.save", - { leaseId: operator.lease.id, name: "checkout" }, - admin, - ); - const copy = await dispatcher.dispatch( - "lease.request", - { baseline: "checkout", platform: "ios" }, - session(), - ); - const stateOf = (): string | undefined => - registry.snapshot.devices.find((device) => device.id === copy.device.id)?.state; - await dispatcher.dispatch("lease.release", { leaseId: copy.lease.id }, session()); - await vi.waitFor(() => expect(stateOf()).toBe("reclaiming")); - - const refusal = await dispatcher.dispatch("baseline.remove", { name: "checkout" }, admin).then( - () => undefined, - (rejected: unknown) => rejected, - ); - - expect(refusal).toMatchObject({ - code: "DEVICE_BUSY", - details: { id: copy.device.id, reason: "reclaiming" }, - }); - await vi.waitFor(() => { - clock.advance(1_000); - expect(stateOf()).toBe("deleted"); - }); - expect(await dispatcher.dispatch("baseline.remove", { name: "checkout" }, admin)).toEqual({ - deletedDevices: [], - name: "checkout", - versions: [1], - }); - }); -}); - -describe("Dispatcher: baseline.remove while a copy is being made", () => { - it("refuses the remove with DEVICE_BUSY and reason busy, naming the device, until the copy is leased", async () => { - const { clock, dispatcher, registry } = await buildDispatcher({ - driverOptions: { latencyMs: { makeReady: 1_000 } }, - }); - const admin = session({ role: "admin" }); - const finish = async (pending: Promise): Promise => { - let done = false; - void pending.then( - () => (done = true), - () => (done = true), - ); - await vi.waitFor(() => { - clock.advance(1_000); - expect(done).toBe(true); - }); - return pending; - }; - const operator = await finish( - dispatcher.dispatch( - "lease.request", - { model: "iPhone 17 Pro", osVersion: "26.5", platform: "ios" }, - session(), - ), - ); - await dispatcher.dispatch( - "baseline.save", - { leaseId: operator.lease.id, name: "checkout" }, - admin, - ); - const copyRequest = dispatcher.dispatch( - "lease.request", - { baseline: "checkout", platform: "ios" }, - session(), - ); - await vi.waitFor(() => - expect( - registry.snapshot.virtualDevices.some( - (device) => device.spec.baseline?.name === "checkout" && device.state !== "deleted", - ), - ).toBe(true), - ); - const making = registry.snapshot.virtualDevices.find( - (device) => device.spec.baseline?.name === "checkout" && device.state !== "deleted", - ); - - const refusal = await dispatcher.dispatch("baseline.remove", { name: "checkout" }, admin).then( - () => undefined, - (rejected: unknown) => rejected, - ); - - expect(refusal).toMatchObject({ - code: "DEVICE_BUSY", - details: { id: making?.id, reason: "busy" }, - }); - await finish(copyRequest); - }); -}); - describe("Dispatcher: doctor baseline sources", () => { it("lists a baseline's source with its name and version, a ready baseline source no row names as an orphan only doctor --purge-orphans deletes, and finds a stale baseline", async () => { const { dispatcher, driver, eventBus, registry } = await buildDispatcher(); diff --git a/src/daemon/dispatcher.ts b/src/daemon/dispatcher.ts index e7b5122cc..2f74967ae 100644 --- a/src/daemon/dispatcher.ts +++ b/src/daemon/dispatcher.ts @@ -1065,13 +1065,7 @@ export class Dispatcher { if (error instanceof UnknownBaselineError) { throw new DispatchError("UNKNOWN_BASELINE", error.message, { name: error.baselineName }); } - if (error instanceof DeviceBusyError) { - throw new DispatchError("DEVICE_BUSY", error.message, { - id: error.id, - reason: error.reason, - }); - } - throw error; + throw describeEnrollmentError(error); } };