// Draft everything's deck option (release 29 G1), the common side: a cut the // converter made has no deck, so flips and threads have nothing to draw on // (draftPrecheck skips them, the tasks refuse). umtool's deck step adds the // minimal deck through its manifest writer (manifest.mjs addDeckChrome, with // chain-draft.mjs deckChrome — loaded from the checkout, as deckChecks loads // report-to-video); then the flips and the threads draft on that cut over the // fake ollama, with the synthetic corpus's upload dates. import { after, before, test } from "node:test"; import assert from "node:assert/strict"; import { mkdir, mkdtemp, readdir, readFile, rm, writeFile } from "node:fs/promises"; import os from "node:os"; import path from "node:path"; import { jsonReply, startFakeOllama, type FakeOllama } from "../../../../testing/llm/fakeOllama.mjs"; import { recordOf } from "../../../../testing/draft/corpus.mjs"; import { createIteration, projectOf, updateIteration, writeIterationFile } from "../../iterations"; import { flips } from "./flips"; import { threads } from "./threads"; import type { TaskDeps } from "./types"; const DRAFT = new URL("../../../../testing/draft/", import.meta.url); const UMTOOL = new URL("../../../../../umtool/lib/report/", import.meta.url); const kit = async (rel: string) => JSON.parse(await readFile(new URL(rel, DRAFT), "utf8")); type DeckStep = { addDeckChrome: (dir: string, chrome: Record) => Promise<{ added: boolean }>; deckChrome: () => Record; draftPrecheck: (task: string, manifest: unknown) => string | null; }; let tmp: string; let ol: FakeOllama; let umtool: DeckStep; before(async () => { tmp = await mkdtemp(path.join(os.tmpdir(), "deck-option-")); ol = await startFakeOllama(); const manifest = await import(new URL("manifest.mjs", UMTOOL).href); const chainDraft = await import(new URL("chain-draft.mjs", UMTOOL).href); umtool = { addDeckChrome: manifest.addDeckChrome, deckChrome: chainDraft.deckChrome, draftPrecheck: chainDraft.draftPrecheck }; }); after(async () => { await ol.close(); await rm(tmp, { recursive: true, force: true }); }); const corpus = { source: "fake", tools: [], call: async (name: string, args: Record = {}) => { if (name !== "get_video_metadata") return ""; const r = recordOf(String(args.channel), String(args.video_id)); if (!r) throw new Error("video not found"); const { cues: _c, ...meta } = r; return JSON.stringify(meta); }, }; let caseN = 0; // The kit's basic report and the cut the converter makes of it (no render.chrome). async function convertedCut() { 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 }); const manifest = await kit("manifests/basic.video.manifest.json"); assert.equal(manifest.render.chrome, undefined, "the converter's cut has no deck"); 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 deps: TaskDeps = { llm: { ollama: { baseUrl: ol.url } }, corpus, cuesOf: async () => null, paths, log: () => {}, now: () => new Date("2026-10-15T12:00:00.000Z"), }; const input = { article: "synth-basic", n: 1, model: "qwen3:8b", projectsRoot }; const manifestNow = async () => JSON.parse(await readFile(path.join(dir, "video.manifest.json"), "utf8")); return { dir, deps, input, manifestNow }; } test("a converted cut: no deck, the flips refused; the deck step adds the minimal deck (a snapshot first), then the flips draft", async () => { const p = await convertedCut(); assert.match(umtool.draftPrecheck("flips", await p.manifestNow()) ?? "", /no on-screen deck/); const refused = await flips(p.input, p.deps); assert.equal(refused.status, "failed"); const r = await umtool.addDeckChrome(p.dir, umtool.deckChrome()); assert.equal(r.added, true); const m = await p.manifestNow(); assert.deepEqual(m.render.chrome, { engine: "hyperframes", layout: "deck", deck: {} }); assert.equal(umtool.draftPrecheck("flips", m), null); assert.ok((await readdir(path.join(p.dir, "revisions"))).some((f) => f.includes("auto-before-deck")), "the cut before the deck is kept"); ol.push(jsonReply({ pairs: [{ topic: "The bakery", then: "c01", now: "c04" }] })); const res = await flips(p.input, p.deps); assert.equal(res.status, "done", res.summary); const after = await p.manifestNow(); assert.equal(after.render.chrome.flips.pairs.length, 1); assert.equal(after.render.chrome.flips.pairs[0].then.entry, "c01"); assert.equal(after.render.chrome.flips.pairs[0].now.entry, "c04"); assert.equal(after.drafted["render.chrome.flips"].task, "flips"); }); test("the deck step on a cut with a deck leaves it as it is; the threads draft on a converted cut given the deck", async () => { const p = await convertedCut(); assert.equal((await umtool.addDeckChrome(p.dir, umtool.deckChrome())).added, true); const once = await readFile(path.join(p.dir, "video.manifest.json"), "utf8"); assert.equal((await umtool.addDeckChrome(p.dir, umtool.deckChrome())).added, false); assert.equal(await readFile(path.join(p.dir, "video.manifest.json"), "utf8"), once, "byte for byte"); ol.push( jsonReply({ threads: [ { id: "bakery", label: "The bakery" }, { id: "contest", label: "The contest" }, ], clips: [ { clip: "c01", thread: "bakery" }, { clip: "c02", thread: "bakery" }, { clip: "c03", thread: "bakery" }, { clip: "c04", thread: "contest" }, { clip: "c05", thread: "contest" }, { clip: "c06", thread: "contest" }, ], }), ); const res = await threads(p.input, p.deps); assert.equal(res.status, "done", res.summary); const m = await p.manifestNow(); assert.deepEqual(m.render.chrome.threads.list.map((t: { id: string }) => t.id), ["bakery", "contest"]); assert.equal(m.timeline.find((e: { id: string }) => e.id === "c05").thread, "contest"); }); test("a cut whose deck the operator set is never touched by the deck step", async () => { const p = await convertedCut(); const m = await p.manifestNow(); m.render.chrome = { engine: "hyperframes", layout: "deck", deck: { height: 200 } }; await writeFile(path.join(p.dir, "video.manifest.json"), `${JSON.stringify(m, null, 2)}\n`); const before = await readFile(path.join(p.dir, "video.manifest.json"), "utf8"); assert.equal((await umtool.addDeckChrome(p.dir, umtool.deckChrome())).added, false); assert.equal(await readFile(path.join(p.dir, "video.manifest.json"), "utf8"), before); });