From 3e55c0dce2681ef1542da5353ff43cd67ea67d34 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 08:35:56 +0100 Subject: [PATCH 1/5] =?UTF-8?q?test:=20reproduce=20#1689=20=E2=80=94=20a?= =?UTF-8?q?=20worker=20with=20no=20iOS=20driver=20reports=20iOS=20capacity?= =?UTF-8?q?=20and=20counts=20it=20in=20the=20global=20running=20limit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cli/index-status-warm-pool.test.ts | 34 ++++++++++++++++++++++++++ src/core/create-core.test.ts | 34 +++++++++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/cli/index-status-warm-pool.test.ts b/src/cli/index-status-warm-pool.test.ts index 5fb921069..2d75e91ab 100644 --- a/src/cli/index-status-warm-pool.test.ts +++ b/src/cli/index-status-warm-pool.test.ts @@ -493,3 +493,37 @@ describe("CLI text output escapes control characters in remote text", () => { }, ); }); + +describe("CLI: status of a worker with no iOS slots (#1689)", () => { + it("simlock status prints no iOS capacity line and no iOS warm reserve for a worker that reports 0 iOS devices and 0 iOS running slots", async () => { + const output = outputCapture(); + const status = { + ...EMPTY_STATUS, + capacity: { + ...EMPTY_STATUS.capacity, + global: { ...EMPTY_STATUS.capacity.global, maxRunning: 1 }, + ios: { ...EMPTY_STATUS.capacity.ios, limit: 0, maxRunning: 0 }, + }, + host: { arch: "x64", os: "Windows", osVersion: "11", tools: [] }, + warmPool: { enabled: true, reserveRunning: { android: 1, ios: 0 }, targets: [] }, + } satisfies StatusGetOutput; + + await runCli( + ["status"], + output.environmentWith({ + connectAdmin: async () => fakeClient({ getStatus: () => Promise.resolve(status) }), + }), + ); + + expect(output.stdout).toBe( + "Daemon: running (worker)\n" + + "Simlock: 0.0.0-test\n" + + `CLI: ${PACKAGE_VERSION}\n` + + "Host: Windows 11 x64\n" + + "Running global: 0 + 0 reserved/1, warm 0\n" + + "Capacity android: managed 0/1, running 0 + 0 reserved/1, warm 0\n" + + "warm pool: enabled, reserve android 1\n" + + "Queue depth: 0\n", + ); + }); +}); diff --git a/src/core/create-core.test.ts b/src/core/create-core.test.ts index 4263dde33..bd18b4675 100644 --- a/src/core/create-core.test.ts +++ b/src/core/create-core.test.ts @@ -10,6 +10,7 @@ import { MemoryLogSink, } from "../ports/index.js"; import { + buildCapacityFigures, type Config, type ConfigOverrides, type Core, @@ -35,6 +36,8 @@ async function build( readonly overrides?: ConfigOverrides; readonly sink?: MemoryLogSink; readonly withAndroid?: boolean; + /** why: a host with no iOS driver at all, as a Windows or Linux worker (#1689). */ + readonly androidOnly?: boolean; } = {}, ) { const clock = new FakeClock(1_000); @@ -49,7 +52,12 @@ async function build( platform: "ios", }); const androidDriver = new FakeDriver({ clock, platform: "android" }); - const drivers = options.withAndroid === true ? [driver, androidDriver] : [driver]; + const drivers = + options.androidOnly === true + ? [androidDriver] + : options.withAndroid === true + ? [driver, androidDriver] + : [driver]; const filesystem = new MemoryFilesystem(); const systemStats = new FakeSystemStats({ cpuCount: 8, totalRamBytes: 32 * 1024 ** 3 }); let next = 1; @@ -622,3 +630,27 @@ describe("createCore", () => { }); }); }); + +describe("createCore on a host with no iOS driver (#1689)", () => { + it("reports no iOS device or running slot, no iOS warm reserve, and a global running limit of the Android slots alone", async () => { + // why: the default resource limits on 8 CPUs and 32 GiB are 4 iOS and 2 Android, 6 in all. + const { core, registry } = await build({ + androidOnly: true, + overrides: { warmPool: { reserveRunning: { android: 1, ios: 1 } } }, + }); + + const figures = buildCapacityFigures(registry.snapshot.virtualDevices, core.capacityReader); + + expect({ + ios: { limit: figures.ios.limit, maxRunning: figures.ios.maxRunning }, + android: { limit: figures.android.limit, maxRunning: figures.android.maxRunning }, + global: { maxRunning: figures.global.maxRunning, overLimit: figures.global.overLimit }, + reserveRunning: core.warmPoolReader.figures().reserveRunning, + }).toStrictEqual({ + ios: { limit: 0, maxRunning: 0 }, + android: { limit: 2, maxRunning: 2 }, + global: { maxRunning: 2, overLimit: false }, + reserveRunning: { android: 1, ios: 0 }, + }); + }); +}); From c9213c746c03917a42875e20ac59428c7afee74a Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 08:47:57 +0100 Subject: [PATCH 2/5] fix(core): a platform with no driver on the host gets no slots, no global running share and no warm reserve (#1689) --- src/core/capacity/index.ts | 1 + src/core/capacity/serving-only.ts | 73 +++++++++++++++++++++++++++++++ src/core/create-core.ts | 8 +++- src/core/warm-pool/converger.ts | 16 +++++-- 4 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 src/core/capacity/serving-only.ts diff --git a/src/core/capacity/index.ts b/src/core/capacity/index.ts index 20bad6cb5..862e0881f 100644 --- a/src/core/capacity/index.ts +++ b/src/core/capacity/index.ts @@ -1,6 +1,7 @@ export { CapacityCoordinator } from "./coordinator.js"; export type { CapacityReservation } from "./coordinator.js"; export { buildCapacityFigures } from "./figures.js"; +export { servingOnly } from "./serving-only.js"; export { CapacityObserver, capacityChangedPayload } from "./observer.js"; export { capacityDevice, capacityDevices, plannedCapacityDevice } from "./devices.js"; export type { CapacityLimits } from "./limits.js"; diff --git a/src/core/capacity/serving-only.ts b/src/core/capacity/serving-only.ts new file mode 100644 index 000000000..1f4510f33 --- /dev/null +++ b/src/core/capacity/serving-only.ts @@ -0,0 +1,73 @@ +import type { + CapacityDecision, + CapacityDevice, + CapacityPlatform, + CapacityStrategy, + PlannedCapacityDevice, + RunningCapacity, +} from "./strategy.js"; + +const PLATFORMS: readonly CapacityPlatform[] = ["ios", "android"]; + +/** + * why: a platform with no driver on this host (iOS on Windows or Linux) can never run a device, so + * it gets no device or running slot and the global running limit counts only the platforms that can + * (#1689). A platform whose driver was refused still serves: its devices hold slots. + */ +export function servingOnly( + strategy: CapacityStrategy, + serves: (platform: CapacityPlatform) => boolean, +): CapacityStrategy { + const unserved = PLATFORMS.filter((platform) => !serves(platform)); + if (unserved.length === 0) return strategy; + const refused = (platform: CapacityPlatform): boolean => unserved.includes(platform); + + const runningCapacity = ( + devices: readonly CapacityDevice[], + reservations: readonly CapacityPlatform[], + ): RunningCapacity => { + const inner = strategy.runningCapacity(devices, reservations); + const entry = (platform: CapacityPlatform) => + refused(platform) + ? { + ...inner[platform], + maxRunning: 0, + overLimit: inner[platform].running + inner[platform].reserved > 0, + } + : inner[platform]; + const ios = entry("ios"); + const android = entry("android"); + const maxRunning = Math.min(inner.global.maxRunning, ios.maxRunning + android.maxRunning); + return { + android, + global: { + ...inner.global, + maxRunning, + overLimit: inner.global.running + inner.global.reserved > maxRunning, + }, + ios, + }; + }; + + return { + canBoot: (device, devices) => + refused(device.platform) + ? { ok: false, reason: "device-limit" } + : strategy.canBoot(device, devices), + canProvision: (device: PlannedCapacityDevice, devices) => + refused(device.platform) + ? { ok: false, reason: "device-limit" } + : strategy.canProvision(device, devices), + canReserveRunning: (platform, devices, reservations): CapacityDecision => { + if (refused(platform)) return { ok: false, reason: "platform-running-limit" }; + const { global } = runningCapacity(devices, reservations); + if (global.running + global.reserved >= global.maxRunning) { + return { ok: false, reason: "global-running-limit" }; + } + return strategy.canReserveRunning(platform, devices, reservations); + }, + deviceLimit: (platform) => (refused(platform) ? 0 : strategy.deviceLimit(platform)), + ramBudget: (devices) => strategy.ramBudget(devices), + runningCapacity, + }; +} diff --git a/src/core/create-core.ts b/src/core/create-core.ts index 9bc174ebc..ffccc2122 100644 --- a/src/core/create-core.ts +++ b/src/core/create-core.ts @@ -4,6 +4,7 @@ import type { StateDatabase } from "../state/index.js"; import { buildCapacityFigures, CapacityCoordinator, + servingOnly, capacityDevices, CapacityObserver, createCapacityStrategy, @@ -194,7 +195,12 @@ export function createCore(options: CoreOptions): Core { }; const capacity = new CapacityCoordinator( - createCapacityStrategy(options.config.capacity, options.systemStats), + servingOnly( + createCapacityStrategy(options.config.capacity, options.systemStats), + (platform) => + options.drivers.some((driver) => driver.platform === platform) || + (options.driverRejections ?? []).some((rejection) => rejection.platform === platform), + ), () => capacityObserver.changed(), memoryPressure, ); diff --git a/src/core/warm-pool/converger.ts b/src/core/warm-pool/converger.ts index 5bed31b91..fc3afa26b 100644 --- a/src/core/warm-pool/converger.ts +++ b/src/core/warm-pool/converger.ts @@ -373,13 +373,23 @@ export class WarmPool { return this.#reports; } + /** why: a platform with virtual devices off or no driver on this host holds no running slot for idle devices (ADR 0084 §2, #1689). */ + #reserveOnServedPlatforms(): { readonly ios: number; readonly android: number } { + return reserveOnVirtualPlatforms( + this.options.config.reserveRunning, + (platform) => + this.options.catalog.virtualDevices(platform) && this.options.hasDriver(platform), + ); + } + /** * What `status`, `doctor` and the console read: the pool as the last pass left it. With the * pool off, or before a pass has run, every configured target as the operator wrote it: short * `disabled` with the pool off, and with no reason before the first pass. */ figures(): WarmPoolFigures { - const { enabled, reserveRunning, targets } = this.options.config; + const { enabled, targets } = this.options.config; + const reserveRunning = this.#reserveOnServedPlatforms(); const reports = enabled && this.#passed ? this.#figured @@ -663,9 +673,7 @@ export class WarmPool { config: { enabled: this.options.config.enabled, maxConcurrentBoots: this.options.config.maxConcurrentBoots, - reserveRunning: reserveOnVirtualPlatforms(this.options.config.reserveRunning, (platform) => - this.options.catalog.virtualDevices(platform), - ), + reserveRunning: this.#reserveOnServedPlatforms(), shutdownAfterMs: this.options.idle.shutdownAfterMs, }, devices, From 234932845bd4de7dbacef8a165c68ba63a2d9045 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 08:48:28 +0100 Subject: [PATCH 3/5] fix(cli): status prints no capacity line and no warm reserve for a platform the host cannot run (#1689) --- src/cli/format.ts | 29 ++++++++++++++----- src/core/capacity/AGENTS.md | 1 + .../content/docs/docs/worker/monitoring.mdx | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/cli/format.ts b/src/cli/format.ts index 3fc36e4a3..2e3d17fc7 100644 --- a/src/cli/format.ts +++ b/src/cli/format.ts @@ -281,10 +281,12 @@ export function formatStatus(status: StatusGetOutput, now: number, cliVersion?: ].join("\n"); } const globalLine = `Running global: ${capacity.global.running} + ${capacity.global.reserved} reserved/${capacity.global.maxRunning}, warm ${capacity.global.warm}${capacity.global.overLimit ? " (over limit)" : ""}`; - const capacityLines = (["ios", "android"] as const).map((platform) => { - const usage = capacity[platform]; - return `Capacity ${platform}: managed ${usage.used}/${usage.limit}, running ${usage.running} + ${usage.reserved} reserved/${usage.maxRunning}, warm ${usage.warm}${usage.overLimit ? " (over limit)" : ""}${usage.atRamBudget ? " (at RAM budget)" : ""}`; - }); + const capacityLines = PLATFORMS.filter((platform) => !absentPlatform(capacity[platform])).map( + (platform) => { + const usage = capacity[platform]; + return `Capacity ${platform}: managed ${usage.used}/${usage.limit}, running ${usage.running} + ${usage.reserved} reserved/${usage.maxRunning}, warm ${usage.warm}${usage.overLimit ? " (over limit)" : ""}${usage.atRamBudget ? " (at RAM budget)" : ""}`; + }, + ); const ramBudget = capacity.ramBudget; const ramLines = ramBudget === undefined @@ -299,7 +301,7 @@ export function formatStatus(status: StatusGetOutput, now: number, cliVersion?: const warmPoolLines = status.warmPool === undefined || daemon.mode === "gateway" ? [] - : formatWarmPool(status.warmPool); + : formatWarmPool(status.warmPool, capacity); const deviceLines = devices.map((device) => { const markers = [ device.foreignStateDetectedAt === undefined ? undefined : "foreign state change", @@ -351,10 +353,23 @@ function deviceKind(device: NonNullable[number]): st return `mode ${esc(String(device.mode))}, serves default mode: ${device.servesDefaultMode ? "yes" : "no"}${baseline}`; } -function formatWarmPool(warmPool: NonNullable): string[] { +const PLATFORMS = ["ios", "android"] as const; + +/** why: a worker with no driver for a platform reports 0 devices and 0 running slots for it (#1689); it has no line. */ +function absentPlatform(usage: { readonly limit: number; readonly maxRunning: number }): boolean { + return usage.limit === 0 && usage.maxRunning === 0; +} + +function formatWarmPool( + warmPool: NonNullable, + capacity: NonNullable, +): string[] { const { enabled, reserveRunning, targets } = warmPool; + const reserve = PLATFORMS.filter((platform) => !absentPlatform(capacity[platform])) + .map((platform) => `${platform} ${reserveRunning[platform]}`) + .join(" "); return [ - `warm pool: ${enabled ? "enabled" : "disabled"}, reserve ios ${reserveRunning.ios} android ${reserveRunning.android}`, + `warm pool: ${enabled ? "enabled" : "disabled"}, reserve ${reserve}`, ...targets.map((target) => { const name = esc( [ diff --git a/src/core/capacity/AGENTS.md b/src/core/capacity/AGENTS.md index 03db1c439..c230ffb48 100644 --- a/src/core/capacity/AGENTS.md +++ b/src/core/capacity/AGENTS.md @@ -17,6 +17,7 @@ Does: how many virtual devices may exist and run at once — limits, RAM budget, - Release is idempotent. Every take and release calls the observer. - `CapacityObserver.changed()` runs after every registry commit and reservation change, and emits `capacity.changed` only when the payload differs from the last one. It is silent until `start()` in `core.converge`, which emits once. - Top-level `limits` and `ramBudget` are folded into `capacity.config` under `resource`, and ignored with a warning under `fixed` (`core/config-role-checks.ts`). +- `servingOnly` wraps the strategy: a platform with no driver and no refused driver on the host gets 0 devices and 0 running slots, and the global running limit is capped at the other platforms' slots (#1689). - Adding a strategy is a directory under `strategies/` and one line in its `index.ts`. ## Known gaps diff --git a/website/src/content/docs/docs/worker/monitoring.mdx b/website/src/content/docs/docs/worker/monitoring.mdx index 2f1beec62..edd7a7d52 100644 --- a/website/src/content/docs/docs/worker/monitoring.mdx +++ b/website/src/content/docs/docs/worker/monitoring.mdx @@ -47,7 +47,7 @@ What each line means: | `Memory pressure` | Shown only while the worker has paused warming or new devices because the host is short of memory: the step, when it began (local time) and why, either `pressure warn` or the available memory against its floor. See `memoryPressure.*` in the [configuration reference](/simlock/docs/reference/configuration). | | `History` | Shown only when something is wrong with the event history. See [Troubleshooting](/simlock/docs/worker/troubleshooting#the-event-history-is-not-written). | | `Running global` | Devices running now, plus slots held for devices that are booting, out of the most that may run at once, and how many of the running ones are warm. | -| `Capacity ios` / `Capacity android` | Per platform: `managed` is devices that exist out of the device limit; `running` is as above. `(over limit)` means more devices exist than the limit allows, for example after you lowered it. `(at RAM budget)` means no more devices fit in the memory set aside for them. | +| `Capacity ios` / `Capacity android` | Per platform: `managed` is devices that exist out of the device limit; `running` is as above. `(over limit)` means more devices exist than the limit allows, for example after you lowered it. `(at RAM budget)` means no more devices fit in the memory set aside for them. A platform the host cannot run, such as iOS on Windows or Linux, has no line, no warm-pool reserve and no share of the global limit; `status --json` still lists it with every figure 0. | | `RAM budget` | Memory the running devices use out of the budget. Shown only with the `resource` capacity strategy. | | `warm pool` | Whether the warm pool is on, the running slots it keeps free per platform, and one row per target and learned kind, with where it came from (`configured` or `learned`): how many devices you want ready, how many are ready, how many are booting, and why a target is short. | | `Device` | One line per device: its id, state, and its device mode, or `physical` and its class for an enrolled physical device. Markers in brackets flag a problem, such as `quarantined (purge retry 2, ...)` or `stalled`. | From 9912abd7ab1414238ee8fb9a17e55052b8665ba5 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 08:51:17 +0100 Subject: [PATCH 4/5] test: fixtures with an iOS driver only serve Android where their claim needs it (#1689) --- src/daemon/dispatcher-leases-capacity.test.ts | 8 +++- .../dispatcher-leases-device-mode.test.ts | 2 + src/daemon/dispatcher-status.test.ts | 1 + src/daemon/server-requests.test.ts | 3 +- .../create-leasing-waiting-reasons.test.ts | 40 +++++++++++++++---- 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/src/daemon/dispatcher-leases-capacity.test.ts b/src/daemon/dispatcher-leases-capacity.test.ts index 195202fbf..7268111aa 100644 --- a/src/daemon/dispatcher-leases-capacity.test.ts +++ b/src/daemon/dispatcher-leases-capacity.test.ts @@ -1,5 +1,7 @@ import { describe, expect, it } from "vitest"; import { type Config } from "../core/index.js"; +import { FakeDriver } from "../core/testing.js"; +import { FakeClock } from "../ports/index.js"; import { classifyError } from "./error-code.js"; import { HOST_SYSTEM, buildDispatcher, flush, gibibyte, session } from "./test-dispatcher.js"; @@ -47,7 +49,11 @@ describe("Dispatcher: a noWait lease.request refused for capacity names the chec holds: true, }, ] as const)("rejects NO_CAPACITY with details.capacityReason $reason at $name", async (row) => { - const { dispatcher } = await buildDispatcher({ capacity: row.capacity }); + // why: a host serves a platform only with a driver for it (#1689), so the global limit above the iOS one needs an Android driver. + const { dispatcher } = await buildDispatcher({ + capacity: row.capacity, + extraDrivers: [new FakeDriver({ clock: new FakeClock(1_000), platform: "android" })], + }); if (row.holds) await dispatcher.dispatch("lease.request", ios, holder()); await expect( diff --git a/src/daemon/dispatcher-leases-device-mode.test.ts b/src/daemon/dispatcher-leases-device-mode.test.ts index f5dfcae02..b9291f70f 100644 --- a/src/daemon/dispatcher-leases-device-mode.test.ts +++ b/src/daemon/dispatcher-leases-device-mode.test.ts @@ -216,6 +216,8 @@ describe("Dispatcher: device mode on every surface", () => { it("status.get on a daemon whose pool is off carries enabled false, the reserve and every configured target with ready 0, booting 0 and short disabled", async () => { const { dispatcher } = await buildDispatcher({ + // why: a platform without a driver on the host reserves nothing (#1689), and the reserve below names Android. + extraDrivers: [new FakeDriver({ clock: new FakeClock(1_000), platform: "android" })], warmPool: { enabled: false, reserveRunning: { android: 1, ios: 0 }, diff --git a/src/daemon/dispatcher-status.test.ts b/src/daemon/dispatcher-status.test.ts index 5d216ea74..f0a61d9af 100644 --- a/src/daemon/dispatcher-status.test.ts +++ b/src/daemon/dispatcher-status.test.ts @@ -439,6 +439,7 @@ describe("Dispatcher: status.get RAM budget", () => { describe("atRamBudget", () => { async function withIosDevices(count: number) { const built = await buildDispatcher({ + extraDrivers: [new FakeDriver({ clock: new FakeClock(1_000), platform: "android" })], capacity: { strategy: "resource", config: { diff --git a/src/daemon/server-requests.test.ts b/src/daemon/server-requests.test.ts index f0007456e..7be282e7d 100644 --- a/src/daemon/server-requests.test.ts +++ b/src/daemon/server-requests.test.ts @@ -24,7 +24,8 @@ describe("DaemonServer", () => { ok: true, payload: { capacity: { - global: { maxRunning: 2, overLimit: false, reserved: 0, running: 0, warm: 0 }, + // why: the harness has an iOS driver only, so the global limit is its one iOS slot (#1689). + global: { maxRunning: 1, overLimit: false, reserved: 0, running: 0, warm: 0 }, ios: { limit: 1, maxRunning: 1, diff --git a/src/leasing/create-leasing-waiting-reasons.test.ts b/src/leasing/create-leasing-waiting-reasons.test.ts index c962ca83f..d716faa12 100644 --- a/src/leasing/create-leasing-waiting-reasons.test.ts +++ b/src/leasing/create-leasing-waiting-reasons.test.ts @@ -11,6 +11,16 @@ describe("createLeasing: a waiting request says why it is not placed (#636)", () ios: { maxDevices: 2, maxRunning: 1 }, maxRunning: 2, }; + // why: a host serves a platform only with a driver for it (#1689), so a global limit above the iOS one needs an Android driver. + const androidDriver = () => new FakeDriver({ clock: new FakeClock(1_000), platform: "android" }); + const bothPlatforms = () => { + const driver = new FakeDriver({ + availableOsVersions: ["26.5"], + clock: new FakeClock(1_000), + platform: "ios", + }); + return { driver, drivers: [driver, androidDriver()] }; + }; const asking = (requesterId: string, more: Record = {}) => ({ ownerId: requesterId, requesterId, @@ -24,7 +34,7 @@ describe("createLeasing: a waiting request says why it is not placed (#636)", () })); it("lists a queued request at the iOS running limit as platform-running-limit and one behind it as behind-earlier-request, and stores no reason", async () => { - const harness = await createHarness({ limits: runningLimit }); + const harness = await createHarness({ limits: runningLimit, ...bothPlatforms() }); await harness.engine.request(request, asking("holder")); void harness.engine.request(request, asking("head")); void harness.engine.request(request, asking("behind")); @@ -40,7 +50,7 @@ describe("createLeasing: a waiting request says why it is not placed (#636)", () }); it("follows the latest attempt: when the head is granted, the request behind it lists its own new reason", async () => { - const harness = await createHarness({ limits: runningLimit }); + const harness = await createHarness({ limits: runningLimit, ...bothPlatforms() }); const holder = await harness.engine.request(request, asking("holder")); const head = harness.engine.request(request, asking("head")); void harness.engine.request(request, asking("behind")); @@ -56,7 +66,7 @@ describe("createLeasing: a waiting request says why it is not placed (#636)", () }); it("cancelling the queued head makes the request behind it plan again and list its own reason", async () => { - const harness = await createHarness({ limits: runningLimit }); + const harness = await createHarness({ limits: runningLimit, ...bothPlatforms() }); await harness.engine.request(request, asking("holder")); const head = harness.engine.request(request, asking("head")); void harness.engine.request(request, asking("behind")); @@ -130,7 +140,11 @@ describe("createLeasing: a waiting request says why it is not placed (#636)", () latencyMs: { provision: 50 }, platform: "ios", }); - const harness = await createHarness({ driver, limits: runningLimit }); + const harness = await createHarness({ + driver, + drivers: [driver, androidDriver()], + limits: runningLimit, + }); const provisioning = harness.engine .request(request, asking("provisioning")) .catch((error: unknown) => error); @@ -170,7 +184,11 @@ describe("createLeasing: a waiting request says why it is not placed (#636)", () platform: "ios", }); driver.failOn("provision", 1, new DriverCrashError("simulator exited")); - const harness = await createHarness({ driver, limits: runningLimit }); + const harness = await createHarness({ + driver, + drivers: [driver, androidDriver()], + limits: runningLimit, + }); const failing = harness.engine .request(request, asking("failing")) .catch((error: unknown) => error); @@ -201,7 +219,11 @@ describe("createLeasing: a waiting request says why it is not placed (#636)", () latencyMs: { resolveSpec: 50 }, platform: "ios", }); - const harness = await createHarness({ driver, limits: runningLimit }); + const harness = await createHarness({ + driver, + drivers: [driver, androidDriver()], + limits: runningLimit, + }); const resolving = harness.engine .request(request, asking("resolving")) .catch((error: unknown) => error); @@ -261,7 +283,11 @@ describe("createLeasing: a waiting request says why it is not placed (#636)", () const clock = new FakeClock(1_000); const driver = new FakeDriver({ availableOsVersions: ["26.5"], clock, platform: "ios" }); driver.failOn("shutdown", 1, new DriverCrashError("cannot stop victim")); - const harness = await createHarness({ driver, limits: runningLimit }); + const harness = await createHarness({ + driver, + drivers: [driver, androidDriver()], + limits: runningLimit, + }); await seedReady(harness); void harness.engine.request({ ...request, model: "iPhone SE" }, asking("new-spec")); From 747a57006f2e3d79af1886cd1b475dc132c97a7b Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 18 Nov 2026 09:06:58 +0100 Subject: [PATCH 5/5] fix(cli): status prints no reserve clause when no platform is served; doctor skips the reserve of a platform with no driver; drop a manual line the code says (#1689) --- src/cli/format.ts | 2 +- src/cli/index-status-warm-pool.test.ts | 78 ++++++++++++++--------- src/core/capacity/AGENTS.md | 1 - src/core/doctor-warm-pool-targets.test.ts | 20 +++++- src/core/doctor.ts | 4 +- 5 files changed, 71 insertions(+), 34 deletions(-) diff --git a/src/cli/format.ts b/src/cli/format.ts index 2e3d17fc7..e8b0a4dce 100644 --- a/src/cli/format.ts +++ b/src/cli/format.ts @@ -369,7 +369,7 @@ function formatWarmPool( .map((platform) => `${platform} ${reserveRunning[platform]}`) .join(" "); return [ - `warm pool: ${enabled ? "enabled" : "disabled"}, reserve ${reserve}`, + `warm pool: ${enabled ? "enabled" : "disabled"}${reserve === "" ? "" : `, reserve ${reserve}`}`, ...targets.map((target) => { const name = esc( [ diff --git a/src/cli/index-status-warm-pool.test.ts b/src/cli/index-status-warm-pool.test.ts index 2d75e91ab..62fdb46ac 100644 --- a/src/cli/index-status-warm-pool.test.ts +++ b/src/cli/index-status-warm-pool.test.ts @@ -495,35 +495,53 @@ describe("CLI text output escapes control characters in remote text", () => { }); describe("CLI: status of a worker with no iOS slots (#1689)", () => { - it("simlock status prints no iOS capacity line and no iOS warm reserve for a worker that reports 0 iOS devices and 0 iOS running slots", async () => { - const output = outputCapture(); - const status = { - ...EMPTY_STATUS, - capacity: { - ...EMPTY_STATUS.capacity, - global: { ...EMPTY_STATUS.capacity.global, maxRunning: 1 }, - ios: { ...EMPTY_STATUS.capacity.ios, limit: 0, maxRunning: 0 }, - }, - host: { arch: "x64", os: "Windows", osVersion: "11", tools: [] }, - warmPool: { enabled: true, reserveRunning: { android: 1, ios: 0 }, targets: [] }, - } satisfies StatusGetOutput; - - await runCli( - ["status"], - output.environmentWith({ - connectAdmin: async () => fakeClient({ getStatus: () => Promise.resolve(status) }), - }), - ); + it.each([ + [ + "iOS", + { ios: { limit: 0, maxRunning: 0 } }, + "Capacity android: managed 0/1, running 0 + 0 reserved/1, warm 0\n" + + "warm pool: enabled, reserve android 1\n", + ], + [ + "both platforms", + { android: { limit: 0, maxRunning: 0 }, ios: { limit: 0, maxRunning: 0 } }, + "warm pool: enabled\n", + ], + ])( + "simlock status prints no capacity line and no warm reserve for a platform a worker reports 0 devices and 0 running slots for: %s", + async (_name, absent, lines) => { + const output = outputCapture(); + const status = { + ...EMPTY_STATUS, + capacity: { + ...EMPTY_STATUS.capacity, + global: { ...EMPTY_STATUS.capacity.global, maxRunning: 1 }, + ios: { ...EMPTY_STATUS.capacity.ios, ...absent.ios }, + android: { + ...EMPTY_STATUS.capacity.android, + ...("android" in absent ? absent.android : {}), + }, + }, + host: { arch: "x64", os: "Windows", osVersion: "11", tools: [] }, + warmPool: { enabled: true, reserveRunning: { android: 1, ios: 0 }, targets: [] }, + } satisfies StatusGetOutput; - expect(output.stdout).toBe( - "Daemon: running (worker)\n" + - "Simlock: 0.0.0-test\n" + - `CLI: ${PACKAGE_VERSION}\n` + - "Host: Windows 11 x64\n" + - "Running global: 0 + 0 reserved/1, warm 0\n" + - "Capacity android: managed 0/1, running 0 + 0 reserved/1, warm 0\n" + - "warm pool: enabled, reserve android 1\n" + - "Queue depth: 0\n", - ); - }); + await runCli( + ["status"], + output.environmentWith({ + connectAdmin: async () => fakeClient({ getStatus: () => Promise.resolve(status) }), + }), + ); + + expect(output.stdout).toBe( + "Daemon: running (worker)\n" + + "Simlock: 0.0.0-test\n" + + `CLI: ${PACKAGE_VERSION}\n` + + "Host: Windows 11 x64\n" + + "Running global: 0 + 0 reserved/1, warm 0\n" + + lines + + "Queue depth: 0\n", + ); + }, + ); }); diff --git a/src/core/capacity/AGENTS.md b/src/core/capacity/AGENTS.md index c230ffb48..03db1c439 100644 --- a/src/core/capacity/AGENTS.md +++ b/src/core/capacity/AGENTS.md @@ -17,7 +17,6 @@ Does: how many virtual devices may exist and run at once — limits, RAM budget, - Release is idempotent. Every take and release calls the observer. - `CapacityObserver.changed()` runs after every registry commit and reservation change, and emits `capacity.changed` only when the payload differs from the last one. It is silent until `start()` in `core.converge`, which emits once. - Top-level `limits` and `ramBudget` are folded into `capacity.config` under `resource`, and ignored with a warning under `fixed` (`core/config-role-checks.ts`). -- `servingOnly` wraps the strategy: a platform with no driver and no refused driver on the host gets 0 devices and 0 running slots, and the global running limit is capped at the other platforms' slots (#1689). - Adding a strategy is a directory under `strategies/` and one line in its `index.ts`. ## Known gaps diff --git a/src/core/doctor-warm-pool-targets.test.ts b/src/core/doctor-warm-pool-targets.test.ts index 30c0b8239..a2a2cf56a 100644 --- a/src/core/doctor-warm-pool-targets.test.ts +++ b/src/core/doctor-warm-pool-targets.test.ts @@ -51,6 +51,7 @@ describe("Doctor: warm pool targets", () => { readonly figures?: ReturnType; readonly driver?: Omit[0], "clock">; readonly virtualDevices?: Partial>; + readonly platforms?: readonly ("ios" | "android")[]; }): Promise { const clock = new FakeClock(10_000); const eventBus = new EventBus(clock); @@ -70,7 +71,9 @@ describe("Doctor: warm pool targets", () => { targets: options.targets ?? [], }, }, - drivers: [new FakeDriver({ clock, platform: "ios", ...options.driver })], + drivers: (options.platforms ?? ["ios", "android"]).map( + (platform) => new FakeDriver({ clock, platform, ...options.driver }), + ), eventBus, registry, warmPool: { @@ -206,6 +209,21 @@ describe("Doctor: warm pool targets", () => { expect(await ask(false)).toStrictEqual([]); }); + it("leaves the reserveRunning of a platform with no driver on this host out of the room the targets are checked against", async () => { + const ask = (platforms: readonly ("ios" | "android")[]) => + findings({ + limit: { global: 2 }, + platforms, + reserve: { android: 2, ios: 0 }, + targets: [{ count: 2, model: "iPhone 17", platform: "ios" }], + }); + + expect(await ask(["ios", "android"])).toStrictEqual([ + expect.objectContaining({ reason: "over-limit", target: "all targets" }), + ]); + expect(await ask(["ios"])).toStrictEqual([]); + }); + it("reports a target short with unknown-model as unreachable", async () => { const found = await findings({ figures: figuresOf([{ model: "iPhone 99", osVersion: "26.0", short: "unknown-model" }]), diff --git a/src/core/doctor.ts b/src/core/doctor.ts index 7ac3bedc9..7b8fb37cd 100644 --- a/src/core/doctor.ts +++ b/src/core/doctor.ts @@ -555,7 +555,9 @@ export class Doctor { { reserveRunning: reserveOnVirtualPlatforms( this.options.config.warmPool.reserveRunning, - (platform) => (platform === "ios" ? ios : android).virtualDevices, + (platform) => + (platform === "ios" ? ios : android).virtualDevices && + this.options.drivers.some((driver) => driver.platform === platform), ), }, limits,