import { test, expect, type APIRequestContext, type Page } from "@playwright/test"; import { execFileSync } from "node:child_process"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; import { warm, WARM_TIMEOUT } from "./warm"; // --------------------------------------------------------------------------- // THE INBOX (plans/umtool-redesign.md, P3) at /, and the dashboard's panels // where they went: /settings/system. The Inbox reads lib/inbox (P2a): one big // number -- the calls waiting on active pieces -- then the cards, grouped and // ranked, as one lit list, each with ONE primary action, Park and Mute. // // WRITES the fixture's REPORTS_ROOT/.umtool/lifecycle.json (zeta and // polemic-alpha parked or done, then active again) and mutes.json (zeta's // ready iterations muted, then unmuted). // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const UMTOOL = path.join(HERE, ".."); const FIXTURE = path.join(UMTOOL, ".e2e-song"); const ZETA = "a:articles/zeta"; const ALPHA = "a:priv/polemic-alpha"; const CALL_GROUPS = ["your-call", "review", "blocking", "notes", "open"]; const ORDER = ["your-call", "review", "blocking", "notes", "open", "ready-to-finish", "quiet"]; type Group = { id: string; decisions: number; hidden: number; cards: { piece: string | null; kind: string }[] }; const groups = async (request: APIRequestContext): Promise => ((await (await request.get("/api/browse/decisions")).json()) as { groups: Group[] }).groups; const setLife = (request: APIRequestContext, piece: string, state: string) => request.post("/api/pieces/lifecycle", { data: { piece, state } }); const card = (page: Page, piece: string, kind: string) => page.locator(`[data-lit-line][data-piece='${piece}'][data-card='${kind}']`); // A WRITE, THEN THE LIST AGAIN. Park, Mark done, Reactivate, Mute, Unmute and Undo POST, then router.refresh(): the // list changes when the refreshed page has been rendered and streamed whole. Three failures of this spec (11 Nov: // :122 Reactivate, :178 Unmute, and Undo after Mark done) were all that step late, not wrong: the POST had answered // 200 and the refresh's request had gone out and been answered, the lifecycle and the mutes are read from disk on // every render (never memoised), and in the one trace that shows it a HEAD of the same page, sent in the same // second, took 5.8 s to answer -- the server was that slow for those seconds (another suite's build beside it) and // the default 5 s expect gave up first. So the FIRST look at the list after such a write waits this long. const SETTLES = { timeout: 20_000 }; test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); await warm(playwright, ["/", "/?hidden=1", "/api/browse/decisions", "/api/rail", "/settings/system", "/projects"]); }); test("the big count is the cards in the five call groups; the groups come in their order; Quiet is folded", async ({ page, request }) => { const g = await groups(request); const calls = g.filter((x) => CALL_GROUPS.includes(x.id)).reduce((n, x) => n + x.cards.length, 0); await page.goto(urls.homeHref()); await expect(page.locator("[data-app-rail] [data-place=inbox]")).toHaveAttribute("aria-current", "page"); // The machine's own calls (a required tool absent, a nearly full disk) are // cards too; on the fixture with nothing probed there are none to count on. const machine = await page.locator("[data-card^='machine-']").count(); await expect(page.locator("[data-inbox-count]")).toHaveAttribute("data-inbox-count", String(calls + machine)); // The rail's count is memoised for a few seconds (lib/rail.ts) and asked once per page load: one // filled before the fixture's last write (the warm-up asks /api/rail) is that much behind, so a // rail that disagrees is asked again once the memo has lapsed. const rail = page.locator("[data-rail-count=inbox]"); await expect(async () => { await expect(rail).toHaveText(/^\d+$/); if ((await rail.textContent()) !== String(calls + machine)) await page.reload(); await expect(rail).toHaveText(String(calls + machine), { timeout: 2_000 }); }).toPass({ timeout: 25_000 }); await expect(page.locator("[data-inbox-note]")).toContainText("quiet"); const shown = await page.locator("[data-lit-list] [data-group]").evaluateAll((els) => els.map((e) => e.getAttribute("data-group"))); expect(shown.length).toBeGreaterThan(2); expect(shown).toEqual(ORDER.filter((id) => shown.includes(id))); // Quiet is one folded line with its count; opening it shows its cards. const quiet = page.locator("[data-group=quiet]"); await expect(quiet).toHaveAttribute("data-collapsed", ""); await expect(quiet.locator("[data-lit-line]")).toHaveCount(0); await quiet.click(); await expect(page.locator("[data-group=quiet] [data-lit-line]").first()).toBeVisible(); }); test("j lights the next card, and only the lit card's action wears Signal", async ({ page }) => { await page.goto(urls.homeHref()); const list = page.locator("[data-lit-list]").first(); await expect(list).toHaveAttribute("data-hydrated", ""); const lines = list.locator("[data-lit-line]"); await expect(lines.nth(0)).toHaveAttribute("data-lit", ""); const bg = (i: number) => lines.nth(i).locator(".lit-go").evaluate((el) => getComputedStyle(el).backgroundColor); const signal = await page.evaluate(() => { const probe = document.createElement("i"); probe.style.color = "var(--signal)"; document.body.append(probe); const c = getComputedStyle(probe).color; probe.remove(); return c; }); // Polled: the fill eases in (the button's colour transition). await expect.poll(() => bg(0)).toBe(signal); expect(await bg(1)).not.toBe(signal); await page.locator("body").press("j"); await expect(lines.nth(1)).toHaveAttribute("data-lit", ""); await expect(lines.nth(1)).toBeFocused(); await expect.poll(() => bg(1)).toBe(signal); await expect.poll(() => bg(0)).not.toBe(signal); }); test("Park hides a piece's calls, Undo brings them back; Show hidden lists them with Reactivate", async ({ page, request }) => { test.slow(); // room for SETTLES on a loaded machine try { await page.goto(urls.homeHref()); const ready = card(page, ZETA, "iteration-ready"); await expect(ready).toBeVisible(); const before = Number(await page.locator("[data-inbox-count]").getAttribute("data-inbox-count")); await ready.click(); await ready.locator("[data-lifecycle-to=parked]").click(); await expect(page.locator(`[data-undo='${ZETA}']`)).toContainText("Parked"); await expect(page.locator(`[data-lit-line][data-piece='${ZETA}']`)).toHaveCount(0, SETTLES); await expect(page.locator("[data-inbox-count]")).not.toHaveAttribute("data-inbox-count", String(before)); await expect(page.locator("[data-show-hidden]")).toContainText(/^Show hidden \d+$/); await page.locator(`[data-undo='${ZETA}']`).getByRole("button", { name: "Undo" }).click(); await expect(ready).toBeVisible(SETTLES); await expect(page.locator("[data-inbox-count]")).toHaveAttribute("data-inbox-count", String(before)); // Parked again, it is listed under Hidden, and Reactivate is its action. expect((await setLife(request, ZETA, "parked")).status()).toBe(200); await page.goto(urls.homeHref({ hidden: true })); const hidden = page.locator(`[data-group=hidden] [data-lit-line][data-piece='${ZETA}']`).first(); await expect(hidden).toBeVisible(); await hidden.click(); await hidden.locator("[data-lifecycle-to=active]").click(); await expect(page.locator(`[data-group=hidden] [data-lit-line][data-piece='${ZETA}']`)).toHaveCount(0, SETTLES); await expect(card(page, ZETA, "iteration-ready")).toBeVisible(); } finally { await setLife(request, ZETA, "active"); } }); test("Mark done on a piece that looks done takes it off the Inbox; Undo puts it back", async ({ page, request }) => { test.slow(); // room for SETTLES on a loaded machine try { await page.goto(urls.homeHref()); const done = page.locator(`[data-group=ready-to-finish] [data-piece='${ALPHA}'][data-card='looks-done']`); await expect(done).toBeVisible(); await done.click(); await done.locator("[data-lifecycle-to=done]").click(); await expect(page.locator(`[data-undo='${ALPHA}']`)).toContainText("Marked done"); await expect(done).toHaveCount(0, SETTLES); await page.locator(`[data-undo='${ALPHA}']`).getByRole("button", { name: "Undo" }).click(); await expect(done).toBeVisible(SETTLES); } finally { await setLife(request, ALPHA, "active"); } }); test("Mute is the server's: the card leaves, its rows stay hidden-by-muted, Muted N lists it with Unmute", async ({ page, request }) => { test.slow(); // room for SETTLES on a loaded machine const rows = async () => ((await (await request.get("/api/browse/decisions")).json()) as { items: { piece?: string; kind: string; hidden: boolean; hiddenBy?: string }[]; muted: number }) try { await page.goto(urls.homeHref()); const ready = card(page, ZETA, "iteration-ready"); await expect(ready).toBeVisible(); await expect(page.locator("[data-lit-list]").first()).toHaveAttribute("data-hydrated", ""); await ready.click(); await ready.locator("[data-mute=mute]").click(); await expect(page.locator(`[data-undo='${ZETA}']`)).toContainText("Muted"); await expect(ready).toHaveCount(0, SETTLES); // Never dropped: every row is still in the API, hidden, and says why. const after = await rows(); const zeta = after.items.filter((d) => d.piece === ZETA && d.kind === "iteration-ready"); expect(zeta.length).toBeGreaterThan(0); expect(zeta.every((d) => d.hidden && d.hiddenBy === "muted")).toBe(true); expect(after.muted).toBeGreaterThanOrEqual(zeta.length); // The other kinds on the same piece are not muted. expect(after.items.some((d) => d.piece === ZETA && d.kind === "iteration-failed" && !d.hidden)).toBe(true); // Another browser (a reload with no storage) sees the same. await page.evaluate(() => localStorage.clear()); await page.reload(); await expect(card(page, ZETA, "iteration-ready")).toHaveCount(0); await expect(page.locator("[data-show-muted]")).toHaveText(/^Muted \d+$/); await page.locator("[data-show-muted]").click(); await expect(page).toHaveURL(/muted=1/); const muted = page.locator(`[data-group=muted] [data-lit-line][data-piece='${ZETA}'][data-card='iteration-ready']`); await expect(muted).toHaveAttribute("data-muted", ""); await muted.click(); await muted.locator("[data-mute=unmute]").click(); await expect(muted).toHaveCount(0, SETTLES); await expect(page.locator(`[data-group=review] [data-lit-line][data-piece='${ZETA}'][data-card='iteration-ready']`)).toBeVisible(); expect((await rows()).items.filter((d) => d.piece === ZETA && d.kind === "iteration-ready").every((d) => !d.hidden)).toBe(true); } finally { await request.post("/api/pieces/mute", { data: { piece: ZETA, kind: "iteration-ready", muted: false } }); } }); test("POST /api/pieces/mute refuses junk", async ({ request }) => { const post = (data: unknown) => request.post("/api/pieces/mute", { data }); expect((await post({ piece: "articles/zeta", kind: "iteration-ready", muted: true })).status()).toBe(400); expect((await post({ piece: ZETA, kind: "Not A Kind", muted: true })).status()).toBe(400); expect((await post({ piece: ZETA, kind: "iteration-ready", muted: "yes" })).status()).toBe(400); expect((await post({ piece: ZETA })).status()).toBe(400); expect((await post({ piece: "p:no-such-project", kind: "unbuilt", muted: true })).status()).toBe(404); }); test("the editor's hand-off, /?from=, lands on Create with the recording's form prefilled (P5)", async ({ page }) => { await page.goto("/?from=testchan%2Fvid1"); await expect(page).toHaveURL(/\/create\?from=testchan%2Fvid1$/); const form = page.locator("[data-make-form=video-recording]"); await expect(form.locator("[data-new-from]")).toHaveValue("testchan/vid1"); await expect(form.locator("[data-new-seed]")).toBeVisible(); // The Inbox itself, with no `from`, is not redirected. await page.goto(urls.homeHref()); await expect(page).toHaveURL(/\/$/); }); // --------------------------------------------------------------------------- // /settings/system: the dashboard's panels. Everything on it is read from the // index and the job registries; nothing on it shells out, and the tools panel // proves that by saying "not checked" until somebody presses the button. // --------------------------------------------------------------------------- test("the projects panel says exactly what /projects' header says", async ({ page }) => { await page.goto(urls.projectsHref()); const header = (await page.locator("header .micro").last().textContent())?.trim(); expect(header).toMatch(/^\d+ projects · \d+ blocking · \d+ open$/); await page.goto(urls.systemHref()); await expect(page.locator("[data-app-rail] [data-place=settings]")).toHaveAttribute("aria-current", "page"); await expect(page.locator("[data-projects-note]")).toHaveText(header!); // One row per kind, each with the six states as segments. await expect(page.locator("[data-state-row]").first()).toBeVisible(); const seg = page.locator("[data-state-seg]").first(); await expect(seg).toHaveAttribute("href", /\/projects\?kind=.+&state=\w+/); // The generation policy's current home is a link away. await expect(page.locator("[data-policy-link]")).toHaveAttribute("href", urls.generationPolicyHref()); }); test("tools read 'not checked' until the button is pressed, and the stubs are found", async ({ page, request }) => { const before = await (await request.get("/api/doctor")).json(); // Runs first in this file, and nothing else in the suite probes. expect(before.checked).toBe(false); await page.goto(urls.systemHref()); await expect(page.locator("[data-tools-checked]")).toHaveAttribute("data-tools-checked", "never"); await page.locator("[data-action=doctor]").click(); // The fixture's YTDLP_BIN and QRENCODE_BIN are node stubs that answer // --version, so both are PRESENT with a version -- proof the probe read the // same env the pipeline does. await expect(page.locator("[data-tool=yt-dlp]")).toHaveAttribute("data-present", "1"); await expect(page.locator("[data-tool=qrencode]")).toHaveAttribute("data-present", "1"); await expect(page.locator("[data-tool=ffmpeg]")).toHaveAttribute("data-present", "1"); const after = await (await request.get("/api/doctor")).json(); expect(after.checked).toBe(true); expect(after.tools.find((t: { id: string }) => t.id === "yt-dlp").version).toContain("fixture"); }); test("umtool doctor reports a deliberately bad path as absent, and exits 1", () => { let code = 0; let stdout = ""; try { stdout = execFileSync("node", ["bin/umtool.mjs", "doctor", "--json"], { cwd: UMTOOL, encoding: "utf8", env: { ...process.env, YTDLP_BIN: path.join(FIXTURE, "bin", "definitely-not-here"), QRENCODE_BIN: path.join(FIXTURE, "bin", "qrencode"), // The fixture's roots, never this shell's media root or cache (empty = unset). UMTOOL_MEDIA_DIR: "", UMTOOL_CACHE_DIR: path.join(FIXTURE, "cache"), }, }); } catch (e) { const err = e as { status: number; stdout: string }; code = err.status; stdout = err.stdout; } const j = JSON.parse(stdout); const yt = j.tools.find((t: { id: string }) => t.id === "yt-dlp"); expect(yt.present).toBe(false); expect(yt.required).toBe(true); expect(j.ok).toBe(false); // A script can gate on it: the report pipeline cannot run without yt-dlp. expect(code).toBe(1); expect(j.tools.find((t: { id: string }) => t.id === "qrencode").present).toBe(true); }); test("/api/jobs has one shape over both registries", async ({ request }) => { const j = await (await request.get("/api/jobs")).json(); expect(j).toHaveProperty("running"); expect(Array.isArray(j.jobs)).toBe(true); for (const it of j.jobs) { expect(["chain", "render"]).toContain(it.source); expect(["running", "done", "failed"]).toContain(it.state); expect(typeof it.href).toBe("string"); } }); test("a build shows in Now, then in the activity list as done", async ({ page, request }) => { const start = await request.post("/api/report/build", { data: { project: "reports/dash-fixture", preset: "fast" }, }); expect(start.ok()).toBeTruthy(); const { job } = (await start.json()) as { job: { id: string } }; // Poll /api/jobs rather than the page: the offline build is ~3 s, and a // page load can land on either side of it. What must be true is that the // job is visible through the ONE endpoint while it runs, with its step. let seenRunning = false; for (let i = 0; i < 100; i += 1) { const j = (await (await request.get("/api/jobs")).json()) as { running: { id: string; progress?: { step: number; of: number } } | null; jobs: { id: string; state: string; href: string }[]; }; if (j.running?.id === job.id) { seenRunning = true; expect(j.running.progress?.of).toBeGreaterThan(0); } const mine = j.jobs.find((x) => x.id === job.id); if (mine && mine.state !== "running") { expect(mine.state).toBe("done"); expect(mine.href).toBe("/projects/reports/dash-fixture"); break; } await new Promise((r) => setTimeout(r, 200)); } expect(seenRunning).toBe(true); await page.goto(urls.systemHref()); const row = page.locator(`[data-activity-id="${job.id}"]`); await expect(row).toHaveAttribute("data-activity-state", "done"); await expect(row.getByRole("link")).toHaveAttribute("href", "/projects/reports/dash-fixture"); await expect(page.locator("[data-now=idle]")).toBeVisible(); }); test("the sources panel counts never-checked projects from the index, not from a probe", async ({ page }) => { await page.goto(urls.systemHref()); const counts = await page.locator("[data-sources-counts]").getAttribute("data-sources-counts"); const [never] = counts!.split("/").map(Number); // The fixture has report projects nothing has preflighted (report-fixture, // bench-fixture, the long-form ones); at least one is never-checked. expect(never).toBeGreaterThan(0); await expect(page.locator("[data-sources-list=never] [data-source-project='reports/longform-fixture']")).toBeVisible(); await expect(page.locator("[data-action=check-sources]")).toBeEnabled(); });