diff --git a/docs/internal/DESIGN.md b/docs/internal/DESIGN.md index 9306ee840..08ab5e71e 100644 --- a/docs/internal/DESIGN.md +++ b/docs/internal/DESIGN.md @@ -30,8 +30,8 @@ Simlock's accent is orange where Apex's is green. | `--text-xs` | 12px | labels, units, a row's second line, a link's count | | `--text-sm` | 14px | links in the sidebar, buttons, table cells, facts | | `--text-md` | 16px | body text, page subtitles, card and panel titles | - | `--text-lg` | 20px | a list's title, an inspector title that is an id | - | `--text-xl` | 28px | a page's and an inspector's title, a tile's number | + | `--text-lg` | 20px | a drawer's title | + | `--text-xl` | 28px | a page's title, a tile's number | | `--text-2xl` | 32px | a lease's countdown | - Weights: 400 for text, 500 for labels and big numbers, 600 for titles, 700 @@ -95,12 +95,12 @@ one. Use the daemon's own word for the state (`leased`, `quarantined`, square of its colour, then the word in `--text` (`Status` in `ui/src/ds/status.tsx`). In a list row, where there is room for the square alone (`StatusDot`), the word is the square's accessible name and its tooltip, -and the chosen row's inspector shows it in full. A worker's square shows the +and the row's drawer shows it in full. A worker's square shows the worst of what is wrong with it: red for a lost or failed worker, amber for a drained or starting one, one over its RAM budget, or a load figure past its threshold, green otherwise (`workerHealth` in `ui/src/model/fleet.ts`). A word the console does not know, from a newer daemon, shows as itself in -`--status-idle`. A count, such as the one on the Attention link, is a number, +`--status-idle`. A count, such as the one on the Inbox link, is a number, not a status: it has neither a status colour nor the accent. Every pair of text and background colour in both themes meets WCAG AA: 4.5:1 @@ -133,12 +133,12 @@ put together from them and draws nothing of its own that one of them already dra - **Sidebar.** The console's navigation, on the left of every signed-in page: the "SIMLOCK" wordmark (`--on-accent` on an `--accent` block), one link per page in a fixed order (Overview, - Attention, then the **Operate** group: Fleet, Leases, Queue; then the **Observe** group: + Inbox, then the **Operate** group: Fleet, Leases, Queue; then the **Observe** group: Activity, Usage; each group under its small label, hidden when collapsed), then at the bottom the connection as a status, "Signed in as " (hidden when collapsed, where the Sign out tooltip reads "Sign out ()"), **Sign out** (absent for a proxy person with no sign-out address) and the collapse button. A link is an icon and its label in `--text-muted`; the current one is `--text` on `--field` with a 2px `--accent` bar on its left and - `aria-current="page"`. Attention carries its count in a small bordered box, and none at zero. + `aria-current="page"`. Inbox carries its count of problems (not heads-ups) in a small bordered box, and none at zero. Collapsed, the sidebar is 64px wide: the labels go, every icon sits on its centre line, each link keeps its name (and a tooltip), the wordmark becomes "S" and the connection its square. Only the operator collapses or widens it, with the button at its bottom; the browser keeps the @@ -147,14 +147,13 @@ put together from them and draws nothing of its own that one of them already dra opens the links and the bottom block under it. - **Page.** A page that is not a list, as the overview: its title (`h1`) and its actions on the right, then its content. No subtitle: the title and what is under it say what the page is. -- **List and inspector.** Attention (attention items) is a list on the left, 260–360px wide, and - the chosen thing in an inspector filling the rest. The list has a header (the page's title as `h1`, a short count - in mono beside it, then its filters), its rows, and the pager under them. A row is one or two - short lines: a status square, a title, one figure on the right, and at most one muted line or - bar under them; the chosen row is `--surface` with a 2px `--accent` bar on its left and - `aria-current="page"`. The address names the chosen thing (`/attention/`). The inspector - has a breadcrumb, the thing's title (`h2`), one muted line under it, actions on the right, and - then cards, facts, tabs and panels. +- **Grouped list and drawer.** Inbox is a page of panels, one per group (Broken, Needs a look, + Heads-up, in that order; a group with no item is left out), under a toolbar of filter chips (All, + then each group). A row is a status square, the condition's word and a muted mono line saying what + it is about; the row is a link to `/inbox/`, which opens a drawer. The drawer has a box + saying what happened, then the facts, one button to the page of what the item is about, and the + last hour's events about it. The address of a key holding a `.` ends in `/`, so a reload finds the + console's page. - **Table and drawer.** Leases, Fleet and Queue are each a table (Leases and Fleet under a toolbar: the filter chips on the left, a search box on the right, at the page title's padding). Activity has the same toolbar over an event feed that scrolls inside itself; Queue has no toolbar, only the Wait p95 tile above its table. Leases' filters are its own; Fleet's are @@ -238,8 +237,7 @@ put together from them and draws nothing of its own that one of them already dra ## Layout - Phone first. Every page works at 360px wide with no sideways scrolling of the page. Under 768px - the sidebar is a bar on top with a menu, and a list page shows its list until something is - chosen and the inspector after (the address says which). Under 768px a table's rows stack into + the sidebar is a bar on top with a menu. Under 768px a table's rows stack into blocks, each cell a line with its column's name beside it (`data-label`). A wide table, of six columns or more, stacks the same way under 1100px. Otherwise a table has a fixed layout: a column of numbers is 8rem wide, the others share the rest, and a long cell wraps or, for an id, @@ -247,7 +245,6 @@ put together from them and draws nothing of its own that one of them already dra - Stat tiles fill the row, each at least 170px wide, and wrap. - From 1024px a chart and the panel beside it share a row, two thirds and one third; two panels of the same weight share it half and half. -- A list page with nothing in its address shows its first row in the inspector on a wide screen. ## Focus and keyboard @@ -262,9 +259,8 @@ put together from them and draws nothing of its own that one of them already dra Short, and only where it says where something came from. Colour changes on hover take 120ms (`--duration`). Moves take 220ms (`--duration-move`) on one easing (`--ease`): the sidebar -widens and narrows; a page rises 10px as it opens; a list slides in from the left and an -inspector from the right, again each time another thing is chosen; a drawer from the right, once, when it opens; the chosen row's bar and a -meter or share bar slide to their new place. Nothing loops, nothing moves on its own, and +widens and narrows; a page rises 10px as it opens; a drawer slides in from the right, once, when it opens; a +meter or share bar slides to its new place. Nothing loops, nothing moves on its own, and charts never animate. With `prefers-reduced-motion: reduce`, there are no transitions and no animations at all. diff --git a/e2e/console/fixtures.ts b/e2e/console/fixtures.ts index 7c8c2a1e6..04de3c645 100644 --- a/e2e/console/fixtures.ts +++ b/e2e/console/fixtures.ts @@ -503,7 +503,7 @@ export async function signIn(page: Page, token: string): Promise { export const NAV = [ { label: "Overview", path: "/" }, - { label: "Attention", path: "/attention" }, + { label: "Inbox", path: "/inbox" }, { label: "Fleet", path: "/fleet" }, { label: "Leases", path: "/leases" }, { label: "Queue", path: "/queue" }, diff --git a/e2e/console/attention.spec.ts b/e2e/console/inbox.spec.ts similarity index 53% rename from e2e/console/attention.spec.ts rename to e2e/console/inbox.spec.ts index 9ea9fd69a..7afce18e3 100644 --- a/e2e/console/attention.spec.ts +++ b/e2e/console/inbox.spec.ts @@ -1,4 +1,4 @@ -import type { Locator, Page } from "@playwright/test"; +import type { Locator, Page, Route } from "@playwright/test"; import { waitFor } from "../helpers/wait.js"; import { @@ -13,7 +13,7 @@ import { test, } from "./fixtures.js"; -/** What `GET /v1/workers` says, as far as these tests read. */ +/** why: What `GET /v1/workers` says, as far as these tests read. */ interface WorkerView { readonly id: string; readonly label?: string; @@ -30,7 +30,7 @@ interface WorkerView { const IOS = { availableOsVersions: ["18.4"], knownModels: ["iPhone 16"] }; -/** The fake driver's script once its reclaim fails, so a released device is quarantined. */ +/** why: The fake driver's script once its reclaim fails, so a released device is quarantined. */ const FAILING_RECLAIM = { ios: { ...IOS, failures: { reclaim: { message: "erase failed", type: "generic" as const } } }, }; @@ -56,7 +56,7 @@ async function workers(daemon: RunningDaemon): Promise { } /** - * Waits, asking every 20 ms, until the daemon's own `GET /v1/workers` says what `predicate` + * why: Waits, asking every 20 ms, until the daemon's own `GET /v1/workers` says what `predicate` * looks for. The console's second starts there: it cannot show a fact before its daemon has it. */ async function untilTheDaemonSays( @@ -88,7 +88,7 @@ async function lease(daemon: RunningDaemon, agent: string): Promise<{ id: string return (granted.json as { lease: { id: string } }).lease; } -/** Leases a device, then releases it with a driver whose reclaim fails: it is quarantined. */ +/** why: Leases a device, then releases it with a driver whose reclaim fails: it is quarantined. */ async function quarantineOne(daemon: RunningDaemon): Promise { const held = await lease(daemon, "console-e2e-quarantine"); await daemon.writeDriverScript(FAILING_RECLAIM); @@ -100,7 +100,7 @@ async function quarantineOne(daemon: RunningDaemon): Promise { } /** - * Leaves a device `provisioning` with nothing working on it, as a daemon that stops mid-boot + * why: Leaves a device `provisioning` with nothing working on it, as a daemon that stops mid-boot * does: a lease starts a boot the driver takes two minutes over, and the daemon stops while * it runs. While the boot runs it is a live operation, never a stall; once the daemon is back * nothing drives it any more. `beforeStart` runs while the daemon is down. @@ -132,17 +132,17 @@ async function strandProvisioning( await daemon.start(); } -async function openAttention(page: Page, daemon: RunningDaemon): Promise { +async function openInbox(page: Page, daemon: RunningDaemon): Promise { await page.goto(daemon.url); await signIn(page, daemon.tokens.operator); // why: a phone folds the navigation into a menu, so the page is opened by its address. await expect(page.getByRole("heading", { level: 1, name: "Overview" })).toBeVisible(); - await page.goto(new URL("/attention", daemon.url).href); - await expect(page.getByRole("heading", { level: 1, name: "Attention" })).toBeVisible(); + await page.goto(new URL("/inbox", daemon.url).href); + await expect(page.getByRole("heading", { level: 1, name: "Inbox" })).toBeVisible(); } function rows(page: Page): Locator { - return page.getByRole("list", { name: "Needs attention" }).getByRole("link"); + return page.locator("main").getByRole("list").getByRole("link"); } function item(page: Page, condition: string, subject: string): Locator { @@ -151,26 +151,254 @@ function item(page: Page, condition: string, subject: string): Locator { .filter({ hasText: subject }); } +async function closeDrawer(page: Page): Promise { + await page.getByRole("dialog").getByRole("button", { name: "Close" }).click(); + await expect(page.getByRole("dialog")).toHaveCount(0); +} + function facts(page: Page): Locator { return page.getByRole("group", { name: "Facts" }); } -/** Whether the page itself scrolls sideways. */ +/** why: Whether the page itself scrolls sideways. */ async function hasHorizontalScroll(page: Page): Promise { return page.evaluate( () => document.documentElement.scrollWidth > document.documentElement.clientWidth, ); } -test.describe("the attention view", () => { - test("draining a worker adds it to the attention view within a second", async ({ page }) => { +test.describe("the Inbox view", () => { + test("/inbox lists a drained worker under Needs a look and a disconnected one under Broken; the chips show one group at a time", async ({ + page, + }) => { + const fleet = await startFleet([ + { driverScript: { ios: IOS }, label: "worker-a" }, + { driverScript: { ios: IOS }, label: "worker-b" }, + ]); + try { + const a = (await workers(fleet.gateway)).find((view) => view.label === "worker-a"); + expect((await fleet.gateway.cli(["worker", "drain", a?.id ?? ""])).code).toBe(0); + await (fleet.workers[1] as RunningDaemon).stop(); + await untilTheDaemonSays( + fleet.gateway, + (views) => + views.find((view) => view.label === "worker-a")?.drained === true && + views.find((view) => view.label === "worker-b")?.connection === "disconnected", + ); + await openInbox(page, fleet.gateway); + + const broken = page.getByRole("region", { name: "Broken" }); + const needsALook = page.getByRole("region", { name: "Needs a look" }); + await expect(broken.getByRole("link", { name: /worker-b/ })).toBeVisible(); + await expect(needsALook.getByRole("link", { name: /worker-a/ })).toBeVisible(); + await expect(page.getByRole("region", { name: "Heads-up" })).toHaveCount(0); + + await page.getByRole("radio", { name: "Broken" }).check(); + await expect(broken).toBeVisible(); + await expect(needsALook).toHaveCount(0); + + await page.getByRole("radio", { name: "Needs a look" }).check(); + await expect(needsALook).toBeVisible(); + await expect(broken).toHaveCount(0); + + await page.getByRole("radio", { name: "All" }).check(); + await expect(broken).toBeVisible(); + await expect(needsALook).toBeVisible(); + } finally { + await disposeFleet(fleet); + } + }); + + test("a waiting request stubbed with a createdAt 61 s before the daemon's now shows under Needs a look, and one at 30 s does not", async ({ + page, + }) => { + const host = await startDaemon("worker", { driverScript: { ios: IOS } }); + try { + // why: a request cannot wait a minute on a real daemon quickly, so the list is stubbed, each + // age counted from the daemon's own clock (its Date header). + await page.route( + (url) => url.pathname === "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/v1/lease-requests", + async (route: Route) => { + const response = await route.fetch(); + const now = new Date(response.headers().date ?? "").getTime(); + const request = (id: string, waitedMs: number) => ({ + createdAt: now - waitedMs, + id, + platform: "ios", + queuePosition: 1, + requesterId: id, + spec: { platform: "ios" }, + stage: "queued", + }); + await route.fulfill({ + json: { requests: [request("long-waiter", 61_000), request("short-waiter", 30_000)] }, + response, + }); + }, + ); + + await openInbox(page, host); + + const needsALook = page.getByRole("region", { name: "Needs a look" }); + await expect( + needsALook.getByRole("link", { name: /long-waiter has waited 1 min/ }), + ).toBeVisible(); + await expect(page.getByRole("link", { name: /short-waiter/ })).toHaveCount(0); + } finally { + await host.dispose(); + } + }); + + test("a lease stubbed with 4 minutes left shows under Heads-up, and one with 10 minutes does not", async ({ + page, + }) => { + const host = await startDaemon("worker", { driverScript: { ios: IOS } }); + try { + // why: a lease cannot be 4 minutes from its deadline on a real daemon quickly, so the list is + // stubbed, each deadline counted from the daemon's own clock (its Date header). + await page.route( + (url) => url.pathname === "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/v1/leases", + async (route: Route) => { + const response = await route.fetch(); + const now = new Date(response.headers().date ?? "").getTime(); + const lease = (id: string, leftMs: number) => ({ + deviceId: "dev_stub", + grantedAt: now - 60_000, + id, + idChosenByRequester: false, + lastRenewedAt: now - 30_000, + ownerId: "tok_stub", + requesterId: "tok_stub", + ttlDeadline: now + leftMs, + ttlMs: 900_000, + }); + await route.fulfill({ + json: { leases: [lease("lease-soon", 4 * 60_000), lease("lease-later", 10 * 60_000)] }, + response, + }); + }, + ); + + await openInbox(page, host); + + const headsUp = page.getByRole("region", { name: "Heads-up" }); + await expect(headsUp.getByRole("link")).toHaveCount(1); + await expect( + headsUp.getByRole("link", { name: /tok_stub · dev_stub ends in 3:\d\d/ }), + ).toBeVisible(); + } finally { + await host.dispose(); + } + }); + + test("an Inbox item whose key holds a . reloads at its address", async ({ page }) => { + const host = await startDaemon("worker", { driverScript: { ios: IOS } }); + try { + // why: a gateway's lease id holds a `.`, which a single host never makes, so the list is stubbed. + await page.route( + (url) => url.pathname === "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/v1/leases", + async (route: Route) => { + const response = await route.fetch(); + const now = new Date(response.headers().date ?? "").getTime(); + await route.fulfill({ + json: { + leases: [ + { + deviceId: "dev_stub", + grantedAt: now - 60_000, + id: "wrk_a.lse_1", + idChosenByRequester: false, + lastRenewedAt: now - 30_000, + ownerId: "tok_stub", + requesterId: "tok_stub", + ttlDeadline: now + 4 * 60_000, + ttlMs: 900_000, + }, + ], + }, + response, + }); + }, + ); + await openInbox(page, host); + + await page.getByRole("region", { name: "Heads-up" }).getByRole("link").click(); + const address = new URL(page.url()).pathname; + expect(address).toBe(`/inbox/${encodeURIComponent("lease/wrk_a.lse_1/ending")}/`); + await page.reload(); + + await expect( + page.getByRole("dialog").getByRole("heading", { name: "tok_stub · dev_stub" }), + ).toBeVisible(); + expect(new URL(page.url()).pathname).toBe(address); + } finally { + await host.dispose(); + } + }); + + test("an Inbox row opens /inbox/ with the what-happened box and the item's details; a cleared item says This is no longer in the Inbox.", async ({ + page, + }) => { + const fleet = await startFleet([{ driverScript: { ios: IOS }, label: "worker-a" }]); + try { + const [a] = await workers(fleet.gateway); + expect((await fleet.gateway.cli(["worker", "drain", a?.id ?? ""])).code).toBe(0); + await openInbox(page, fleet.gateway); + + await item(page, "drained", "worker-a").click(); + + await expect(page).toHaveURL(new RegExp(`/inbox/${encodeURIComponent(`${a?.id}/drained`)}$`)); + const drawer = page.getByRole("dialog"); + await expect(drawer.getByRole("heading", { name: "worker-a" })).toBeVisible(); + await expect(drawer.getByRole("region", { name: "What happened" })).toContainText( + "worker-a is drained", + ); + await expect(facts(page)).toContainText(/Leases still held\s*0/); + await expect(drawer.getByRole("link", { name: "Open worker" })).toHaveAttribute( + "href", + `/fleet/${encodeURIComponent(a?.id ?? "")}`, + ); + + expect((await fleet.gateway.cli(["worker", "undrain", a?.id ?? ""])).code).toBe(0); + await untilTheDaemonSays(fleet.gateway, (views) => views[0]?.drained === false); + + await expect(drawer).toContainText("This is no longer in the Inbox.", { timeout: 1_000 }); + await expect(drawer.getByRole("region", { name: "What happened" })).toHaveCount(0); + } finally { + await disposeFleet(fleet); + } + }); + + test("with /v1/lease-requests stubbed to fail, the Inbox says Could not check: waiting requests and not Nothing needs you", async ({ + page, + }) => { + const host = await startDaemon("worker", { driverScript: { ios: IOS } }); + try { + await page.route( + (url) => url.pathname === "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/v1/lease-requests", + (route) => + route.fulfill({ + json: { error: { code: "INTERNAL", message: "The queue is down." } }, + status: 500, + }), + ); + await openInbox(page, host); + + await expect(page.getByText("Could not check: waiting requests")).toBeVisible(); + await expect(page.getByText("Nothing needs you.")).toHaveCount(0); + } finally { + await host.dispose(); + } + }); + + test("draining a worker adds it to the Inbox view within a second", async ({ page }) => { const fleet = await startFleet([ { driverScript: { ios: IOS }, label: "worker-a" }, { driverScript: { ios: IOS }, label: "worker-b" }, ]); try { - await openAttention(page, fleet.gateway); - await expect(page.getByText("Nothing needs attention.")).toBeVisible(); + await openInbox(page, fleet.gateway); + await expect(page.getByText("Nothing needs you.")).toBeVisible(); const b = (await workers(fleet.gateway)).find((view) => view.label === "worker-b"); expect((await fleet.gateway.cli(["worker", "drain", b?.id ?? ""])).code).toBe(0); @@ -183,11 +411,14 @@ test.describe("the attention view", () => { await expect(drained).toBeVisible({ timeout: 1_000 }); await expect(drained).toHaveAttribute( "href", - `/attention/${encodeURIComponent(`${b?.id}/drained`)}`, + `/inbox/${encodeURIComponent(`${b?.id}/drained`)}`, ); await expect(rows(page)).toHaveCount(1); - await expect(page).toHaveURL(/\/attention$/); - await expect(page.getByRole("heading", { level: 2, name: "worker-b" })).toBeVisible(); + await expect(page).toHaveURL(/\/inbox$/); + await drained.click(); + await expect( + page.getByRole("dialog").getByRole("heading", { name: "worker-b" }), + ).toBeVisible(); await expect(page.getByRole("link", { name: "Open worker" })).toHaveAttribute( "href", `/fleet/${encodeURIComponent(b?.id ?? "")}`, @@ -208,7 +439,7 @@ test.describe("the attention view", () => { try { const [a] = await workers(fleet.gateway); expect((await fleet.gateway.cli(["worker", "drain", a?.id ?? ""])).code).toBe(0); - await openAttention(page, fleet.gateway); + await openInbox(page, fleet.gateway); const drained = item(page, "drained", "worker-a"); await expect(drained).toBeVisible(); @@ -216,31 +447,7 @@ test.describe("the attention view", () => { await untilTheDaemonSays(fleet.gateway, (views) => views[0]?.drained === false); await expect(drained).toHaveCount(0, { timeout: 1_000 }); - await expect(page.getByText("Nothing needs attention.")).toBeVisible(); - } finally { - await disposeFleet(fleet); - } - }); - - test("an item named in the URL that stops needing attention says Resolved. with a link back", async ({ - page, - }) => { - const fleet = await startFleet([{ driverScript: { ios: IOS }, label: "worker-a" }]); - try { - const [a] = await workers(fleet.gateway); - expect((await fleet.gateway.cli(["worker", "drain", a?.id ?? ""])).code).toBe(0); - await openAttention(page, fleet.gateway); - await item(page, "drained", "worker-a").click(); - await expect(page).toHaveURL(/\/attention\/.+/); - await expect(page.getByRole("heading", { level: 2, name: "worker-a" })).toBeVisible(); - - expect((await fleet.gateway.cli(["worker", "undrain", a?.id ?? ""])).code).toBe(0); - await untilTheDaemonSays(fleet.gateway, (views) => views[0]?.drained === false); - - await expect(page.getByText("Resolved.")).toBeVisible({ timeout: 1_000 }); - await page.getByRole("link", { name: "Back to Attention" }).click(); - await expect(page).toHaveURL(/\/attention$/); - await expect(page.getByText("Nothing needs attention.")).toBeVisible(); + await expect(page.getByText("Nothing needs you.")).toBeVisible(); } finally { await disposeFleet(fleet); } @@ -252,8 +459,8 @@ test.describe("the attention view", () => { { driverScript: { ios: IOS }, label: "worker-b" }, ]); try { - await openAttention(page, fleet.gateway); - await expect(page.getByText("Nothing needs attention.")).toBeVisible(); + await openInbox(page, fleet.gateway); + await expect(page.getByText("Nothing needs you.")).toBeVisible(); await (fleet.workers[1] as RunningDaemon).stop(); await untilTheDaemonSays( @@ -278,7 +485,7 @@ test.describe("the attention view", () => { const fleet = { gateway, workers: [] as RunningDaemon[] }; let hangUp = () => {}; try { - // Joined by hand rather than with `startFleet`, which has no way to pass the worker the + // why: Joined by hand rather than with `startFleet`, which has no way to pass the worker the // stall threshold. const worker = await startDaemon("worker", { ...STALLING, @@ -296,7 +503,7 @@ test.describe("the attention view", () => { await quarantineOne(worker); await strandProvisioning(worker); let devices: WorkerView["devices"] = []; - // A stall starts with no event, so the gateway learns of it on its next periodic read of + // why: A stall starts with no event, so the gateway learns of it on its next periodic read of // the worker, every 30 seconds. await untilTheDaemonSays( fleet.gateway, @@ -313,15 +520,18 @@ test.describe("the attention view", () => { const quarantined = devices.find((device) => device.state === "quarantined"); const stalled = devices.find((device) => device.stalled === true); - await openAttention(page, fleet.gateway); + await openInbox(page, fleet.gateway); await expect(item(page, "incompatible", "old-worker")).toBeVisible(); await item(page, "incompatible", "old-worker").click(); await expect(facts(page)).toContainText("Gateway protocol"); await expect(facts(page)).toContainText("Worker protocol"); + await closeDrawer(page); + await item(page, "quarantined", "iPhone 16 on worker-a").click(); await expect(facts(page)).toContainText(quarantined?.id ?? ""); + await closeDrawer(page); await item(page, "stalled", "iPhone 16 on worker-a").click(); await expect(facts(page)).toContainText(stalled?.id ?? ""); @@ -341,7 +551,7 @@ test.describe("the attention view", () => { const { limitBytes } = (status.json as { capacity: { ramBudget: { limitBytes: number } } }) .capacity.ramBudget; await quarantineOne(host); - // Back with each iOS device costing more than the whole budget: the devices it already + // why: Back with each iOS device costing more than the whole budget: the devices it already // has put it over. await strandProvisioning(host, async () => { const set = await host.cli([ @@ -365,10 +575,10 @@ test.describe("the attention view", () => { }); const quarantined = view?.devices.find((device) => device.state === "quarantined"); const stalled = view?.devices.find((device) => device.state === "provisioning"); - // Past its one-second threshold, and nothing works on it since the restart. + // why: Past its one-second threshold, and nothing works on it since the restart. expect(stalled?.stalled, "the stranded device is reported stalled").toBe(true); - await openAttention(page, host); + await openInbox(page, host); const name = view?.id ?? ""; await expect(item(page, "quarantined", `iPhone 16 on ${name}`)).toBeVisible(); @@ -380,6 +590,7 @@ test.describe("the attention view", () => { await item(page, "quarantined", `iPhone 16 on ${name}`).click(); await expect(facts(page)).toContainText(/Cause\s*Purge failed: Error: erase failed/); + await closeDrawer(page); await item(page, "over RAM budget", name).click(); await expect(facts(page)).toContainText(/Used\s*\d+\.\d\d GiB/); @@ -389,7 +600,9 @@ test.describe("the attention view", () => { } }); - test("the attention count shows in the shell from every view", async ({ page }) => { + test("the sidebar's Inbox count equals the problem items and is hidden at 0", async ({ + page, + }) => { const gateway = await startDaemon("gateway"); const hangUps: (() => void)[] = []; try { @@ -399,22 +612,72 @@ test.describe("the attention view", () => { gateway, (views) => views.filter((view) => view.connection === "incompatible").length === 2, ); + // why: a request that has waited two minutes is a problem item and counts; a lease about to end + // is a heads-up and does not. Neither can be had quickly from a real daemon, so both are stubbed, + // the waiting list by `waiters` so that it can empty. + let waiters = ["long-waiter"]; + await page.route( + (url) => url.pathname === "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/v1/lease-requests", + async (route: Route) => { + const response = await route.fetch(); + const now = new Date(response.headers().date ?? "").getTime(); + await route.fulfill({ + json: { + requests: waiters.map((id) => ({ + createdAt: now - 125_000, + id, + platform: "ios", + queuePosition: 1, + requesterId: id, + spec: { platform: "ios" }, + stage: "queued", + })), + }, + response, + }); + }, + ); + await page.route( + (url) => url.pathname === "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/v1/leases", + async (route: Route) => { + const response = await route.fetch(); + const now = new Date(response.headers().date ?? "").getTime(); + await route.fulfill({ + json: { + leases: [ + { + deviceId: "dev_stub", + grantedAt: now - 60_000, + id: "lease-soon", + idChosenByRequester: false, + lastRenewedAt: now - 30_000, + ownerId: "tok_stub", + requesterId: "tok_stub", + ttlDeadline: now + 60_000, + ttlMs: 900_000, + }, + ], + }, + response, + }); + }, + ); await page.goto(gateway.url); await signIn(page, gateway.tokens.operator); - const attention = page + const inboxLink = page .getByRole("navigation", { name: "Console" }) - .getByRole("link", { name: /^Attention/ }); + .getByRole("link", { name: /^Inbox/ }); for (const label of NAV_LABELS) { await page .getByRole("navigation", { name: "Console" }) .getByRole("link", { name: label }) .click(); await expect(page.getByRole("heading", { level: 1, name: label })).toBeVisible(); - await expect(attention).toHaveAccessibleName("Attention 2 items"); + await expect(inboxLink).toHaveAccessibleName("Inbox 3 items"); } - // One worker hangs up and is removed: its item goes, and one from the count. + // why: One worker hangs up and is removed: its item goes, and one from the count. hangUps.shift()?.(); await untilTheDaemonSays(gateway, (views) => views.some((view) => view.id === "wrk_old_1" && view.connection === "disconnected"), @@ -422,14 +685,25 @@ test.describe("the attention view", () => { const removed = await gateway.cli(["worker", "remove", "wrk_old_1"]); expect(removed.code, removed.stderr).toBe(0); await untilTheDaemonSays(gateway, (views) => views.length === 1); - await expect(attention).toHaveAccessibleName("Attention 1 item"); + await expect(inboxLink).toHaveAccessibleName("Inbox 2 items"); + + waiters = []; + await expect(inboxLink).toHaveAccessibleName("Inbox 1 item"); + + hangUps.shift()?.(); + await untilTheDaemonSays(gateway, (views) => + views.some((view) => view.id === "wrk_old_2" && view.connection === "disconnected"), + ); + const removedLast = await gateway.cli(["worker", "remove", "wrk_old_2"]); + expect(removedLast.code, removedLast.stderr).toBe(0); + await expect(inboxLink).toHaveAccessibleName("Inbox"); } finally { for (const hangUp of hangUps) hangUp(); await gateway.dispose(); } }); - test("the Attention view has no horizontal scroll at 360px wide", async ({ page }) => { + test("the Inbox view has no horizontal scroll at 360px wide", async ({ page }) => { const gateway = await startDaemon("gateway"); let hangUp = () => {}; try { @@ -440,10 +714,13 @@ test.describe("the attention view", () => { await untilTheDaemonSays(gateway, (views) => views.length === 1); await page.setViewportSize({ height: 740, width: 360 }); - await openAttention(page, gateway); + await openInbox(page, gateway); await expect(rows(page)).toHaveCount(1); expect(await hasHorizontalScroll(page)).toBe(false); + // why: a panel clips what overflows it, so the page never scrolls; the row itself must fit. + const box = await rows(page).boundingBox(); + expect(box?.width ?? Infinity).toBeLessThanOrEqual(360); await rows(page).click(); await expect(page.getByRole("heading", { level: 2, name: /^aworkerwith/ })).toBeVisible(); expect(await hasHorizontalScroll(page)).toBe(false); @@ -453,15 +730,15 @@ test.describe("the attention view", () => { } }); - test("the Attention view is usable with the keyboard alone", async ({ browserName, page }) => { - // Safari moves focus to links with Option-Tab; plain Tab reaches only form controls there. + test("the Inbox view is usable with the keyboard alone", async ({ browserName, page }) => { + // why: Safari moves focus to links with Option-Tab; plain Tab reaches only form controls there. const tab = browserName === "webkit" ? "Alt+Tab" : "Tab"; const gateway = await startDaemon("gateway"); let hangUp = () => {}; try { hangUp = await joinOldWorker(gateway, { id: "wrk_old", label: "old-worker" }); await untilTheDaemonSays(gateway, (views) => views.length === 1); - /** Tabs forward until `link` has focus, and follows it with Enter. */ + /** why: Tabs forward until `link` has focus, and follows it with Enter. */ const follow = async (link: Locator) => { for (let step = 0; step < 20; step += 1) { if (await link.evaluate((element) => element === document.activeElement)) break; @@ -477,9 +754,9 @@ test.describe("the attention view", () => { await expect(page.getByRole("heading", { level: 1, name: "Overview" })).toBeVisible(); await follow( - page.getByRole("navigation", { name: "Console" }).getByRole("link", { name: /^Attention/ }), + page.getByRole("navigation", { name: "Console" }).getByRole("link", { name: /^Inbox/ }), ); - await expect(page.getByRole("heading", { level: 1, name: "Attention" })).toBeVisible(); + await expect(page.getByRole("heading", { level: 1, name: "Inbox" })).toBeVisible(); await follow(item(page, "incompatible", "old-worker")); await expect(page.getByRole("heading", { level: 2, name: "old-worker" })).toBeVisible(); diff --git a/e2e/console/leases.spec.ts b/e2e/console/leases.spec.ts index 09d2eb117..4951ff204 100644 --- a/e2e/console/leases.spec.ts +++ b/e2e/console/leases.spec.ts @@ -539,7 +539,7 @@ test.describe("the leases page", () => { await expect(leaseRow(page, soon.id)).toBeVisible(); await expect(leaseRow(page, later.id)).toBeVisible(); - await page.getByRole("radio", { name: "Expiring" }).check(); + await page.getByRole("radio", { name: "Ending < 5 min" }).check(); await expect(leaseRow(page, soon.id)).toBeVisible(); await expect(leaseRow(page, later.id)).toHaveCount(0); diff --git a/e2e/console/overview.spec.ts b/e2e/console/overview.spec.ts index ffd3bccc3..d9c8781a2 100644 --- a/e2e/console/overview.spec.ts +++ b/e2e/console/overview.spec.ts @@ -1,7 +1,17 @@ -import type { Page } from "@playwright/test"; +import type { Page, Route } from "@playwright/test"; import { waitFor } from "../helpers/wait.js"; -import { expect, type RunningDaemon, settled, signIn, startDaemon, test } from "./fixtures.js"; +import { + disposeFleet, + expect, + joinOldWorker, + type RunningDaemon, + settled, + signIn, + startDaemon, + startFleet, + test, +} from "./fixtures.js"; const IOS = { availableOsVersions: ["18.4"], knownModels: ["iPhone 16"] }; const ONE_DEVICE = { limits: { ios: { maxDevices: 1, maxRunning: 1 }, maxRunning: 1 } }; @@ -15,6 +25,7 @@ const RANGES = [ ] as const; const CHARTS = ["leasesHeld", "queueDepth", "slotsUsed"] as const; +const OVERVIEW_CHARTS = ["leasesHeld", "queueDepth"] as const; interface Stats { readonly totals: { readonly granted: number; readonly wait: { readonly p95: number | null } }; @@ -100,7 +111,7 @@ async function tablesOf(page: Page): Promise { } function expectedTables(stats: Stats): readonly (readonly string[])[] { - return CHARTS.map((key) => + return OVERVIEW_CHARTS.map((key) => [...stats.series].reverse().map((point) => (point[key] === null ? "—" : String(point[key]))), ); } @@ -109,7 +120,7 @@ test.describe("the Overview's figures", () => { // why: a run is charted once its minute is over, which can take most of a minute. test.describe.configure({ timeout: 150_000 }); - test("picking each of 1 hour, 6 hours, 24 hours and 7 days writes its ?range=, and the two tiles and all three chart tables equal GET /v1/stats", async ({ + test("picking each of 1 hour, 6 hours, 24 hours and 7 days writes its ?range=, and the Wait p95 tile and the two chart tables equal GET /v1/stats", async ({ page, }) => { const host = await startDaemon("worker", { config: ONE_DEVICE, driverScript: { ios: IOS } }); @@ -127,9 +138,6 @@ test.describe("the Overview's figures", () => { ).toBeVisible(); const stats = await statsOf(host, range.since); - await expect - .poll(() => tileText(page, "Granted")) - .toBe(`Granted | ${stats.totals.granted} | ${range.unit}`); await expect .poll(() => tileText(page, "Wait p95")) .toBe(`Wait p95 | ${waitText(stats.totals.wait.p95)} | ${range.unit}`); @@ -150,21 +158,20 @@ test.describe("the Overview's figures", () => { await scriptedRun(host); await openOverview(page, host, "/?range=6h"); await expect(page.getByRole("radio", { name: "6 hours" })).toBeChecked(); - await expect(tile(page, "Granted")).toBeVisible(); - const before = [await tileText(page, "Granted"), await tileText(page, "Wait p95")]; + await expect(tile(page, "Wait p95")).toBeVisible(); + const before = [await tileText(page, "Wait p95")]; await page.reload(); await expect(page.getByRole("heading", { level: 1, name: "Overview" })).toBeVisible(); await expect(page.getByRole("radio", { name: "6 hours" })).toBeChecked(); - await expect.poll(() => tileText(page, "Granted")).toBe(before[0]); - await expect.poll(() => tileText(page, "Wait p95")).toBe(before[1]); + await expect.poll(() => tileText(page, "Wait p95")).toBe(before[0]); } finally { await host.dispose(); } }); - test("a daemon stop and start, with the events behind the figures pruned, shows the same Wait p95, Granted and chart rows", async ({ + test("a daemon stop and start, with the events behind the figures pruned, shows the same Wait p95 and chart rows", async ({ page, }) => { const host = await startDaemon("worker", { @@ -174,14 +181,13 @@ test.describe("the Overview's figures", () => { try { await scriptedRun(host); await openOverview(page, host, "/?range=24h"); - await expect(tile(page, "Granted")).toBeVisible(); + await expect(tile(page, "Wait p95")).toBeVisible(); const before = { - granted: await tileText(page, "Granted"), rows: (await tablesOf(page)).map((rows) => rows.filter((row) => row !== "—")), wait: await tileText(page, "Wait p95"), }; - expect(before.rows).toHaveLength(3); + expect(before.rows).toHaveLength(2); expect(before.rows.every((rows) => rows.length > 0)).toBe(true); await host.stop(); @@ -194,7 +200,6 @@ test.describe("the Overview's figures", () => { events: { event: string }[]; }; expect(events.filter((entry) => entry.event === "lease.granted")).toEqual([]); - await expect.poll(() => tileText(page, "Granted")).toBe(before.granted); await expect.poll(() => tileText(page, "Wait p95")).toBe(before.wait); const after = (await tablesOf(page)).map((rows) => rows.filter((row) => row !== "—")); expect(after.map((rows, index) => rows.slice(-(before.rows[index]?.length ?? 0)))).toEqual( @@ -205,19 +210,19 @@ test.describe("the Overview's figures", () => { } }); - test("a lease granted while the Overview is open raises Granted within 2 seconds with no reload", async ({ + test("a lease granted while the Overview is open raises Leased within 2 seconds with no reload", async ({ page, }) => { const host = await startDaemon("worker", { driverScript: { ios: IOS } }); try { await openOverview(page, host); - await expect(tile(page, "Granted")).toBeVisible(); - await expect(tile(page, "Granted")).toContainText("0"); + await expect(tile(page, "Leased")).toBeVisible(); + await expect(tile(page, "Leased")).toContainText("0"); const granted = await host.cli([...LEASE, "--agent-id", "late", "--detach"]); expect(granted.code, granted.stderr).toBe(0); - await expect(tile(page, "Granted").locator(".stat-value")).toHaveText("1", { + await expect(tile(page, "Leased").locator(".stat-value")).toHaveText("1", { timeout: 2_000, }); } finally { @@ -225,16 +230,38 @@ test.describe("the Overview's figures", () => { } }); - test("Overview's tiles and links land on /queue, /fleet and /activity, not Not found", async ({ + test("on a single host, Overview shows all five numbers and both charts, and no Activity panel", async ({ page, }) => { + const host = await startDaemon("worker", { driverScript: { ios: IOS } }); + try { + await openOverview(page, host); + + for (const label of ["Leased", "Waiting", "Workers", "Wait p95", "Ending soon"]) { + await expect(tile(page, label), label).toBeVisible(); + } + await expect + .poll(() => tileText(page, "Leased")) + .toMatch(/^Leased \| 0 \| of \d+ · \d+ ready$/); + await expect.poll(() => tileText(page, "Workers")).toBe("Workers | 1 | of 1"); + await expect.poll(() => tileText(page, "Waiting")).toMatch(/^Waiting \| 0 \|/); + await expect.poll(() => tileText(page, "Ending soon")).toBe("Ending soon | 0 | under 5 min"); + await expect(page.getByRole("region", { name: "Leases held" })).toBeVisible(); + await expect(page.getByRole("region", { name: "Requests in the queue" })).toBeVisible(); + await expect(page.locator("#main details.chart-data")).toHaveCount(2); + await expect(page.getByRole("region", { name: "Activity" })).toHaveCount(0); + } finally { + await host.dispose(); + } + }); + + test("Overview's tiles and links land on /queue and /fleet, not Not found", async ({ page }) => { const host = await startDaemon("worker", { driverScript: { ios: IOS } }); try { const links = [ { follow: () => tile(page, "Waiting").getByRole("link").click(), path: "/queue" }, { follow: () => tile(page, "Workers").getByRole("link").click(), path: "/fleet" }, - { follow: () => page.getByRole("link", { name: /^All \d+$/ }).click(), path: "/fleet" }, - { follow: () => page.getByRole("link", { name: "All events" }).click(), path: "/activity" }, + { follow: () => page.getByRole("link", { name: "Open Fleet" }).click(), path: "/fleet" }, ]; await openOverview(page, host); for (const { follow, path } of links) { @@ -272,3 +299,260 @@ test.describe("the Overview's figures", () => { } }); }); + +async function workerConnection(host: RunningDaemon, label: string): Promise { + const { workers } = (await operatorGet(host, "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/v1/workers")) as { + workers: { label?: string; connection: string }[]; + }; + return workers.find((worker) => worker.label === label)?.connection; +} + +test.describe("the Overview's Inbox lines", () => { + test("an empty Inbox shows Nothing needs you and no Needs you panel; a disconnected worker shows the panel with that item first, and All in Inbox (1)", async ({ + page, + }) => { + const fleet = await startFleet([ + { driverScript: { ios: IOS }, label: "worker-a" }, + { driverScript: { ios: IOS }, label: "worker-b" }, + ]); + try { + await openOverview(page, fleet.gateway); + await expect(page.getByText("Nothing needs you")).toBeVisible(); + await expect(page.getByRole("heading", { name: "Needs you" })).toHaveCount(0); + + await (fleet.workers[1] as RunningDaemon).stop(); + await waitFor( + async () => (await workerConnection(fleet.gateway, "worker-b")) === "disconnected", + { + label: "worker-b disconnected", + }, + ); + + const panel = page.getByRole("region", { name: "Needs you" }); + await expect(panel).toBeVisible(); + await expect(page.getByText("Nothing needs you")).toHaveCount(0); + await expect(panel.getByRole("link").first()).toContainText("worker-b"); + await expect(panel.getByRole("link", { name: "All in Inbox (1)" })).toBeVisible(); + } finally { + await disposeFleet(fleet); + } + }); + + test("with five problem items the panel shows four, and a row opens /inbox/", async ({ + page, + }) => { + const gateway = await startDaemon("gateway"); + const hangUps: (() => void)[] = []; + try { + for (let index = 1; index <= 5; index += 1) { + hangUps.push( + await joinOldWorker(gateway, { id: `wrk_old_${index}`, label: `old-${index}` }), + ); + } + await waitFor( + async () => { + const { workers } = (await operatorGet(gateway, "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/v1/workers")) as { + workers: { connection: string }[]; + }; + return workers.filter((worker) => worker.connection === "incompatible").length === 5; + }, + { label: "five incompatible workers" }, + ); + await openOverview(page, gateway); + + const panel = page.getByRole("region", { name: "Needs you" }); + await expect(panel.getByRole("listitem")).toHaveCount(4); + await expect(panel.getByRole("link", { name: "All in Inbox (5)" })).toBeVisible(); + await panel.getByRole("listitem").first().getByRole("link").click(); + await expect(page).toHaveURL(/\/inbox\/wrk_old_\d%2Fincompatible$/); + } finally { + for (const hangUp of hangUps) hangUp(); + await gateway.dispose(); + } + }); + + test("with /v1/lease-requests stubbed to fail, Overview says Could not check: waiting requests and not Nothing needs you", async ({ + page, + }) => { + const host = await startDaemon("worker", { driverScript: { ios: IOS } }); + try { + await page.route( + (url) => url.pathname === "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/v1/lease-requests", + (route) => + route.fulfill({ + json: { error: { code: "INTERNAL", message: "The queue is down." } }, + status: 500, + }), + ); + await openOverview(page, host); + + await expect(page.getByText("Could not check: waiting requests")).toBeVisible(); + await expect(page.getByText("Nothing needs you")).toHaveCount(0); + } finally { + await host.dispose(); + } + }); +}); + +test.describe("the Overview when the workers cannot be read", () => { + test("with /v1/workers stubbed to fail, Overview says Could not check: workers and shows no capacity", async ({ + page, + }) => { + const host = await startDaemon("worker", { driverScript: { ios: IOS } }); + try { + // why: signing in reads /v1/workers, so the stub goes in once the operator is in. + await openOverview(page, host); + await page.route( + (url) => url.pathname === "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/v1/workers", + (route) => + route.fulfill({ + json: { error: { code: "INTERNAL", message: "The fleet is down." } }, + status: 500, + }), + ); + await page.reload(); + + await expect(page.getByText("Could not check: workers")).toBeVisible(); + await expect(page.getByRole("region", { name: "Capacity · all workers" })).toHaveCount(0); + await expect(page.getByText("Nothing needs you")).toHaveCount(0); + } finally { + await host.dispose(); + } + }); +}); + +test.describe("the Overview's five numbers", () => { + test("show the daemon's values: one lease held of four devices with three ready, one request waiting with its longest wait, two of two workers, Wait p95, and Ending soon counting a lease with 4 minutes left and not one with 10", async ({ + page, + }) => { + const fleet = await startFleet([ + { driverScript: { ios: IOS }, label: "worker-a" }, + { driverScript: { ios: IOS }, label: "worker-b" }, + ]); + try { + const held: string[] = []; + for (const agent of ["one", "two", "three", "four"]) { + const granted = await fleet.gateway.cli([...LEASE, "--agent-id", agent, "--detach"]); + expect(granted.code, granted.stderr).toBe(0); + held.push((granted.json as { lease: { id: string } }).lease.id); + } + for (const id of held.slice(1)) { + const released = await fleet.gateway.cli(["release", id]); + expect(released.code, released.stderr).toBe(0); + } + await waitFor( + async () => { + const { workers } = (await operatorGet(fleet.gateway, "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/v1/workers")) as { + workers: { devices: { state: string }[] }[]; + }; + const states = workers.flatMap((worker) => worker.devices.map((device) => device.state)); + return states.length === 4 && states.filter((state) => state === "ready").length === 3; + }, + { label: "four devices, three ready" }, + ); + // why: a request is stubbed as waiting 2 minutes and a lease as ending, at times a real daemon cannot reach quickly, + // each counted from the daemon's own clock (its Date header). + await page.route( + (url) => url.pathname === "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/v1/lease-requests", + async (route: Route) => { + const response = await route.fetch(); + const now = new Date(response.headers().date ?? "").getTime(); + await route.fulfill({ + json: { + requests: [ + { + createdAt: now - 125_000, + id: "req_stub", + platform: "ios", + queuePosition: 1, + requesterId: "stub", + stage: "queued", + }, + ], + }, + response, + }); + }, + ); + await page.route( + (url) => url.pathname === "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/v1/leases", + async (route: Route) => { + const response = await route.fetch(); + const now = new Date(response.headers().date ?? "").getTime(); + const { leases } = (await response.json()) as { + leases: { id: string; ttlDeadline: number }[]; + }; + const [first] = leases; + if (first === undefined) throw new Error("the daemon lists no lease"); + await route.fulfill({ + json: { + leases: [ + { ...first, ttlDeadline: now + 4 * 60_000 }, + { ...first, id: "lease-later", ttlDeadline: now + 10 * 60_000 }, + ], + }, + response, + }); + }, + ); + + await openOverview(page, fleet.gateway); + + const stats = await statsOf(fleet.gateway, "1h"); + await expect.poll(() => tileText(page, "Leased")).toBe("Leased | 1 | of 4 · 3 ready"); + await expect + .poll(() => tileText(page, "Waiting")) + .toMatch(/^Waiting \| 1 \| longest 2 min \d+ s$/); + await expect.poll(() => tileText(page, "Workers")).toBe("Workers | 2 | of 2"); + await expect + .poll(() => tileText(page, "Wait p95")) + .toBe(`Wait p95 | ${waitText(stats.totals.wait.p95)} | last hour`); + await expect.poll(() => tileText(page, "Ending soon")).toBe("Ending soon | 1 | under 5 min"); + } finally { + await disposeFleet(fleet); + } + }); +}); + +test.describe("the Overview's workers table", () => { + test("lists all workers with no pager, and Open Fleet goes to /fleet", async ({ page }) => { + const fleet = await startFleet([ + { driverScript: { ios: IOS }, label: "worker-a" }, + { driverScript: { ios: IOS }, label: "worker-b" }, + ]); + try { + await openOverview(page, fleet.gateway); + + const workersPanel = page.getByRole("region", { name: "Workers" }); + await expect(workersPanel.locator("tbody tr")).toHaveCount(2); + await expect(workersPanel.getByRole("link", { name: "worker-a" })).toBeVisible(); + await expect(workersPanel.getByRole("link", { name: "worker-b" })).toBeVisible(); + await expect(page.getByRole("navigation", { name: /pages$/ })).toHaveCount(0); + + await page.getByRole("link", { name: "Open Fleet" }).click(); + await expect(page).toHaveURL(/\/fleet$/); + } finally { + await disposeFleet(fleet); + } + }); +}); + +test.describe("the range chips", () => { + test("sit in the shared toolbar on Overview and on Usage", async ({ page }) => { + const host = await startDaemon("worker", { driverScript: { ios: IOS } }); + try { + for (const path of ["/", "/usage"]) { + await page.goto(new URL(path, host.url).toString()); + if (path === "/") await signIn(page, host.tokens.operator); + await expect(page.getByRole("heading", { level: 1 })).toBeVisible(); + const chips = page.locator("#main .toolbar .toolbar-start").getByRole("group", { + name: "Range", + }); + await expect(chips, path).toBeVisible(); + await expect(chips.getByRole("radio")).toHaveCount(4); + } + } finally { + await host.dispose(); + } + }); +}); diff --git a/e2e/console/shell.spec.ts b/e2e/console/shell.spec.ts index 26f925ef2..6aff56dba 100644 --- a/e2e/console/shell.spec.ts +++ b/e2e/console/shell.spec.ts @@ -1,5 +1,5 @@ import { AxeBuilder } from "@axe-core/playwright"; -import type { Page } from "@playwright/test"; +import type { Page, Route } from "@playwright/test"; import { expect, @@ -109,7 +109,7 @@ test.describe("the shell", () => { await expect(page.getByLabel("Operator token")).toBeVisible(); }); - test("the sidebar shows Overview and Attention, then the Operate group, then the Observe group, each with its label", async ({ + test("the sidebar shows Overview and Inbox, then the Operate group, then the Observe group, each with its label", async ({ daemon, page, }) => { @@ -120,7 +120,7 @@ test.describe("the shell", () => { await expect(nav.getByRole("link")).toHaveText([...NAV_LABELS]); expect(NAV.map((entry) => `${entry.label} ${entry.path}`)).toEqual([ "Overview /", - "Attention /attention", + "Inbox /inbox", "Fleet /fleet", "Leases /leases", "Queue /queue", @@ -135,7 +135,7 @@ test.describe("the shell", () => { await expect(section.getByRole("link")).toHaveText([...group.links]); } await expect(nav.getByRole("link", { name: "Overview" })).toHaveCount(1); - await expect(nav.getByRole("group").getByRole("link", { name: "Attention" })).toHaveCount(0); + await expect(nav.getByRole("group").getByRole("link", { name: "Inbox" })).toHaveCount(0); }); test("/fleet, /queue and /activity open the pages titled Fleet, Queue and Activity; /workers, /waiting and /events show Not found", async ({ @@ -222,7 +222,7 @@ test.describe("the shell", () => { }); for (const colorScheme of ["light", "dark"] as const) { - test(`the shell passes an automated WCAG AA contrast check in both themes (${colorScheme})`, async ({ + test(`the shell, and Overview and Inbox empty and busy, pass an automated WCAG AA contrast check (${colorScheme})`, async ({ daemon, page, }) => { @@ -248,6 +248,69 @@ test.describe("the shell", () => { await expect(page.getByRole("button", { name: "Sign out" })).toBeVisible(); await expect(page.getByRole("heading", { level: 1, name: "Overview" })).toBeVisible(); expect(await audit()).toEqual([]); + + await page.goto("/inbox"); + await expect(page.getByRole("heading", { level: 1, name: "Inbox" })).toBeVisible(); + await expect(page.getByText("Nothing needs you.")).toBeVisible(); + expect(await audit()).toEqual([]); + + // why: a request that has waited two minutes and a lease about to end fill the Inbox's groups + // and the Overview's panel; neither can be had quickly from a real daemon, so both are stubbed. + await page.route( + (url) => url.pathname === "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/v1/lease-requests", + async (route: Route) => { + const response = await route.fetch(); + const now = new Date(response.headers().date ?? "").getTime(); + await route.fulfill({ + json: { + requests: [ + { + createdAt: now - 125_000, + id: "req_busy", + queuePosition: 1, + requesterId: "busy-agent", + spec: { platform: "ios" }, + stage: "queued", + }, + ], + }, + response, + }); + }, + ); + await page.route( + (url) => url.pathname === "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/v1/leases", + async (route: Route) => { + const response = await route.fetch(); + const now = new Date(response.headers().date ?? "").getTime(); + await route.fulfill({ + json: { + leases: [ + { + deviceId: "dev_busy", + grantedAt: now - 60_000, + id: "lse_busy", + idChosenByRequester: false, + lastRenewedAt: now - 30_000, + ownerId: "tok_busy", + requesterId: "tok_busy", + ttlDeadline: now + 60_000, + ttlMs: 900_000, + }, + ], + }, + response, + }); + }, + ); + await page.goto("/inbox"); + await expect(page.getByRole("region", { name: "Needs a look" })).toBeVisible(); + await expect(page.getByRole("region", { name: "Heads-up" })).toBeVisible(); + expect(await audit()).toEqual([]); + + await page.goto("/"); + await expect(page.getByRole("region", { name: "Needs you" })).toBeVisible(); + expect(await audit()).toEqual([]); }); } }); diff --git a/e2e/console/usage.spec.ts b/e2e/console/usage.spec.ts index 97e5b1df9..a14e856cd 100644 --- a/e2e/console/usage.spec.ts +++ b/e2e/console/usage.spec.ts @@ -221,20 +221,17 @@ test.describe("the Usage page", () => { } }); - test("clicking the Overview's Granted tile on /?range=7d opens /usage?range=7d", async ({ - page, - }) => { + test("shows the Device slots in use chart in the shared frame", async ({ page }) => { const host = await startDaemon("worker", { driverScript: { ios: IOS } }); try { - await page.goto(new URL("/?range=7d", host.url).toString()); + await page.goto(new URL("/usage?range=6h", host.url).toString()); await signIn(page, host.tokens.operator); - await expect(page.getByRole("heading", { level: 1, name: "Overview" })).toBeVisible(); - - await page.getByRole("link", { name: /Granted/ }).click(); - await expect(page.getByRole("heading", { level: 1, name: "Usage" })).toBeVisible(); - expect(new URL(page.url()).pathname + new URL(page.url()).search).toBe("/usage?range=7d"); - await expect(page.getByRole("radio", { name: "7 days" })).toBeChecked(); + + await expect( + page.getByRole("heading", { name: "Device slots in use, last 6 hours", exact: true }), + ).toBeVisible(); + await expect(page.locator("#main details.chart-data")).toHaveCount(1); } finally { await host.dispose(); } diff --git a/e2e/console/views.spec.ts b/e2e/console/views.spec.ts index 6d7591ae7..0392dc7b3 100644 --- a/e2e/console/views.spec.ts +++ b/e2e/console/views.spec.ts @@ -1,5 +1,5 @@ import { AxeBuilder } from "@axe-core/playwright"; -import type { Page } from "@playwright/test"; +import type { Page, Route } from "@playwright/test"; import { expect, @@ -76,7 +76,7 @@ async function openSignedIn(page: Page, host: RunningDaemon): Promise { // why: an open drawer hides the page behind it from assistive technology. function opensDrawer(path: string): boolean { - return /^\/(leases|queue|activity)\/./.test(path) || /^\/fleet\/[^/?]+\/./.test(path); + return /^\/(leases|queue|activity|inbox)\/./.test(path) || /^\/fleet\/[^/?]+\/./.test(path); } async function visit(page: Page, host: RunningDaemon, path: string): Promise { @@ -163,7 +163,7 @@ test.describe("every view", () => { } await visit(page, host, "/"); - await expect(page.locator("#main .chart")).toHaveCount(3); + await expect(page.locator("#main .chart")).toHaveCount(2); const chart = page.locator(".chart [tabindex='0']").first(); await chart.focus(); await page.keyboard.press("ArrowLeft"); @@ -192,11 +192,11 @@ test.describe("every view", () => { for (const [path, title, index] of [ ["/", "Leases held, last hour", 0], ["/", "Requests in the queue, last hour", 1], - ["/", "Device slots in use, last hour", 2], + ["/usage", "Device slots in use, last hour", 0], ["/activity", "Activity", 0], ] as const) { await visit(page, host, path); - if (path === "/") await expect(page.locator("#main .chart")).toHaveCount(3); + if (path === "/") await expect(page.locator("#main .chart")).toHaveCount(2); const chart = page.locator("#main .chart").nth(index); const heading = page.getByRole("heading", { name: title, exact: true }); const ring = () => chart.evaluate((element) => getComputedStyle(element).outlineStyle); @@ -287,6 +287,43 @@ test.describe("every view", () => { })); expect(found, path).toEqual({ styles: 0, violations: [] }); } + // why: a healthy host has nothing in its Inbox, so a request that has waited two minutes is + // stubbed to give the Inbox a row and its drawer something to open. + await page.route( + (url) => url.pathname === "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/v1/lease-requests", + async (route: Route) => { + const response = await route.fetch(); + const now = new Date(response.headers().date ?? "").getTime(); + await route.fulfill({ + json: { + requests: [ + { + createdAt: now - 125_000, + id: "req_busy", + queuePosition: 1, + requesterId: "busy-agent", + spec: { platform: "ios" }, + stage: "queued", + }, + ], + }, + response, + }); + }, + ); + for (const path of [ + "/inbox", + "/", + `/inbox/${encodeURIComponent("request/req_busy/waiting")}`, + ]) { + await visit(page, host, path); + if (opensDrawer(path)) await expect(page.getByRole("dialog")).toBeVisible(); + const found = await page.evaluate(() => ({ + styles: document.querySelectorAll("style").length, + violations: (window as unknown as { cspViolations: string[] }).cspViolations, + })); + expect(found, path).toEqual({ styles: 0, violations: [] }); + } expect(errors).toEqual([]); } finally { await host.dispose(); @@ -330,60 +367,16 @@ test.describe("every view", () => { }); } - test("the overview's tiles show the numbers the daemon gives", async ({ page }) => { + test("the Overview's Leased tile opens Leases", async ({ page }) => { const { host } = await hostWithLease(); try { - const tiles = () => - page - .getByRole("list", { name: "Fleet at a glance" }) - .getByRole("listitem") - .evaluateAll((items) => - items.map((item) => - [...item.querySelectorAll(".stat-label, .stat-value, .stat-unit")] - .map((part) => part.textContent) - .join(" | "), - ), - ); - const response = await fetch(new URL("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/v1/workers", host.url), { - headers: { Authorization: `Bearer ${host.tokens.operator}` }, - }); - const { workers } = (await response.json()) as { - workers: { capacity?: { ios: { limit: number }; android: { limit: number } } }[]; - }; - const limit = workers.reduce( - (sum, worker) => - sum + (worker.capacity?.ios.limit ?? 0) + (worker.capacity?.android.limit ?? 0), - 0, - ); await openSignedIn(page, host); - await expect - .poll(async () => (await tiles()).slice(0, 4)) - .toEqual([ - `Utilisation | ${Math.round((100 * 1) / limit)} | %`, - `Leases | 1 | of ${limit}`, - "Waiting | 0 | none", - "Workers | 1 | of 1 up", - ]); - const stats = (await ( - await fetch(new URL("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/v1/stats?since=1h", host.url), { - headers: { Authorization: `Bearer ${host.tokens.operator}` }, - }) - ).json()) as { totals: { granted: number; wait: { p95: number | null } } }; - const wait = stats.totals.wait.p95; - await expect - .poll(async () => (await tiles()).slice(4)) - .toEqual([ - `Granted | ${stats.totals.granted} | last hour`, - `Wait p95 | ${ - wait === null - ? "—" - : wait < 1_000 - ? `${Math.round(wait)} ms` - : `${Math.floor(wait / 1_000)} s` - } | last hour`, - ]); - await page.getByRole("link", { name: /^Leases 1/ }).click(); + await page + .getByRole("list", { name: "Fleet at a glance" }) + .getByRole("link", { name: /^Leased 1/ }) + .click(); + await expect(page.getByRole("heading", { level: 1, name: "Leases" })).toBeVisible(); } finally { await host.dispose(); diff --git a/ui/AGENTS.md b/ui/AGENTS.md index 2d5bb18a1..675d1bb90 100644 --- a/ui/AGENTS.md +++ b/ui/AGENTS.md @@ -29,8 +29,8 @@ Each layer imports only the layers below it. `.dependency-cruiser.mjs` enforces 1. Model: a pure builder in `src/model/.ts` turns route data into the page's view model (`overviewOf` in `overview.ts`). Shared rules live once: `workerHealth`, `workerSlots` - (`fleet.ts`), `eventSummary`, `eventTone` (`activity.ts`), `attentionTone` - (`attention.ts`), the word → tone tables (`tones.ts`), page paths (`paths.ts`). + (`fleet.ts`), `eventSummary`, `eventTone` (`activity.ts`), `inboxTone` + (`inbox.ts`), the word → tone tables (`tones.ts`), page paths (`paths.ts`). 2. State: a hook in `src/state/.ts` reads routes with `useLiveResource`, turns each into a `LoadView` (`resource.ts`: `loadView`, `mapView`, `bothViews`), and maps it through the builder. It re-exports the view-model types the screen needs. @@ -54,21 +54,20 @@ fails leaves none. `useDaemonMode` (`state/live.tsx`) gives it to state (ADR 003 ## Pages -| Path | Screen | Layout | -| ---------------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | -| `/` | Overview | stat tiles, range picker, three charts, capacity, workers table, attention, activity | -| `/fleet[/[/]]` | Fleet | table; a worker opens as its own page (load, capacity, leases, tabs Devices, Warm pool, Host, Events in `?tab=`); a device opens in a `Drawer` | -| `/leases[/]` | Leases | toolbar (filters, search) + table; the lease opens in a `Drawer` (Details, Screen, Events) | -| `/queue[/]` | Queue | Wait p95 tile + table; a request opens in a `Drawer` | -| `/attention[/]` | Attention | list + inspector | -| `/activity[/]` | Activity | chart, toolbar (type chips, search) + event feed that scrolls back through the history; an event opens in a `Drawer` with the payload | -| `/usage` | Usage | range picker, stat tiles, panels of tables (workers, requesters page in the URL) | - -The sidebar groups the pages: Overview and Attention, then Operate (Fleet, Leases, Queue), then +| Path | Screen | Layout | +| ---------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------- | +| `/` | Overview | range chips in the toolbar, five stat tiles, Needs you, capacity, two charts, workers table | +| `/fleet[/[/]]` | Fleet | table; a worker opens as its own page (load, capacity, leases, tabs Devices, Warm pool, Host, Events in `?tab=`); a device opens in a `Drawer` | +| `/leases[/]` | Leases | toolbar (filters, search) + table; the lease opens in a `Drawer` (Details, Screen, Events) | +| `/queue[/]` | Queue | Wait p95 tile + table; a request opens in a `Drawer` | +| `/inbox[/]` | Inbox | toolbar (group chips) + a panel per group; an item opens in a `Drawer` (what happened, facts, events) | +| `/activity[/]` | Activity | chart, toolbar (type chips, search) + event feed that scrolls back through the history; an event opens in a `Drawer` with the payload | +| `/usage` | Usage | range chips in the toolbar, stat tiles, the Device slots in use chart, panels of tables (workers, requesters page in the URL) | + +The sidebar groups the pages: Overview and Inbox, then Operate (Fleet, Leases, Queue), then Observe (Activity, Usage); a route's `group` in `routes.ts` puts it in one. -On a list page (Attention) the URL names the chosen item; with none, the first item shows on a wide screen -and the list alone on a phone. Leases, Queue and Activity show the list alone, and the chosen item opens in a drawer over it +Leases, Queue, Inbox and Activity show the list alone, and the chosen item opens in a drawer over it (`state/drawer.ts`: closing steps back when the drawer was opened from the list). Activity's `EventFeed` (`data/event-feed.ts`) holds the events: the stream, the last hour and the gap after a reconnect add @@ -82,7 +81,7 @@ Lists page in the URL (`state/paging.ts`, `model/paging.ts`). `src/ds/index.ts` exports every component. Tokens and base elements: `foundation.css`. - Frame: `AppFrame`, `Sidebar` (collapsible; width kept per browser by `data/preferences.ts`), - `Page`, `MasterDetail`, `ListPane`, `List`, `ListRow`, `Inspector`, `Drawer`, `DrawerTabs` + `Page`, `ListRow`, `Drawer`, `DrawerTabs` (a modal panel over the page, closed by an `IconButton` from `button.tsx`; Base UI), `Toolbar` (filters left, search right), `DesignProvider` (Base UI's `CSPProvider`, so no `