import { test, expect, type APIRequestContext } from "@playwright/test"; import { existsSync, readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // The drafts review (release 28, M0). A drafted field shows "drafted by // " and its review state beside it, with Approve / Reject (a note // required); an edit makes it the operator's (the mark goes); the review page // lists every drafted field, and an alternative a draft task kept for the // operator's field is written with "Use this"; a FINAL build refuses a drafted // field until it is approved, then builds. Verdicts are drafts.review.json // beside the manifest. Fixtures: e2e/fixtures/draft-review-fixture.mjs. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/draft-review-fixture"; const DIR = path.join(FIXTURE, "reports", "draft-review-fixture"); const BUILD_PROJECT = "reports/draft-review-build-fixture"; const BUILD_DIR = path.join(FIXTURE, "reports", "draft-review-build-fixture"); type Entry = { id: string; onscreen?: { title?: string }; drafted?: Record; lines?: unknown[] }; const manifest = (dir = DIR) => JSON.parse(readFileSync(path.join(dir, "video.manifest.json"), "utf8")) as { timeline: Entry[] }; const entry = (id: string, dir = DIR) => manifest(dir).timeline.find((e) => e.id === id)!; const review = (dir = DIR): Record => { const f = path.join(dir, "drafts.review.json"); return existsSync(f) ? JSON.parse(readFileSync(f, "utf8")) : {}; }; test("badges: drafted by , approve, reject with a note; an edit makes the field the operator's", async ({ page }) => { await page.goto(urls.section(PROJECT, "review")); await expect(page.locator("[data-review-link]")).toHaveAttribute("data-review-link", "3"); // The On-screen table (folded: the deck is off) -- c02's title was drafted, c01's was not. await page.goto(urls.section(PROJECT, "onscreen")); await page.getByTestId("onscreen-words-folded").locator("summary").click(); const c02 = page.locator('[data-draft-badge="onscreen/c02/onscreen"]'); await expect(c02).toHaveAttribute("data-state", "unreviewed"); await expect(c02.locator("[data-draft-by]")).toHaveText("drafted by qwen3:8b"); await expect(page.locator('[data-draft-badge="onscreen/c01/onscreen"]')).toHaveCount(0); await c02.locator('[data-draft-action="approve"]').click(); await expect(c02).toHaveAttribute("data-state", "approved"); expect(review()["onscreen/c02/onscreen"].verdict).toBe("approved"); // The teaser's lines: a rejection needs its note. await page.getByTestId("structure-folded").locator("summary").click(); const t01 = page.locator('[data-draft-badge="teaser/t01/lines"]'); await expect(t01.locator("[data-draft-by]")).toHaveText("drafted by claude-sonnet-5-5"); await t01.locator('[data-draft-action="reject"]').click(); await expect(t01.locator("[data-draft-error]")).toContainText("a rejection needs its note"); await t01.locator("[data-draft-note]").fill("the lease is not next season"); await t01.locator('[data-draft-action="reject"]').click(); await expect(t01).toHaveAttribute("data-state", "rejected"); expect(review()["teaser/t01/lines"]).toMatchObject({ verdict: "rejected", note: "the lease is not next season" }); // Edit c02's drafted title: saved through the manifest writer, it is the // operator's now -- no mark, no badge. const row = page.locator('[data-testid="onscreen-row"][data-entry="c02"]'); await row.getByTestId("onscreen-title").fill("My own title"); await page.getByTestId("onscreen-save").click(); await expect(c02).toHaveCount(0); expect(entry("c02").onscreen).toEqual({ title: "My own title" }); expect(entry("c02").drafted).toBeUndefined(); }); test("the review page: every drafted field, the narration's badge, and Use this for the operator's field", async ({ page }) => { await page.goto(urls.section(PROJECT, "review")); await page.locator("[data-review-link]").click(); await expect(page).toHaveURL(new RegExp(`/projects/${PROJECT}/review$`)); // The review opens on the audition deck (release 32 R1); this walks the list. await page.locator("[data-review-view=list]").click(); await expect(page).toHaveURL(new RegExp(`/projects/${PROJECT}/review\\?view=list$`)); // The narration and the teaser are drafted; a final build would refuse them. const k01 = page.locator('[data-draft-row="narrate/k01/narration"]'); await expect(k01).toHaveAttribute("data-state", "unreviewed"); await expect(k01.locator("[data-draft-text]")).toHaveText("Half a year on, the county said yes."); await expect(page.locator('[data-draft-row="teaser/t01/lines"]')).toBeVisible(); await expect(page.locator("[data-drafts-gate]")).toHaveAttribute("data-drafts-gate", "refuses"); // c01's title is the operator's: the draft that could not replace it is an // alternative under it. Use this writes it as the operator's edit. const alt = page.locator('[data-draft-alternatives="onscreen/c01/onscreen"]'); await expect(alt.locator("[data-draft-alternative-text]")).toHaveText("Kept aside title"); await alt.locator("[data-draft-use]").click(); await expect(alt).toHaveCount(0); expect(entry("c01").onscreen).toEqual({ title: "Kept aside title" }); expect(entry("c01").drafted).toBeUndefined(); // Approve the narration here; the narration page shows who drafted it, and its state. await k01.locator('[data-draft-action="approve"]').click(); await expect(k01).toHaveAttribute("data-state", "approved"); await page.goto(urls.narrationHref(PROJECT)); const card = page.locator('[data-narration-card="k01"]'); await expect(card.locator("[data-narration-drafted]")).toHaveText("drafted by qwen3:8b"); await expect(card).toHaveAttribute("data-state", "approved"); }); async function build(request: APIRequestContext, replace = false) { const start = await request.post(`/api/report/build${replace ? "?replace=1" : ""}`, { data: { project: BUILD_PROJECT, preset: "final" } }); expect(start.ok(), await start.text()).toBeTruthy(); const { job } = (await start.json()) as { job: { id: string } }; let done: { state: string; error: string | null } = { state: "running", error: null }; const until = Date.now() + 240_000; while (Date.now() < until) { done = (await (await request.get(`/api/report/build?job=${job.id}`)).json()) as typeof done; if (done.state !== "running") break; await new Promise((r) => setTimeout(r, 400)); } return done; } test("a final build refuses an unapproved draft, and builds once it is approved", async ({ page, request }) => { test.setTimeout(360_000); const refused = await build(request); expect(refused.state).toBe("failed"); expect(JSON.stringify(refused)).toContain("timeline c02: its on-screen text (drafted by qwen3:8b) is not approved"); expect(existsSync(path.join(BUILD_DIR, "out", "draft-review-build-fixture.mp4"))).toBe(false); await page.goto(urls.reviewHref(BUILD_PROJECT, { view: "list" })); const row = page.locator('[data-draft-row="onscreen/c02/onscreen"]'); await row.locator('[data-draft-action="approve"]').click(); await expect(row).toHaveAttribute("data-state", "approved"); await expect(page.locator("[data-drafts-gate]")).toHaveAttribute("data-drafts-gate", "passes"); const done = await build(request); expect(done.state, done.error ?? "").toBe("done"); expect(existsSync(path.join(BUILD_DIR, "out", "draft-review-build-fixture.mp4"))).toBe(true); });