From 028b8bc72dfe81b280a10868ca8c651673413a1f Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sat, 17 Oct 2026 08:23:19 +0200 Subject: [PATCH 1/5] =?UTF-8?q?test:=20reproduce=20#406=20=E2=80=94=20cons?= =?UTF-8?q?ole=20fleet=20totals=20count=20a=20starting=20worker's=20leases?= =?UTF-8?q?=20and=20devices=20as=20zero?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/model/overview.test.ts | 85 +++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/ui/src/model/overview.test.ts b/ui/src/model/overview.test.ts index 76239e186..58e57e4d7 100644 --- a/ui/src/model/overview.test.ts +++ b/ui/src/model/overview.test.ts @@ -61,6 +61,21 @@ const fleet = [ worker("down-1", [], { connection: "disconnected" }), ]; +// A worker whose uplink is open but which answers `starting`: its view carries no leases, no +// devices and no capacity, which is "not known" (ADR 0005, #365), not "none". A gateway sends +// exactly this view (test: "lists no device or lease for a worker that is starting..." in +// src/gateway/dispatcher.test.ts), and it holds whatever the console cannot see: its live leases. +function unread(id: string): WorkerView { + return { + connection: "connected", + drained: false, + health: "starting", + id, + label: id, + lastSeenAt: NOW, + } as unknown as WorkerView; +} + describe("the overview", () => { it("counts the fleet's headline figures from what the workers, the queue and the events say", () => { const requests = [{ createdAt: NOW - 74_000, id: "r1" }] as unknown as WaitingRequest[]; @@ -147,4 +162,74 @@ describe("the overview", () => { expect(workers[0]?.slotsLabel).toBe("2 leased, 1 ready, 3 free"); expect(workers[2]).not.toHaveProperty("cpu"); }); + + it("leaves the fleet's lease and device figures and the lease chart unknown, not zero, while a connected worker is starting", () => { + // Three leases granted inside the hour, none released: three live leases. The gateway holds + // them on the starting worker, whose view does not report them; the console cannot know how + // many there are, so it must not name a total that counts that worker's leases as none. + const events = [ + event(1, "lease.granted", NOW - 10 * 60 * 1_000), + event(2, "lease.granted", NOW - 9 * 60 * 1_000), + event(3, "lease.granted", NOW - 8 * 60 * 1_000), + ]; + + const alone = overviewOf({ events, now: NOW, requests: [], workers: [unread("mini-3")] }); + + expect(alone.tiles.map((tile) => [tile.label, tile.value])).toEqual([ + ["Utilisation", "—"], + ["Leases", "—"], + ["Waiting", "0"], + ["Workers", "1"], + ["Granted", "3"], + ]); + + // The chart counts back from the fleet total, so with the total read as 0 it draws every + // minute at 0 and its summary says "Now 0" while three gateway-issued leases are live. + expect(alone.minutes).toEqual([]); + expect(alone.chartSummary).toBe(""); + + // The capacity bar reads its running devices and limits from the same absent fields, so a + // fleet of one starting worker says "0 of 0 running" while that machine's devices are live. + expect(alone.platforms.map((p) => [p.name, p.running, p.limit])).toEqual([ + ["iOS", undefined, undefined], + ["Android", undefined, undefined], + ]); + + const row = alone.workers[0]; + expect(row).toBeDefined(); + expect(row).not.toHaveProperty("leases"); + expect(row?.slotsLabel).toBe("Not reported"); + + // A fleet of which one worker has reported cannot call its own count the fleet's total + // either: the same three live leases still sit on the unread worker. + const reporting = worker("mini-1", [ + device("a", "leased", "ios"), + device("b", "ready", "ios"), + ]); + const mixed = overviewOf({ + events, + now: NOW, + requests: [], + workers: [reporting, unread("mini-3")], + }); + + expect(mixed.tiles.map((tile) => [tile.label, tile.value])).toEqual([ + ["Utilisation", "—"], + ["Leases", "—"], + ["Waiting", "0"], + ["Workers", "2"], + ["Granted", "3"], + ]); + expect(mixed.minutes).toEqual([]); + expect(mixed.chartSummary).toBe(""); + + // What the reporting worker has read still shows: the unknown is the unread worker's, not + // the whole page's. + expect( + mixed.workers.map((r) => [r.name, r.leases, r.slotsLabel]), + ).toEqual([ + ["mini-1", 1, "1 leased, 1 ready, 4 free"], + ["mini-3", undefined, "Not reported"], + ]); + }); }); From 8f5d2aa162c1d31f083438c7d7d4ce34b450c9fd Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sat, 17 Oct 2026 08:36:03 +0200 Subject: [PATCH 2/5] fix: overview leaves fleet totals unknown while a connected worker is starting 1 failing -> 0 failing --- ui/src/model/overview.ts | 39 +++++++++++++++++++++---------- ui/src/model/workers.ts | 12 +++++++++- ui/src/screens/overview/index.tsx | 32 +++++++++++++++++-------- 3 files changed, 60 insertions(+), 23 deletions(-) diff --git a/ui/src/model/overview.ts b/ui/src/model/overview.ts index 9049291d4..a6be703d0 100644 --- a/ui/src/model/overview.ts +++ b/ui/src/model/overview.ts @@ -10,7 +10,7 @@ import { itemPath } from "./paths"; import { formatDuration } from "./time"; import type { Tone, Toned } from "./tones"; import type { WaitingRequest } from "./waiting"; -import { leasesHeld, type WorkerView, workerName, workerPath } from "./workers"; +import { isUnread, leasesHeld, type WorkerView, workerName, workerPath } from "./workers"; export interface OverviewTile { readonly label: string; @@ -21,8 +21,8 @@ export interface OverviewTile { export interface PlatformUse { readonly name: string; - readonly running: number; - readonly limit: number; + readonly running?: number; + readonly limit?: number; readonly leasedPercent: number; readonly readyPercent: number; readonly busyPercent: number; @@ -43,7 +43,7 @@ export interface OverviewWorker { readonly slotsLabel: string; readonly cpu?: Gauge; readonly memory?: Gauge; - readonly leases: number; + readonly leases?: number; } export interface OverviewItem { @@ -82,6 +82,10 @@ function percentOf(part: number, whole: number): number { function platformUse(workers: readonly WorkerView[], platform: "ios" | "android"): PlatformUse { const live = workers.filter((worker) => worker.connection === "connected"); + const name = platform === "ios" ? "iOS" : "Android"; + if (workers.some(isUnread)) { + return { busyPercent: 0, leasedPercent: 0, name, readyPercent: 0 }; + } const limit = live.reduce((sum, worker) => sum + (worker.capacity?.[platform].limit ?? 0), 0); const devices = live.flatMap((worker) => (worker.devices ?? []).filter((device) => device.spec.platform === platform), @@ -95,7 +99,7 @@ function platformUse(workers: readonly WorkerView[], platform: "ios" | "android" busyPercent: percentOf(busy, limit), leasedPercent: percentOf(leased, limit), limit, - name: platform === "ios" ? "iOS" : "Android", + name, readyPercent: percentOf(ready, limit), running: leased + ready + busy, }; @@ -108,7 +112,7 @@ function gauge(percent: number | undefined): Gauge | undefined { } function overviewWorker(worker: WorkerView): OverviewWorker { - const slots = workerSlots(worker); + const slots = isUnread(worker) ? [] : workerSlots(worker); const gauges = worker.connection === "connected" && worker.load !== undefined ? loadGauges(worker.load) : {}; const cpu = gauge(gauges.cpu); @@ -116,11 +120,11 @@ function overviewWorker(worker: WorkerView): OverviewWorker { return { health: workerHealth(worker), id: worker.id, - leases: worker.leases?.length ?? 0, name: workerName(worker), slots, - slotsLabel: slotsLabel(slots), + slotsLabel: isUnread(worker) ? "Not reported" : slotsLabel(slots), to: workerPath(worker.id), + ...(worker.leases === undefined ? {} : { leases: worker.leases.length }), ...(cpu === undefined ? {} : { cpu }), ...(memory === undefined ? {} : { memory }), }; @@ -141,15 +145,25 @@ function tiles( now: number, ): readonly OverviewTile[] { const held = leasesHeld(workers); - const limit = platforms.reduce((sum, platform) => sum + platform.limit, 0); + const limit = platforms.reduce((sum, platform) => sum + (platform.limit ?? 0), 0); const connected = workers.filter((worker) => worker.connection === "connected").length; const granted = events.filter( (event) => event.event === "lease.granted" && event.timestamp > now - HOUR, ).length; const oldest = Math.min(...requests.map((request) => request.createdAt)); + const unknown = held === undefined; return [ - { label: "Utilisation", unit: "%", value: String(Math.round(percentOf(held, limit))) }, - { label: "Leases", to: "/leases", unit: `of ${formatCount(limit)}`, value: formatCount(held) }, + { + label: "Utilisation", + unit: "%", + value: unknown ? "—" : String(Math.round(percentOf(held, limit))), + }, + { + label: "Leases", + to: "/leases", + unit: unknown ? "not reported" : `of ${formatCount(limit)}`, + value: unknown ? "—" : formatCount(held), + }, { label: "Waiting", to: "/waiting", @@ -176,7 +190,8 @@ export function overviewOf(input: { }): Overview { const { events, now, requests, workers } = input; const platforms = [platformUse(workers, "ios"), platformUse(workers, "android")]; - const minutes = leaseHistory(leasesHeld(workers), events, now); + const held = leasesHeld(workers); + const minutes = held === undefined ? [] : leaseHistory(held, events, now); return { activity: [...events] .sort((a, b) => b.seq - a.seq) diff --git a/ui/src/model/workers.ts b/ui/src/model/workers.ts index f05d4afc8..09e2059a5 100644 --- a/ui/src/model/workers.ts +++ b/ui/src/model/workers.ts @@ -38,7 +38,17 @@ export function capacityByPlatform( ]; } -export function leasesHeld(workers: readonly WorkerView[]): number { +// why: a connected worker that sends no `leases` or `devices` (it is starting) has not said what it +// holds; "not known" is not "none", so a fleet that includes one has no count. +export function isUnread(worker: WorkerView): boolean { + return ( + worker.connection === "connected" && + (worker.leases === undefined || worker.devices === undefined) + ); +} + +export function leasesHeld(workers: readonly WorkerView[]): number | undefined { + if (workers.some(isUnread)) return undefined; return workers.reduce((sum, worker) => sum + (worker.leases?.length ?? 0), 0); } diff --git a/ui/src/screens/overview/index.tsx b/ui/src/screens/overview/index.tsx index 4fb576282..b36edc444 100644 --- a/ui/src/screens/overview/index.tsx +++ b/ui/src/screens/overview/index.tsx @@ -47,14 +47,20 @@ export function OverviewBody({ overview }: { readonly overview: Overview }) { - -

{overview.chartSummary}

- + {overview.minutes.length === 0 ? ( +

Not reported.

+ ) : ( + <> + +

{overview.chartSummary}

+ + + )}
@@ -92,7 +98,13 @@ function PlatformBar({ platform }: { readonly platform: PlatformUse }) {

{platform.name} - {platform.running} of {platform.limit} running + {platform.running === undefined || platform.limit === undefined ? ( + — + ) : ( + <> + {platform.running} of {platform.limit} running + + )}

- {worker.leases} + {worker.leases ?? —} ))} From a9cc2281f7d95d02d9fcc02cd8d60c3acc48a7fd Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sat, 17 Oct 2026 08:47:13 +0200 Subject: [PATCH 3/5] test: pin the overview's not-known renders; docs: say what the console shows while a worker starts (#406) --- docs/CONSOLE.md | 12 ++++++---- ui/src/screens/overview/overview.test.tsx | 28 +++++++++++++++++++++-- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/docs/CONSOLE.md b/docs/CONSOLE.md index e1e1518ce..5c9f081a1 100644 --- a/docs/CONSOLE.md +++ b/docs/CONSOLE.md @@ -140,19 +140,23 @@ The console opens on **Overview**: the whole fleet on one page. - **Tiles**: how full the fleet is (leases held, as a share of every running slot on connected workers), the leases held, the requests waiting and the longest wait, the workers connected of all, and the leases granted in the - last hour. A tile that has a page of its own opens it. + last hour. A tile that has a page of its own opens it. While a connected + worker is still starting, the first two show a dash: its leases are not + known yet. - **Leases held, last hour**: a chart of how many leases were held at the end of each minute. It starts from the leases held now and counts back through the lease events of the last hour, the same events the Events page shows, so it can only go back as far as those. A lease that ends with no event, such as one on a worker removed from a gateway, is not counted back. The line under it says now, the highest and the lowest, and **Minute by minute** - lists each minute's number. + lists each minute's number. It says "Not reported." in the same case. - **Capacity**: per platform, the devices running of the limit, and a bar - split into leased, ready and booting. + split into leased, ready and booting. A dash stands in for the figures in + the same case. - **Workers**: a row per worker with its status square, a square per device slot (leased, ready, booting, quarantined, absent or free), its CPU and - memory, and the leases it holds. Select a worker to open it. + memory, and the leases it holds (a dash while it is starting). Select a + worker to open it. - **Attention** and **Activity**: what needs you, and the latest events. Each opens its own page. diff --git a/ui/src/screens/overview/overview.test.tsx b/ui/src/screens/overview/overview.test.tsx index 01e3f133b..760bd657b 100644 --- a/ui/src/screens/overview/overview.test.tsx +++ b/ui/src/screens/overview/overview.test.tsx @@ -22,19 +22,32 @@ const quiet: Overview = { }; describe("the overview screen", () => { - it("says so in one line where a fleet has no workers, nothing needs attention and nothing happened", () => { + it("says so in one line where a fleet has no workers, no lease count, nothing needs attention and nothing happened", () => { const shown = text(renderToStaticMarkup()); expect(shown).toContain("No workers have connected."); + expect(shown).toContain("Not reported."); + expect(shown).not.toContain("Minute by minute"); expect(shown).toContain("Nothing needs attention."); expect(shown).toContain("No events in the last hour."); }); - it("names each worker's health in its square, and its devices in words beside the slots", () => { + it("names each worker's health in its square, its devices in words beside the slots, and a muted dash where a count is not known", () => { const html = renderToStaticMarkup( { slotsLabel: "1 leased, 1 free", to: "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/workers/w1", }, + { + health: { tone: "warn", word: "starting" }, + id: "w2", + name: "mac-mini-02", + slots: [], + slotsLabel: "Not reported", + to: "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/workers/w2", + }, ], }} />, @@ -57,5 +78,8 @@ describe("the overview screen", () => { expect(html).toContain('role="img" aria-label="1 leased, 1 free"'); expect(html).toContain('href="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/workers/w1"'); expect(text(html)).not.toContain("memory 88%"); + expect(html).toContain('—'); + expect(html).toContain('—

'); + expect(text(html)).toContain("2 of 4 running"); }); }); From 8aec784c1b3626b95099d873f0750ade3c6aa49c Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sat, 17 Oct 2026 09:08:55 +0200 Subject: [PATCH 4/5] fix(ui): unknown overview figures name no unit and draw no bar (#406) --- docs/CONSOLE.md | 7 +++---- ui/src/model/overview.ts | 6 +++--- ui/src/screens/overview/index.tsx | 19 +++++++++++-------- ui/src/screens/overview/overview.test.tsx | 1 + 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/docs/CONSOLE.md b/docs/CONSOLE.md index 5c9f081a1..1aa849a08 100644 --- a/docs/CONSOLE.md +++ b/docs/CONSOLE.md @@ -140,9 +140,8 @@ The console opens on **Overview**: the whole fleet on one page. - **Tiles**: how full the fleet is (leases held, as a share of every running slot on connected workers), the leases held, the requests waiting and the longest wait, the workers connected of all, and the leases granted in the - last hour. A tile that has a page of its own opens it. While a connected - worker is still starting, the first two show a dash: its leases are not - known yet. + last hour. A tile that has a page of its own opens it. While a + worker's devices and leases are not known, the first two show a dash. - **Leases held, last hour**: a chart of how many leases were held at the end of each minute. It starts from the leases held now and counts back through the lease events of the last hour, the same events the Events page shows, so @@ -155,7 +154,7 @@ The console opens on **Overview**: the whole fleet on one page. the same case. - **Workers**: a row per worker with its status square, a square per device slot (leased, ready, booting, quarantined, absent or free), its CPU and - memory, and the leases it holds (a dash while it is starting). Select a + memory, and the leases it holds (a dash while they are not known). Select a worker to open it. - **Attention** and **Activity**: what needs you, and the latest events. Each opens its own page. diff --git a/ui/src/model/overview.ts b/ui/src/model/overview.ts index a6be703d0..3d0a3be1a 100644 --- a/ui/src/model/overview.ts +++ b/ui/src/model/overview.ts @@ -15,7 +15,7 @@ import { isUnread, leasesHeld, type WorkerView, workerName, workerPath } from ". export interface OverviewTile { readonly label: string; readonly value: string; - readonly unit: string; + readonly unit?: string; readonly to?: string; } @@ -155,13 +155,13 @@ function tiles( return [ { label: "Utilisation", - unit: "%", + ...(unknown ? {} : { unit: "%" }), value: unknown ? "—" : String(Math.round(percentOf(held, limit))), }, { label: "Leases", to: "/leases", - unit: unknown ? "not reported" : `of ${formatCount(limit)}`, + ...(unknown ? {} : { unit: `of ${formatCount(limit)}` }), value: unknown ? "—" : formatCount(held), }, { diff --git a/ui/src/screens/overview/index.tsx b/ui/src/screens/overview/index.tsx index b36edc444..fbe22069c 100644 --- a/ui/src/screens/overview/index.tsx +++ b/ui/src/screens/overview/index.tsx @@ -93,12 +93,13 @@ export function OverviewBody({ overview }: { readonly overview: Overview }) { } function PlatformBar({ platform }: { readonly platform: PlatformUse }) { + const known = platform.running !== undefined && platform.limit !== undefined; return (

{platform.name} - {platform.running === undefined || platform.limit === undefined ? ( + {!known ? ( — ) : ( <> @@ -107,13 +108,15 @@ function PlatformBar({ platform }: { readonly platform: PlatformUse }) { )}

- + {known ? ( + + ) : null}
); } diff --git a/ui/src/screens/overview/overview.test.tsx b/ui/src/screens/overview/overview.test.tsx index 760bd657b..c47c20790 100644 --- a/ui/src/screens/overview/overview.test.tsx +++ b/ui/src/screens/overview/overview.test.tsx @@ -81,5 +81,6 @@ describe("the overview screen", () => { expect(html).toContain('—'); expect(html).toContain('—

'); expect(text(html)).toContain("2 of 4 running"); + expect(html.match(/class="share-bar"/g)).toHaveLength(1); }); }); From fb7b9acdc1694a53e7337eed5030c661fcab1a10 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Sat, 17 Oct 2026 09:12:26 +0200 Subject: [PATCH 5/5] test(ui): trim overview test comments to the comment lint (#406) --- ui/src/model/overview.test.ts | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/ui/src/model/overview.test.ts b/ui/src/model/overview.test.ts index 58e57e4d7..e29bcbea6 100644 --- a/ui/src/model/overview.test.ts +++ b/ui/src/model/overview.test.ts @@ -61,7 +61,7 @@ const fleet = [ worker("down-1", [], { connection: "disconnected" }), ]; -// A worker whose uplink is open but which answers `starting`: its view carries no leases, no +// why: A worker whose uplink is open but which answers `starting`: its view carries no leases, no // devices and no capacity, which is "not known" (ADR 0005, #365), not "none". A gateway sends // exactly this view (test: "lists no device or lease for a worker that is starting..." in // src/gateway/dispatcher.test.ts), and it holds whatever the console cannot see: its live leases. @@ -164,9 +164,6 @@ describe("the overview", () => { }); it("leaves the fleet's lease and device figures and the lease chart unknown, not zero, while a connected worker is starting", () => { - // Three leases granted inside the hour, none released: three live leases. The gateway holds - // them on the starting worker, whose view does not report them; the console cannot know how - // many there are, so it must not name a total that counts that worker's leases as none. const events = [ event(1, "lease.granted", NOW - 10 * 60 * 1_000), event(2, "lease.granted", NOW - 9 * 60 * 1_000), @@ -183,13 +180,9 @@ describe("the overview", () => { ["Granted", "3"], ]); - // The chart counts back from the fleet total, so with the total read as 0 it draws every - // minute at 0 and its summary says "Now 0" while three gateway-issued leases are live. expect(alone.minutes).toEqual([]); expect(alone.chartSummary).toBe(""); - // The capacity bar reads its running devices and limits from the same absent fields, so a - // fleet of one starting worker says "0 of 0 running" while that machine's devices are live. expect(alone.platforms.map((p) => [p.name, p.running, p.limit])).toEqual([ ["iOS", undefined, undefined], ["Android", undefined, undefined], @@ -200,12 +193,7 @@ describe("the overview", () => { expect(row).not.toHaveProperty("leases"); expect(row?.slotsLabel).toBe("Not reported"); - // A fleet of which one worker has reported cannot call its own count the fleet's total - // either: the same three live leases still sit on the unread worker. - const reporting = worker("mini-1", [ - device("a", "leased", "ios"), - device("b", "ready", "ios"), - ]); + const reporting = worker("mini-1", [device("a", "leased", "ios"), device("b", "ready", "ios")]); const mixed = overviewOf({ events, now: NOW, @@ -223,11 +211,7 @@ describe("the overview", () => { expect(mixed.minutes).toEqual([]); expect(mixed.chartSummary).toBe(""); - // What the reporting worker has read still shows: the unknown is the unread worker's, not - // the whole page's. - expect( - mixed.workers.map((r) => [r.name, r.leases, r.slotsLabel]), - ).toEqual([ + expect(mixed.workers.map((r) => [r.name, r.leases, r.slotsLabel])).toEqual([ ["mini-1", 1, "1 leased, 1 ready, 4 free"], ["mini-3", undefined, "Not reported"], ]);