// THE RULING-3 PIN FOR A VIDEO's READS (lane reads-find; operator ruling 3, 15 Nov 2026: "edits change only what is // SPOKEN -- shown text never changes"). After a Replace in EITHER scope and after the re-read queue has run and its // re-reads are picked, every card draws byte-identically to before: the reading pin's drawn() -- its plain card, its // followed card, its blocks (and the paragraphs an excerpt tile hides), its thread tiles' modes, its screens -- and a // narrated card's every field but its narration. One exception, named and not pinned: an item whose playing take was // read BEFORE the rule (unstamped, other words) moves to the shown-text rule when its re-read is picked -- the preview // says so (post-item.mjs LEGACY_EDIT_TEXT). Temp dirs, a stub tts, invented people; noLiveEditor first. import "./noLiveEditor.mjs"; import assert from "node:assert/strict"; import { mkdtemp, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { after, test } from "node:test"; import { applyReplace, applySayOnly, replacePlan } from "./readsReplace.mjs"; import { enqueueRereads, pickReads, readBatches, runOneItem } from "./readsQueue.mjs"; import { postsCommand } from "./postsCli.mjs"; import { cardNarrationCommand } from "./cardNarrationCli.mjs"; import { projectReads } from "./reads.mjs"; import { keepCardReading, readManifestOf, readsProject, wavOf } from "./reads.fixtures.mjs"; import { drawn } from "../../report-to-video/post-reading-pin.fixtures.mjs"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-reads-pin-")); after(() => rm(ROOT, { recursive: true, force: true })); delete process.env.UMTOOL_CAST_FILE; const stubAsk = async (body) => { await wavOf(body.out); return { jobId: "job", result: { wav: body.out, engine: body.engine, voice: body.voice, tuning: { temperature: 0.55, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2, takes: 3 }, reading: body.reading ?? 0 } }; }; const run = (p) => async (argv) => { if (argv[0] === "posts") return postsCommand(argv.slice(1), { root: p.root, tts: stubAsk, out: () => {}, err: () => {} }); return cardNarrationCommand(argv.slice(1), { root: p.root, narrate: async ({ narrations }) => { for (const n of narrations) await keepCardReading(p.dir, n, { createdAt: new Date().toISOString() }); return new Map(narrations.map((n) => [n.id, { seconds: 1.4 }])); }, out: () => {}, err: () => {} }); }; /** What every item DRAWS: a post's drawn() hashes; any other entry, every field but its narration. */ const drawnCut = (m) => m.timeline.map((e) => (e.type === "post" ? { id: e.id, ...drawn(e) } : (({ narration: _n, ...rest }) => rest)(e))); test("THE PIN: replace (these reads, then everywhere), re-read every changed line, pick the new reads -- the cut draws as before", async () => { const p = await readsProject(ROOT, "pin"); const before = drawnCut(await readManifestOf(p)); // These reads: a post's script, a thread read's own words, a screen line (said-as made), the card. await applyReplace(p, "north", "northern", { reportsRoot: p.root }); await applyReplace(p, "Tuesday", "Tuesday evening", { reportsRoot: p.root }); await applyReplace(p, "tolls", "toll charges", { reportsRoot: p.root }); assert.deepEqual(drawnCut(await readManifestOf(p)), before, "after These reads"); // Everywhere: a pronunciation entry. await applySayOnly(p, "ministry", "min-is-tree", { reportsRoot: p.root }); assert.deepEqual(drawnCut(await readManifestOf(p)), before, "after Everywhere"); // The re-read queue, each step as the app runs it, then Pick every new read. const q = await enqueueRereads(p, { reportsRoot: p.root, queueDir: path.join(p.root, ".umtool-queue") }); assert.deepEqual(q.steps.map((s) => s.item), ["p-1", "p-2", "c-1"]); for (const s of q.steps) assert.equal((await runOneItem(p, s.item, s.reads, { reportsRoot: p.root, run: run(p), log: () => {} })).code, 0, s.item); assert.deepEqual(drawnCut(await readManifestOf(p)), before, "after the re-reads (unpicked)"); await pickReads(p, { which: "new", reportsRoot: p.root }); const m = await readManifestOf(p); assert.deepEqual(drawnCut(m), before, "after the picks"); // The reads say the new words, and are fresh. const rows = (await projectReads(p, { reportsRoot: p.root })).rows; assert.deepEqual(rows.filter((r) => r.state !== "fresh" && r.state !== "recorded").map((r) => `${r.id} ${r.state}`), []); assert.match(m.timeline[0].narration.takes.at(-1).script, /northern pier/); assert.equal(m.timeline[0].narration.takes.at(-1).forReading, true); assert.ok((await readBatches(p.dir)).length === 1); }); test("THE EXCEPTION, named: an item playing a take read before the rule is said in the replace's preview", async () => { const p = await readsProject(ROOT, "legacy"); const m = await readManifestOf(p); // His playing take says other words than the post, unstamped (made before reads were kept apart from the card). const t = m.timeline[0].narration.takes[0]; t.script = "The ferry leaves at noon.\n\nBring a coat."; m.timeline[0].narration.script = t.script; await writeFile(path.join(p.dir, "video.manifest.json"), JSON.stringify(m, null, 2)); const plan = await replacePlan(p, "coat", "warm coat", { reportsRoot: p.root }); assert.match(plan.notes["p-1"].join(" "), /read before reads were kept apart from the card/); });