// PRESENT MODE's payload (present.mjs): a cut -- or a take -- as slides, in cut order, keyed by a post's own id; // the censor data by kind when the payload can uncensor and none when it cannot; section dividers from the markers, // day dividers for a chronological posts reel. Made-up names, a made-up slur ("zorbo", the project's own), and // temporary projects only. // // Run with: pnpm test:scripts 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"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-present-")); after(() => rm(ROOT, { recursive: true, force: true })); // Never the real corpus: the play view looks for cached windows and markup under the channels dir. process.env.CHANNELS_DIR = path.join(ROOT, "channels"); // The projects are under it: the built-segment lookup (serve.mjs segmentFor) reads only inside the read roots. process.env.REPORTS_DIR = path.join(ROOT, "reports"); process.env.UMTOOL_PRINTS_CACHE = path.join(ROOT, "prints"); const { presentPayload, presentFrom, censorData, publicPostEntry, dayIn, dayLabel, isPostReel, PRESENT_DEFAULTS } = await import("./present.mjs"); const { presentCommand, presentPath } = await import("./presentCli.mjs"); const post = (id, o = {}) => ({ type: "post", id: `p-${id}`, post: `subj-x/${id}`, platform: "x", author: "The Subject", handle: "subject", date: "2026-10-30T10:00:00.000Z", text: `post ${id}`, url: `https://x.com/subject/status/${id}`, subjects: ["subject"], ...o, }); async function project(name, timeline, render = {}, { takes = {} } = {}) { const dir = path.join(ROOT, "reports", name); await mkdir(dir, { recursive: true }); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: name, title: `The ${name} cut`, provenance: { siteOrigin: "https://archive.example", channelSlug: "subj-x", channelsDir: path.join(ROOT, "channels") }, render: { width: 1920, height: 1080, fps: 30, transition: 0, ...render }, timeline, }, null, 2)); for (const [id, patch] of Object.entries(takes)) { await mkdir(path.join(dir, "takes", id), { recursive: true }); await writeFile(path.join(dir, "takes", id, "take.json"), JSON.stringify({ id, group: "takes", order: 1, label: `Take ${id}`, kind: "different", preview: "preview.mp4", window: "full", patch })); } return { id: name, dir }; } // The mixed cut: a clip with a gap, a clip the walk rejected, a thread post answering a private account (its // picture censored, a name redacted, a slur), an excerpted post, a teaser; a marker after c01 opens a section. const MIXED = [ { type: "clip", id: "c01", video: "v1", start: 10, end: 18, lock: true, quote: "the first clip", gaps: [{ from: 12, to: 13 }], onscreen: { title: "24 Oct 2020" } }, { type: "clip", id: "c02", video: "v2", start: 100, end: 103, lock: true, verdict: "rejected", reason: "irrelevant" }, post("1", { text: "@someone_private Yes, Quentin Example was there, the zorbo.", replyingTo: "someone_private", parents: [{ id: "9", author: "Private Person", handle: "someone_private", date: "2026-10-30T09:00:00.000Z", text: "is Quentin Example real?", url: "https://x.com/someone_private/status/9" }], media: [{ src: "posts-media/subj-x/1/1_1.png", kind: "image", width: 320, height: 180, blur: { on: true, band: { below: 0.5 } } }], }), post("2", { text: "One long post, read in part: only this bit is read and the rest is dimmed.", excerpt: ["only this bit is read"], date: "2026-10-31T10:00:00.000Z" }), { type: "teaser", id: "t01", seconds: 4, lines: ["Next Season", { text: "The Big Build" }], tail: "?" }, ]; const MIXED_RENDER = { chrome: { engine: "hyperframes", layout: "deck", deck: { markers: [{ after: "c01", label: "The posts" }] } }, posts: { redact: [{ term: "Quentin Example" }], slurs: { add: ["zorbo"] } }, }; test("slides in cut order: a section opener, the clip's kept spans, the rejected clip left out, posts keyed by the post's id, the teaser", async () => { const p = await project("mixed", MIXED, MIXED_RENDER); const pl = await presentPayload(p); assert.equal(pl.version, 1); assert.equal(pl.take, null, "no take: the manifest"); assert.deepEqual(pl.capabilities, { canUncensor: true }); assert.deepEqual(pl.settings, PRESENT_DEFAULTS); assert.deepEqual( pl.slides.map((s) => [s.kind, s.id]), [["section", "section-0"], ["clip", "c01"], ["section", "section-1"], ["post", "subj-x/1"], ["post", "subj-x/2"], ["teaser", "t01"]], ); assert.deepEqual(pl.sections.map((s) => [s.id, s.label]), [["section-0", "The mixed cut"], ["section-1", "The posts"]]); const clip = pl.slides.find((s) => s.id === "c01"); assert.deepEqual(clip.spans, [{ from: 10, to: 12 }, { from: 13, to: 18 }], "the cut minus its gap"); assert.equal(clip.seconds, 7); assert.equal(clip.entry, "c01"); assert.equal(clip.section, "section-0"); assert.equal(clip.media, null, "no cached window: nothing to play"); const p1 = pl.slides.find((s) => s.id === "subj-x/1"); assert.equal(p1.entry, "p-1", "the entry it was cut from rides along"); assert.equal(p1.post.id, "p-1"); assert.equal(p1.section, "section-1"); assert.equal(p1.date, "2026-10-30"); assert.equal(p1.dateLabel, "Oct 30"); assert.ok(p1.plan && p1.plan.total > 0, "Play's plan for the item"); assert.equal(p1.narration, null); const p2 = pl.slides.find((s) => s.id === "subj-x/2"); assert.deepEqual(p2.excerpt, [{ start: 29, end: 50 }], "the excerpt's span in the card's words"); assert.equal(p2.post.text.slice(29, 50), "only this bit is read"); assert.equal(p2.censor, null, "nothing censored on it"); const t = pl.slides.find((s) => s.id === "t01"); assert.deepEqual(t.lines, ["Next Season", "The Big Build"]); assert.equal(t.tail, "?"); }); test("the censor data by kind: the redacted name and the slur in each string drawn, the private author, the censored picture", async () => { const p = await project("mixed-censor", MIXED, MIXED_RENDER); const pl = await presentPayload(p); const s = pl.slides.find((x) => x.id === "subj-x/1"); assert.deepEqual(s.censor.counts, { names: 2, slurs: 1, authors: 1, pictures: 1 }); const text = s.post.text; const red = s.censor.marks.filter((m) => m.kind === "redact"); assert.deepEqual(red.map((m) => m.field), ["text", "parents.0.text"]); assert.equal(text.slice(red[0].start, red[0].end), "Quentin Example"); const slur = s.censor.marks.find((m) => m.kind === "slur"); assert.equal(slur.field, "text"); assert.equal(text.slice(slur.start, slur.end), "zorbo"); assert.equal(slur.mask, "*****"); assert.deepEqual(s.censor.authors.map((a) => [a.where, a.handle, a.reason]), [["parents[0]", "someone_private", "private"]]); assert.deepEqual(s.censor.media, [{ kind: "blur", i: 0, style: "blur", boxes: [[0, 0.5, 1, 0.5]], band: [0, 0.5, 1, 0.5], strength: 7, label: "Censored" }]); // The words as written: the viewer toggles the card, never these. assert.match(text, /Quentin Example/); }); test("canUncensor false: the posts censored, the private authors nameless, no reveal data anywhere", async () => { const p = await project("mixed-public", MIXED, MIXED_RENDER); const pl = await presentPayload(p, { canUncensor: false }); assert.deepEqual(pl.capabilities, { canUncensor: false }); const s = pl.slides.find((x) => x.id === "subj-x/1"); assert.equal(s.censor, null); const json = JSON.stringify(pl); const where = (leak) => { const paths = []; const walk = (v, p) => { if (typeof v === "string") { if (v.includes(leak)) paths.push(p); } else if (v && typeof v === "object") for (const [k, x] of Object.entries(v)) walk(x, `${p}.${k}`); }; walk(pl, ""); return paths.join(", "); }; for (const leak of ["Quentin", "zorbo", "someone_private", "Private Person"]) assert.ok(!json.includes(leak), `${leak} is in the public payload at ${where(leak)}`); assert.equal(s.post.parents[0].handle, "xxxxxxxx", "a handle that names nobody: the card still blurs it"); assert.equal(s.post.parents[0].author, null); assert.match(s.post.text, /^@xxxxxxxx Yes/, "his mention of her drawn blurred"); assert.equal(s.post.replyingTo, "xxxxxxxx"); assert.ok(s.post.text.includes(""), "the redaction's marks are in the words"); // The censored picture stays censored (its blur is how it is drawn). assert.equal(s.post.media[0].blur.on, true); }); test("a take's patch is applied as Play applies it; bare plays the manifest alone; an unknown take is an error", async () => { const p = await project("taken", MIXED, MIXED_RENDER, { takes: { t1: { title: "The take's title", render: { posts: { redact: [{ term: "Quentin Example" }, { term: "Yes" }] } } } }, }); // A take is the latest working take only once rendered: named, it plays its patch. const pl = await presentPayload(p, { take: "t1" }); assert.equal(pl.take?.id, "t1"); assert.equal(pl.title, "The take's title"); assert.equal(pl.slides.find((x) => x.id === "subj-x/1").censor.counts.names, 3, "the take's own term counted"); const bare = await presentPayload(p, { bare: true }); assert.equal(bare.take, null); assert.equal(bare.slides.find((x) => x.id === "subj-x/1").censor.counts.names, 2); assert.match(String((await presentPayload(p, { take: "nope" })).error), /nope/); }); test("a chronological posts reel with no markers: a day divider per calendar day, in the posts' clock zone", async () => { const p = await project("reel", [ post("1", { date: "2026-11-03T03:30:00.000Z" }), // Nov 2 in New York post("2", { date: "2026-11-03T15:00:00.000Z" }), post("3", { date: "2026-11-03T20:00:00.000Z" }), post("4", { date: "2026-11-05T12:00:00.000Z" }), ], { posts: { clock: { zone: "America/New_York" } } }); const pl = await presentPayload(p); assert.equal(pl.zone, "America/New_York"); assert.deepEqual( pl.slides.map((s) => s.id), ["day-2026-11-02", "subj-x/1", "day-2026-11-03", "subj-x/2", "subj-x/3", "day-2026-11-05", "subj-x/4"], ); assert.deepEqual(pl.sections.map((s) => [s.kind, s.label, s.date]), [["day", "Nov 2", "2026-11-02"], ["day", "Nov 3", "2026-11-03"], ["day", "Nov 5", "2026-11-05"]]); assert.equal(pl.slides[1].dateLabel, "Nov 2"); }); test("no markers and not a chronological reel: one section, no divider; the same post twice gets two ids", async () => { const p = await project("plain", [ { type: "clip", id: "c01", video: "v1", start: 1, end: 3, lock: true }, post("1", { id: "p-a" }), post("1", { id: "p-b" }), ]); const pl = await presentPayload(p); assert.deepEqual(pl.slides.map((s) => s.id), ["c01", "subj-x/1", "subj-x/1~2"]); assert.deepEqual(pl.sections, [{ id: "cut", kind: "cut", label: "The plain cut" }]); }); test("the pure helpers: days in a zone, their labels, what a posts reel is, the censor data of a clean post", () => { assert.equal(dayIn("2026-11-03T03:30:00.000Z", "America/New_York"), "2026-11-02"); assert.equal(dayIn("2026-11-03T03:30:00.000Z", "UTC"), "2026-11-03"); assert.equal(dayIn("not a date", "UTC"), null); assert.equal(dayLabel("2026-11-03"), "Nov 3"); assert.equal(dayLabel("2026-13-03"), null); assert.equal(isPostReel([{ type: "post", post: { date: "2026-01-01" } }, { type: "post", post: { date: "2026-01-02" } }]), true); assert.equal(isPostReel([{ type: "post", post: { date: "2026-01-02" } }, { type: "post", post: { date: "2026-01-01" } }]), false, "out of order"); assert.equal(isPostReel([{ type: "post", post: { date: "2026-01-01" } }, { type: "clip" }]), false, "a clip among them"); assert.equal(censorData(post("1"), null), null); assert.equal(publicPostEntry(post("1"), null).text, "post 1"); assert.equal(typeof presentFrom, "function"); }); test("umtool present: the address, the slides, --json the payload, --public censored", async () => { await project("cli", MIXED, MIXED_RENDER); const lines = []; const errs = []; const run = (args) => presentCommand(args, { root: path.join(ROOT, "reports"), out: (s) => lines.push(s), err: (s) => errs.push(s), env: { UMTOOL_URL: "http://umtool.test:9/" }, open: (u) => lines.push(`OPEN ${u}`) }); assert.equal(await run(["cli", "--open"]), 0, errs.join("\n")); assert.equal(lines[0], "http://umtool.test:9/projects/cli/present"); assert.match(lines[1], /cli · the draft · 6 slide\(s\), 2 post\(s\) · 2 section\(s\)/); assert.ok(lines.some((l) => /post +subj-x\/1 +Oct 30 .*\[2 names, 1 slurs, 1 authors, 1 pictures\]/.test(l)), lines.join("\n")); assert.equal(lines.at(-1), "OPEN http://umtool.test:9/projects/cli/present"); lines.length = 0; assert.equal(await run(["cli", "--json", "--public"]), 0); const doc = JSON.parse(lines.join("\n")); assert.equal(doc.url, "http://umtool.test:9/projects/cli/present"); assert.equal(doc.capabilities.canUncensor, false); assert.equal(await run(["cli", "--take", "a", "--cut"]), 1); assert.equal(await run([]), 2); assert.equal(presentPath("a/b c", { take: "t1", slide: "subj-x/1" }), "/projects/a/b%20c/present?take=t1#subj-x/1"); assert.equal(presentPath("a", { bare: true }), "/projects/a/present?cut=1"); }); test("the intro (render.intro) is the first slide, before any divider, in the first section's band; its words ride along", async () => { const p = await project("intro-mixed", MIXED, { ...MIXED_RENDER, intro: { style: "title-card", lines: ["29 October 2026"] } }); const pl = await presentPayload(p); assert.deepEqual( pl.slides.map((s) => [s.kind, s.id]).slice(0, 3), [["intro", "brand-intro"], ["section", "section-0"], ["clip", "c01"]], ); const intro = pl.slides[0]; assert.equal(intro.section, "section-0"); assert.equal(intro.style, "title-card"); assert.equal(intro.title, "The intro-mixed cut", "title-card: the project's title"); assert.deepEqual(intro.lines, ["29 October 2026"]); assert.equal(intro.seconds, 4.18); assert.equal(intro.label, "Intro"); // A chronological posts reel that opens on an intro is still a posts reel: the intro, then its days. const reel = await project("intro-reel", [post("1"), post("2", { date: "2026-10-31T10:00:00.000Z" })], { intro: "boot-dark" }); const r = await presentPayload(reel); assert.deepEqual(r.slides.map((s) => s.kind), ["intro", "day", "post", "day", "post"]); assert.equal(r.slides[0].section, "day-2026-10-30"); // No render.intro, no intro slide. const none = await presentPayload(await project("intro-none", MIXED, MIXED_RENDER)); assert.ok(!none.slides.some((s) => s.kind === "intro")); }); test("hidden regions (clip-censor.mjs): a clip slide carries its own boxes and its recording's, on a public payload too; Play's entry carries them", async () => { const own = { style: "black", boxes: [{ box: [0.1, 0.1, 0.2, 0.2], from: 1.5, to: 2.5 }] }; const p = await project("hidden", [ { type: "clip", id: "c01", video: "v1", start: 1, end: 3, lock: true, censor: own }, { type: "clip", id: "c02", video: "v2", start: 1, end: 3, lock: true }, ], { censor: [{ video: "v1", style: "blur", boxes: [[0.6, 0.6, 0.3, 0.3]] }] }); for (const canUncensor of [true, false]) { const pl = await presentPayload(p, { canUncensor }); const c1 = pl.slides.find((s) => s.id === "c01"); const c2 = pl.slides.find((s) => s.id === "c02"); assert.equal(c1.hidden.length, 2, `the clip's box and its recording's (canUncensor ${canUncensor})`); assert.deepEqual(c1.hidden.map((g) => g.style).sort(), ["black", "blur"]); const black = c1.hidden.find((g) => g.style === "black"); assert.deepEqual([black.from, black.to], [1.5, 2.5], "its span, source seconds"); assert.deepEqual(c2.hidden, [], "another recording: none"); } const { playView } = await import("./playView.mjs"); const view = await playView(p); assert.equal(view.entries.find((e) => e.id === "c01").censor.length, 2, "Play draws the same boxes"); }); test("a PUBLIC payload never names the raw window of a clip that hides regions: its built segment when it hides exactly them, else none; the operator's keeps the window", async () => { const own = { style: "black", boxes: [[0.1, 0.1, 0.2, 0.2]] }; const timeline = [ { type: "clip", id: "c01", video: "v1", start: 1, end: 3, lock: true, censor: own }, { type: "clip", id: "c02", video: "v2", start: 1, end: 3, lock: true }, ]; const p = await project("withheld", timeline); await mkdir(path.join(p.dir, "out", "clips-raw"), { recursive: true }); await writeFile(path.join(p.dir, "out", "clips-raw", "v1_0.00-6.00.mp4"), "raw window one"); await writeFile(path.join(p.dir, "out", "clips-raw", "v2_0.00-6.00.mp4"), "raw window two"); const op = await presentPayload(p); assert.equal(op.slides.find((s) => s.id === "c01").media?.name, "v1_0.00-6.00.mp4", "the operator's page plays the window, overlaid"); const pub = await presentPayload(p, { canUncensor: false }); const json = JSON.stringify(pub); assert.ok(!json.includes("v1_0.00-6.00"), "no path to the raw window anywhere in the public payload"); const c1 = pub.slides.find((s) => s.id === "c01"); assert.equal(c1.media, null); assert.equal(c1.censored, null, "no build here: the slide says it is not shown"); // The same clip without regions: unchanged. assert.deepEqual(pub.slides.find((s) => s.id === "c02"), (await presentPayload(p, { canUncensor: false })).slides.find((s) => s.id === "c02")); assert.equal(pub.slides.find((s) => s.id === "c02").media?.name, "v2_0.00-6.00.mp4"); assert.equal("censored" in pub.slides.find((s) => s.id === "c02"), false); // A built segment that hides exactly its regions: played instead; one cut with other boxes is not. const segs = path.join(p.dir, "out", "segments"); await mkdir(segs, { recursive: true }); await writeFile(path.join(segs, "c01.mp4"), "built"); await writeFile(path.join(segs, "c01.cut.json"), JSON.stringify({ version: 1, id: "c01", start: 1, end: 3, censor: [] })); assert.equal((await presentPayload(p, { canUncensor: false })).slides.find((s) => s.id === "c01").censored, null, "a segment cut without the boxes"); await writeFile(path.join(segs, "c01.cut.json"), JSON.stringify({ version: 1, id: "c01", start: 1, end: 3, censor: [{ box: [0.1, 0.1, 0.2, 0.2], style: "black" }] })); const built = (await presentPayload(p, { canUncensor: false })).slides.find((s) => s.id === "c01"); assert.equal(typeof built.censored.segment, "number"); assert.equal(built.censored.seconds, 2); assert.equal(built.media, null); }); test("a public Present of a TAKE plays the take's own built segment, by the same exact-boxes rule -- never the draft's under its name", async () => { const own = { style: "black", boxes: [[0.1, 0.1, 0.2, 0.2]] }; const p = await project("take-seg", [{ type: "clip", id: "c01", video: "v1", start: 1, end: 3, lock: true, censor: own }], {}, { takes: { t1: { title: "The take" } } }); await mkdir(path.join(p.dir, "out", "clips-raw"), { recursive: true }); await writeFile(path.join(p.dir, "out", "clips-raw", "v1_0.00-6.00.mp4"), "raw window"); const rec = (censor) => JSON.stringify({ version: 1, id: "c01", start: 1, end: 3, censor }); const HID = [{ box: [0.1, 0.1, 0.2, 0.2], style: "black" }]; // The draft's segment hides the boxes; the take's is a different file. const draft = path.join(p.dir, "out", "sourced", "segments"); const takeSegs = path.join(p.dir, "takes", "t1", "out", "sourced", "segments"); await mkdir(draft, { recursive: true }); await mkdir(takeSegs, { recursive: true }); await writeFile(path.join(draft, "c01.mp4"), "the draft's"); await writeFile(path.join(draft, "c01.cut.json"), rec(HID)); const { utimes } = await import("node:fs/promises"); await utimes(path.join(draft, "c01.mp4"), new Date(1_000_000_000_000), new Date(1_000_000_000_000)); // The take's segment cut WITHOUT the boxes: not used, and the draft's is not used in its place. await writeFile(path.join(takeSegs, "c01.mp4"), "the take's"); await writeFile(path.join(takeSegs, "c01.cut.json"), rec([])); const slide = async () => (await presentPayload(p, { take: "t1", canUncensor: false })).slides.find((s) => s.entry === "c01"); assert.equal((await slide()).censored, null); // The take's hiding them: it is the one named. await writeFile(path.join(takeSegs, "c01.cut.json"), rec(HID)); await utimes(path.join(takeSegs, "c01.mp4"), new Date(1_500_000_000_000), new Date(1_500_000_000_000)); const c = (await slide()).censored; assert.equal(c.take, "t1"); assert.equal(c.segment, 1_500_000_000_000); // The draft presented: the draft's, with no take. const d = (await presentPayload(p, { canUncensor: false })).slides.find((s) => s.entry === "c01").censored; assert.deepEqual([d.segment, d.take], [1_000_000_000_000, undefined]); // The lookup takes a take id, never a path; the route's rule is the same exact-boxes rule. const { segmentFor, segmentHidesAsAsked } = await import("./serve.mjs"); assert.equal(await segmentFor(p, "c01", { take: "../t1" }), null); assert.equal(await segmentFor(p, "c01", { take: "t1/../.." }), null); const seg = await segmentFor(p, "c01", { take: "t1" }); assert.equal(seg.rel, "takes/t1/out/sourced/segments/c01.mp4"); const clip = { type: "clip", id: "c01", video: "v1", start: 1, end: 3, censor: own }; assert.equal(await segmentHidesAsAsked(seg.abs, clip, { render: {} }), true); assert.equal(await segmentHidesAsAsked(seg.abs, { ...clip, censor: { boxes: [[0, 0, 0.5, 0.5]] } }, { render: {} }), false, "a box changed since: stale, refused"); await writeFile(path.join(takeSegs, "c01.cut.json"), rec([])); assert.equal(await segmentHidesAsAsked(seg.abs, clip, { render: {} }), false, "a segment cut without them"); });