diff --git a/docs/internal/DESIGN.md b/docs/internal/DESIGN.md index 4c96cbc52..1ca6ddf3f 100644 --- a/docs/internal/DESIGN.md +++ b/docs/internal/DESIGN.md @@ -224,6 +224,14 @@ put together from them and draws nothing of its own that one of them already dra - **Long ids** (a lease's, a worker's, a device's) stay on one line, cut with an ellipsis. The whole id is in the element's `title`, in the text a copy or a screen reader reads, and on the details page. +- **Search.** A dialog near the top of the page over a dim layer (`--bg`, 1px `--border-strong`), + 36rem wide at most: a box, then the results in groups, each group an uppercase label in + `--text-muted` over its rows. The highlighted row is `--field` with the same 2px `--accent` + inset edge as the current page in the sidebar; orange marks interaction only. A group still + loading, or one that failed, shows one `--text-muted` line in place of rows. The box is a + combobox and the list a listbox, and the highlight is the active descendant; it is kept by the + result's id, not its place, so a group that fills in above never moves it. It sits under the + confirm dialog, so an action's confirm opens over it. - **Buttons.** Primary: filled `--accent` with `--on-accent` text. Secondary: outlined in `--border-strong`, `--text`. Quiet: text only. All are labels. - **Inputs.** A `--field` fill and a 1px `--border-strong` border. A select is @@ -236,7 +244,7 @@ put together from them and draws nothing of its own that one of them already dra `--accent`, an area with a faint fill of it (8%), horizontal grid lines in `--border`, axis labels in Geist Mono `--text-muted`. Every colour comes from the stylesheet by class. Nothing moves: animation is off. Every chart has a - title saying what it counts, its numbers as a line of text under it, and every bucket as a table behind a disclosure named by the bucket width ("Minute by minute", "Every 5 minutes", "Hour by hour"), so + title saying what it counts, its numbers as a line of text under it, and every bucket in a table only a screen reader reads, so nothing is visible only in the picture. A chart can be focused, and the arrow keys step through it. Its focus ring goes round the whole chart, for keyboard focus only: a click on a chart draws none. @@ -271,6 +279,8 @@ put together from them and draws nothing of its own that one of them already dra for keyboard focus (`:focus-visible`), not on a mouse click. - The first control on every signed-in page is "Skip to content", visible only when focused. +- ⌘K and Ctrl+K open the search while the console has focus and no drawer or dialog is open; the + browser's own use of the chord is stopped. Closing the search returns focus to where it was. ## Motion diff --git a/docs/internal/adr/README.md b/docs/internal/adr/README.md index 2a3359397..3f744e060 100644 --- a/docs/internal/adr/README.md +++ b/docs/internal/adr/README.md @@ -75,6 +75,5 @@ the status is stale. | [0034](0034-one-worker-per-user-and-the-folder-says-what-a-daemon-is.md) | One worker per user, and the folder says what a daemon is | Accepted — not yet implemented | | [0035](0035-a-gateway-sends-chosen-fleet-events-to-webhook-destinations.md) | A gateway sends chosen fleet events to webhook destinations | Accepted — not yet implemented | | [0036](0036-daemon-state-is-a-sqlite-database-whose-tables-each-owner-keeps.md) | Daemon state is a SQLite database, and each owner keeps its own tables | Accepted — not yet implemented | -| [0038](0038-the-warm-pool-learns-its-kinds-from-leases-and-boots-for-every-queued-request.md) | The warm pool learns its kinds from leases, and boots for every queued request | Accepted — not yet implemented | -| [0037](0037-the-console-acts-through-the-http-routes-on-base-ui.md) | The console acts through the HTTP routes, on Base UI | Proposed | | [0037](0037-the-console-acts-through-the-http-routes-on-base-ui.md) | The console acts through the HTTP routes, on Base UI | Accepted — not yet implemented | +| [0038](0038-the-warm-pool-learns-its-kinds-from-leases-and-boots-for-every-queued-request.md) | The warm pool learns its kinds from leases, and boots for every queued request | Accepted — not yet implemented | diff --git a/e2e/console/leases.spec.ts b/e2e/console/leases.spec.ts index 4951ff204..243e8888e 100644 --- a/e2e/console/leases.spec.ts +++ b/e2e/console/leases.spec.ts @@ -446,7 +446,7 @@ test.describe("the leases page", () => { const title = await boxOf(page.getByRole("heading", { level: 1, name: "Leases" })); const chips = await boxOf(page.getByRole("group", { name: "Filter leases" })); const search = await boxOf(page.getByRole("searchbox", { name: "Search leases" })); - const table = await boxOf(page.locator("main table")); + const table = await boxOf(page.locator("main .table-card")); expect(chips.x).toBeCloseTo(title.x, 0); expect(search.x).toBeGreaterThan(chips.x + chips.width); diff --git a/e2e/console/overview.spec.ts b/e2e/console/overview.spec.ts index d9c8781a2..b20e3c70b 100644 --- a/e2e/console/overview.spec.ts +++ b/e2e/console/overview.spec.ts @@ -101,7 +101,7 @@ async function tileText(page: Page, label: string): Promise { } async function tablesOf(page: Page): Promise { - const tables = page.locator("#main details.chart-data"); + const tables = page.locator("#main table.chart-data"); const count = await tables.count(); return Promise.all( Array.from({ length: count }, (_, index) => @@ -248,7 +248,7 @@ test.describe("the Overview's figures", () => { 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.locator("#main table.chart-data")).toHaveCount(2); await expect(page.getByRole("region", { name: "Activity" })).toHaveCount(0); } finally { await host.dispose(); @@ -308,7 +308,7 @@ async function workerConnection(host: RunningDaemon, label: string): Promise { - 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 ({ + test("an empty Inbox shows Nothing needs you in the Needs you panel; a disconnected worker shows the panel with that item first, and All in Inbox (1)", async ({ page, }) => { const fleet = await startFleet([ @@ -317,8 +317,9 @@ test.describe("the Overview's Inbox lines", () => { ]); 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 expect( + page.getByRole("region", { name: "Needs you" }).getByText("Nothing needs you"), + ).toBeVisible(); await (fleet.workers[1] as RunningDaemon).stop(); await waitFor( diff --git a/e2e/console/search.spec.ts b/e2e/console/search.spec.ts new file mode 100644 index 000000000..a271f20e5 --- /dev/null +++ b/e2e/console/search.spec.ts @@ -0,0 +1,322 @@ +import type { Page } from "@playwright/test"; + +import { waitFor } from "../helpers/wait.js"; +import { + disposeFleet, + expect, + type RunningDaemon, + signIn, + startDaemon, + startFleet, + test, +} from "./fixtures.js"; + +const ONE_DEVICE = { limits: { ios: { maxDevices: 1, maxRunning: 1 }, maxRunning: 1 } }; +const IOS = { availableOsVersions: ["18.4"], knownModels: ["iPhone 16"] }; + +async function readJson(daemon: RunningDaemon, path: string): Promise { + const response = await fetch(new URL(path, daemon.url), { + headers: { Authorization: `Bearer ${daemon.tokens.operator}` }, + }); + return (await response.json()) as T; +} + +// why: a host with one device held by `nav-holder` and one request, `nav-waiter`, waiting behind it. +async function startHostWithQueue(): Promise { + const host = await startDaemon("worker", { config: ONE_DEVICE, driverScript: { ios: IOS } }); + const args = ["lease", "--platform", "ios", "--device", "iPhone 16", "--os", "18.4"]; + const granted = await host.cli([...args, "--detach", "--agent-id", "nav-holder"]); + expect(granted.code, granted.stderr).toBe(0); + host.cliBackground([...args, "--agent-id", "nav-waiter"]); + await waitFor( + async () => + (await readJson<{ requests: unknown[] }>(host, "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/v1/lease-requests")).requests.length === 1, + { label: "the daemon lists the waiting request" }, + ); + return host; +} + +async function openConsole(page: Page, token: string, path = "/"): Promise { + await page.goto(path); + await signIn(page, token); + await expect(page.getByRole("button", { name: "Search or jump to…" })).toBeVisible(); +} + +test.describe("the search box", () => { + test("⌘K and Ctrl+K open the dialog and focus the box, the sidebar button opens it too, and Escape closes it and returns focus", async ({ + daemon, + page, + }) => { + await openConsole(page, daemon.tokens.operator); + const dialog = page.getByRole("dialog", { name: "Search" }); + const box = dialog.getByRole("combobox", { name: "Search pages, items and actions" }); + + for (const shortcut of ["Meta+k", "Control+k"]) { + await page.keyboard.press(shortcut); + await expect(dialog).toBeVisible(); + await expect(box).toBeFocused(); + await page.keyboard.press("Escape"); + await expect(dialog).toBeHidden(); + } + + const button = page.getByRole("button", { name: "Search or jump to…" }); + await button.click(); + await expect(dialog).toBeVisible(); + await expect(box).toBeFocused(); + await page.keyboard.press("Escape"); + await expect(dialog).toBeHidden(); + await expect(button).toBeFocused(); + }); +}); + +test.describe("the search list", () => { + test("the first result is highlighted, ↑ and ↓ move the highlight, and Enter runs the highlighted result", async ({ + daemon, + page, + }) => { + await openConsole(page, daemon.tokens.operator); + await page.keyboard.press("Control+k"); + const highlighted = page.getByRole("dialog", { name: "Search" }).locator("[data-highlighted]"); + await expect(highlighted).toHaveText("Overview"); + await page.keyboard.press("ArrowDown"); + await page.keyboard.press("ArrowDown"); + await expect(highlighted).toHaveText("Fleet"); + await page.keyboard.press("ArrowUp"); + await expect(highlighted).toHaveText("Inbox"); + await page.keyboard.press("Enter"); + await expect(page).toHaveURL(/\/inbox$/); + }); +}); + +test.describe("the search while data loads", () => { + test("opened before the data loads, each group says Loading… and fills in while the highlight stays, and a failed read says it could not load", async ({ + page, + }) => { + const host = await startHostWithQueue(); + try { + let release: () => void = () => undefined; + const gate = new Promise((resolve) => { + release = resolve; + }); + await page.route(/\/v1\/leases$/, async (route) => { + await gate; + await route.continue(); + }); + await openConsole(page, host.tokens.operator, new URL("/", host.url).toString()); + await page.keyboard.press("Control+k"); + const dialog = page.getByRole("dialog", { name: "Search" }); + await dialog.getByRole("combobox").fill("nav"); + const highlighted = dialog.locator("[data-highlighted]"); + await expect(highlighted).toContainText("nav-waiter"); + await expect(dialog.getByText("Loading…")).toHaveCount(2); + await expect(dialog.getByRole("option", { name: /nav-holder/ })).toHaveCount(0); + + release(); + await expect(dialog.getByRole("option", { name: /nav-holder/ })).toHaveCount(2); + await expect(dialog.getByText("Loading…")).toHaveCount(0); + await expect(highlighted).toContainText("nav-waiter"); + await expect(highlighted).toHaveCount(1); + + await page.keyboard.press("Escape"); + await page.unroute(/\/v1\/leases$/); + await page.route(/\/v1\/workers$/, (route) => + route.fulfill({ body: "{}", contentType: "application/json", status: 500 }), + ); + await page.reload(); + await expect(page.getByRole("button", { name: "Search or jump to…" })).toBeVisible(); + await page.keyboard.press("Control+k"); + await dialog.getByRole("combobox").fill("nav"); + await expect(dialog.getByText("Could not load workers.")).toBeVisible(); + await expect(dialog.getByText("Could not load devices.")).toBeVisible(); + await expect(dialog.getByRole("option", { name: /nav-holder/ })).toHaveCount(2); + } finally { + await host.dispose(); + } + }); +}); + +test.describe("the search during live updates", () => { + test("a live update while the dialog is open changes neither the list nor the highlight, and reopening builds the list again", async ({ + page, + }) => { + const host = await startHostWithQueue(); + try { + await openConsole(page, host.tokens.operator, new URL("/", host.url).toString()); + await page.keyboard.press("Control+k"); + const dialog = page.getByRole("dialog", { name: "Search" }); + const box = dialog.getByRole("combobox"); + await box.fill("nav"); + const options = dialog.getByRole("option"); + const before = await options.allInnerTexts(); + expect(before).toHaveLength(4); + await page.keyboard.press("ArrowDown"); + const highlighted = dialog.locator("[data-highlighted]"); + await expect(highlighted).toHaveText(before[1] ?? ""); + + const refetched = page.waitForResponse( + async (response) => + response.url().endsWith("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/v1/lease-requests") && + (await response.text()).includes("nav-late"), + ); + host.cliBackground([ + "lease", + "--platform", + "ios", + "--device", + "iPhone 16", + "--os", + "18.4", + "--agent-id", + "nav-late", + ]); + await refetched; + await page.evaluate( + () => new Promise((resolve) => requestAnimationFrame(() => requestAnimationFrame(resolve))), + ); + expect(await options.allInnerTexts()).toEqual(before); + await expect(highlighted).toHaveText(before[1] ?? ""); + + await page.keyboard.press("Escape"); + await page.keyboard.press("Control+k"); + await box.fill("nav-late"); + await expect(options.first()).toContainText("nav-late"); + } finally { + await host.dispose(); + } + }); +}); + +test.describe("the search shortcut", () => { + test("⌘K does nothing while a drawer is open", async ({ page }) => { + const host = await startHostWithQueue(); + try { + const [request] = (await readJson<{ requests: { id: string }[] }>(host, "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/v1/lease-requests")) + .requests as [{ id: string }]; + await page.goto(new URL(`/queue/${request.id}`, host.url).toString()); + await signIn(page, host.tokens.operator); + const drawer = page.getByRole("dialog"); + await expect(drawer).toHaveCount(1); + await expect(drawer).toContainText("nav-waiter"); + await page.keyboard.press("Control+k"); + await page.keyboard.press("Meta+k"); + await expect(page.getByRole("dialog", { name: "Search" })).toHaveCount(0); + await expect(drawer).toHaveCount(1); + await expect(drawer).toContainText("nav-waiter"); + } finally { + await host.dispose(); + } + }); +}); + +test.describe("the search list when nothing matches", () => { + test('no results shows "No results for "', async ({ daemon, page }) => { + await openConsole(page, daemon.tokens.operator); + await page.keyboard.press("Control+k"); + const dialog = page.getByRole("dialog", { name: "Search" }); + await expect(dialog.getByText("No results for")).toBeHidden(); + await dialog.getByRole("combobox").fill("zzz"); + await expect(dialog.getByText("No results for zzz", { exact: true })).toBeVisible(); + await expect(dialog.getByRole("option")).toHaveCount(0); + }); +}); + +test.describe("the search results", () => { + test("a typed name and Enter go to its page, worker, device, lease or request", async ({ + page, + }) => { + const host = await startHostWithQueue(); + try { + const [worker] = ( + await readJson<{ workers: { id: string; label?: string }[] }>(host, "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/v1/workers") + ).workers as [{ id: string; label?: string }]; + const [lease] = ( + await readJson<{ leases: { id: string; deviceId: string }[] }>(host, "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/v1/leases") + ).leases as [{ id: string; deviceId: string }]; + const [request] = (await readJson<{ requests: { id: string }[] }>(host, "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/v1/lease-requests")) + .requests as [{ id: string }]; + await openConsole(page, host.tokens.operator, new URL("/", host.url).toString()); + const box = page.getByRole("combobox", { name: "Search pages, items and actions" }); + const goTo = async (typed: string, path: RegExp) => { + // why: ⌘K does nothing while a drawer is open, so the one the last step opened is closed first. + if ((await page.getByRole("dialog").count()) > 0) await page.keyboard.press("Escape"); + await expect(page.getByRole("dialog")).toHaveCount(0); + await page.keyboard.press("Control+k"); + await box.fill(typed); + await page.keyboard.press("Enter"); + await expect(page.getByRole("dialog", { name: "Search" })).toBeHidden(); + await expect(page).toHaveURL(path); + }; + const encoded = (id: string) => encodeURIComponent(id).replaceAll(".", "\\."); + + await goTo("fleet", /\/fleet$/); + await goTo(worker.label ?? worker.id, new RegExp(`/fleet/${encoded(worker.id)}$`)); + await goTo("iphone", new RegExp(`/fleet/${encoded(worker.id)}/${encoded(lease.deviceId)}$`)); + await goTo("nav-holder", new RegExp(`/leases/${encoded(lease.id)}/?$`)); + await goTo("nav-waiter", new RegExp(`/queue/${encoded(request.id)}$`)); + } finally { + await host.dispose(); + } + }); +}); + +test.describe("the search actions", () => { + test("an action runs as from its menu: drain with its toast and Undo, release and cancel after their confirms, remove after the name is typed", async ({ + page, + }) => { + const fleet = await startFleet([ + { driverScript: { ios: IOS }, label: "gone-a" }, + { driverScript: { ios: IOS }, label: "live-b" }, + ]); + const host = await startHostWithQueue(); + try { + const [stopped] = fleet.workers as [RunningDaemon]; + await stopped.stop(); + await waitFor( + async () => + ( + await readJson<{ workers: { connection: string }[] }>(fleet.gateway, "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/v1/workers") + ).workers.some((view) => view.connection === "disconnected"), + { label: "the gateway sees the stopped worker disconnected" }, + ); + const run = async (typed: string) => { + await expect(page.getByRole("alertdialog")).toHaveCount(0); + await page.keyboard.press("Control+k"); + await page.getByRole("combobox", { name: "Search pages, items and actions" }).fill(typed); + await page.keyboard.press("Enter"); + await expect(page.getByRole("dialog", { name: "Search" })).toBeHidden(); + }; + + await openConsole(page, fleet.gateway.tokens.operator, fleet.gateway.url); + await run("drain live-b"); + await expect(page.getByText("live-b drained", { exact: true })).toBeVisible(); + await page.getByRole("button", { name: "Undo" }).click(); + await expect(page.getByText("live-b takes leases again")).toBeVisible(); + + await run("remove gone-a"); + const removal = page.getByRole("alertdialog", { name: "Remove gone-a?" }); + const remove = removal.getByRole("button", { name: "Remove worker" }); + await expect(remove).toBeDisabled(); + await removal.getByRole("textbox").fill("gone-"); + await expect(remove).toBeDisabled(); + await removal.getByRole("textbox").fill("gone-a"); + await expect(remove).toBeEnabled(); + await removal.getByRole("button", { name: "Keep" }).click(); + + await page.goto(host.url); + await signIn(page, host.tokens.operator); + await expect(page.getByRole("button", { name: "Search or jump to…" })).toBeVisible(); + await run("release nav-holder"); + await expect( + page.getByRole("alertdialog", { name: "Release nav-holder's lease?" }), + ).toBeVisible(); + await page.getByRole("button", { name: "Keep" }).click(); + await run("cancel nav-waiter"); + await expect( + page.getByRole("alertdialog", { name: "Cancel nav-waiter's request?" }), + ).toBeVisible(); + } finally { + await host.dispose(); + await disposeFleet(fleet); + } + }); +}); diff --git a/e2e/console/shell.spec.ts b/e2e/console/shell.spec.ts index 9d9133c61..5419c058f 100644 --- a/e2e/console/shell.spec.ts +++ b/e2e/console/shell.spec.ts @@ -87,7 +87,13 @@ test.describe("the shell", () => { ), ); } - expect(controls).toEqual(["Skip to content", ...NAV_LABELS, "Sign out", "Collapse sidebar"]); + expect(controls).toEqual([ + "Skip to content", + "Search or jump to…", + ...NAV_LABELS, + "Sign out", + "Collapse sidebar", + ]); expect(visited).toEqual(controls); // why: focus is on the sidebar toggle; walk back past Sign out to the last page link, then open @@ -101,7 +107,7 @@ test.describe("the shell", () => { await expect(page.getByRole("heading", { level: 1, name: entry.label })).toBeVisible(); } - await page.keyboard.press(back); + await pressTimes(back, 2); await expect(page.getByRole("link", { name: "Skip to content" })).toBeFocused(); await page.keyboard.press("Enter"); await expect(page.locator("#main")).toBeFocused(); diff --git a/e2e/console/usage.spec.ts b/e2e/console/usage.spec.ts index a14e856cd..46d748ab1 100644 --- a/e2e/console/usage.spec.ts +++ b/e2e/console/usage.spec.ts @@ -231,7 +231,7 @@ test.describe("the Usage page", () => { 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); + await expect(page.locator("#main table.chart-data")).toHaveCount(1); } finally { await host.dispose(); } diff --git a/e2e/console/views.spec.ts b/e2e/console/views.spec.ts index 298b7985b..41a556642 100644 --- a/e2e/console/views.spec.ts +++ b/e2e/console/views.spec.ts @@ -111,10 +111,6 @@ test.describe("every view", () => { for (const path of every(pages)) { await visit(page, host, path); - // why: a drawer makes the page behind it inert, so its disclosures cannot be opened. - if (!opensDrawer(path)) { - for (const summary of await page.locator("#main summary").all()) await summary.click(); - } expect(await hasHorizontalScroll(page), path).toBe(false); } } finally { @@ -170,9 +166,8 @@ test.describe("every view", () => { await chart.focus(); await page.keyboard.press("ArrowLeft"); await expect(page.locator(".chart-tip")).toContainText("leases held"); - await page.locator("#main summary").first().focus(); - await page.keyboard.press("Enter"); - await expect(page.getByRole("columnheader", { name: "Leases held" })).toBeVisible(); + // why: the chart's numbers are a table only a screen reader reads; it holds no stop for the keyboard. + await expect(page.getByRole("table", { name: "Leases held" })).toBeAttached(); await visit(page, host, "/activity"); await page.getByRole("radio", { name: "All" }).focus(); await page.keyboard.press("ArrowRight"); @@ -281,7 +276,6 @@ test.describe("every view", () => { if (!opensDrawer(path) && (await chart.count()) > 0) { await chart.hover(); await expect(page.locator(".chart-tip")).toBeVisible(); - await page.locator("#main summary").first().click(); } const found = await page.evaluate(() => ({ styles: document.querySelectorAll("style").length, @@ -332,7 +326,7 @@ test.describe("every view", () => { } }); - test("no