import { test, expect, type Page } from "@playwright/test"; import { existsSync, readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { BOARD_CASE } from "./fixtures/research-fixture.mjs"; import { writeReactionCorpus } from "yt-dlp-transcript-common/testing/clips/reactionStream.mjs"; import * as urls from "./urls"; import { WARM_TIMEOUT, warm } from "./warm"; // --------------------------------------------------------------------------- // Create (plans/umtool-redesign.md, P5; canvas "Create"): "What are you // making?" -- one lit list of lines, each opening its form inline, each form a // shell over a writer that already exists. Every path is driven to its writer // on the fixture and the editor stub: // // research POST /api/research/cases → the case's board // article r28's NewArticleForm → report-draft (article-new.spec // drives the form; here the line, the chip, the estimate) // article-board R2's hand-off: the plan, then the seeded sweep (stub) // video-board R2's hand-off: the plan, then the project // video-article the chain's steps, then the chain as a umtool job // video-recording /?from= (the editor's hand-off) prefilled → a project // video-highlights the clip finder's seed on a synthetic stream → a project // with proposed clips, then "Find the clips" as a job // video-report the sweep reports on disk → a project // song a song // // WRITES (each removed after): .umtool/research/p5-*, articles/p5-board, // p5-board/, p5-rec/, p5-rep/, reports/videos/p5-song/; a chain job on // zeta i1, cancelled; channels/synth-reacts (a synthetic stream) and p35-hl/ // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const STUB_LOG = path.join(FIXTURE, "editor-stub.requests.json"); const stubAsked = (route: string) => existsSync(STUB_LOG) ? (JSON.parse(readFileSync(STUB_LOG, "utf8")) as { route?: string; [k: string]: unknown }[]).filter((r) => r.route === route) : []; const caseJson = (id: string) => JSON.parse(readFileSync(path.join(FIXTURE, ".umtool", "research", id, "case.json"), "utf8")); const manifestOf = (dir: string) => JSON.parse(readFileSync(path.join(FIXTURE, dir, "video.manifest.json"), "utf8")); const WRITTEN = [ ".umtool/research/p5-case", ".umtool/research/p5-board", "articles/p5-board", "p5-board", "p5-rec", "p5-rep", "reports/videos/p5-song", "channels/synth-reacts", "p35-hl", "channels/synth-two", "p36-find", "p36-find-again", "p36-ui", ]; const clean = () => { for (const p of WRITTEN) rmSync(path.join(FIXTURE, p), { recursive: true, force: true }); }; const line = (page: Page, make: string) => page.locator(`[data-make-line="${make}"]`); const form = (page: Page, make: string) => page.locator(`[data-make-form="${make}"]`); test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); clean(); await warm(playwright, [urls.createHref(), urls.createHref({ make: "article" }), "/api/research/cases", "/api/articles/channels"]); }); test.afterAll(clean); test("the lines, grouped Research · Article · Video · Song; the policy chip links Settings; + Create is lit, no place", async ({ page }) => { await page.goto(urls.createHref()); await expect(page.getByRole("navigation", { name: "Breadcrumb" }).locator("h1")).toHaveText("What are you making?"); await expect(page.locator("[data-make-group]")).toHaveText([/^Research/, /^Article/, /^Video/, /^Song/]); // Ten: R5 added "A recurring report" under Article; release 35 "Highlights from a recording" under Video. await expect(page.locator("[data-make-line]")).toHaveCount(10); // The boards and the reports on disk are counted on their lines. await expect(line(page, "article-board")).toContainText(/ · \d+ quotes?/); await expect(line(page, "video-report")).toContainText(/ · \d+ found/); const chip = page.locator("[data-policy-chip]"); await expect(chip).toHaveAttribute("data-policy-chip", "balanced"); await expect(chip).toHaveText("Generation: balanced · Claude Code: sweeps · API: report revisions, research, frames · local: video revisions, drafts, verdicts, clip labels, the video assistant, claim groups for a cut"); await expect(chip).toHaveAttribute("href", urls.generationPolicyHref()); const rail = page.locator("[data-app-rail]"); await expect(rail.locator("[data-rail-create]")).toHaveAttribute("aria-current", "page"); await expect(rail.locator("nav[aria-label=Main] > a[aria-current]")).toHaveCount(0); // The rail's + Create from anywhere comes here. await page.goto(urls.workHref()); await page.locator("[data-app-rail] [data-rail-create]").click(); await expect(page).toHaveURL(/\/create$/); }); test("keys: j/k light the lines, Enter opens the form on its first field, Escape closes it back to the line", async ({ page }) => { await page.goto(urls.createHref()); await expect(page.locator("[data-lit-list][data-hydrated]")).toBeAttached(); await expect(line(page, "research")).toHaveAttribute("data-lit", ""); await page.keyboard.press("j"); await expect(line(page, "article")).toHaveAttribute("data-lit", ""); await page.keyboard.press("Enter"); await expect(form(page, "article")).toBeVisible(); await expect(page).toHaveURL(/\/create\?make=article$/); await expect(form(page, "article").getByRole("textbox", { name: "question" })).toBeFocused(); // The form's own keys are the form's: j types, it does not move the light. await page.keyboard.type("jk"); await expect(line(page, "article")).toHaveAttribute("data-lit", ""); await page.keyboard.press("Escape"); await expect(form(page, "article")).toHaveCount(0); await expect(page.locator('[data-make="article"]')).toBeFocused(); await expect(page).toHaveURL(/\/create$/); // Down the left column and into the right: the head follows the column. for (let i = 0; i < 3; i++) await page.keyboard.press("j"); await expect(line(page, "video-article")).toHaveAttribute("data-lit", ""); const head = await page.locator(".lit-head").boundingBox(); const lit = await line(page, "video-article").boundingBox(); expect(Math.abs(head!.x - lit!.x)).toBeLessThan(2); }); test("fits 1366×768: every line, and an open form under its line", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 768 }); await page.goto(urls.createHref()); for (const g of await page.locator("[data-make-group]").all()) { const b = await g.boundingBox(); expect(b!.y + b!.height).toBeLessThanOrEqual(768); } await page.goto("/?from=testchan%2Fvid1"); const f = await form(page, "video-recording").boundingBox(); expect(f!.y + f!.height).toBeLessThanOrEqual(768); const w = await page.evaluate(() => document.documentElement.scrollWidth); expect(w).toBeLessThanOrEqual(1366); }); test("Research a question → a case (R2's store), and its board opens", async ({ page }) => { await page.goto(urls.createHref({ make: "research" })); const f = form(page, "research"); await expect(f.getByRole("textbox", { name: "question" })).toBeFocused(); await f.getByRole("textbox", { name: "question" }).fill("lighthouse budget"); await f.getByRole("textbox", { name: "case title" }).fill("P5 case"); await f.getByRole("button", { name: "Open a case" }).click(); await page.waitForURL(/\/research\/p5-case$/, { timeout: 20_000 }); await expect(page.getByRole("navigation", { name: "Breadcrumb" }).locator("h1")).toHaveText("P5 case"); expect(caseJson("p5-case")).toMatchObject({ title: "P5 case", scope: { query: "lighthouse budget" } }); expect(caseJson("p5-case").scope.source).toMatch(/^local:/); }); test("Article from a question: the estimate before it runs, under the policy's chip (the form is article-new.spec's)", async ({ page }) => { await page.goto(urls.createHref({ make: "article" })); const f = form(page, "article"); await expect(f.getByRole("form", { name: "new article" })).toBeVisible(); // The policy is the chip, not a panel, on Create. await expect(page.getByRole("region", { name: "generation policy" })).toHaveCount(0); await expect(f.locator("[data-estimate]")).toContainText("1 earlier run on claude-sonnet-5-5: typical $0.42, most $0.42 · stops at $5.00 (its cap)"); await expect(f.locator("[data-estimate]")).toContainText("today $0.42 of $20.00"); await f.getByRole("radio", { name: /research/ }).check(); await expect(f.locator("[data-estimate]")).toHaveAttribute("data-estimate", "research"); await f.getByRole("button", { name: "Cancel" }).click(); await expect(form(page, "article")).toHaveCount(0); }); test("from a board: R2's hand-offs, planned then confirmed — an article (a seeded sweep) and a video (a project)", async ({ page, request }) => { const made = await (await request.post("/api/research/cases", { data: { title: "P5 board" } })).json(); expect(made.case.id).toBe("p5-board"); const source = caseJson(BOARD_CASE).scope.source; for (const t of [400, 404]) { const pinned = await request.post("/api/research/cases/p5-board/quotes", { data: { source, channel: "night-desk", video: "nd-2023", t } }); expect(pinned.ok(), await pinned.text()).toBe(true); } // The article: the plan names the model and the cap; nothing is asked of the editor until the confirm. await page.goto(urls.createHref({ make: "article-board", case: "p5-board" })); const f = form(page, "article-board"); await expect(f.getByRole("combobox", { name: "board" })).toHaveValue("p5-board"); const before = stubAsked("report-draft").length; await f.getByRole("button", { name: "Plan the article" }).click(); const art = page.locator('dialog[data-handoff="article"]'); await expect(art).toContainText("the board as cited markdown: 2 quotes"); await expect(art).toContainText(/Runs on\s*claude-/); expect(stubAsked("report-draft").length).toBe(before); await art.getByRole("button", { name: /^Start the sweep/ }).click(); await page.waitForURL(/\/articles\/p5-board/, { timeout: 20_000 }); const asked = stubAsked("report-draft").at(-1)!; expect(asked).toMatchObject({ task: "sweep", article: "p5-board" }); expect(String(asked.seed)).toContain("P5 board"); expect(caseJson("p5-board").handoffs.map((h: { to: string }) => h.to)).toEqual(["article"]); // The video: its plan lists the cue spans; the confirm writes the project. await page.goto(urls.createHref({ make: "video-board", case: "p5-board" })); await form(page, "video-board").getByRole("button", { name: "Plan the video" }).click(); const vid = page.locator('dialog[data-handoff="video"]'); await expect(vid).toContainText("2 — each the cue span of a pinned quote"); await expect(vid).toContainText("night-desk/nd-2023"); await vid.getByRole("button", { name: "Create the project" }).click(); await page.waitForURL(/\/projects\/p5-board$/, { timeout: 20_000 }); expect(manifestOf("p5-board").timeline).toHaveLength(2); }); test("Video from an article: the chain's steps for its iteration, then the chain runs as a umtool job", async ({ page, request }) => { await page.goto(urls.createHref({ make: "video-article", article: "zeta" })); const f = form(page, "video-article"); await expect(f.getByRole("combobox", { name: "article" })).toHaveValue("zeta"); // The default is the newest done iteration with its OWN report (zeta's i2, a // revise-report), never i3, a video revision carrying i1's report; the plan // line names it. The chain runs over the one chosen. await expect(f.getByRole("combobox", { name: "iteration" })).toHaveValue("2"); await expect(f.locator("[data-chain-iteration]")).toHaveText("i2 · revise-report:"); await f.getByRole("combobox", { name: "iteration" }).selectOption("3"); await expect(f.locator("[data-chain-iteration]")).toHaveText("i3 · revise-video (the report of i1):"); await f.getByRole("combobox", { name: "iteration" }).selectOption("1"); await expect(f.locator("[data-chain-iteration]")).toHaveText("i1 · sweep:"); await expect(f.locator("[data-chain-plan]")).toContainText(/\d+ of 10 steps to run, from “/); await f.getByRole("button", { name: "Make the video" }).click(); await page.waitForURL(/\/articles\/zeta\?tab=iterations$/, { timeout: 20_000 }); // It is umtool's own job; stop it (a cancelled chain is a paused one). const running = (await (await request.get("/api/jobs")).json()).running as { id: string; label: string } | null; if (running) { expect(running.label).toBe("chain zeta i1"); await request.post("/api/articles/chain", { data: { cancel: running.id } }); } await expect.poll(async () => (await (await request.get("/api/jobs")).json()).running, { timeout: 30_000 }).toBeNull(); }); test("Video from a recording: the editor's /?from= lands here prefilled, and makes the project", async ({ page }) => { await page.goto("/?from=testchan%2Fvid1"); await expect(page).toHaveURL(/\/create\?from=testchan%2Fvid1$/); const f = form(page, "video-recording"); await expect(f.locator("[data-new-from]")).toHaveValue("testchan/vid1"); await expect(f.locator("[data-new-slug]")).toBeFocused(); await expect(f.locator("[data-new-kind]")).toHaveCount(0); await page.keyboard.type("p5-rec"); await page.keyboard.press("Enter"); await page.waitForURL(/\/projects\/p5-rec$/, { timeout: 20_000 }); expect(manifestOf("p5-rec").provenance.channelSlug).toBe("testchan"); }); test("Highlights from a recording: the clip finder proposes clips marked by the assistant, then finds the clips as a job", async ({ page, request }) => { // A synthetic reaction stream with its speakers (diarization.json), no sound. writeReactionCorpus(path.join(FIXTURE, "channels"), { channel: "synth-reacts", video: "react001" }); await page.goto(urls.createHref({ make: "video-highlights" })); const f = form(page, "video-highlights"); await f.locator("[data-new-from]").fill("synth-reacts/react001"); const seed = f.locator("[data-new-seed]"); await expect(seed).toHaveValue("reactions"); await expect(seed.locator("option[value=reactions]")).toBeEnabled(); await expect(f.locator("[data-new-target]")).toHaveValue("600"); await f.locator("[data-new-target]").fill("60"); await f.locator("[data-new-laugh-min]").fill("0.15"); await f.locator("[data-new-scope-to]").fill("500"); await f.locator("[data-new-slug]").fill("p35-hl"); await f.getByRole("button", { name: "Find the clips" }).click(); await page.waitForURL(/\/projects\/p35-hl$/, { timeout: 20_000 }); const m = manifestOf("p35-hl"); expect(m.render.transition).toBe(0); expect(m.timeline.length).toBeGreaterThan(0); for (const c of m.timeline) { expect(c.assist.by).toBe("assistant"); expect(c.cutStart).toBeGreaterThanOrEqual(c.start); } const reactions = () => JSON.parse(readFileSync(path.join(FIXTURE, "p35-hl", "reactions.json"), "utf8")); expect(reactions().params.target).toBe(60); expect(reactions().params.laughMin).toBe(0.15); expect(reactions().params.scope).toEqual([0, 500]); // "Find the clips" ran as umtool's job: the CLI, with no sound on disk, proposes from the transcript. await expect.poll(async () => (await (await request.get("/api/jobs")).json()).running, { timeout: 60_000 }).toBeNull(); const summary = (await (await request.get("/api/report/clips?project=p35-hl")).json()).reactions; expect(summary.speakers.map((s: { role: string }) => s.role)).toEqual(["host", "subject"]); expect(summary.used).toBeGreaterThan(0); expect(summary.laughSource).toBe("text"); }); test("Find clips from the editor (release 36): mode new with the worker token scaffolds the segment's project and analyzes it; asked again, the same project; a wrong token is refused", async ({ request }) => { // A synthetic stream that reacts to two narrated videos, with its chat replay; no sound. writeReactionCorpus(path.join(FIXTURE, "channels"), { channel: "synth-two", video: "two001", two: true, chat: true, meta: { webpage_url: "https://www.youtube.com/watch?v=two001", channel: "Synth Two" }, }); const ask = (data: Record, token = "umtool-e2e-token") => request.post("/api/report/clips", { headers: { authorization: `Bearer ${token}` }, data }); const wrong = await ask({ mode: "new", slug: "p36-find", from: "synth-two/two001" }, "not-the-token"); expect(wrong.status()).toBe(401); expect(existsSync(path.join(FIXTURE, "p36-find"))).toBe(false); const r = await ask({ mode: "new", slug: "p36-find", from: "synth-two/two001", scope: "auto", segment: "s2", target: 120 }); expect(r.ok()).toBe(true); const made = await r.json(); expect(made).toMatchObject({ project: "p36-find", created: true, segment: "s2", scope: [1500, 2390], href: "/projects/p36-find/clips" }); expect(made.segments.map((s: { id: string }) => s.id)).toEqual(["s1", "s2"]); // A channel on no site: each clip links its YouTube page at its second; the site-less look. const m = manifestOf("p36-find"); expect(m.provenance.channel).toBe("Synth Two"); expect(m.render).toMatchObject({ headerHeight: 0, footerHeight: 0, qr: false, transition: 0.22, transitionStyle: "blurslide", loudness: { target: -16 }, room: { tail: true, head: true } }); for (const c of m.timeline) expect(c.citeUrl).toBe(`https://www.youtube.com/watch?v=two001&t=${c.cite}s`); const done = async (id: string) => (await (await request.get(`/api/report/clips?job=${id}`)).json()).state; await expect.poll(() => done(made.jobId), { timeout: 60_000 }).toBe("done"); const summary = (await (await request.get("/api/report/clips?project=p36-find")).json()).reactions; expect(summary.segment).toBe("s2"); expect(summary.segments.length).toBe(2); expect(summary.chat.lagS).toBe(6); expect(summary.used).toBeGreaterThan(0); // Asked again for the same video's s2: that project, analyzed again (not a second one). const again = await (await ask({ mode: "new", slug: "p36-find-again", from: "synth-two/two001", segment: "s2" })).json(); expect(again).toMatchObject({ project: "p36-find", created: false }); await expect.poll(() => done(again.jobId), { timeout: 60_000 }).toBe("done"); expect(existsSync(path.join(FIXTURE, "p36-find-again"))).toBe(false); }); test("Highlights from a recording, the video found for you: the form's Video picks the 2nd narrated video", async ({ page, request }) => { writeReactionCorpus(path.join(FIXTURE, "channels"), { channel: "synth-two", video: "two001", two: true }); await page.goto(urls.createHref({ make: "video-highlights" })); const f = form(page, "video-highlights"); await f.locator("[data-new-from]").fill("synth-two/two001"); await expect(f.locator("[data-new-seed]")).toHaveValue("reactions"); await f.locator("[data-new-video]").selectOption("s2"); await expect(f.locator("[data-new-scope-from]")).toBeDisabled(); await f.locator("[data-new-slug]").fill("p36-ui"); await f.getByRole("button", { name: "Find the clips" }).click(); await page.waitForURL(/\/projects\/p36-ui$/, { timeout: 20_000 }); const r = JSON.parse(readFileSync(path.join(FIXTURE, "p36-ui", "reactions.json"), "utf8")); expect(r.params.scope).toEqual([1500, 2390]); expect(r.segment).toBe("s2"); await expect.poll(async () => (await (await request.get("/api/jobs")).json()).running, { timeout: 60_000 }).toBeNull(); }); test("Video from a sweep report: the reports on disk are offered, and one becomes a project", async ({ page }) => { await page.goto(urls.createHref({ make: "video-report" })); const f = form(page, "video-report"); const pick = f.getByRole("combobox", { name: "sweep report" }); await expect(pick).toBeFocused(); // Every sweep report the walk finds (an article's sweep iteration among them), then a path by hand. const bike = pick.locator("option", { hasText: "reports/bike-fixture" }); await expect(bike).toHaveCount(1); await expect(pick.locator("option").last()).toHaveText("A path typed by hand…"); await pick.selectOption((await bike.getAttribute("value"))!); await f.locator("[data-new-slug]").fill("p5-rep"); await f.locator("[data-new-create]").click(); await page.waitForURL(/\/projects\/p5-rep$/, { timeout: 20_000 }); expect(existsSync(path.join(FIXTURE, "p5-rep", "sweep-report.md"))).toBe(true); }); test("A song: the song scaffold", async ({ page }) => { await page.goto(urls.createHref({ make: "song" })); const f = form(page, "song"); await expect(f.locator("[data-new-slug]")).toBeFocused(); await f.locator("[data-new-slug]").fill("p5-song"); await f.getByRole("button", { name: "Create the song" }).click(); await page.waitForURL(/\/projects\/.*p5-song$/, { timeout: 20_000 }); expect(existsSync(path.join(FIXTURE, "reports", "videos", "p5-song"))).toBe(true); });