import { test, expect, type Page } from "@playwright/test"; import { createServer, type Server } from "node:http"; import type { AddressInfo } from "node:net"; import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; import { WARM_TIMEOUT, warm } from "./warm"; import { UI_OPS, UI_OPS_SITE_PLACEHOLDER, UI_OPS_SPEAKER } from "./fixtures/ui-ops-fixture.mjs"; // --------------------------------------------------------------------------- // OPERATIONS UI (UI notes 2026-10-30), each through the app: // // #9 the sites the cut's links depend on, each with its deploy's date, and // the warning when cited videos are newer than it; Publish asks // the editor (its stub records build-deploy) // #10 the link policy: "these channels direct" saved through its writer, // the check's clip-link-policy row and its one-press fix, and a new // clip written by the policy // #18 the render queue panel, read from the slot's own files (the // fixture's: HEAVY_LOCK_FILE), and a take's ETA from past renders // #15 the walk's speaker badge and Check speaker (the fake embedder) // // Fixture: fixtures/ui-ops-fixture.mjs, written for this file alone. Serial: // each test leaves what the next reads. // --------------------------------------------------------------------------- test.describe.configure({ mode: "serial" }); const PROJECT = `reports/${UI_OPS}`; const SPEAKERS = `reports/${UI_OPS_SPEAKER}`; const FIXTURE = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", ".e2e-song"); const DIR = path.join(FIXTURE, "reports", UI_OPS); const MANIFEST = path.join(DIR, "video.manifest.json"); const SITE_DIR = path.join(FIXTURE, "sites", "ui-ops-site"); const HEAVY = path.join(FIXTURE, "heavy"); const STUB_LOG = path.join(FIXTURE, "editor-stub.requests.json"); type Entry = { id: string; type: string; citeUrl?: string; channel?: string; video?: string }; const entries = () => (JSON.parse(readFileSync(MANIFEST, "utf8")) as { timeline: Entry[] }).timeline; const entry = (id: string) => entries().find((e) => e.id === id); // Screenshots for the morning review, when asked for (UI_OPS_SHOTS=). const SHOTS = process.env.UI_OPS_SHOTS ?? ""; const shot = async (page: Page, name: string, el?: ReturnType) => { if (!SHOTS) return; mkdirSync(SHOTS, { recursive: true }); if (el) await el.screenshot({ path: path.join(SHOTS, `${name}.png`) }); else await page.screenshot({ path: path.join(SHOTS, `${name}.png`), fullPage: false }); }; // The site the QRs link: built 9 Oct, with uiopschan's u1 only -- no u2 // (uploaded the 20th), no uiopsdirect. let server: Server; let origin = ""; const startSite = () => new Promise((resolve) => { server = createServer((req, res) => { const p = new URL(req.url ?? "/", "http://x").pathname; const json = (doc: unknown) => { res.writeHead(200, { "content-type": "application/json" }); res.end(JSON.stringify(doc)); }; if (p === "/corpus.json") { return json({ spec: 5, generatedAt: "2026-10-09T10:00:00.000Z", site: { title: "UI ops archive" }, channels: [{ slug: "uiopschan", manifests: { transcripts: `${origin}/transcripts/uiopschan/manifest.json` } }], }); } if (p === "/transcripts/uiopschan/manifest.json") return json({ pageCount: 1, slugToPage: { u1: 0 } }); if (p === "/transcripts/uiopschan/page-0000.json") return json([{ id: "u1" }]); res.writeHead(404); res.end(); }); server.listen(0, "127.0.0.1", () => { origin = `http://127.0.0.1:${(server.address() as AddressInfo).port}`; resolve(); }); }); test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); await startSite(); writeFileSync(MANIFEST, readFileSync(MANIFEST, "utf8").split(UI_OPS_SITE_PLACEHOLDER).join(origin)); // The site the QRs open, as transcripts/sites//site.json names it. mkdirSync(SITE_DIR, { recursive: true }); writeFileSync(path.join(SITE_DIR, "site.json"), JSON.stringify({ siteId: "ui-ops-site", siteTitle: "UI Ops Site", siteUrl: origin, channels: [{ slug: "uiopschan", order: 0 }] })); await warm(playwright, [urls.projectHref(PROJECT, { tab: "overview" }), urls.takesHref(PROJECT), urls.clipBenchHref(SPEAKERS, "k04")]); }); test.afterAll(() => { server?.close(); rmSync(SITE_DIR, { recursive: true, force: true }); rmSync(HEAVY, { recursive: true, force: true }); }); const row = (page: Page, kind: string, target: string) => page.locator(`[data-decision="${kind}"][data-target="${target}"]`); test("#9 the sites the links depend on: the deploy's date, the cited videos newer than it, and Publish ", async ({ page }) => { const host = new URL(origin).host; await page.goto(urls.projectHref(PROJECT, { tab: "overview" })); const site = page.locator(`[data-link-site="${host}"]`); await expect(site).toHaveAttribute("data-link-site-id", "ui-ops-site"); await expect(site.locator("[data-link-site-deploy]")).toContainText("deploy date unknown · not checked yet"); // Check links reads every site's corpus.json; its date is the deploy's. await site.locator('[data-settle-button="links"]').click(); await expect(site).toHaveAttribute("data-link-site-deployed", "2026-10-09", { timeout: 30_000 }); await expect(site.locator("[data-link-site-deploy]")).toContainText("deployed 2026-10-09 (its corpus.json)"); await expect(site).toHaveAttribute("data-link-site-newer", "1"); await expect(site.locator("[data-link-site-warning]")).toHaveText("1 cited video is newer than this deploy: o02 (uploaded 2026-10-20)"); const behind = row(page, "site-deploy-behind", host); await expect(behind).toContainText("ui-ops-site's deploy is from 2026-10-09; 1 cited video is newer: o02 (uploaded 2026-10-20)"); await expect(behind.locator("[data-fix]")).toHaveAttribute("data-fix", `pnpm ops build-deploy --json '{"siteId":"ui-ops-site"}'`); await shot(page, "9-site-deploy-warning"); await shot(page, "9-site-deploy-warning-panel", site); // Publish asks the editor's build-deploy (the stub records it). await site.locator('[data-settle-button="publish-ui-ops-site"]').click(); await expect(site.locator('[data-settle="publish-site"] [data-settle-said]')).toContainText(/queued on the editor's publish queue \(job deploy-\d+\)/); const asked = (JSON.parse(readFileSync(STUB_LOG, "utf8")) as { route?: string; siteId?: string; authorization?: string }[]).filter((r) => r.route === "build-deploy"); expect(asked.at(-1)).toMatchObject({ siteId: "ui-ops-site", authorization: "Bearer umtool-e2e-token" }); }); test("#10 the link policy: cite via ui-ops-site, uiopsdirect direct; the check's row and its fix; a new clip is written by it", async ({ page }) => { await page.goto(urls.projectHref(PROJECT, { tab: "overview" })); const panel = page.locator("[data-link-policy]"); await expect(panel).toHaveAttribute("data-link-policy", "none"); // "Cite via ui-ops-site; uiopsdirect direct." await panel.locator("[data-link-policy-via]").selectOption(origin); await panel.locator('[data-link-policy-direct="uiopsdirect"]').check(); await panel.locator("[data-link-policy-save]").click(); await expect(panel.locator("[data-link-policy-said]")).toContainText("saved"); await expect(panel).toHaveAttribute("data-link-policy", "set"); expect((JSON.parse(readFileSync(MANIFEST, "utf8")) as { provenance: { linkPolicy?: unknown } }).provenance.linkPolicy).toEqual({ via: origin, direct: ["uiopsdirect"] }); // Only o03 breaks it: o01 and o02 already open ui-ops-site. await expect(page.locator('[data-decision="clip-link-policy"]')).toHaveCount(1); const policyRow = row(page, "clip-link-policy", "o03"); await expect(policyRow).toContainText(`uiopsdirect links direct by the project's link policy, but its QR opens ${new URL(origin).host}`); await expect(policyRow.locator('[data-settle-button="o03"]')).toHaveText("Link its YouTube page"); await expect(policyRow.locator("[data-fix]")).toHaveAttribute("data-fix", `umtool window ${PROJECT} o03 --cite-url 'https://www.youtube.com/watch?v=d1&t=10s'`); await shot(page, "10-link-policy-row"); await shot(page, "10-link-policy-panel", panel); await policyRow.locator('[data-settle-button="o03"]').click(); await expect(row(page, "clip-link-policy", "o03")).toHaveCount(0); expect(entry("o03")?.citeUrl).toBe("https://www.youtube.com/watch?v=d1&t=10s"); await shot(page, "10-link-policy-fixed"); // A new clip of the direct channel: the inserter writes its YouTube page. const r = await page.request.post("/api/report/timeline", { data: { project: PROJECT, op: "insert", afterId: "o03", entry: { type: "clip", channel: "uiopsdirect", video: "d1", start: 20, end: 24, citeUrl: `${origin}/?v=uiopsdirect%2Fd1&t=20` } }, }); expect(r.ok()).toBe(true); const added = entries().find((e) => e.type === "clip" && e.video === "d1" && e.id !== "o03"); expect(added?.citeUrl).toBe("https://www.youtube.com/watch?v=d1&t=20s"); }); test("#18 the render queue: what runs and waits at the heavy slot, from its files, and a take's ETA from past renders", async ({ page }) => { // The slot's own files, as queue-lock writes them (the fixture's slot): an // e2e suite running, a render of this project waiting for memory. Both name // live pids (this worker and its parent), so they count. const lock = path.join(HEAVY, "heavy-queue.lock"); const put = (file: string, doc: unknown) => { mkdirSync(path.dirname(file), { recursive: true }); writeFileSync(file, JSON.stringify(doc)); }; const now = Date.now(); put(`${lock}.jobs/${process.pid}.json`, { pid: process.pid, estimateMb: 1500, build: false, exclusive: false, worktree: "/w/lane-a", branch: "lane/a", cmd: "playwright test", startedAt: new Date(now - 12 * 60_000).toISOString() }); put(path.join(HEAVY, "e2e-editor-queue.lock.holder.json"), { name: "e2e-editor", pid: process.pid, worktree: "/w/lane-a", branch: "lane/a", cmd: "playwright test", startedAt: new Date(now - 13 * 60_000).toISOString() }); put(`${lock}.waiting/${process.ppid}.json`, { pid: process.ppid, estimateMb: 6020, build: false, exclusive: false, worktree: "/w/main", branch: "main", cmd: `node /repo/umtool/report-to-video/build-video.mjs ${DIR}/.take-draft-3.render.json --out ${DIR}/takes/draft-3/out --progress ndjson`, since: new Date(now - 3 * 60_000).toISOString(), stage: "memory", stageSince: new Date(now - 2 * 60_000).toISOString(), }); await page.goto(urls.takesHref(PROJECT)); const q = page.locator("[data-render-queue]"); await expect(q).toHaveAttribute("data-render-queue", "busy", { timeout: 15_000 }); await expect(q.locator("[data-render-queue-held-by]")).toHaveText("held by e2e suite e2e-editor"); const running = q.locator('[data-queue-state="running"]'); await expect(running).toHaveCount(1); await expect(running).toContainText("e2e suite e2e-editor"); await expect(running).toContainText("lane-a (lane/a)"); await expect(running).toContainText("12 min"); const waiting = q.locator('[data-queue-state="waiting"]'); await expect(waiting).toContainText("render of draft-3"); await expect(waiting).toContainText("at the head of the line, for memory"); await expect(q.locator("[data-render-queue-mine]")).toContainText("draft-3: waiting 3 min — at the head of the line, for memory"); // The ETA: draft-2 (from draft-1) 240 s for 30 s; draft-0 and draft-1 600 s fresh. const eta = q.locator("[data-take-eta]"); await expect(eta).toHaveAttribute("data-take-eta", "known"); await expect(eta.locator("[data-take-eta-reuse]")).toHaveText("~4 min made from draft-2 (reuse)"); await expect(eta.locator("[data-take-eta-fresh]")).toHaveText("~10 min fresh"); await eta.locator("summary").click(); await expect(eta).toContainText("draft-0 (fresh): 0:30 of video in 10 min (from its files' times)"); await shot(page, "18-render-queue-eta", q); await shot(page, "18-render-queue-page"); // The job lets go: its ticket is gone and the panel says so. rmSync(HEAVY, { recursive: true, force: true }); await expect(q).toHaveAttribute("data-render-queue", "idle", { timeout: 15_000 }); await expect(q.locator("[data-render-queue-held-by]")).toHaveText("the heavy slot is free"); }); test("#15 the walk's speaker badge: Check speaker scores the clip against the named voices", async ({ page }) => { await page.goto(urls.clipBenchHref(SPEAKERS, "k04")); const badge = page.locator("[data-speaker-badge]"); await expect(badge).toHaveAttribute("data-speaker-badge", "unchecked"); await expect(badge.locator("[data-speaker-line]")).toHaveText("Speaker: not checked"); await badge.locator("[data-speaker-check]").click(); await expect(badge).toHaveAttribute("data-speaker-badge", "matches", { timeout: 60_000 }); await expect(badge.locator("[data-speaker-line]")).toHaveText(/^Speaker: matches Host \d\.\d\d \/ Guest 0\.\d\d$/); await expect(badge.locator("[data-speaker-reference]")).toHaveText("vs Host 2 · Guest 1"); await expect(badge.locator("[data-speaker-reference]")).toHaveAttribute("title", /^measured against: Host: 2 pieces \(2 kept\) · Guest: 1 piece \(1 kept\) · \d{4}-\d\d-\d\d \d\d:\d\d$/); await shot(page, "15-speaker-badge", page.locator("[data-verdict-bar]").first()); await shot(page, "15-speaker-badge-page"); // This clip is Host's: it joins Host's reference set. await badge.locator("[data-speaker-add-open]").click(); await badge.locator("[data-speaker-voice]").fill("Host"); await badge.locator("[data-speaker-add]").click(); await expect(badge).toContainText("in Host’s voice"); const speakers = JSON.parse(readFileSync(path.join(FIXTURE, "reports", UI_OPS_SPEAKER, "speakers.json"), "utf8")) as { speakers: { name: string; clips?: string[] }[] }; expect(speakers.speakers.find((s) => s.name === "Host")?.clips).toEqual(["k01", "k02", "k04"]); });