// lane/screen-reads REVIEW 1 (12 Nov): the reviewer's probes ($J/screen-reads/review/p1-p9) as tests, one a finding. Each // must-fix is a privacy leak or a wrong word in a read; the rule throughout: nothing is drawn or said that the operator // did not choose -- when an excerpt, a take or a line no longer matches, the build REFUSES, never falls back to more. import assert from "node:assert/strict"; import { test } from "node:test"; import { postCardHtml, postItemPlan, validatePostItem } from "./post-item.mjs"; import { threadReadErrors, validateThreadReadWarnings } from "./post-thread.mjs"; import { redactEntry } from "./post-redact.mjs"; import { anonymiseEntry, anonymityProblems } from "./post-anon.mjs"; import { REDACT_MARK } from "./post-redact.mjs"; import { lineOfText, maskShapes, screenDrawErrors, screenLineSaid, screenPieces, screenRows, screenTileHtml, screenWarnings, validateScreens, } from "./post-screens.mjs"; const IMG = { src: "posts-media/savvy-x/2117/2117_2.jpg", kind: "image", width: 900, height: 1400 }; const base = (screens, o = {}) => ({ type: "post", id: "p-1", post: "savvy-x/2117", platform: "x", author: "Savvy", handle: "MadamSavvy", date: "2026-11-02T01:40:36.000Z", text: "Your turn.", media: [IMG], screens, ...o }); /** A thread read of `roles` ([id, n]…), each part saying the line as it is now (as the read would have said it). */ function narr(e, roles) { const parts = [{ n: 1, para: 0, text: "Your turn.", role: "post", start: 0, seconds: 1 }]; let t = 1.8; roles.forEach(([id, n], i) => { const sc = e.screens.find((s) => s.id === id); const text = screenLineSaid(sc, n); parts.push({ n: parts.length + 1, para: (i + 1) * 100, text, role: `screen:${id}:${n}`, start: t, seconds: 2 }); t += 2.8; }); return { ...e, narration: { script: "Your turn.", pick: 0, takes: [{ file: "narration/posts/1/take-1.orpheus-thread.wav", engine: "orpheus", voice: "x", seconds: t, script: "x", parts }] } }; } const shown = (t) => maskShapes(t).text.replace(new RegExp(REDACT_MARK, "g"), "█"); const card = (e, o = {}) => { const plan = postItemPlan(e, { postNarration: { lead: 0.4 } }); return postCardHtml(e, { width: 1600, height: 900, follow: true, thread: plan.follow?.thread ?? null, ...o }); }; // --------------------------------------------------------------------------- // MUST 1: a stale take -- the line changed, removed or moved after the read -- is refused. // --------------------------------------------------------------------------- test("MUST 1 (p4): a line's words changed after the read: the guard refuses (old audio under new lit text)", () => { const S = { id: "s1", media: 0, kind: "text", read: [{ line: 0, text: "Jenny said it was fine" }], lines: [{ text: "Long preamble nobody needs. Jenny said it was fine. And then a private aside about her family." }] }; const e = narr(base([S]), [["s1", 0]]); assert.deepEqual(threadReadErrors(e, {}), []); const e2 = structuredClone(e); e2.screens[0].lines[0].text = "Long preamble. Jenny said it was NOT fine at all. aside"; e2.screens[0].read = [{ line: 0, text: "Jenny said it was NOT fine" }]; assert.deepEqual(validatePostItem(e2), []); assert.ok(threadReadErrors(e2, {}).some((x) => /line 0 of screen s1 changed since the read/.test(x)), threadReadErrors(e2, {}).join("\n")); }); test("MUST 1 (p6): a line removed (the bench's ×, or line.=off) under a read: refused -- the take would SAY the removed line", () => { const S = { id: "s1", media: 0, kind: "dm", read: [{ line: 0 }, { line: 2 }], lines: [{ who: "a", text: "my home address is 12 Elm Street Springfield" }, { who: "b", text: "ok" }, { who: "a", text: "see you there" }, { who: "b", text: "bye now" }] }; const e = narr(base([S]), [["s1", 0], ["s1", 2]]); assert.deepEqual(threadReadErrors(e, {}), []); // The probe's own case: the line filtered out, `read` left as it was -- each role now names another line. const e1 = structuredClone(e); e1.screens[0].lines = e1.screens[0].lines.slice(1); const errs1 = threadReadErrors(e1, {}); assert.ok(errs1.some((x) => /line 0 of screen s1 changed since the read/.test(x)), errs1.join("\n")); assert.ok(errs1.some((x) => /line 2 of screen s1 changed since the read/.test(x)), errs1.join("\n")); // The read remapped as the bench's × and `line.=off` now do: the roles name lines the screen no longer reads. const e2 = structuredClone(e); e2.screens[0].lines = e2.screens[0].lines.slice(1); e2.screens[0].read = [{ line: 1 }]; const errs = threadReadErrors(e2, {}); assert.ok(errs.some((x) => /reads line 0 of screen s1, which the screen does not read/.test(x)), errs.join("\n")); assert.ok(errs.some((x) => /reads line 2 of screen s1, which the screen does not read/.test(x)), errs.join("\n")); // A part that stored the line it was made from is judged by it, exactly. const e3 = structuredClone(e); e3.narration.takes[0].parts[1].line = "my home address is 12 Elm Street"; assert.ok(threadReadErrors(e3, {}).some((x) => /line 0 of screen s1 changed since the read/.test(x))); }); // --------------------------------------------------------------------------- // MUST 2: title, time and who are masked on the card. // --------------------------------------------------------------------------- test("MUST 2 (p3): an e-mail or phone number in a title, a time or a speaker never reaches the card; the lint names them", () => { const S = { id: "s1", media: 0, kind: "email", title: "Email from savvy.r@gmail.com", read: "all", lines: [{ who: "savvy.r@gmail.com", text: "Hello there friend", time: "555-201-4477" }, { who: "+1 555 201 4477", text: "Card 4111 1111 1111 1111 please" }] }; for (const red of [undefined, false]) { const e = narr(base([S], red === undefined ? {} : { redact: red }), [["s1", 0], ["s1", 1]]); assert.deepEqual(validatePostItem(e), []); const html = card(e); for (const needle of ["savvy.r@gmail.com", "555-201-4477", "555 201 4477", "4111"]) assert.ok(!html.includes(needle), `${needle} (redact ${red})`); assert.ok(!screenLineSaid(S, 1).includes("4111")); } const w = screenWarnings(base([S]), { narrated: false }); assert.ok(w.some((x) => /screen s1's title holds/.test(x))); assert.ok(w.some((x) => /screen s1 line 0's time holds/.test(x))); assert.ok(w.some((x) => /screen s1 line 1's speaker holds/.test(x))); assert.ok(!w.some((x) => /savvy\.r|555|4111/.test(x)), "no value quoted"); }); // --------------------------------------------------------------------------- // MUST 3: a pasted line never splits a shape into a speaker. // --------------------------------------------------------------------------- test("MUST 3 (p7): `Order number: 4419`, `Ref: AB-1234`, `Tracking: 1Z999AA1`, `Order #: 48213` stay one line, masked", () => { for (const raw of ["Confirmation code: 552-118", "Order #: 48213", "Order number: 4419", "Tracking: 1Z999AA1", "savvy@gmail.com: hi there", "Phone: 555 201 4477", "Ref: AB-1234"]) { const l = lineOfText(raw); assert.equal(l.who, undefined, `${raw}: no speaker split off`); assert.equal(shown(l.text), shown(raw), `${raw}: masked as the whole line is`); assert.ok(/█/.test(shown(l.text)), `${raw}: something masked`); } assert.deepEqual(lineOfText("TheQuartering: what's your email | 11:32 AM"), { who: "TheQuartering", text: "what's your email", time: "11:32 AM" }); }); // --------------------------------------------------------------------------- // MUST 4 + SHOULD e: the shapes. // --------------------------------------------------------------------------- test("MUST 4 (p1, p2): cards, spaced SSNs and local numbers, dash/dot separators, fullwidth digits, `is` after the keyword, non-ASCII e-mail -- all masked", () => { const masked = [ ["card 4111 1111 1111 1111 exp 12/27", "card ████ ████ ████ ████ exp █████"] /* exp MM/YY masked since review 2 */, ["Order: 1234 5678 9012 3456 7890", "Order: ████ ████ ████ ████ ████"], ["call 555 – 123 – 4567", "call ███ █ ███ █ ████"], ["call 555 · 123 · 4567", "call ███ █ ███ █ ████"], ["call 555-123-4567", "call ████████████"], ["Your order number is 48213", "Your order number is █████"], ["confirmation code is 5521", "confirmation code is ████"], ["ssn 123 45 6789", "ssn ███ ██ ████"], ["call 555 1234", "call ███ ████"], ["jöhn.doe@exämple.com", "████████████████████"], ["tracking 1Z 999 AA1 01 2345 6784", "tracking ██ ███ ███ ██ ████ ████"], ["Your order is 48213", "Your order is █████"], ["code 12345", "code █████"], ["account ending 4821", "account ending ████"], ]; for (const [t, want] of masked) assert.equal(shown(t), want, t); // Still shown: amounts, weights, years, times, DATES (should-fix e). for (const t of ["Total $104.90 USD", "1,000,000 views", "$1,250.00 refund", "lost 12.5 lbs since 2024", "400 pounds", "290", "at 12:18 PM", "on 11/02/2026 at 10:42", "weighed 312.4 on 2026-11-02", "zip 90210"]) assert.equal(shown(t), t, t); }); // --------------------------------------------------------------------------- // MUST 5: the redaction and anonymity passes keep excerpts -- and a broken excerpt is refused, never drawn whole. // --------------------------------------------------------------------------- test("MUST 5 (p4): a redaction term inside an excerpt: the card draws the excerpt (labelled), never the whole line", () => { const S = { id: "s1", media: 0, kind: "text", read: [{ line: 0, text: "Jenny said it was fine" }], lines: [{ text: "Long preamble nobody needs. Jenny said it was fine. And then a private aside about her family." }] }; const e = narr(base([S]), [["s1", 0]]); const red = { terms: ["Jenny"] }; const r = redactEntry(e, red); const rows = screenRows(r.screens[0]); assert.equal(rows.filter((x) => !x.gap).length, 1); assert.ok(!rows[0].text.includes("private aside") && !rows[0].text.includes("preamble"), rows[0].text); const html = card(e, { redaction: red }); assert.ok(!html.includes("private aside")); assert.ok(html.includes("data-screen-excerpt")); assert.ok(!html.includes("Jenny")); assert.deepEqual(screenDrawErrors(r), []); }); test("MUST 5 (p5): after the anonymity pass the excerpt is the excerpt (its @handle rewritten), never the whole line", () => { const set = new Map([["secretkid", "Kid A"]]); const S = { id: "s1", media: 0, kind: "dm", read: [{ line: 0, text: "ask @secretkid about it" }], lines: [{ who: "secretkid", text: "private stuff first. ask @secretkid about it. more private stuff" }] }; const a = anonymiseEntry(base([S]), set); const rows = screenRows(a.screens[0]).filter((x) => !x.gap); assert.equal(rows.length, 1); assert.equal(rows[0].text, "ask @Kid_A about it."); assert.deepEqual(screenDrawErrors(a), []); }); test("MUST 5: an excerpt that no longer matches the line as drawn is NOT drawn whole: the line is left out and the build is told", () => { const S = { id: "s1", media: 0, kind: "text", read: [{ line: 0, text: "said it was fine" }], lines: [{ text: "Preamble. He said it was fine. Private aside." }] }; const broken = structuredClone(S); broken.lines[0].text = "Preamble. He said it was okay. Private aside."; const rows = screenRows(broken); assert.ok(!rows.some((r) => !r.gap && /Private aside/.test(r.text)), JSON.stringify(rows)); assert.equal(screenLineSaid(broken, 0), ""); assert.ok(screenDrawErrors(base([broken])).some((x) => /line 0 of screen s1: its excerpt is not in the line/.test(x))); assert.ok(validateScreens(base([broken])).some((x) => /\.read\[0\]\.text is not a run of line 0's words/.test(x))); }); // --------------------------------------------------------------------------- // SHOULD b, c, d, f. // --------------------------------------------------------------------------- test("SHOULD b (p9): a screenshot of a post names its author from a DRAWN line, never a redacted one", () => { const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]); const sc = { id: "s1", media: 0, kind: "post", read: [{ line: 1 }], lines: [{ who: "secret_person", text: "hidden words", redact: true }, { text: "visible words" }] }; const html = screenTileHtml({ author: "A", handle: "aa", media: [{ kind: "image" }], redact: false }, sc, { k: 1, size: 30, blocks: new Map(), shown: () => true, h: { esc } }); assert.ok(!html.includes("secret_person") && !html.includes("hidden words")); }); test("SHOULD c (p5): the anonymity lint catches a speaker, title or time that writes an anonymous handle in any form", () => { const S = { id: "s1", media: 0, kind: "dm", read: "all", title: "chat with secretkid", lines: [{ who: "SecretKid (alt)", text: "hi" }, { who: "x.com/secretkid", text: "yo", time: "@secretkid" }] }; const m = { timeline: [base([S])] }; const errs = anonymityProblems(m, {}, { set: new Map([["secretkid", "Kid A"]]) }).errors; assert.ok(errs.filter((x) => /screen s1/.test(x)).length >= 3, errs.join("\n")); assert.ok(!errs.some((x) => /secretkid/i.test(x)), "never the real handle"); }); test("SHOULD d: lint and validation name a line, never quote its value", () => { const S = { id: "s1", media: 0, kind: "dm", read: [{ line: 0, text: "my secret words here" }], lines: [{ who: "privateperson", text: "something else entirely" }] }; const v = validateScreens(base([S])); assert.ok(v.some((x) => /read\[0\]\.text is not a run of line 0's words/.test(x))); assert.ok(!v.some((x) => /secret words/.test(x))); const w = screenWarnings(base([{ ...S, read: "all" }]), { narrated: true, takeRoles: ["screen:s1:0"] }); assert.ok(w.some((x) => /line 0's speaker is drawn blurred/.test(x)), w.join("\n")); assert.ok(!w.some((x) => /privateperson/.test(x))); }); test("SHOULD f (p8): at the limits (8 screens × 60 long lines, each an excerpt) the plan and the card stay quick", () => { const W = "the of and to in is you that it he was for on are as with his they I at be this have from or one had by word but not what all were we when your can said there use an each which she do how their if will up".split(" "); const line = Array.from({ length: 110 }, (_, i) => W[(i * 7) % W.length]).join(" ").slice(0, 598); const ex = line.split(" ").slice(40, 80).join(" "); const mk = (id) => ({ id, media: 0, kind: "dm", read: Array.from({ length: 60 }, (_, n) => ({ line: n, text: ex })), lines: Array.from({ length: 60 }, (_, n) => ({ who: n % 2 ? "x" : "y", text: line })) }); const e0 = base(Array.from({ length: 8 }, (_, i) => mk(`s${i + 1}`))); let t = performance.now(); const pcs = screenPieces(e0); assert.equal(pcs.length, 480); const parts = [{ n: 1, para: 0, text: "Your turn.", role: "post", start: 0, seconds: 1 }]; let s = 2; pcs.forEach((p, i) => { parts.push({ n: parts.length + 1, para: (i + 1) * 100, text: p.text, role: p.role, start: s, seconds: 1 }); s += 1.5; }); const e = { ...e0, narration: { script: "Your turn.", pick: 0, takes: [{ file: "narration/posts/1/take-1.orpheus-thread.wav", engine: "orpheus", voice: "x", seconds: s, script: "x", parts }] } }; t = performance.now(); const plan = postItemPlan(e, { postNarration: { lead: 0.4 } }); const planMs = performance.now() - t; t = performance.now(); postCardHtml(e, { width: 1600, height: 900, follow: true, thread: plan.follow?.thread ?? null }); const cardMs = performance.now() - t; assert.ok(planMs < 1500, `plan ${planMs.toFixed(0)} ms`); assert.ok(cardMs < 1500, `card ${cardMs.toFixed(0)} ms`); }); test("MINOR: a narration with attach: after does not play the screens' spans -- the lint says so", () => { const S = { id: "s1", media: 0, kind: "dm", read: "all", lines: [{ who: "a", text: "hello" }] }; const e = narr(base([S]), [["s1", 0]]); e.narration.attach = "after"; assert.ok(validateThreadReadWarnings({ timeline: [e], render: {} }).some((x) => /attach: after/.test(x))); });