// TASK teaser (release 28 M3) over the S0 kit's manifests and the basic // report, against the fake ollama: a cut with no teaser gets one after its // last clip; each code check refuses what it should (count, length, one line, // quotation marks, a quote's run, names and numbers, the build's own // validateTeaser); the better of two kept; the operator's lines kept and the // draft an alternative; the umtool lint passes on what is written. import { after, before, test } from "node:test"; import assert from "node:assert/strict"; import { execFile } from "node:child_process"; import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { promisify } from "node:util"; import { jsonReply, startFakeOllama, type FakeOllama } from "../../../../testing/llm/fakeOllama.mjs"; import { createIteration, projectOf, updateIteration, writeIterationFile } from "../../iterations"; import { loadDeckChecks, type DeckChecks } from "./deckChecks"; import { checkTeaser, claimGist, fitTeaserLines, parseTeaser, teaser, teaserEvidence } from "./teaser"; import type { DraftFile } from "./media"; import type { TaskDeps } from "./types"; const HERE = path.dirname(fileURLToPath(import.meta.url)); const ROOT = path.resolve(HERE, "../../../../.."); const DRAFT = new URL("../../../../testing/draft/", import.meta.url); const kit = async (rel: string) => JSON.parse(await readFile(new URL(rel, DRAFT), "utf8")); const run = promisify(execFile); let tmp: string; let ol: FakeOllama; let deck: DeckChecks; before(async () => { tmp = await mkdtemp(path.join(os.tmpdir(), "teaser-task-")); ol = await startFakeOllama(); deck = await loadDeckChecks(ROOT); }); after(async () => { await ol.close(); await rm(tmp, { recursive: true, force: true }); }); let caseN = 0; async function project(manifest: unknown, withDeck = true) { caseN++; const paths = { articlesDir: path.join(tmp, `reports-${caseN}`), exportIndexDir: path.join(tmp, `idx-${caseN}`) }; const projectsRoot = path.join(tmp, `projects-${caseN}`); await mkdir(paths.articlesDir, { recursive: true }); await createIteration("synth-basic", { kind: "sweep", model: "qwen3:8b", question: "q", scope: { channels: ["synth-kitchen"] } }, paths); const report = await kit("reports/basic.report.json"); await writeIterationFile("synth-basic", 1, "report.json", report, paths); const dir = projectOf(projectsRoot, "synth-basic", 1); await mkdir(dir, { recursive: true }); await writeFile(path.join(dir, "video.manifest.json"), `${JSON.stringify(manifest, null, 2)}\n`); await writeFile(path.join(dir, "report.json"), JSON.stringify(report)); await updateIteration("synth-basic", 1, { status: "done", projectDir: dir }, paths); const lines: string[] = []; const deps: TaskDeps = { llm: { ollama: { baseUrl: ol.url } }, corpus: { source: "none", tools: [], call: async () => "" }, cuesOf: async () => null, paths, log: (l) => lines.push(l), now: () => new Date("2026-10-13T12:00:00.000Z"), ...(withDeck ? { deckChecks: async () => deck } : {}), }; const manifestNow = async () => JSON.parse(await readFile(path.join(dir, "video.manifest.json"), "utf8")); const draft = async () => JSON.parse(await readFile(path.join(dir, "teaser-draft.json"), "utf8")) as DraftFile; const input = (o: Record = {}) => ({ article: "synth-basic", n: 1, model: "qwen3:8b", projectsRoot, ...o }); return { dir, deps, lines, manifestNow, draft, input, report }; } test("teaser, the recorded run: a cut with none gets one after its last clip; the better of two kept; the umtool lint passes", async () => { const m = await kit("manifests/basic.video.manifest.json"); const p = await project(m); const r = await kit("runs/teaser.json"); ol.push(...r.turns); const out = await teaser(p.input(), p.deps); assert.equal(out.status, "done", `${out.summary}\n${p.lines.join("\n")}`); assert.equal(ol.remaining(), 0); const after = await p.manifestNow(); assert.deepEqual(after.timeline.map((e: { id: string }) => e.id).slice(-2), ["c06", "teaser"]); const t = after.timeline.at(-1); assert.deepEqual(t, { type: "teaser", id: "teaser", lines: ["Synth Kitchen", "The bakery", "The contest", "What the baker says"], drafted: { lines: { task: "teaser", model: "qwen3:8b", at: "2026-10-13T12:00:00.000Z", iteration: 1, attempt: 2 } }, }); const first = ((await p.draft()).units.teaser as { attempts: { hard: string[] }[] }).attempts[0]!.hard.join("\n"); assert.match(first, /line 2 repeats a quote \("would never sell the bakery"\)/); assert.match(first, /line 4: number “two” is not in the report/); const lint = await run(process.execPath, [path.join(ROOT, "umtool/report-to-video/lint.mjs"), path.join(p.dir, "video.manifest.json"), "--json"]).catch((e) => e); assert.deepEqual(JSON.parse(lint.stdout).errors, [], lint.stdout); }); test("teaser's checks, each alone; the build's validateTeaser is one of them", async () => { const m = await kit("manifests/basic.video.manifest.json"); const report = await kit("reports/basic.report.json"); const u = { id: "teaser", entry: null, evidence: teaserEvidence(report, m), quotes: Object.values(report.citations).map((c) => (c as { quote: string }).quote), deck }; const hard = (lines: string[], unit: typeof u = u) => checkTeaser(lines, unit).hard; assert.deepEqual(hard(["Synth Kitchen", "The bakery", "The contest"]), []); assert.match(hard(["Synth Kitchen", "The bakery"]).join(), /2 lines \(3 to 5\)/); assert.match(hard(["Synth Kitchen", "The bakery", "The contest", "The bakery", "The contest", "Synth Kitchen"]).join(), /6 lines \(3 to 5\)/); assert.match(hard(["Synth Kitchen", "The bakery", "x".repeat(71)]).join(), /line 3 is 71 characters \(at most 70\)/); assert.match(hard(["Synth Kitchen", "The\nbakery", "The contest"]).join(), /line 2 is more than one line/); assert.match(hard(["Synth Kitchen", "“The bakery”", "The contest"]).join(), /line 2 has quotation marks/); assert.deepEqual(hard(["Synth Kitchen", "The baker's bakery", "The contest"]), [], "an apostrophe is not a quotation"); assert.match(hard(["Synth Kitchen", "The bakery", "In 2025"]).join(), /line 3: number 2025 is not in the report/); assert.match(hard(["Synth Kitchen", "The bakery", "Then ask Marco"]).join(), /line 3: name “Marco” is not in the report/); // A Title Case line's unknown capital is soft (the review holds it). assert.match(checkTeaser(["Synth Kitchen", "The bakery", "Ask Marco"], u).soft.join(), /line 3: name “Marco”/); // A middle line is a title: past its row's fit, code sets its end as the // second tier; a line no split can fit (one long word) the build refuses. assert.deepEqual(hard(["Synth Kitchen", "The bakery and the contest and the oven", "The contest"]), []); assert.match(hard(["Synth Kitchen", "Thebakeryandthecontestandtheovenandmore", "The contest"]).join(), /it would not build: .*lines\[1\]/); // Without the build's check nothing is written. assert.match(hard(["Synth Kitchen", "The bakery", "The contest"], { ...u, deck: null as never }).join(), /not available, so the lines are not written/); assert.equal(claimGist('She says she would not sell: "I would never sell the bakery to a chain"'), "She says she would not sell"); assert.deepEqual(parseTeaser({ lines: [" a ", { text: "b" }, ""] }), ["a", "b"]); assert.throws(() => parseTeaser({}), /no "lines"/); }); test("teaser: the operator's lines kept (forced, the draft an alternative); a teaser with no deck check is not written", async () => { const full = await kit("manifests/full.video.manifest.json"); const p = await project(full); const skipped = await teaser(p.input(), p.deps); assert.equal(skipped.status, "failed"); assert.match(String((await p.draft()).units.fin!.skipped), /the operator's/); ol.push(jsonReply({ lines: ["Synth Kitchen", "The bakery", "The contest"] })); const forced = await teaser(p.input({ force: true }), p.deps); assert.match(forced.summary, /^0 teaser\(s\) drafted, 1 as alternatives/); assert.deepEqual((await p.manifestNow()).timeline.at(-1).lines, full.timeline.at(-1).lines); assert.deepEqual((await p.draft()).alternatives.map((a) => [a.target.entry, a.reason]), [["fin", "operator"]]); // Dates in the evidence: the full kit's clips carry none, the evidence says so by leaving them out. assert.doesNotMatch(teaserEvidence(p.report, full), /Sources dated/); const dated = structuredClone(full); dated.timeline.find((e: { id: string }) => e.id === "c07").date = "2026-03-01"; dated.timeline.find((e: { id: string }) => e.id === "c01").date = "2026-01-05"; assert.match(teaserEvidence(p.report, dated), /Sources dated: January 2026 to March 2026/); const q = await project(await kit("manifests/basic.video.manifest.json"), false); ol.push(jsonReply({ lines: ["Synth Kitchen", "The bakery", "The contest"] }), jsonReply({ lines: ["Synth Kitchen", "The bakery", "The contest"] })); const none = await teaser(q.input(), q.deps); assert.equal(none.status, "failed"); assert.equal((await q.manifestNow()).timeline.some((e: { type: string }) => e.type === "teaser"), false, "no teaser added"); assert.equal(ol.remaining(), 0); }); test("teaser: a line past its role's row gets its end as the second tier; one that fits, or cannot be split, stays as written", () => { const long = "Why can a glucose crash save a life?"; // 36: a title fits 34 assert.deepEqual(fitTeaserLines(["Overline", long, "Kicker"]), ["Overline", { text: long, break: "life?" }, "Kicker"]); assert.deepEqual(fitTeaserLines(["Overline", "Short title", "Kicker"]), ["Overline", "Short title", "Kicker"]); // Roles follow position: one line is a title, two are an overline and a title. assert.deepEqual(fitTeaserLines([long]), [{ text: long, break: "life?" }]); assert.deepEqual(fitTeaserLines([long, long]), [long, { text: long, break: "life?" }]); assert.deepEqual(fitTeaserLines(["Overline", "x".repeat(40), "Kicker"]), ["Overline", "x".repeat(40), "Kicker"]); });