// lane/screen-reads REVIEW 2 (12 Nov): the reviewer's probes q1/q2 as tests. Three blockers -- the staleness guard // judged on the drawn (anonymised) copy; a line take that says a shape or extra words; dash-written SSNs and phone runs // split by a decimal -- and five should-fixes. The build's ENFORCED lint (build-video.mjs enforcedLint, the seam the // build and every take's render go through) is where a read of a screen is refused. Temp dirs only. import assert from "node:assert/strict"; import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { after, test } from "node:test"; import { buildVideo, enforcedLint, selectVariant } from "./build-video.mjs"; import { anonymiseEntry, anonymiseManifest } from "./post-anon.mjs"; import { projectAnonymousSet } from "./project-characters-file.mjs"; import { draftScript } from "./post-narration.mjs"; import { threadReadErrors, validateScreenReads } from "./post-thread.mjs"; import { REDACT_MARK } from "./post-redact.mjs"; import { maskShapes, screenLineSaid, screenWarnings } from "./post-screens.mjs"; const TMP = await mkdtemp(path.join(tmpdir(), "umtool-screens-review2-")); after(() => rm(TMP, { recursive: true, force: true })); const shown = (t) => maskShapes(t).text.replace(new RegExp(REDACT_MARK, "g"), "█"); const IMG = { src: "a.jpg", kind: "image", width: 10, height: 10 }; const mk = (lines, read = "all") => ({ type: "post", id: "p-1", post: "x/1", platform: "x", author: "A", handle: "aa", date: "2026-11-02T01:40:36.000Z", text: "Your turn.", url: "https://x.com/aa/status/1", media: [IMG], screens: [{ id: "s1", media: 0, kind: "dm", read, lines }] }); /** A thread read of every read line, each part storing the line and the speaker it was made from (as the read does). */ function take(e) { const sc = e.screens[0]; const parts = [{ n: 1, para: 0, text: "Your turn.", role: "post", start: 0, seconds: 1 }]; sc.lines.forEach((l, n) => { const s = screenLineSaid(sc, n); if (s) parts.push({ n: parts.length + 1, para: (n + 1) * 100, text: s, line: draftScript(s).script, speaker: l.who ?? "", role: `screen:s1:${n}`, start: 2 + n * 3, seconds: 2 }); }); return { ...e, narration: { script: "Your turn.", pick: 0, takes: [{ file: "narration/posts/1/take-1.orpheus-thread.wav", engine: "orpheus", voice: "x", seconds: 20, script: "x", parts }] } }; } // --------------------------------------------------------------------------- // MUST 1: staleness is judged on the cut AS WRITTEN; the build's enforced lint refuses a stale read, never a fresh one. // --------------------------------------------------------------------------- const CHARS = { format: "umtool-project-characters", version: 1, characters: [{ id: "anon-1", name: "Real Guy", anonymous: true, shown: "Anon 1", handles: ["secretkid"] }] }; const wholeOf = (e) => ({ schemaVersion: 1, title: "T", slug: "t", provenance: {}, render: { width: 1280, height: 720, fps: 30 }, timeline: [e] }); async function project(name, whole) { const dir = path.join(TMP, name); await mkdir(path.join(dir, "narration/posts/1"), { recursive: true }); await writeFile(path.join(dir, "narration/characters.json"), JSON.stringify(CHARS)); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(whole)); return dir; } const seam = async (dir, whole) => { const anonymity = await projectAnonymousSet(dir, whole); const cut = selectVariant(whole, "sourced"); const drawn = anonymiseManifest(cut, anonymity.doc, { set: anonymity.set }); return enforcedLint(drawn, { manifestDir: dir, whole, only: null, validators: false }, { cut, anonymity }); }; test("MUST 1 (q1): a line mentioning an anonymous handle -- its fresh read is not refused (as drawn or at the build's seam)", async () => { // As a synthesized read says it (the shown name), so the anonymity lint is quiet too. const e = take(mk([{ who: "bob", text: "ask @secretkid about it" }])); e.narration.takes[0].parts[1].text = "ask Anon 1 about it."; assert.deepEqual(threadReadErrors(e, {}), []); assert.deepEqual(threadReadErrors(anonymiseEntry(e, new Map([["secretkid", "Anon 1"]])), {}), [], "the drawn copy is self-consistent too"); const whole = wholeOf(e); const lint = await seam(await project("q1", whole), whole); assert.ok(!lint.errors.some((x) => /screen s1|changed since the read/.test(x)), lint.errors.join("\n")); }); test("MUST 1: the build's enforced lint REFUSES a stale screen read -- at the seam and through a take's render manifest", async () => { const e = take(mk([{ who: "bob", text: "ask @secretkid about it" }, { who: "aa", text: "will do" }])); e.narration.takes[0].parts[1].text = "ask Anon 1 about it."; e.screens[0].lines[1].text = "will NOT do"; const whole = wholeOf(e); const dir = await project("stale", whole); const lint = await seam(dir, whole); assert.ok(lint.errors.some((x) => /line 1 of screen s1 changed since the read/.test(x)), lint.errors.join("\n")); const renderManifest = path.join(dir, ".take-t1.render.json"); await writeFile(renderManifest, JSON.stringify(whole)); await assert.rejects(buildVideo({ manifestPath: renderManifest, opts: { noNetwork: true, skipFetch: true } }), /lint: .*line 1 of screen s1 changed since the read/); // The fresh one's render stops on its missing files alone, never on its screen. const fresh = wholeOf(take(mk([{ who: "bob", text: "ask @secretkid about it" }]))); fresh.timeline[0].narration.takes[0].parts[1].text = "ask Anon 1 about it."; const d2 = await project("fresh", fresh); const rm2 = path.join(d2, ".take-t2.render.json"); await writeFile(rm2, JSON.stringify(fresh)); await assert.rejects(buildVideo({ manifestPath: rm2, opts: { noNetwork: true, skipFetch: true } }), (err) => /lint:/.test(err.message) && !/screen s1/.test(err.message)); }); test("SHOULD (who): a speaker-only edit under a read is refused -- the old voice under a new name", () => { const base = take(mk([{ who: "bob", text: "hello there" }, { who: "aa", text: "see you soon" }])); assert.deepEqual(threadReadErrors(base, {}), []); const x = structuredClone(base); x.screens[0].lines[0].who = "SomeoneElse"; assert.ok(threadReadErrors(x, {}).some((m) => /line 0 of screen s1 changed since the read/.test(m))); const y = structuredClone(base); y.screens[0].lines[1].side = "left"; assert.deepEqual(threadReadErrors(y, {}), [], "a side is not a word"); // A part that recorded no speaker (a take made before speakers were recorded, or by hand) is judged by its words // alone: an unchanged line is not refused for it. const z = structuredClone(base); for (const pt of z.narration.takes[0].parts) delete pt.speaker; assert.deepEqual(threadReadErrors(z, {}), []); }); // --------------------------------------------------------------------------- // MUST 2: what a screen piece SAYS holds no shape -- refused by the build's enforced lint. // --------------------------------------------------------------------------- test("MUST 2: a screen part that says a shape (a recorded line take saying the number) is refused by validateScreenReads", () => { const e = take(mk([{ who: "bob", text: "please call me at 555 201 4477 tonight after work ok" }])); assert.deepEqual(validateScreenReads({ timeline: [e] }), []); e.narration.takes[0].parts[1].text = "please call me at 555 201 4477 tonight after work ok"; assert.ok(validateScreenReads({ timeline: [e] }).some((x) => /part 2 \(line 0 of screen s1\) says a long number or a phone number/.test(x))); assert.ok(!validateScreenReads({ timeline: [e] }).some((x) => /555/.test(x)), "never the value"); }); // --------------------------------------------------------------------------- // MUST 3 + SHOULD keywords: the shapes. // --------------------------------------------------------------------------- test("MUST 3 (q1): dash- and dot-written SSNs, 3-2-4 groups, a phone run around a decimal -- masked; plausible dates kept", () => { for (const [t, want] of [ ["my social is 123-45-6789", "my social is ███████████"], ["call 555-12-3456", "call ███████████"], ["1234-56-7890", "████████████"], ["acct 12/34/5678", "acct ██████████"], ["SSN: 078.05.1120", "SSN: ███████████"], ["call 555 201-44.77 now", "call ███ █████████ now"], ]) assert.equal(shown(t), want, t); for (const t of ["on 11/02/2026 at 10:42", "weighed 312.4 on 2026-11-02", "lost 41.2 lbs, 312.4 to 271.2", "since 02.11.26", "weights 312.4 310.2 308.0 305.5", "paid $104.90 today"]) assert.equal(shown(t), t, t); }); test("SHOULD (keywords): cvv, cvc, security code, exp MM/YY, a date of birth -- masked", () => { for (const [t, want] of [ ["exp 12/27 cvv 123", "exp █████ cvv ███"], ["cvc 4821", "cvc ████"], ["security code 991", "security code ███"], ["DOB 1990-04-12", "DOB ██████████"], ["my birthday is 4/12/1990", "my birthday is █████████"], ["born 04/12/1990", "born ██████████"], ]) assert.equal(shown(t), want, t); }); test("SHOULD (split digits): two adjacent lines whose digits together make a shape -- the lint names the lines", () => { const e = mk([{ who: "a", text: "my card is 4111 1111" }, { who: "a", text: "1111 1111" }, { who: "a", text: "call 555 201" }, { who: "a", text: "4477 thanks" }, { who: "a", text: "ok" }]); const w = screenWarnings(e, { narrated: false }); assert.ok(w.some((x) => /lines 0 and 1 of screen s1 together hold/.test(x)), w.join("\n")); assert.ok(w.some((x) => /lines 2 and 3 of screen s1 together hold/.test(x)), w.join("\n")); assert.ok(!w.some((x) => /lines 3 and 4/.test(x))); assert.ok(!w.some((x) => /4111|555/.test(x))); }); test("SHOULD (draw errors up front): an excerpt not in its line as drawn is refused by the build's enforced lint", async () => { const e = take(mk([{ who: "bob", text: "Preamble. He said it was fine. Private aside." }], [{ line: 0, text: "said it was fine" }])); const whole = wholeOf(e); whole.timeline[0].screens[0].read = [{ line: 0, text: "said it was okay" }]; const lint = await seam(await project("draw", whole), whole); assert.ok(lint.errors.some((x) => /line 0 of screen s1: its excerpt is not in the line as drawn/.test(x)), lint.errors.join("\n")); });