// lane/screens-2, review round 1: what the review found, each pinned by a test made failing first. // M1 a read the build refuses is never played by a preview: playableEntry, Play's view, Present (operator and public) // M2 a screen made from its read IS the post's read (the post part not read twice); no part of a read says what the // item's screens hide (the enforced lint); `add --from-read` says only what is true // i the public payload carries the screens as the card draws them, never raw // Temp dirs only; no audio is made (the takes are placeholders the payloads only name). 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 { draftScript } from "umtool-report-to-video/post-narration"; import { screenLineSaid, withoutLines } from "umtool-report-to-video/post-screens"; import { itemReadRefusals, playableEntry, readSaysHiddenErrors, validateScreenReads } from "umtool-report-to-video/post-thread"; import { presentPayload } from "./present.mjs"; import { playViewWith } from "./playView.mjs"; import { postsCommand } from "./postsCli.mjs"; import { threadReadPlan } from "./postThreadRead.mjs"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-screens-review3-")); after(() => rm(ROOT, { recursive: true, force: true })); const IMG = { src: "posts-media/savvy-x/2117/2117_2.jpg", kind: "image", width: 900, height: 1400 }; const DM = { id: "s1", media: 0, kind: "dm", read: "all", checked: { by: "op", at: "2026-11-12T10:00:00.000Z" }, lines: [ { who: "TheQuartering", text: "what is your address so I can send it" }, { who: "MadamSavvy", text: "it is 12 Elm Street Springfield" }, { who: "TheQuartering", text: "You can't be this dumb" }, ] }; const THREAD = "narration/posts/2117/take-1.orpheus-thread.wav"; function narrated(e) { const parts = [{ n: 1, para: 0, text: "Hey, you told me.", voice: "tara", role: "post", start: 0, seconds: 1 }]; let t = 1.5; e.screens[0].lines.forEach((l, n) => { const said = screenLineSaid(e.screens[0], n); parts.push({ n: parts.length + 1, para: 100 * (n + 1), text: said, voice: "leo", role: `screen:s1:${n}`, start: t, seconds: 1, line: draftScript(said).script, speaker: l.who }); t += 1.5; }); return { ...e, narration: { script: "Hey, you told me.", pick: 0, takes: [{ file: THREAD, engine: "orpheus", voice: "tara+leo", seconds: t, script: "x", parts, read: { kind: "thread", parents: "0" } }] } }; } const ITEM = narrated({ type: "post", id: "p-2117", post: "savvy-x/2117", platform: "x", author: "Savvy", handle: "MadamSavvy", date: "2026-11-02T01:40:36.000Z", text: "Hey, you told me.", subjects: ["MadamSavvy"], media: [IMG], screens: [structuredClone(DM)] }); // The g1 probe's edits: each made UNDER the read (the writer takes them; the build refuses the old read). const EDITS = { "words of line 1 edited": (sc) => ({ ...sc, lines: sc.lines.map((l, i) => (i === 1 ? { ...l, text: "it is somewhere in town" } : l)) }), "line 0 gets a phone number": (sc) => ({ ...sc, lines: sc.lines.map((l, i) => (i === 0 ? { ...l, text: "what is your address call 555 201 4477" } : l)) }), "line 2 gets an anonymous handle": (sc) => ({ ...sc, lines: sc.lines.map((l, i) => (i === 2 ? { ...l, text: "ask @secretkid about it" } : l)) }), "line 1 given to someone else": (sc) => ({ ...sc, lines: sc.lines.map((l, i) => (i === 1 ? { ...l, who: "Stranger" } : l)) }), "line 0 removed": (sc) => withoutLines(sc, [0]), "line 1 redacted": (sc) => ({ ...sc, lines: sc.lines.map((l, i) => (i === 1 ? { ...l, redact: true } : l)) }), "line 1 no longer read": (sc) => ({ ...sc, read: [{ line: 0 }, { line: 2 }] }), }; const edited = (f) => ({ ...ITEM, screens: [f(structuredClone(ITEM.screens[0]))] }); async function project(name, item) { const dir = path.join(ROOT, name); await mkdir(path.join(dir, "narration"), { recursive: true }); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: name, title: name, provenance: { channelsDir: "../channels", channelSlug: "chan" }, render: { width: 1920, height: 1080, fps: 30 }, timeline: [item] }, null, 2)); return { id: name, dir }; } test("M1 playableEntry: the read as made plays; after each g1 edit the item plays WITHOUT its read (no narration, no take), the reason said", () => { assert.equal(playableEntry(ITEM), ITEM, "a read the build plays: the item itself"); for (const [name, f] of Object.entries(EDITS)) { const e = edited(f); assert.ok(itemReadRefusals(e).length > 0, name); const p = playableEntry(e); assert.equal(p.narration, undefined, name); assert.ok(!JSON.stringify(p).includes(THREAD), `${name}: no reference to the old take`); assert.match(p.readRefused.reason, /make the read again/); } }); test("M1 Play and Present: a refused read is in no view and no payload -- operator or public -- and Present's public data carries no raw line (i)", async () => { for (const [name, f] of Object.entries(EDITS)) { const p = await project(`m1-${Object.keys(EDITS).indexOf(name)}`, edited(f)); const view = await playViewWith(p, {}); assert.ok(!view.error, String(view.error)); const pe = view.view.entries.find((x) => x.id === "p-2117"); assert.equal(pe.post.narration, undefined, `${name}: Play`); assert.equal(pe.postPlan.narration ?? null, null, `${name}: Play's plan`); assert.ok(pe.readRefused, `${name}: Play says why`); for (const canUncensor of [true, false]) { const pay = await presentPayload(p, { canUncensor }); assert.ok(!pay.error, String(pay.error)); const s = pay.slides.find((x) => x.kind === "post"); assert.equal(s.narration, null, `${name}: Present ${canUncensor ? "operator" : "public"}`); assert.ok(!JSON.stringify(pay).includes(THREAD), `${name}: no stale audio in the payload`); if (!canUncensor) { const raw = JSON.stringify(s.post.screens); assert.ok(!/555|4477/.test(raw), `${name}: a phone number never in the public data`); } } } // The read as made: played, in both. const ok = await project("m1-ok", ITEM); const pay = await presentPayload(ok, { canUncensor: false }); assert.equal(pay.slides.find((x) => x.kind === "post").narration.file, THREAD); }); test("i: an item whose read draws no screen carries no screen in the public payload (the card draws none)", async () => { const sc = { id: "s1", media: 0, kind: "dm", title: "Mail to savvy@gmail.com", read: "all", lines: [{ who: "Stranger", text: "my email is jane.doe@example.com", time: "555-201-4477" }] }; const p = await project("i-pub", { ...ITEM, narration: undefined, screens: [sc] }); const pay = await presentPayload(p, { canUncensor: false }); assert.deepEqual(pay.slides.find((x) => x.kind === "post").post.screens, []); assert.ok(!/jane\.doe|savvy@gmail|4477/.test(JSON.stringify(pay))); const op = await presentPayload(p, { canUncensor: true }); assert.ok(JSON.stringify(op.slides.find((x) => x.kind === "post").post.screens).includes("jane.doe@example.com"), "the operator's own screen, as written"); }); test("M2 the enforced lint: no part of an item's read says a number or an e-mail its screens mask, nor a redacted line's words -- whoever's part it is", () => { const sc = { id: "s1", media: 0, kind: "text", source: "read", read: "all", lines: [{ text: "I never said that." }, { text: "Order number: 4419283 was refunded." }, { text: "my secret plan for the house", redact: true }] }; const plain = (script) => ({ type: "post", id: "p-7", post: "kir-x/7", platform: "x", author: "K", handle: "kirsche", date: "2026-11-02T01:40:36.000Z", text: "@thequartering", media: [IMG], screens: [sc], narration: { script, takes: [{ file: "narration/posts/7/take-1.kokoro-af_heart.wav", engine: "kokoro", voice: "af_heart", seconds: 3, script }], pick: 0 } }); assert.ok(readSaysHiddenErrors(plain("I never said that. Order number: 4419283 was refunded.")).some((x) => /its picked take says a number that line 1 of screen s1 masks/.test(x))); assert.ok(readSaysHiddenErrors(plain("the order was 4419 283")).length > 0, "its digits however they are joined"); assert.ok(readSaysHiddenErrors(plain("here is my secret plan for the house")).some((x) => /line 2 of screen s1, which is redacted/.test(x))); assert.deepEqual(readSaysHiddenErrors(plain("I never said that.")), []); assert.deepEqual(readSaysHiddenErrors(plain("I paid $99.95 on 11/02/2026")), [], "amounts and dates are never shapes"); // Through the cut: the build's enforced lint (validateScreenReads) refuses it; a cut without screens is untouched. assert.ok(validateScreenReads({ timeline: [plain("Order number: 4419283 was refunded.")] }).length > 0); const { screens: _s, ...noScreens } = plain("Order number: 4419283 was refunded."); assert.deepEqual(validateScreenReads({ timeline: [noScreens] }), []); // A message names the part and the line, never the value. assert.ok(readSaysHiddenErrors(plain("Order number: 4419283")).every((x) => !x.includes("4419283"))); }); test("M2 --from-read: its screen IS the post's read -- the post part is not read again, no take of it reused, a --post-take refused; `add` says only what is true (probe f2)", async () => { const take = { file: "narration/posts/7/take-1.kokoro-af_heart.wav", engine: "kokoro", voice: "af_heart", seconds: 3, script: "I never said that.\nOrder number: 4419283 was refunded." }; const item = { type: "post", id: "p-7", post: "kir-x/7", platform: "x", author: "Kirsche", handle: "kirsche", date: "2026-11-02T01:40:36.000Z", text: "@thequartering", media: [IMG], narration: { script: take.script, takes: [take], pick: 0 } }; await project("fr", item); const lines = []; const posts = async (args) => { lines.length = 0; const code = await postsCommand(args, { root: ROOT, out: (s) => lines.push(s), err: (s) => lines.push(s) }); return { code, text: lines.join("\n") }; }; let r = await posts(["screen", "fr", "p-7", "add", "--from-read"]); assert.equal(r.code, 0, r.text); assert.match(r.text, /the item still plays its read as it was/); assert.match(r.text, /the build REFUSES the read as it is .*says a number that line 1 of screen s1 masks/); r = await posts(["screen", "fr", "p-7", "read", "--dry-run", "--json"]); assert.equal(r.code, 0, r.text); const j = JSON.parse(r.text); assert.deepEqual(j.parts.map((p) => p.role), ["screen:s1:0", "screen:s1:1"], "the post part is not read: the screen's lines are its read"); assert.ok(j.parts.every((p) => !p.take), "no take reused"); assert.ok(j.parts.every((p) => !/4419283/.test(p.text)), "the masked number never said"); assert.ok(j.skipped.some((s) => s.role === "post" && /screen s1's lines/.test(s.why))); r = await posts(["screen", "fr", "p-7", "read", "--dry-run", "--post-take", "1"]); assert.notEqual(r.code, 0); assert.match(r.text, /own words are its screen s1's lines/); // A typed screen (not from its read) reads his words as before. const typed = { ...item, screens: [{ id: "s1", media: 0, kind: "text", source: "transcribed", read: "all", lines: [{ text: "hello" }] }] }; assert.deepEqual(threadReadPlan({ render: {}, timeline: [typed] }, typed, {}).pieces.map((p) => p.role), ["post", "screen:s1:0"]); }); // --------------------------------------------------------------------------- // SHOULD-FIXES (b, d, e, f, j) -- a is in postScreensRound2.test.mjs (content-based ownership). // --------------------------------------------------------------------------- import { readFile, readdir, stat } from "node:fs/promises"; import { encodeWav16 } from "yt-dlp-transcript-common/lib/montage/voiceMatch.mjs"; import { VOICE_A, VOICE_B, syntheticVoice, withSilence } from "yt-dlp-transcript-common/testing/audio/syntheticVoice.mjs"; import { claimRecordedTake, keepRecording } from "./postRecord.mjs"; import { heardProblem, recordScreenLine } from "./screenLineRecord.mjs"; import { lineTakeProblem } from "./postThreadRead.mjs"; import { linesOfRead } from "umtool-report-to-video/post-screens"; import { lineTakeWarnings } from "umtool-report-to-video/post-thread"; const tone = async (file, voice = VOICE_A, seconds = 1) => { await mkdir(path.dirname(file), { recursive: true }); await writeFile(file, encodeWav16(withSilence(syntheticVoice({ ...voice, seconds }), { before: 0.1, after: 0.1 }))); }; const OWN_TAKE = { file: "narration/posts/2117/take-1.kokoro-af_heart.wav", engine: "kokoro", voice: "af_heart", seconds: 1, script: "Hey, you told me." }; const plainItem = () => ({ ...ITEM, narration: { script: "Hey, you told me.", takes: [OWN_TAKE], pick: 0 } }); test("b: two recordings kept at once never write one file; a recording already there is never overwritten (an exclusive claim, the next number)", async () => { const p = await project("b-claim", plainItem()); // A recording already on disk at the number the item would give next (not in the manifest: a crash, another session). const there = path.join(p.dir, "narration/posts/2117/take-2.recorded-operator.wav"); await tone(there, VOICE_B, 0.5); const before = await readFile(there); const a = path.join(ROOT, "b-a.wav"); const b = path.join(ROOT, "b-b.wav"); await tone(a, VOICE_A, 1); await tone(b, VOICE_B, 1.3); const e = JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")).timeline[0]; const got = await Promise.allSettled([keepRecording(p, e, [{ file: a, text: "x" }]), keepRecording(p, e, [{ file: b, text: "x" }])]); const files = got.filter((x) => x.status === "fulfilled").map((x) => x.value.take.file); assert.ok(files.length >= 1); assert.ok(!files.includes("narration/posts/2117/take-2.recorded-operator.wav"), "the file already there was not taken"); assert.deepEqual(await readFile(there), before, "never overwritten"); const names = (await readdir(path.join(p.dir, "narration/posts/2117"))).filter((f) => /^take-\d+\.recorded-operator\.wav$/.test(f)); assert.equal(new Set(names).size, names.length); assert.ok(names.length >= 3, `both recordings kept in files of their own: ${names}`); for (const f of names) assert.ok((await stat(path.join(p.dir, "narration/posts/2117", f))).size > 0, `${f} is a recording, not an empty claim`); // The claim itself: exclusive, the next number while one is there. const c1 = await claimRecordedTake(p.dir, e, "operator"); const c2 = await claimRecordedTake(p.dir, e, "operator"); assert.notEqual(c1.rel, c2.rel); }); test("d: --check-words refuses an anonymous author's handle or name in any spoken form, and a number said in words (probe h1)", () => { const o = { handles: ["secretkid"], names: ["Jeremy Smith"], terms: ["Jenny"], lineTakeProblem }; for (const heard of ["ask secretkid about it", "ask secretkid's mom about it", "ask secret kid about it", "ask Secret Kid about it", "ask SecretKid. about it", "ask @secretkid about it", "call five five five two oh one four four seven seven", "my number is 555 201 4477", "email jane at gmail dot com", "ask Jeremy Smith about it", "ask jeremysmith's dog", "ask jenny about it"]) { assert.ok(heardProblem(heard, "ask Kid A about it", o).refused, heard); } assert.deepEqual(heardProblem("ask Kid A about it", "ask Kid A about it", o), { refused: null, warning: null }); assert.ok(heardProblem("about it ask Kid A", "ask Kid A about it", o).warning, "other words: a warning"); assert.equal(heardProblem("one or two of them", "one or two of them", o).refused, null, "a few number words are words"); }); test("e: linesOfRead leaves out only Orpheus's tags -- any other is the picture's words (probe f1 e)", () => { assert.deepEqual(linesOfRead("I never said that. Press <1> to call a "), [{ text: "I never said that. Press <1> to call a " }]); assert.deepEqual(linesOfRead(" ok "), [{ text: "ok" }]); }); const CHARS = { format: "umtool-project-characters", version: 1, characters: [ { id: "tq", name: "Jeremy", handles: ["thequartering"], synthetic: { voice: "kokoro:am_michael" }, recorded: { convert: { engine: "openvoice", voice: "kokoro:am_michael" } } }, { id: "other", name: "Other", handles: ["someoneelse"], synthetic: { voice: "kokoro:af_sky" }, recorded: { convert: { engine: "openvoice", voice: "kokoro:af_sky" } } }, ] }; const stubOps = (heard = null) => async (route, body) => { if (route === "/api/ops/transcribe") { await writeFile(body.out, JSON.stringify({ words: String(heard ?? "").split(/\s+/).filter(Boolean).map((w, i) => ({ w, start: i * 0.3, end: i * 0.3 + 0.25 })) })); return { jobId: "t", result: {} }; } await tone(body.out, VOICE_B, 1); return { jobId: "j", result: route.endsWith("voice-convert") ? { op: "convert", engine: "openvoice", voice: String(body.voice ?? "").split(":").pop() } : { op: "enhance", engine: "deepfilternet" } }; }; test("f: record --as only names the line's speaker's character -- another character or the narrator is refused (probe a1)", async () => { const p = await project("f-as", plainItem()); await writeFile(path.join(p.dir, "narration", "characters.json"), JSON.stringify(CHARS)); await mkdir(path.join(p.dir, ".umtool"), { recursive: true }); await writeFile(path.join(p.dir, ".umtool", "cast.json"), JSON.stringify({ format: "umtool-cast", version: 1, characters: [{ id: "me", name: "Me", handles: ["operator"], voice: "kokoro:bm_george", convert: { engine: "openvoice" }, narrator: true }] })); const f = path.join(ROOT, "f.wav"); await tone(f); await assert.rejects(() => recordScreenLine(p, "p-2117", "screen:s1:0", f, { as: "other", ask: stubOps() }), /not the character of line 0's speaker \(that is tq\)/); await assert.rejects(() => recordScreenLine(p, "p-2117", "screen:s1:0", f, { as: "me", ask: stubOps() }), /the narrator is never a screen line's voice/); const ok = await recordScreenLine(p, "p-2117", "screen:s1:0", f, { as: "tq", ask: stubOps(), clean: false }); assert.match(ok.disclosure, /am_michael/); }); test("j: an unheard line take is said to be one -- the record's note, the lint per chosen take; a heard one records what it was heard saying, against which words", async () => { const p = await project("j-heard", plainItem()); await writeFile(path.join(p.dir, "narration", "characters.json"), JSON.stringify(CHARS)); const f = path.join(ROOT, "j.wav"); await tone(f); const r = await recordScreenLine(p, "p-2117", "screen:s1:2", f, { ask: stubOps(), clean: false, convert: false }); assert.ok(r.notes.some((x) => /not heard: nothing checked what the recording says/.test(x))); const h = await recordScreenLine(p, "p-2117", "screen:s1:2", f, { ask: stubOps("You can't be this dumb"), clean: false, convert: false, checkWords: true }); assert.equal(h.heard, true); const m = JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); const e = m.timeline[0]; const [unheard, heard] = e.narration.takes.slice(1); assert.equal(unheard.screenLine.heard, undefined); assert.deepEqual([heard.screenLine.heard.against, heard.screenLine.heard.words], ["You can't be this dumb", "You can't be this dumb"]); const chose = (id) => ({ ...e, screens: [{ ...e.screens[0], lineTakes: { 2: id } }] }); assert.ok(lineTakeWarnings(chose("take-2.recorded-operator")).some((x) => /line take 2 of screen s1 line 2 was not heard -- nothing verified what the recording says/.test(x))); assert.ok(!lineTakeWarnings(chose("take-3.recorded-operator")).some((x) => /was not heard/.test(x))); }); // --------------------------------------------------------------------------- // RE-CHECK: the public payload is built from what the card draws (M); one verdict on the item as written (b); one // accessor for an item's playable read (e). // --------------------------------------------------------------------------- import { publicScreens } from "./present.mjs"; import { playableAsWritten, playableTake } from "umtool-report-to-video/post-thread"; import { postCardHtml, postItemPlan } from "umtool-report-to-video/post-item"; /** Every string anywhere in a value (keys too), any depth. */ const strings = (v, out = []) => { if (typeof v === "string") out.push(v); else if (Array.isArray(v)) v.forEach((x) => strings(x, out)); else if (v && typeof v === "object") for (const [k, x] of Object.entries(v)) strings(x, out.concat(k)); return out; }; const MARKED = { type: "post", id: "p-2117", post: "savvy-x/2117", platform: "x", author: "Savvy", handle: "MadamSavvy", date: "2026-11-02T01:40:36.000Z", text: "Hey, you told me.", subjects: ["MadamSavvy"], media: [IMG], screens: [ { id: "s1", media: 0, kind: "dm", title: "Mail to TITLEMARK@example.com", read: [{ line: 0, text: "keep this part" }, { line: 1 }, { line: 4 }], lines: [ { who: "MadamSavvy", text: "keep this part CUTREMAINDER words", time: "call 555 201 4477" }, { who: "TheQuartering", text: "ring 555 777 8888 now", time: "11:32 AM" }, { who: "TheQuartering", text: "OMITTEDLINE never chosen" }, { who: "TheQuartering", text: "REDACTEDWORDS alpha beta gamma", redact: true }, { who: "secretkid", text: "ask @secretkid about it" }, ] }, { id: "s2", media: 0, kind: "text", read: "all", lines: [{ text: "UNREADSCREEN its words" }] }, ], }; const narratedMarked = () => { const e = structuredClone(MARKED); const parts = [{ n: 1, para: 0, text: "Hey, you told me.", voice: "tara", role: "post", start: 0, seconds: 1 }]; let t = 1.5; for (const n of [0, 1, 4]) { const said = screenLineSaid(e.screens[0], n); parts.push({ n: parts.length + 1, para: 100 * (n + 1), text: said, voice: "leo", role: `screen:s1:${n}`, start: t, seconds: 1, line: draftScript(said).script, speaker: e.screens[0].lines[n].who }); t += 1.5; } return { ...e, narration: { script: "Hey, you told me.", pick: 0, takes: [{ file: THREAD, engine: "orpheus", voice: "tara+leo", seconds: t, script: "x", parts, read: { kind: "thread", parents: "0" } }] } }; }; test("M (re-check): the WHOLE public payload holds nothing the card does not draw -- an excerpt's remainder, a line not read, a screen not read, a redacted line, a masked number, a title's or a time's shape, an anonymous handle; the operator payload as before", async () => { const p = await project("m-public", narratedMarked()); await writeFile(path.join(p.dir, "narration", "characters.json"), JSON.stringify({ format: "umtool-project-characters", version: 1, characters: [{ id: "kid", name: "Secret Kid", handles: ["secretkid"], anonymous: true }] })); const pub = await presentPayload(p, { canUncensor: false }); assert.ok(!pub.error, String(pub.error)); const all = strings(pub).join("\n"); for (const marker of ["CUTREMAINDER", "OMITTEDLINE", "UNREADSCREEN", "REDACTEDWORDS", "alpha beta", "555 201 4477", "4477", "555 777 8888", "8888", "TITLEMARK", "secretkid", "Secret Kid"]) { assert.ok(!all.toLowerCase().includes(marker.toLowerCase()), `${marker} is nowhere in the public payload`); } // What the card draws IS there: the excerpt's run cut "…", a "⋯" row for the lines left out, the read lines masked. const sc = pub.slides.find((x) => x.kind === "post").post.screens; assert.deepEqual(sc.map((x) => x.id), ["s1"], "only the screens the card draws"); const rows = sc[0].rows; assert.equal(rows[0].text, "keep this part…"); assert.ok(rows.some((r) => r.gap), "the lines left out are a gap row, not their words"); assert.ok(rows.some((r) => /^ring\b/.test(r.text) && !/\d/.test(r.text)), "a read line, its number masked"); assert.equal("lines" in sc[0], false, "no lines to draw from but the rows drawn"); // The card itself draws none of the markers either (the payload and the card agree). const e = narratedMarked(); const plan = postItemPlan(e, {}); const html = postCardHtml(e, { width: 1600, height: 900, follow: true, thread: plan.follow?.thread ?? null }); for (const marker of ["CUTREMAINDER", "OMITTEDLINE", "UNREADSCREEN", "REDACTEDWORDS"]) assert.ok(!html.includes(marker), `${marker} not on the card`); // The operator's payload: the screens as written, unchanged. const op = await presentPayload(p, { canUncensor: true }); const opScreens = op.slides.find((x) => x.kind === "post").post.screens; assert.deepEqual(opScreens.map((x) => x.lines.map((l) => l.text)), MARKED.screens.map((x) => x.lines.map((l) => l.text.replace("@secretkid", "@Anon_1"))), "every line as written (the anonymity pass as before)"); assert.deepEqual(opScreens.map((x) => x.read), MARKED.screens.map((x) => x.read)); // A read refused: no screen drawn, none in the public data. assert.deepEqual(publicScreens(MARKED, { roles: [] }), []); }); test("b (re-check): the card page's verdict is the item AS WRITTEN's, applied to the item as drawn (playableAsWritten)", async () => { const stale = edited(EDITS["words of line 1 edited"]); // The drawn copy may differ (the anonymity pass, the censor): the verdict is the written one's either way. const drawnLooksFine = { ...stale, screens: ITEM.screens }; const out = playableAsWritten(stale, drawnLooksFine); assert.equal(out.narration, undefined); assert.ok(out.readRefused); const fine = playableAsWritten(ITEM, { ...ITEM, screens: stale.screens }); assert.equal(fine.narration.takes[0].file, THREAD, "written fine: the drawn copy plays"); // The route calls it with the item as written. const src = await readFile(new URL("../../app/api/report/post-item/route.ts", import.meta.url), "utf8"); assert.match(src, /playableAsWritten\(found\.written \?\? found\.item, found\.item\)/); assert.match(src, /const written = .*before the anonymity pass|The item AS WRITTEN \(before the anonymity pass\)/); }); test("e (re-check): every player, preview and payload reads an item's take through playableTake -- no direct picked-take read outside the allow-list", async () => { assert.equal(playableTake(edited(EDITS["line 1 redacted"])), null); assert.equal(playableTake(ITEM).file, THREAD); assert.equal(playableTake({ ...ITEM, readRefused: { reason: "x" } }), null); const root = new URL("../../", import.meta.url); // The files that play, preview or ship an item's read. const files = ["lib/report/present.mjs", "lib/report/playView.mjs", "lib/report/postBenchData.ts", "components/projects/review/PostItemPlayer.tsx", "components/projects/present/PresentView.tsx", "app/api/report/post-item/route.ts"]; for (const dir of ["components/projects/review/playEngine"]) for (const f of await readdir(new URL(dir, root))) if (/\.(ts|tsx|mjs)$/.test(f) && !/\.test\./.test(f)) files.push(`${dir}/${f}`); // Allowed: the card route's word-timing ops, which time the take on record (a write), never play it. const ALLOW = [/const take = pickedTake\(found\.item\) as .*script\?: string; parts\?: unknown\[\]/, /const take = found\.item \? \(pickedTake\(found\.item\) as .*\{ file: string \}\) \| null\) : null;/]; const bad = []; for (const f of files) { const lines = (await readFile(new URL(f, root), "utf8")).split("\n"); lines.forEach((l, i) => { if (/^\s*(\/\/|\*)/.test(l)) return; if ((/\bpickedTake\(/.test(l) || /\bnarration\??\.takes\b/.test(l)) && !ALLOW.some((re) => re.test(l))) bad.push(`${f}:${i + 1}: ${l.trim().slice(0, 120)}`); }); } assert.deepEqual(bad, [], "read an item's take through playableTake (post-thread.mjs)"); });