import { test, expect } from "@playwright/test"; import { existsSync, readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // Verify by playing the citation (release 32 R1). The drafts review is an // audition deck: card 1's cited window is on disk and is its player's video; // → keeps it (drafts.review.json); card 2's window is not on disk -- Fetch // clip asks the editor stub, and the card plays what it wrote; ← cuts, z // undoes, a reason chip rides in the note; ↑ edits the narration on the card; // the list shows the same verdicts. And the article page's Verify quotes / // Check report, each quote with its own Play. Fixtures: // e2e/fixtures/review-player-fixture.mjs, sites-fixture.mjs (priv/polemic-alpha). // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/review-player-fixture"; const DIR = path.join(FIXTURE, "reports", "review-player-fixture"); const STUB_LOG = path.join(FIXTURE, "editor-stub.requests.json"); type Verdict = { verdict: string | null; note: string }; const review = (): Record => { const f = path.join(DIR, "drafts.review.json"); if (!existsSync(f)) return {}; const doc = JSON.parse(readFileSync(f, "utf8")) as { rows?: Record } & Record; return doc.rows ?? doc; }; const manifest = () => JSON.parse(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")) as { timeline: { id: string; narration?: { text: string }; drafted?: unknown }[] }; test("the audition deck: play the span, keep, fetch a missing clip, cut, undo, edit; the list agrees", async ({ page, request }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 900 }); await page.goto(urls.reviewHref(PROJECT)); const card = page.locator("[data-card-top]"); await expect(card).toHaveAttribute("data-card", "onscreen/p01/onscreen"); await expect(card.locator("[data-card-value]")).toHaveText("On disk title"); await expect(card.locator("[data-card-drafted]")).toHaveText("drafted by qwen3:8b · onscreen"); await expect(page.locator("[data-deck-count]")).toContainText("1 / 3 · 0 kept · 0 cut"); // One counter and one hint row, the deck's own: none in the bench's top bar. await expect(page.locator("[data-bench-top] [data-bench-keys]")).toHaveCount(0); await expect(page.locator("[data-bench-top]")).not.toContainText("to review"); await expect(page.locator("[data-deck-hint]")).toHaveAttribute("data-deck-hint", "shown"); // Video first: the project's cached window, served with ranges. await expect(card.locator("[data-play]")).toHaveAttribute("data-play", "window", { timeout: 15_000 }); const video = card.locator("video[data-player]"); await expect(video).toHaveAttribute("src", /\/api\/report\/raw\?.*file=vid9_0\.00-9\.00\.mp4/); const res = await request.get((await video.getAttribute("src"))!, { headers: { range: "bytes=0-99" } }); expect(res.status()).toBe(206); // The lit line: the quote, word by word. await expect(card.locator("[data-lit-quote] [data-word]")).toHaveCount(7); // Start (the gesture that lets every card play itself), then → keeps it. await page.locator("[data-deck-start]").click(); await expect(page.locator("[data-deck-start]")).toHaveCount(0); await page.keyboard.press("ArrowRight"); await expect.poll(() => review()["onscreen/p01/onscreen"]?.verdict).toBe("approved"); // Card 2: nothing on disk. Fetch clip asks the editor as fetch_clip does, then plays it. await expect(card).toHaveAttribute("data-card", "onscreen/p02/onscreen"); await expect(card.locator("[data-play]")).toHaveAttribute("data-play", "none"); await card.locator("[data-fetch-clip]").click(); await expect(card.locator("[data-play]")).toHaveAttribute("data-play", "window", { timeout: 30_000 }); await expect(card.locator("video[data-player]")).toHaveAttribute("src", /\/api\/(report\/raw|sites\/media)\?/); const asked = (JSON.parse(readFileSync(STUB_LOG, "utf8")) as Record[]).filter((q) => q.videoId === "vid8"); expect(asked.at(-1)).toMatchObject({ channelSlug: "testchan", videoId: "vid8", from: 0, to: 9, pad: 3, requestedBy: "umtool" }); // A word marked misheard rides in the note; ← cuts, z undoes. await card.locator('[data-word="0"]').click(); await expect(card.locator('[data-word="0"]')).toHaveAttribute("data-misheard", ""); await page.locator("body").press("ArrowLeft"); await expect.poll(() => review()["onscreen/p02/onscreen"]?.verdict).toBe("rejected"); expect(review()["onscreen/p02/onscreen"].note).toBe("cut on the deck · misheard: This"); await page.locator("body").press("z"); await expect.poll(() => review()["onscreen/p02/onscreen"]?.verdict ?? null).toBeNull(); await expect(card).toHaveAttribute("data-card", "onscreen/p02/onscreen"); await page.locator('[data-cut-reason="wrong moment"]').click(); await page.locator('[data-deck-action="cut"]').click(); await expect.poll(() => review()["onscreen/p02/onscreen"]?.note).toBe("wrong moment · misheard: This"); // Card 3: a narration with no clip. ↑ edits it on the card; Enter keeps it as edited. await expect(card).toHaveAttribute("data-card", "narrate/k01/narration"); await expect(card).toContainText("Not drawn over a clip"); await page.locator("body").press("ArrowUp"); const edit = card.locator("[data-card-edit]"); await expect(edit).toHaveValue("A drafted narration line."); await edit.fill("A narration line, said better."); await edit.press("Enter"); await expect.poll(() => manifest().timeline.find((e) => e.id === "k01")?.narration?.text).toBe("A narration line, said better."); await expect.poll(() => review()["narrate/k01/narration"]?.verdict).toBe("approved"); // The deck's end: what was cut, and the way back. const summary = page.locator("[data-deck-summary]"); await expect(summary).toContainText("1 kept · 1 cut · 1 edited"); await expect(summary.locator('[data-summary-row="onscreen/p02/onscreen"]')).toContainText("Fetched title"); // The list shows the same verdicts. await page.locator("[data-review-view=list]").click(); await expect(page).toHaveURL(/\/review\?view=list$/); await expect(page.locator('[data-draft-row="onscreen/p01/onscreen"]')).toHaveAttribute("data-state", "approved"); await expect(page.locator('[data-draft-row="onscreen/p02/onscreen"]')).toHaveAttribute("data-state", "rejected"); }); test("the article page: Verify quotes plays each quote; Check report says what compose would", async ({ page }) => { await page.goto(urls.articleHref({ site: "priv", id: "polemic-alpha" }, { tab: "article" })); const checks = page.locator("[data-article-checks]"); await checks.locator('[data-check="quotes"]').click(); const quotes = page.locator("[data-quote-checks]"); await expect(quotes).toHaveAttribute("data-quote-checks", "2", { timeout: 30_000 }); const c1 = quotes.locator('[data-quote-check="c1"]'); await expect(c1).toHaveAttribute("data-status", /.+/); await expect(c1).toContainText("The vote was rigged and everybody knew."); await c1.locator("[data-check-play]").click(); await expect(c1.locator("[data-play]")).toHaveAttribute("data-play", "window", { timeout: 15_000 }); await expect(c1.locator("video[data-player]")).toHaveAttribute("src", /corpus=.*sv1.*clips/); await checks.locator('[data-check="check"]').click(); const check = page.locator("[data-report-check]"); await expect(check).toBeVisible({ timeout: 60_000 }); await expect(check.locator("[data-check-summary]")).toContainText(/compose would (pass|fail)/); });