commit 38f9154bd84f1dd5e50218d1f683670d13dc5261
parent 1f70f16412ba4f95ee619bde15fac0b0cd8e1316
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 8 Nov 2026 04:01:06 -0500
umtool: present payload tests, and a public payload that names nobody
present.test.mjs: slide order and ids (a post's own id, a twin's ~2), the
clip's kept spans, the rejected clip left out, the excerpt's span, the censor
data by kind, the take's patch, day dividers in the clock's zone, the CLI.
A public payload (canUncensor false) gives a blurred author a handle that
names nobody -- the card still blurs it, and his mentions of them too -- and
its outline words are drawn from the censored post.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 258 insertions(+), 16 deletions(-)
diff --git a/umtool/lib/report/present.mjs b/umtool/lib/report/present.mjs
@@ -64,6 +64,8 @@ const isObj = (v) => !!v && typeof v === "object" && !Array.isArray(v);
const str = (v) => (typeof v === "string" ? v : "");
const fin = (v) => typeof v === "number" && Number.isFinite(v);
const text = (v) => str(v).replace(/\s+/g, " ").trim();
+/** The handle a blurred author is given in a public payload: it names nobody, and the card blurs it. */
+const NOBODY = "xxxxxxxx";
const MON = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
/** `YYYY-MM-DD` of a moment in `zone` (an IANA name), or null. */
@@ -186,29 +188,44 @@ export function censorData(entry, red) {
*/
export function publicPostEntry(entry, red) {
const out = /** @type {Record<string, any>} */ (structuredClone(redactEntry(entry, red)));
+ // A blurred author keeps a handle that names nobody: the card's rule still blurs it, and a mention of it in any
+ // words is drawn blurred too (wordsHtml) -- the real handle is nowhere in the data.
+ const blurred = new Set();
+ const blank = (r) => {
+ if (!isObj(r)) return;
+ if (r.handle) blurred.add(String(r.handle).replace(/^@/, "").toLowerCase());
+ r.author = null;
+ r.handle = NOBODY;
+ delete r.url;
+ delete r.avatar;
+ };
for (const a of cardAuthors(entry)) {
if (!a.redact) continue;
- const blank = (r) => {
- if (!isObj(r)) return;
- r.author = null;
- r.handle = null;
- delete r.url;
- delete r.avatar;
- };
- if (a.where === "author") {
- out.author = null;
- out.handle = null;
- delete out.url;
- } else if (a.where === "replyingTo") out.replyingTo = "xxxxxxxx";
- else if (a.where === "quoted") blank(out.quoted);
+ if (a.where === "author") blank(out);
+ else if (a.where === "replyingTo") {
+ if (out.replyingTo) blurred.add(String(out.replyingTo).replace(/^@/, "").toLowerCase());
+ out.replyingTo = NOBODY;
+ } else if (a.where === "quoted") blank(out.quoted);
else {
const m = /^(parents|links)\[(\d+)\]$/.exec(a.where);
if (m) blank(out[m[1]]?.[Number(m[2])]);
}
}
+ if (blurred.size) {
+ const unmention = (v) => (typeof v === "string" ? v.replace(/@([A-Za-z0-9_]{1,30})/g, (m, h) => (blurred.has(h.toLowerCase()) ? `@${NOBODY}` : m)) : v);
+ const words = (r) => {
+ if (!isObj(r)) return;
+ for (const k of ["text", "paraphrase", "transcript"]) if (k in r) r[k] = unmention(r[k]);
+ };
+ words(out);
+ (Array.isArray(out.parents) ? out.parents : []).forEach(words);
+ words(out.quoted);
+ (Array.isArray(out.links) ? out.links : []).forEach(words);
+ if (typeof out.replyingTo === "string" && blurred.has(out.replyingTo.replace(/^@/, "").toLowerCase())) out.replyingTo = NOBODY;
+ if (Array.isArray(out.subjects)) out.subjects = out.subjects.filter((h) => !blurred.has(String(h).replace(/^@/, "").toLowerCase()));
+ }
const take = pickedTake(entry);
if (isObj(out.narration)) out.narration = take ? { takes: [{ file: take.file, seconds: take.seconds, ...(fin(take.rate) ? { rate: take.rate } : {}) }], pick: 0 } : { off: true };
- delete out.redact;
delete out.notes;
return out;
}
@@ -217,6 +234,13 @@ export function publicPostEntry(entry, red) {
// THE SLIDES.
// ---------------------------------------------------------------------------
+/** A public post's outline words: its author (or "a private account") and its words, each mark a block. */
+function publicHeading(entry) {
+ const words = cardText(entry).replace(/^RT @[A-Za-z0-9_]+:\s*/, "").replace(/[\uE000-\uF8FF]+/g, "▇▇").replace(/\s+/g, " ").trim();
+ const who = str(entry.author) || (entry.handle ? `@${entry.handle}` : "a private account");
+ return `${who}: ${words.length > 80 ? `${words.slice(0, 77)}…` : words || "(no words)"}`;
+}
+
/** A chronological reel of posts: every played entry a post item, their dates in order. */
export function isPostReel(entries) {
const posts = entries.filter((e) => e.type === "post");
@@ -307,15 +331,16 @@ export function presentFrom({ view, manifest, red, canUncensor = true }) {
const take = pickedTake(post);
const spans = excerptSpansOf(post);
const excerpt = spans ? excerptRanges(cardText(post), spans) : null;
+ const shown = canUncensor ? post : publicPostEntry(post, red);
slides.push({
id: unique(postSlideId(e)),
kind: "post",
section: sec,
entry: e.id,
- label: e.heading,
+ label: canUncensor ? e.heading : publicHeading(shown),
date: day,
dateLabel: dayLabel(day),
- post: canUncensor ? post : publicPostEntry(post, red),
+ post: shown,
plan: e.postPlan,
progress: e.postProgress ?? null,
clock: e.postClock ?? null,
diff --git a/umtool/lib/report/present.test.mjs b/umtool/lib/report/present.test.mjs
@@ -0,0 +1,217 @@
+// 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");
+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 manifest · 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");
+});