import { test, expect } from "@playwright/test"; import { mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { WARM_TIMEOUT, warm } from "./warm"; import { claimFingerprint } from "yt-dlp-transcript-common/lib/report/verdictProposals"; // --------------------------------------------------------------------------- // Verdict proposals (release 29 M8): a synthetic fact-check in the fixture's // article store with two unruled claims a model proposed verdicts for // (`verdicts.proposed.json` beside it). The Inbox's `verdict-proposed` card // (Review) → the article's tab → Approve sets the claim's verdict (the stub // editor runs the REAL verdict-review over the fixture's store), Reject // leaves the claim unruled; the card goes once nothing waits. Release 29's // review fixes: a stale proposal (its claim changed) is counted, not shown; a // proposal rewritten between view and click is refused. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const ARTICLES = path.join(HERE, "..", ".e2e-song", "articles"); const ID = "vprop-check"; const DIR = path.join(ARTICLES, ID); const AT = "2026-10-15T10:00:00.000Z"; const MODEL = "qwen3:8b"; const report = { format: "archilyzer-report", version: 1, id: ID, kind: "factcheck", title: "The Bakery Check", citations: { q1: { kind: "video", channel: "sitechan", id: "sv1", start: 3, end: 6, quote: "The vote was rigged and everybody knew." }, }, sections: [ { id: "s1", title: "The shop", claims: [ { id: "c1", text: "The article says she opened the shop in spring.", verdict: "CORROBORATED", citations: ["q1"] }, { id: "c2", text: "The article says the oven was broken for a month.", citations: ["q1"] }, { id: "c3", text: "The article says she sold the van.", citations: ["q1"] }, { id: "c4", text: "The article says she moved the shop.", citations: ["q1"] }, ], }, ], }; // Each proposal carries the fingerprint of the claim it judged; c4's judged // another claim (a revision moved the ids): stale, never shown. const fp = (id: string) => claimFingerprint(report.sections[0]!.claims.find((c) => c.id === id)!, report.citations); const proposals = { format: "archilyzer-verdict-proposals", version: 1, article: ID, proposals: { c2: { verdict: "PARTLY", reason: "She says the oven ran hot, not that it was broken.", model: MODEL, promptVersion: "2", at: AT, fingerprint: fp("c2"), status: "proposed" }, c3: { verdict: "CONTRADICTED", reason: "She says she kept the van.", model: MODEL, promptVersion: "2", at: AT, fingerprint: fp("c3"), status: "proposed" }, c4: { verdict: "CORROBORATED", reason: "Another claim's.", model: MODEL, promptVersion: "2", at: AT, fingerprint: "0000000000000000", status: "proposed" }, }, updatedAt: AT, }; const claims = () => (JSON.parse(readFileSync(path.join(DIR, "report.json"), "utf8")) as typeof report).sections[0]!.claims as { id: string; verdict?: string }[]; const sidecar = () => JSON.parse(readFileSync(path.join(DIR, "verdicts.proposed.json"), "utf8")) as typeof proposals; test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); rmSync(DIR, { recursive: true, force: true }); mkdirSync(DIR, { recursive: true }); writeFileSync(path.join(DIR, "report.json"), JSON.stringify(report, null, 2) + "\n"); writeFileSync(path.join(DIR, "verdicts.proposed.json"), JSON.stringify(proposals, null, 2) + "\n"); await warm(playwright, ["/", `/articles/${ID}?tab=article`, "/api/browse/decisions"]); }); test.afterAll(() => { rmSync(DIR, { recursive: true, force: true }); }); test("an Inbox row → the article's proposals → Approve sets the verdict, Reject leaves the claim; the card goes", async ({ page, request }) => { // The API: one row per waiting proposal, in Review, its action the article's tab. const rows = ((await (await request.get("/api/browse/decisions")).json()) as { items: { kind: string; target: string; group: string; piece?: string; action: { label: string; href: string } }[]; }).items.filter((d) => d.kind === "verdict-proposed" && d.piece === `a:articles/${ID}`); expect(rows.map((d) => d.target).sort()).toEqual(["c2", "c3"]); expect(rows.every((d) => d.group === "review")).toBe(true); expect(rows[0]!.action).toEqual({ label: "Review verdicts", href: `/articles/${ID}?tab=article` }); await page.goto("/"); const card = page.locator("[data-group=review] [data-card=verdict-proposed]").filter({ hasText: "The Bakery Check" }); await expect(card).toHaveCount(1); await expect(card.locator("[data-count]")).toHaveText("2"); await expect(card.locator("[data-card-title]")).toHaveText("The Bakery Check · 2 verdicts proposed"); await expect(card.locator("small")).toHaveText(`by ${MODEL} · prompt v2`); await card.locator("[data-action-link]").click(); await expect(page).toHaveURL(new RegExp(`/articles/${ID}\\?tab=article$`)); const panel = page.getByRole("region", { name: "verdict proposals" }); await expect(panel.locator("[data-proposal]")).toHaveCount(2); await expect(panel).toContainText("2 waiting · 1 stale (the claim changed since)"); const c2 = panel.locator('[data-proposal="c2"]'); await expect(c2.locator("[data-proposed]")).toHaveText("PARTLY"); await expect(c2).toContainText("She says the oven ran hot"); await c2.getByRole("button", { name: "Approve" }).click(); await expect(panel.getByRole("status")).toHaveText("Approved: c2 is PARTLY."); await expect(panel.locator('[data-proposal="c2"]')).toHaveCount(0); expect(claims().find((c) => c.id === "c2")!.verdict).toBe("PARTLY"); expect(sidecar().proposals.c2.status).toBe("approved"); // Another run rewrites c3's proposal after the page showed it: the review is refused. const doc = sidecar(); writeFileSync(path.join(DIR, "verdicts.proposed.json"), JSON.stringify({ ...doc, proposals: { ...doc.proposals, c3: { ...doc.proposals.c3, verdict: "PARTLY", at: "2026-10-15T11:00:00.000Z" } } }, null, 2) + "\n"); await panel.locator('[data-proposal="c3"]').getByRole("button", { name: "Reject" }).click(); await expect(panel.getByRole("status")).toContainText("changed since it was shown"); expect(sidecar().proposals.c3.status).toBe("proposed"); // Read again, it is the new one; reject that. await page.reload(); const c3 = page.getByRole("region", { name: "verdict proposals" }).locator('[data-proposal="c3"]'); await expect(c3.locator("[data-proposed]")).toHaveText("PARTLY"); await c3.getByRole("textbox", { name: "note on c3" }).fill("the window is too short"); await c3.getByRole("button", { name: "Reject" }).click(); await expect(page.getByRole("region", { name: "verdict proposals" }).getByRole("status")).toHaveText("Rejected: c3 stays unruled."); expect(claims().find((c) => c.id === "c3")!.verdict).toBeUndefined(); expect(sidecar().proposals.c3).toMatchObject({ status: "rejected", note: "the window is too short" }); // The operator's ruling stayed as it was. expect(claims().find((c) => c.id === "c1")!.verdict).toBe("CORROBORATED"); // Nothing waits: the card is gone. await page.goto("/"); await expect(page.locator("[data-group=review] [data-card=verdict-proposed]").filter({ hasText: "The Bakery Check" })).toHaveCount(0); });