import { test, expect, type Page } from "@playwright/test"; import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // THE INGREDIENT LIFE-CYCLE RAIL (umtool redesign, lane L5; operator, 9 Nov 2026: "the stage rail could be good // for viewing a downloaded clip or other video ingredient to see its entire life cycle"): /ingredients// // shows one recording across nine stages -- found, downloaded, transcribed, clock, windows, used in, checked, // rendered, published -- each a pill (✓, a count, ! or —) and a panel, and each stage's action says what it // costs and where it lands before it posts to the editor's (stubbed) or umtool's own route. // // Fixture: e2e/fixtures/ingredient-rail-fixture.mjs -- railchan/railvid used by reports/rail-a (ra1, ra2; a saved // version v1 holding ra1, rendered) and reports/rail-b (rb1); railrumble/v7rslug1 (embed id v7rembd1) cited by // reports/rail-r. WRITES (rail-b's links.json, maybe rail-a's quote-check.json): its own. // // INGREDIENT_SHOTS (a directory): the page's screenshots at 1366×768 go there too. // --------------------------------------------------------------------------- test.describe.configure({ mode: "serial" }); const FIXTURE = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", ".e2e-song"); const STUB_LOG = path.join(FIXTURE, "editor-stub.requests.json"); const SHOTS = process.env.INGREDIENT_SHOTS ?? null; const RAIL = urls.ingredientHref("railchan", "railvid"); type StubRequest = { route?: string; slug?: string; id?: string; items?: { slug: string; id: string; clipId?: string }[]; dryRun?: boolean; windows?: string[] }; const stubLog = (): StubRequest[] => { try { return JSON.parse(readFileSync(STUB_LOG, "utf8")) as StubRequest[]; } catch { return []; } }; const railAsks = (route: string) => stubLog().filter((r) => r.route === route && (r.slug === "railchan" || (r.items ?? []).some((i) => i.slug === "railchan"))); const shot = async (page: Page, name: string) => { await page.screenshot({ path: test.info().outputPath(name) }); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, name) }); }; const pill = (page: Page, key: string) => page.locator(`[data-ingredient-rail] [data-stage="${key}"]`); const openStage = async (page: Page, key: string) => { await pill(page, key).click(); await expect(page.locator(`[data-stage-panel="${key}"]`)).toBeVisible(); }; /** Ask, read the confirmation (cost, queue), Start, and wait for the answer. */ async function runAction(page: Page, id: string, { cost, queue }: { cost: string; queue?: RegExp }) { await page.locator(`[data-action-ask="${id}"]`).click(); const confirm = page.locator(`[data-action-confirm="${id}"]`); await expect(confirm).toBeVisible({ timeout: 20_000 }); await expect(confirm).toHaveAttribute("data-action-cost", cost); if (queue) await expect(confirm.locator("[data-action-queue]")).toHaveText(queue); await confirm.locator(`[data-action-start="${id}"]`).click(); await expect(page.locator(`[data-action-result="${id}"]`)).toBeVisible({ timeout: 30_000 }); await expect(page.locator(`[data-action-error="${id}"]`)).toHaveCount(0); } test.beforeEach(async ({ page }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 768 }); }); test("all nine pills render: ✓, a count, ! or — from the files that exist, and the page fits 1366×768", async ({ page }) => { await page.goto(RAIL); await expect(page.locator("[data-ingredient]")).toHaveAttribute("data-ingredient", "railchan/railvid"); const rail = page.locator("[data-ingredient-rail] [data-stage]"); await expect(rail).toHaveCount(9); await expect(rail).toHaveText([/Found/, /Downloaded/, /Transcribed/, /Clock/, /Windows/, /Used in/, /Checked/, /Rendered/, /Published/]); const want: Record = { found: ["count", "1"], downloaded: ["ok", "✓"], transcribed: ["ok", "✓"], clock: ["none", "—"], windows: ["warn", "!"], used: ["count", "3"], checked: ["count", "1"], rendered: ["count", "1"], published: ["count", "1"], }; for (const [key, [kind, text]] of Object.entries(want)) { await expect(pill(page, key), key).toHaveAttribute("data-pill", kind); await expect(pill(page, key), key).toHaveAttribute("data-pill-text", text); } // The first stage that warns is the one open: two windows, one clip no window holds. await expect(page.locator('[data-stage-panel="windows"]')).toBeVisible(); await expect(page.locator("[data-stage-line]")).toHaveText("2 windows, 1 clip not fetched"); await expect(page.locator('[data-window="200.00-230.00"]')).toContainText("no project uses it now"); await expect(page.locator("[data-uncovered]")).toContainText("reports/rail-a ra2"); // The stage with no data says so in one line. await openStage(page, "clock"); await expect(page.locator("[data-stage-line]")).toContainText("No time map"); // Downloaded read the metadata's head only: its title, not the webpage_url past the formats. await openStage(page, "downloaded"); await expect(page.locator('[data-stage-panel="downloaded"]')).toContainText("The Rail Recording"); await expect(page.locator('[data-stage-panel="downloaded"]')).toContainText("1 metadata rewrite"); await openStage(page, "transcribed"); await expect(page.locator("[data-stage-line]")).toContainText("vtt, 100% of 5:00"); // App-like: no page scroll at 1366×768. expect(await page.evaluate(() => document.documentElement.scrollHeight <= window.innerHeight + 1)).toBe(true); await openStage(page, "windows"); await shot(page, "ingredient-rail.png"); }); test("Used in lists both projects, each clip a link to its bench, the saved version beside the draft", async ({ page }) => { await page.goto(RAIL); await openStage(page, "used"); const rows = page.locator("[data-used-row]"); await expect(rows).toHaveCount(3); await expect(page.locator('[data-used-row="reports/rail-a#ra1"]')).toContainText("draft, v1"); await expect(page.locator('[data-used-row="reports/rail-a#ra2"]')).toContainText("draft"); await expect(page.locator('[data-used-row="reports/rail-b#rb1"]')).toContainText("reports/rail-b"); await expect(page.locator('[data-used-row="reports/rail-a#ra1"] [data-used-open]')).toHaveAttribute("href", urls.clipBenchHref("reports/rail-a", "ra1")); await expect(page.locator("[data-stage-line]")).toHaveText("3 clips in 2 projects"); await shot(page, "ingredient-used.png"); // Rendered: the version v1 holds ra1, rendered; Play opens it at that clip. await openStage(page, "rendered"); await expect(page.locator('[data-rendered-row="reports/rail-a#ra1@v1"]')).toContainText("version v1"); await expect(page.locator('[data-rendered-row="reports/rail-a#ra1@v1"] [data-rendered-play]')).toHaveAttribute("href", urls.playHref("reports/rail-a", { take: "v1", clip: "ra1" })); // Checked and Published read the projects' own files. await openStage(page, "checked"); await expect(page.locator('[data-checked-row="reports/rail-a#ra1"]')).toHaveAttribute("data-status", "ok"); await expect(page.locator('[data-checked-row="reports/rail-a#ra2"]')).toContainText("not checked"); await openStage(page, "published"); await expect(page.locator('[data-published-row="reports/rail-b#rb1"]')).toHaveAttribute("data-state", "ok"); await expect(page.locator('[data-published-row="reports/rail-a#ra1"]')).toContainText("never checked"); }); test("?window= focuses one window: it is lit, and the stages after it narrow to the clips it plays", async ({ page }) => { await page.goto(urls.ingredientHref("railchan", "railvid", { from: 10, to: 40 })); await expect(page.locator("[data-ingredient-focus]")).toHaveAttribute("data-ingredient-focus", "10.00-40.00"); await expect(page.locator('[data-stage-panel="windows"]')).toBeVisible(); await expect(page.locator("[data-window-focused]")).toHaveCount(1); await expect(page.locator('[data-window="10.00-40.00"]')).toHaveAttribute("data-window-focused", "1"); await expect(page.locator('[data-window="10.00-40.00"]')).toContainText("cuts rail-a ra1, rail-b rb1"); await expect(pill(page, "used")).toHaveAttribute("data-pill-text", "2"); await openStage(page, "used"); await expect(page.locator("[data-used-row]")).toHaveCount(2); await expect(page.locator('[data-used-row="reports/rail-a#ra2"]')).toHaveCount(0); await expect(page.locator("[data-stage-line]")).toHaveText("2 clips in 2 projects (of 3 from this recording)"); await expect(page.locator("[data-checked-row]")).toHaveCount(0); // the checked panel is not open await openStage(page, "checked"); await expect(page.locator("[data-checked-row]")).toHaveCount(2); await shot(page, "ingredient-window.png"); }); test("Rumble: the folder slug and the embed id open the same recording, and the page shows both", async ({ page }) => { for (const id of ["v7rembd1", "v7rslug1"]) { await page.goto(urls.ingredientHref("railrumble", id)); await expect(page.locator("[data-ingredient]")).toHaveAttribute("data-ingredient", "railrumble/v7rslug1"); await expect(page.locator("[data-ingredient-site-id]")).toHaveAttribute("data-ingredient-site-id", "v7rembd1"); await expect(pill(page, "used")).toHaveAttribute("data-pill-text", "1"); } await openStage(page, "used"); await expect(page.locator('[data-used-row="reports/rail-r#rr1"]')).toBeVisible(); await openStage(page, "downloaded"); await expect(page.locator('[data-action-ask="persist"]')).toHaveText("Persist the whole recording…"); }); test("the entry points: the clip bench's Life cycle and Play's clip row link the clip's recording", async ({ page }) => { await page.goto(urls.clipBenchHref("reports/rail-a", "ra1")); await expect(page.locator("[data-bench-top] [data-bench-life]")).toHaveAttribute("href", RAIL); await page.goto(urls.playHref("reports/rail-a", { clip: "ra1" })); await expect(page.locator("[data-play-life]")).toHaveAttribute("href", RAIL, { timeout: 30_000 }); }); test("each action asks first -- what it costs, the queue it lands on -- then posts to the right route", async ({ page, request }) => { await page.goto(RAIL); // Downloaded: persist-videos, the editor's dry run first. await openStage(page, "downloaded"); const persists = railAsks("persist-videos").length; await runAction(page, "persist", { cost: "network", queue: /railchan channel's download queue/ }); const persist = railAsks("persist-videos").slice(persists); expect(persist.map((r) => !!r.dryRun)).toEqual([true, false]); expect(persist[1].items).toEqual([{ slug: "railchan", id: "railvid" }]); // Transcribed: transcribe-one, on the GPU. await openStage(page, "transcribed"); const transcribes = railAsks("transcribe-one").length; await runAction(page, "transcribe", { cost: "gpu", queue: /transcribe-one:railchan:railvid/ }); expect(railAsks("transcribe-one").slice(transcribes)).toMatchObject([{ slug: "railchan", id: "railvid" }]); // Windows: fetch-windows for the clip no window holds (rail-a's own body, narrowed to it), then a targeted evict. await openStage(page, "windows"); const fetches = railAsks("fetch-windows").length; await runAction(page, "fetch-reports/rail-a", { cost: "network", queue: /clips:youtube/ }); const fetch = railAsks("fetch-windows").slice(fetches); expect(fetch.map((r) => !!r.dryRun)).toEqual([true, false]); expect(fetch[1].items?.map((i) => `${i.slug}/${i.id}#${i.clipId}`)).toEqual(["railchan/railvid#ra2"]); const evicts = railAsks("evict-clips").length; await runAction(page, "evict-200.00-230.00.mp4", { cost: "disk" }); expect(railAsks("evict-clips").slice(evicts)).toMatchObject([{ slug: "railchan", id: "railvid", windows: ["200.00-230.00"] }]); // Published: umtool's own link check (/api/report/links) -- the site refuses at once, so the link is unverified. await openStage(page, "published"); const links = page.waitForRequest((r) => r.url().endsWith("/api/report/links") && r.method() === "POST"); await runAction(page, "links-reports/rail-b", { cost: "network" }); expect((await links).postDataJSON()).toEqual({ project: "reports/rail-b" }); await expect(page.locator('[data-published-row="reports/rail-b#rb1"]')).toHaveAttribute("data-state", "unverified", { timeout: 15_000 }); // Checked: a quote check, a umtool job (its transcriptions the editor's); it is let finish before the next spec. await openStage(page, "checked"); await runAction(page, "quote-check-reports/rail-a", { cost: "gpu", queue: /umtool's job runner/ }); await expect(page.locator('[data-action-result="quote-check-reports/rail-a"]')).toContainText("quote check started"); await expect .poll(async () => ((await (await request.get("/api/jobs")).json()) as { running: unknown }).running, { timeout: 90_000 }) .toBeNull(); }); test("another site's page may not start an action: a foreign Origin is refused, and so is a body that is not JSON", async ({ request }) => { const body = { action: "transcribe", ch: "railchan", id: "railvid", step: "plan" }; const foreign = await request.post("/api/ingredients/action", { data: body, headers: { origin: "http://evil.example", "sec-fetch-site": "cross-site" } }); expect(foreign.status()).toBe(403); const form = await request.post("/api/ingredients/action", { data: JSON.stringify(body), headers: { "content-type": "text/plain" } }); expect(form.status()).toBe(415); // A start without the plan's key is refused before the editor is asked. const asked = railAsks("transcribe-one").length; const keyless = await request.post("/api/ingredients/action", { data: { ...body, step: "start" } }); expect(keyless.status()).toBe(400); expect(railAsks("transcribe-one").length).toBe(asked); });