import { test, expect } from "@playwright/test"; import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { WARM_TIMEOUT, warm } from "./warm"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // BY HAND (release 32 R2): what a model does to an article, done with no model. // // hand-respell a fact-check in the fixture's article store, current on its // i1, quoting sitechan/sv1 ("The vote was rigged and // everybody knew."): Fix a mishearing -> the preview's word // hunks per file -> Apply -> both reports respelled, the // backups listed, the quote still checks // hand-blank started BLANK on Create (no model, no editor job), then a // claim added by hand: a new section, a verdict, a citation // picked from the record's cues after pasting a moment; a quote // that is not in the record is refused and nothing is written. // The record is hand-chan/hv1, written here as the corpus has // one (metadata + an English VTT), which the quote check reads. // // hand-fill-e2e a report-video project made here (an empty timeline): Fill // empty fields by hand on its Media tab writes the YouTube text // and an X post as the operator's, no drafted mark // // WRITES articles/hand-respell/, articles/hand-blank/, channels/hand-chan/, // hand-fill-e2e/ (removed after) // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const ARTICLES = path.join(FIXTURE, "articles"); const RESPELL = "hand-respell"; const BLANK = "hand-blank"; const AT = "2026-10-16T10:00:00.000Z"; const CHANNEL = path.join(FIXTURE, "channels", "hand-chan"); const FILL = "hand-fill-e2e"; const ts = (s: number) => new Date(s * 1000).toISOString().slice(11, 23); const VTT = "WEBVTT\nKind: captions\nLanguage: en\n\n" + ([ [0, 3, "Opening line of the hand source."], [3, 6, "The vote was rigged and everybody knew."], [6, 9, "Nobody checked it at the time."], ] as const) .map(([a, b, t]) => `${ts(a)} --> ${ts(b)}\n${t}\n`) .join("\n"); const report = { format: "archilyzer-report", version: 1, id: RESPELL, kind: "factcheck", title: "The Vote 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 vote", claims: [{ id: "c1", text: "The article says the vote was rigged.", citations: ["q1"] }] }], }; const json = (file: string) => JSON.parse(readFileSync(file, "utf8")); const put = (file: string, v: unknown) => { mkdirSync(path.dirname(file), { recursive: true }); writeFileSync(file, JSON.stringify(v, null, 2) + "\n"); }; test.beforeAll(async ({ playwright }) => { test.setTimeout(WARM_TIMEOUT); for (const id of [RESPELL, BLANK]) rmSync(path.join(ARTICLES, id), { recursive: true, force: true }); put(path.join(CHANNEL, "config.json"), { handling: "youtube", name: "Hand Channel", url: "https://www.youtube.com/@handchan/videos" }); put(path.join(CHANNEL, "data", "hv1", "metadata.info.json"), { id: "hv1", title: "Hand source", channel: "hand-chan", upload_date: "20240315", duration: 9, webpage_url: "https://www.youtube.com/watch?v=hv1", extractor_key: "Youtube", }); writeFileSync(path.join(CHANNEL, "data", "hv1", "transcript.en.vtt"), VTT); const dir = path.join(ARTICLES, RESPELL); put(path.join(dir, "report.json"), report); put(path.join(dir, "iterations", "1", "iteration.json"), { format: "archilyzer-iteration", version: 1, article: RESPELL, n: 1, kind: "sweep", model: "qwen3:8b", parent: null, copyOf: null, question: "What was said about the vote?", status: "done", usage: {}, steps: [], createdAt: AT, updatedAt: AT, endedAt: AT, }); put(path.join(dir, "iterations", "1", "report.json"), report); put(path.join(dir, "iterations", "current.json"), { format: "archilyzer-iterations-current", version: 1, report: 1, reportFrom: 1, video: null, reportAt: AT }); await warm(playwright, [urls.articleHref({ site: "articles", id: RESPELL }, { tab: "iterations" }), `/api/articles/by-hand?article=${RESPELL}`, urls.newArticleHref()]); }); test.afterAll(() => { for (const id of [RESPELL, BLANK]) rmSync(path.join(ARTICLES, id), { recursive: true, force: true }); rmSync(CHANNEL, { recursive: true, force: true }); rmSync(path.join(FIXTURE, FILL), { recursive: true, force: true }); }); test("Fix a mishearing: the preview's word hunks per file, then Apply writes both reports and lists the backups", async ({ page }) => { // The drafts review's "fix this mishearing" link: ?heard= opens the form, filled. await page.goto(`${urls.articleHref({ site: "articles", id: RESPELL }, { tab: "iterations" })}&heard=everybody`); const tools = page.getByRole("region", { name: "by hand" }); await expect(tools.getByRole("combobox", { name: "iteration to work on" })).toHaveValue("1"); const form = tools.getByRole("region", { name: "fix a mishearing" }); await expect(form.getByRole("textbox", { name: "heard forms" })).toHaveValue("everybody"); await form.getByRole("textbox", { name: "reads as" }).fill("everyone"); await form.getByRole("button", { name: "Preview" }).click(); // Two files (the iteration's report and the article's), each its quote's hunk. const plan = form.locator("[data-respell-plan]"); await expect(plan).toHaveAttribute("data-respell-plan", "2"); await expect(plan.locator("[data-respell-target='iteration-report']")).toContainText("iterations/1/report.json"); await expect(plan.locator("[data-respell-target='article-report']")).toBeVisible(); await expect(plan.locator("[data-respell-hunk]").first()).toContainText("everyone"); // Nothing written by the preview. expect(json(path.join(ARTICLES, RESPELL, "report.json")).citations.q1.quote).toBe("The vote was rigged and everybody knew."); // A field changed since the preview: Apply waits for a new one. await form.getByRole("textbox", { name: "respelling note" }).fill("a synthetic note"); await expect(plan.getByRole("button", { name: "Apply" })).toBeDisabled(); await form.getByRole("button", { name: "Preview" }).click(); await plan.getByRole("button", { name: "Apply" }).click(); await expect(form.locator("[data-respell-applied]")).toContainText("Applied: 2 changes in 2 files"); await expect(form.locator("[data-respell-backups]")).toHaveAttribute("data-respell-backups", "2"); for (const file of [path.join(ARTICLES, RESPELL, "report.json"), path.join(ARTICLES, RESPELL, "iterations", "1", "report.json")]) { const doc = json(file); expect(doc.citations.q1.quote).toBe("The vote was rigged and everyone knew."); expect(doc.respellings).toEqual([{ heard: ["everybody"], reads: "everyone", note: "a synthetic note" }]); } // The report's respellings are listed with their heard forms. await expect(form.getByRole("list", { name: "respellings" })).toContainText("“everybody” → everyone"); }); test("start blank on Create, then add a claim by hand: a new section, a verdict, a citation from the record's cues", async ({ page }) => { await page.goto(urls.newArticleHref()); const form = page.getByRole("form", { name: "new article" }); await form.getByRole("radio", { name: "start blank (no model)" }).check(); await form.getByRole("textbox", { name: "article title" }).fill("A Blank Check"); await form.getByRole("textbox", { name: "article id" }).fill(BLANK); await form.getByRole("button", { name: "Start blank" }).click(); await expect(page).toHaveURL(new RegExp(`/articles/${BLANK}\\?tab=iterations$`)); const card = page.locator("[data-iteration='1']"); await expect(card).toHaveAttribute("data-kind", "hand"); await expect(card).toHaveAttribute("data-status", "done"); const tools = page.getByRole("region", { name: "by hand" }); await tools.getByRole("button", { name: "Add a claim" }).click(); const claim = tools.getByRole("form", { name: "add a claim" }); await claim.getByRole("combobox", { name: "claim section" }).selectOption(""); await claim.getByRole("textbox", { name: "new section title" }).fill("The Vote"); await claim.getByRole("textbox", { name: "claim text" }).fill("The article says the vote was rigged."); await claim.getByRole("combobox", { name: "claim verdict" }).selectOption("CORROBORATED"); // A quote that is not in the record: refused, nothing written. await claim.getByRole("textbox", { name: "citation channel" }).fill("hand-chan"); await claim.getByRole("textbox", { name: "citation id" }).fill("hv1"); await claim.getByRole("textbox", { name: "citation start" }).fill("3"); await claim.getByRole("textbox", { name: "citation end" }).fill("6"); await claim.getByRole("textbox", { name: "citation quote" }).fill("The vote was never rigged at all."); await claim.getByRole("button", { name: "Add this citation" }).click(); await claim.getByRole("button", { name: "Save claim" }).click(); await expect(claim.locator("[data-hand-error]").last()).toContainText("does not check against the record"); expect(json(path.join(ARTICLES, BLANK, "iterations", "1", "report.json")).sections).toEqual([]); await claim.locator("[data-hand-new-citation='0']").getByRole("button", { name: "Remove" }).click(); // The moment pasted, its cues shown; a click takes the line as the quote. await claim.getByRole("textbox", { name: "moment" }).fill("hand-chan/hv1@0:03"); await claim.getByRole("button", { name: "Find" }).click(); await claim.locator("[data-cue='3']").click(); await expect(claim.getByRole("textbox", { name: "citation quote" })).toHaveValue("The vote was rigged and everybody knew."); await expect(claim.getByRole("textbox", { name: "citation end" })).toHaveValue("6"); await claim.getByRole("button", { name: "Add this citation" }).click(); await claim.getByRole("button", { name: "Save claim" }).click(); await expect(tools.locator("[data-hand-said]")).toContainText("c1 saved in i1"); const doc = json(path.join(ARTICLES, BLANK, "iterations", "1", "report.json")); expect(doc.sections).toEqual([{ id: "the-vote", title: "The Vote", claims: [{ id: "c1", text: "The article says the vote was rigged.", verdict: "CORROBORATED", citations: ["h1"] }] }]); expect(doc.citations.h1).toEqual({ kind: "video", channel: "hand-chan", id: "hv1", start: 3, end: 6, quote: "The vote was rigged and everybody knew." }); // Still one iteration, nothing made current: "Use this iteration" is the person's. expect(readdirSync(path.join(ARTICLES, BLANK, "iterations")).filter((n) => /^\d+$/.test(n))).toEqual(["1"]); expect(existsSync(path.join(ARTICLES, BLANK, "report.json"))).toBe(false); await expect(card.getByRole("button", { name: "Use this iteration" })).toBeVisible(); await card.getByRole("button", { name: "Use this iteration" }).click(); await expect(page.locator("[data-current-report='1']")).toBeVisible(); expect(json(path.join(ARTICLES, BLANK, "report.json")).sections[0].claims[0].verdict).toBe("CORROBORATED"); }); test("Fill empty fields by hand on the Media tab: the YouTube text and an X post, written as yours (no drafted mark)", async ({ page, request }) => { rmSync(path.join(FIXTURE, FILL), { recursive: true, force: true }); const made = await request.post("/api/projects/new", { data: { kind: "report-video", slug: FILL, title: "Hand fill" } }); expect(made.status()).toBe(200); const id = (await made.json()).id as string; await page.goto(urls.projectHref(id, { tab: "media" })); const fill = page.getByRole("region", { name: "fill by hand" }); await expect(fill).toHaveAttribute("data-hand-fill", "3"); await fill.getByRole("button", { name: "Fill empty fields by hand" }).click(); // No deck: the flips and threads say where they come from. await expect(fill).toContainText("drawn by the on-screen deck"); await fill.getByRole("textbox", { name: "YouTube title" }).fill("A Synthetic Title"); await fill.getByRole("textbox", { name: "YouTube description" }).fill("A synthetic description."); await fill.getByRole("textbox", { name: "X post" }).fill("A synthetic post."); await fill.getByRole("button", { name: "Save what is filled" }).click(); await expect(fill.locator("[data-hand-fill-status='ok']")).toContainText("written by hand: publish.youtube, publish.x"); await expect(fill).toHaveAttribute("data-hand-fill", "1"); const m = json(path.join(FIXTURE, FILL, "video.manifest.json")); expect(m.publish).toEqual({ youtube: { title: "A Synthetic Title", description: "A synthetic description." }, x: { post: "A synthetic post." } }); expect(m.drafted ?? {}).toEqual({}); });