// A post item's word zooms through the writer and the CLI (postFxCli.mjs, // manifest.mjs updatePostFx), and a take's word timings (`posts narrate --words`: // the editor's transcription, stood in for here, aligned to the script). import assert from "node:assert/strict"; import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { after, test } from "node:test"; import { postsCommand } from "./postsCli.mjs"; import { takeWords, takeWordSources } from "./postFxCli.mjs"; import { updatePostFx } from "./manifest.mjs"; import { wordZoomTimes } from "umtool-report-to-video/word-zoom"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-post-fx-")); after(() => rm(ROOT, { recursive: true, force: true })); const REPORTS = path.join(ROOT, "reports"); const TEXT = "stop me and save me from myself, barbecue if no one does, I'm going after him."; const item = (id, o = {}) => ({ type: "post", id: `p-${id}`, post: `subj-x/${id}`, platform: "x", author: "THE SUBJECT", handle: "Subject", date: "2026-11-03T10:00:00.000Z", text: TEXT, ...o, }); async function project(name, timeline) { const dir = path.join(REPORTS, name); await mkdir(dir, { recursive: true }); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: name, title: name, render: { width: 1920, height: 1080, fps: 30 }, timeline }, null, 2)); return { id: name, dir }; } const manifest = async (p) => JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); const cli = async (args) => { const lines = []; const errs = []; const code = await postsCommand(args, { root: REPORTS, out: (s) => lines.push(s), err: (s) => errs.push(s) }); return { code, out: lines.join("\n"), err: errs.join("\n") }; }; test("posts fx: add (an un-narrated post gets the reading estimate), set, ls, remove -- refused in the build's words", async () => { const p = await project("fx", [item("1")]); let r = await cli(["fx", "fx", "p-1", "add", "word-zoom", "--match", "barbecue", "--scale", "2.5", "--hold", "1.5", "--ease", "snap", "--highlight", "off"]); assert.equal(r.code, 0, r.err); assert.match(r.out, /not narrated: at 3.33 s, the reading estimate/); assert.match(r.out, /#1 word-zoom "barbecue" \(post, 1st\) at 3.33 s \(set by hand\) · 2.5× in 0.5 s, held 1.5 s, snap, highlight off/); let fx = (await manifest(p)).timeline[0].fx; assert.deepEqual(fx, [{ kind: "word-zoom", match: "barbecue", scale: 2.5, hold: 1.5, ease: "snap", highlight: false, at: 3.33 }]); r = await cli(["fx", "fx", "p-1", "set", "1", "--at", "2.9", "--highlight", "default"]); assert.equal(r.code, 0, r.err); fx = (await manifest(p)).timeline[0].fx; assert.equal(fx[0].at, 2.9); assert.equal(fx[0].highlight, undefined); // Not in the words: refused, nothing written. r = await cli(["fx", "fx", "p-1", "add", "word-zoom", "--match", "because", "--at", "1"]); assert.equal(r.code, 1); assert.match(r.err, /fx\[1\]\.match "because" is not in the post's words/); assert.equal((await manifest(p)).timeline[0].fx.length, 1); r = await cli(["fx", "fx", "p-1", "ls", "--json"]); assert.equal(JSON.parse(r.out).times[0].t, 2.9); r = await cli(["fx", "fx", "p-1", "remove", "1"]); assert.equal(r.code, 0, r.err); assert.equal((await manifest(p)).timeline[0].fx, undefined); assert.match(r.out, /no effects/); await assert.rejects(updatePostFx(p.dir, "p-1", { remove: 0 }), /has no effects/); }); test("posts narrate --words: the take transcribed by the editor (its parts, at their starts), aligned to the script, kept on the take", async () => { const take = { file: "narration/posts/1/take-1.orpheus-zac.wav", engine: "orpheus", voice: "zac", seconds: 6, script: TEXT }; const p = await project("words", [item("1", { narration: { script: TEXT, takes: [take], lead: 0.5, rate: 1.25 }, fx: [{ kind: "word-zoom", match: "barbecue" }] })]); // Before: no time. assert.match(wordZoomTimes((await manifest(p)).timeline[0])[0].error, /no word timings yet/); const asked = []; // The editor stood in for: it "hears" the script with the typo read as the word it means. const ask = async (route, body) => { asked.push({ route, body }); const heard = TEXT.replace("barbecue", "barbeque").split(" ").map((w, i) => ({ w, start: i * 0.4, end: i * 0.4 + 0.3, conf: 0.9 })); await mkdir(path.dirname(body.out), { recursive: true }); await writeFile(body.out, JSON.stringify({ path: body.path, cues: [], text: "", words: heard })); return { jobId: "job-1", result: null }; }; const project1 = { id: "words", dir: p.dir }; const r = await takeWords(project1, (await manifest(p)).timeline[0], { ask, worker: "parakeet-cpu" }); assert.deepEqual(asked.map((a) => [a.route, a.body.words, a.body.workerId, path.relative(p.dir, a.body.out)]), [["/api/ops/transcribe", true, "parakeet-cpu", "narration/posts/1/take-1.orpheus-zac.words.json"]]); assert.equal(r.heard, r.of); const e = (await manifest(p)).timeline[0]; assert.deepEqual(e.narration.takes[0].words[7], { w: "barbecue", start: 2.8, end: 3.1 }); // Its time: lead 0.5 + 2.8 ÷ 1.25. assert.equal(wordZoomTimes(e)[0].t, 2.74); // A take read part by part: each part transcribed on its own file, at its start. const parted = { ...take, parts: [{ n: 1, file: "narration/posts/1/take-1.parts/p01.wav", start: 0, seconds: 2 }, { n: 2, file: "narration/posts/1/take-1.parts/p02.wav", start: 2.6, seconds: 3 }] }; assert.deepEqual(await takeWordSources(p.dir, parted), [{ file: take.file, offset: 0 }]); // the parts' files are not there: the take's await mkdir(path.join(p.dir, "narration/posts/1/take-1.parts"), { recursive: true }); for (const f of ["p01", "p02"]) await writeFile(path.join(p.dir, `narration/posts/1/take-1.parts/${f}.wav`), ""); assert.deepEqual(await takeWordSources(p.dir, parted), [{ file: parted.parts[0].file, offset: 0 }, { file: parted.parts[1].file, offset: 2.6 }]); }); test("posts fx add caption: the chip's text kept (CJK too), timed by the reading estimate, its knobs set -- a zoom's knobs refused", async () => { const p = await project("cap", [item("1", { text: "I have achieved Fudōshin. Its amazing." })]); let r = await cli(["fx", "cap", "p-1", "add", "caption", "--match", "Fudōshin", "--text", "不動心 · fudōshin — \"immovable mind\""]); assert.equal(r.code, 0, r.err); assert.match(r.out, /0 word zoom\(s\), 1 caption\(s\)/); assert.match(r.out, /#1 caption "Fudōshin" \(post, 1st\) at 2.00 s \(the reading estimate\) · "不動心 · fudōshin — "immovable mind"" · in 0.15 s before, held 2.5 s, below/); assert.deepEqual((await manifest(p)).timeline[0].fx, [{ kind: "caption", match: "Fudōshin", text: "不動心 · fudōshin — \"immovable mind\"" }]); r = await cli(["fx", "cap", "p-1", "set", "1", "--place", "above", "--hold", "3", "--at", "1.5"]); assert.equal(r.code, 0, r.err); assert.deepEqual((await manifest(p)).timeline[0].fx[0], { kind: "caption", match: "Fudōshin", text: "不動心 · fudōshin — \"immovable mind\"", place: "above", hold: 3, at: 1.5 }); r = await cli(["fx", "cap", "p-1", "set", "1", "--place", "left"]); assert.equal(r.code, 1); assert.match(r.err, /fx\[0\]\.place must be one of below, above, side/); r = await cli(["fx", "cap", "p-1", "add", "caption", "--match", "Fudōshin"]); assert.match(r.err, /add caption needs --text/); r = await cli(["fx", "cap", "p-1", "add", "caption", "--match", "Fudōshin", "--text", "x", "--scale", "2"]); assert.match(r.err, /--scale is a word zoom's knob/); r = await cli(["fx", "cap", "p-1", "add", "word-zoom", "--match", "amazing", "--text", "x"]); assert.match(r.err, /--text and --place are a caption's knobs/); r = await cli(["fx", "cap", "p-1", "ls", "--json"]); assert.deepEqual(JSON.parse(r.out).times, [{ i: 0, t: 1.5, source: "at" }]); }); test("posts fx add slam: its glyphs and word kept, its hits listed (the estimate's start, 0.45 s apart), its knobs set -- a zoom's refused on it, its own on a zoom", async () => { const p = await project("slam", [item("1")]); let r = await cli(["fx", "slam", "p-1", "add", "slam", "--text", "不動心", "--match", "barbecue"]); assert.equal(r.code, 0, r.err); // "barbecue" is word 7: 1 + 7/3. assert.match(r.out, /#1 slam "不動心" on "barbecue" \(post, 1st\) hits at 3\.33, 3\.78, 4\.23 s \(the reading estimate\), gone by 6\.18 s · per glyph, 3\.5× in, held 1\.6 s, over-match, #f5c542\/#000000, face jp, sfx trailer-hit/); r = await cli(["fx", "slam", "p-1", "set", "1", "--gap", "0.3", "--face", "sc", "--from-scale", "4", "--whole", "--swell", "--volume", "0.8"]); assert.equal(r.code, 0, r.err); assert.deepEqual((await manifest(p)).timeline[0].fx, [{ kind: "slam", text: "不動心", match: "barbecue", gap: 0.3, face: "sc", fromScale: 4, whole: true, swell: true, volume: 0.8 }]); r = await cli(["fx", "slam", "p-1", "set", "1", "--per-glyph", "--no-swell", "--gap", "default"]); assert.equal(r.code, 0, r.err); assert.deepEqual((await manifest(p)).timeline[0].fx[0], { kind: "slam", text: "不動心", match: "barbecue", face: "sc", fromScale: 4, volume: 0.8 }); r = await cli(["fx", "slam", "p-1", "ls", "--json"]); assert.deepEqual(JSON.parse(r.out).times[0].landings, [3.33, 3.78, 4.23]); r = await cli(["fx", "slam", "p-1", "add", "slam", "--text", "心", "--match", "barbecue", "--scale", "2"]); assert.equal(r.code, 2); assert.match(r.err, /--scale is not a slam's knob/); r = await cli(["fx", "slam", "p-1", "add", "word-zoom", "--match", "myself", "--at", "1", "--from-scale", "2"]); assert.equal(r.code, 2); assert.match(r.err, /--from-scale is a slam's knob/); r = await cli(["fx", "slam", "p-1", "add", "slam", "--text", "心", "--match", "nowhere"]); assert.equal(r.code, 1); assert.match(r.err, /match "nowhere" is not in the post's words/); r = await cli(["fx", "slam", "p-1", "add", "slam", "--text", "心"]); assert.equal(r.code, 2); assert.match(r.err, /add slam needs --match/); }); test("posts fx slam --bar: the translation bar set (its style too), shown by ls, cleared with --bar off", async () => { const p = await project("slambar", [item("1")]); let r = await cli(["fx", "slambar", "p-1", "add", "slam", "--text", "不動心", "--match", "barbecue", "--gap", "0.22", "--volume", "0.5", "--bar", "fudōshin — \"immovable mind\""]); assert.equal(r.code, 0, r.err); assert.match(r.out, /0\.22 s apart from the reading estimate/); assert.match(r.out, /· on a dark bar "fudōshin — "immovable mind""/); r = await cli(["fx", "slambar", "p-1", "set", "1", "--bar-style", "gold"]); assert.equal(r.code, 0, r.err); assert.deepEqual((await manifest(p)).timeline[0].fx[0], { kind: "slam", text: "不動心", match: "barbecue", gap: 0.22, volume: 0.5, bar: "fudōshin — \"immovable mind\"", barStyle: "gold" }); // A style with no bar is refused in the build's words. r = await cli(["fx", "slambar", "p-1", "set", "1", "--bar", "off"]); assert.equal(r.code, 1); assert.match(r.err, /the slam has no bar/); r = await cli(["fx", "slambar", "p-1", "set", "1", "--bar", "off", "--bar-style", "default"]); assert.equal(r.code, 0, r.err); assert.equal((await manifest(p)).timeline[0].fx[0].bar, undefined); });