// What a read SAYS of an anonymous author (characters C3 review, must-fix 6), on disk: projectRedaction carries the // video's anonymous handles; a single take and a thread read's parts are asked to say the shown name, and the take // records the handles it said so; this video's characters unread refuses the read. And must-fix 5 (a take a thread // read is made of is never deleted from under it), should-fix g (an explicit --speed is kept as asked) and h (a // thread take with a recorded part discloses each part truthfully). No editor: the tts op is a stub; temp dirs. import assert from "node:assert/strict"; import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { after, test } from "node:test"; import { encodeWav16 } from "yt-dlp-transcript-common/lib/montage/voiceMatch.mjs"; import { VOICE_A, syntheticVoice, withSilence } from "yt-dlp-transcript-common/testing/audio/syntheticVoice.mjs"; import { postNarrationDisclosure } from "umtool-report-to-video/post-narration"; import { makeTake } from "./postNarrationCli.mjs"; import { postsCommand } from "./postsCli.mjs"; import { projectRedaction } from "./postRedaction.mjs"; import { threadTake } from "./postThreadRead.mjs"; import { projectCharacters, rereadPlan } from "./castProject.mjs"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-anon-read-")); after(() => rm(ROOT, { recursive: true, force: true })); const wav = async (file) => { await mkdir(path.dirname(file), { recursive: true }); await writeFile(file, encodeWav16(withSilence(syntheticVoice({ ...VOICE_A, seconds: 1 }), { before: 0.2, after: 0.2 }))); }; const stubAsk = (asked) => async (body) => { asked.push(body); await wav(body.out); return { jobId: `job-${asked.length}`, result: { wav: body.out, engine: body.engine, voice: body.voice } }; }; const DIR = path.join(ROOT, "anon"); const project = { id: "anon", dir: DIR }; const post = (id, handle, author, o = {}) => ({ type: "post", id, post: `chan/${id}`, platform: "x", author, handle, date: "2026-10-30T10:00:00.000Z", text: `words of ${id}`, ...o }); const manifestOf = (timeline) => ({ schemaVersion: 1, slug: "anon", title: "A", provenance: { channelsDir: "../channels", channelSlug: "chan" }, render: { width: 1920, height: 1080, fps: 30, postNarration: { engine: "kokoro", voice: "af_heart" } }, timeline }); await mkdir(path.join(DIR, "narration"), { recursive: true }); await writeFile(path.join(DIR, "narration", "characters.json"), JSON.stringify({ format: "umtool-project-characters", version: 1, characters: [{ id: "anon-1", name: "Anon 1", anonymous: true, shown: "Anon 1", handles: ["realguy"] }] })); await writeFile(path.join(DIR, "video.manifest.json"), JSON.stringify(manifestOf([ post("p-1", "host", "Host", { narration: { script: "Thanks @RealGuy for this." } }), post("p-2", "host", "Host", { parents: [{ id: "9", handle: "realguy", author: "Real Guy", date: "2026-10-30T09:00:00.000Z", text: "Ask @RealGuy anything" }], narration: { script: "My answer." } }), ]), null, 2)); const manifest = async () => JSON.parse(await readFile(path.join(DIR, "video.manifest.json"), "utf8")); test("a synthesized read says the shown name: a single take and a thread read's parts; the take records the handles", async () => { const red = await projectRedaction(DIR, await manifest()); assert.deepEqual(Object.fromEntries(red.anon), { realguy: "Anon 1" }); assert.ok(red.anon.postIds instanceof Set, "the whole set: its post ids too"); const asked = []; const m = await manifest(); const t = await makeTake(project, m.timeline[0], { render: m.render, ask: stubAsk(asked), redaction: red }); assert.equal(asked[0].text, "Thanks Anon 1 for this."); assert.equal(t.take.said, "Thanks Anon 1 for this.", "what it said is kept: the lint reads it"); assert.equal(t.take.script, "Thanks @RealGuy for this.", "the script kept as written"); assert.equal(t.take.speedAsked, undefined, "no speed asked: no key"); const r = await threadTake(project, (await manifest()).timeline[1], { red, ask: stubAsk(asked), lanes: null, map: {}, cast: {}, item: null }); const parentAsk = asked.find((b) => /anything/.test(b.text)); assert.equal(parentAsk.text, "Ask Anon 1 anything"); assert.equal(r.take.said, undefined, "a thread take's script IS what it said"); assert.ok(!/realguy/i.test(r.take.script)); for (const b of asked) assert.ok(!/realguy/i.test(b.text), b.text); }); test("this video's characters unread: a read is refused, never said with the real handle", async () => { const D2 = path.join(ROOT, "broken"); await mkdir(path.join(D2, "narration"), { recursive: true }); await writeFile(path.join(D2, "narration", "characters.json"), "{ nope"); await assert.rejects(projectRedaction(D2, manifestOf([])), /characters are not read/); }); test("must-fix 5: a take another take is made of is never deleted -- refused before anything is moved", async () => { const D3 = path.join(ROOT, "del"); const T1 = { file: "narration/posts/1/take-1.recorded.wav", engine: "recorded", voice: "operator", seconds: 1.4, script: "My own line.", source: { kind: "recorded", voice: "operator" } }; const T2 = { file: "narration/posts/1/take-2.kokoro-thread.wav", engine: "kokoro", voice: "bf_emma+operator", seconds: 3, script: "q\n\nMy own line.", read: { kind: "thread", parents: "0", postTake: { n: 1, file: T1.file } }, parts: [{ n: 1, para: 0, text: "q", voice: "bf_emma", engine: "kokoro", role: "parent:0", piece: 0, file: "narration/parts-cache/abc.wav", start: 0, seconds: 1, gapBefore: 0 }, { n: 2, para: 100, text: "My own line.", voice: "operator", role: "post", piece: 1, file: T1.file, take: "take-1.recorded", start: 1.8, seconds: 1.2, gapBefore: 0.8 }] }; for (const t of [T1, T2]) await wav(path.join(D3, t.file)); await writeFile(path.join(D3, "video.manifest.json"), JSON.stringify({ ...manifestOf([post("p-1", "host", "Host", { parents: [{ id: "20", handle: "guest", author: "G", text: "q" }], narration: { script: "My own line.", takes: [T1, T2], pick: 1 } })]), slug: "del" })); const lines = []; const code = await postsCommand(["narrate", "del", "p-1", "--delete", "1"], { root: ROOT, out: (s) => lines.push(s), err: (s) => lines.push(s) }); assert.equal(code, 2, lines.join("\n")); assert.match(lines.join(" "), /is a part of take 2 .* nothing moved/); assert.ok((await stat(path.join(D3, T1.file))).isFile(), "the recording is where it was"); assert.equal((await stat(path.join(D3, "narration/posts/1/.trash")).catch(() => null)), null, "nothing in the trash"); // h: its disclosure says each part truthfully -- a synthesized parent, a recorded reading. const e = JSON.parse(await readFile(path.join(D3, "video.manifest.json"), "utf8")).timeline[0]; assert.equal(postNarrationDisclosure(e), "Narration: synthetic voice (Kokoro-82M · bf_emma); a recorded reading"); const conv = { file: "narration/posts/1/take-3.derived.wav", engine: "derived", voice: "am_michael", seconds: 1.4, script: "My own line.", source: { kind: "take", from: "take-1.recorded" }, steps: [{ op: "convert", engine: "seed-vc", voice: "kokoro:am_michael" }] }; const T4 = { ...T2, file: "narration/posts/1/take-4.kokoro-thread.wav", parts: [T2.parts[0], { ...T2.parts[1], file: conv.file, take: "take-3.derived", voice: "am_michael" }] }; assert.equal(postNarrationDisclosure({ ...e, narration: { ...e.narration, takes: [T1, T2, conv, T4], pick: 3 } }), "Narration: synthetic voice (Kokoro-82M · bf_emma); a recorded reading converted to a stock voice (seed-vc · kokoro:am_michael)"); }); test("should-fix g: a single take made with an explicit --speed is kept as asked -- not drift, and a re-read asks it again", () => { const take = { file: "narration/posts/1/take-1.kokoro.wav", engine: "kokoro", voice: "af_heart", seconds: 2, script: "Hi.", speed: 1.3, speedAsked: true }; const m = manifestOf([post("p-1", "host", "Host", { narration: { takes: [take], pick: 0 } })]); const cast = { format: "umtool-cast", version: 2, characters: [{ id: "host", name: "Host", handles: ["host"], synthetic: { voice: "kokoro:af_heart" } }] }; assert.deepEqual(projectCharacters(m, { cast }).characters.flatMap((c) => c.drift), [], "1.3 as asked, no preset speed: not drift"); // Another voice now: drift by the voice, and the re-read keeps the speed it was asked at. const cast2 = { ...cast, characters: [{ ...cast.characters[0], synthetic: { voice: "kokoro:am_adam" } }] }; const drift = projectCharacters(m, { cast: cast2 }).characters.flatMap((c) => c.drift); assert.equal(drift.length, 1); assert.deepEqual(rereadPlan("anon", m, drift, ["host"]).items[0].argv, ["posts", "narrate", "anon", "p-1", "--take", "--speed", "1.3"]); // Without speedAsked (a take made before it was recorded): unknown is no claim -- not drift. const m2 = manifestOf([post("p-1", "host", "Host", { narration: { takes: [{ ...take, speedAsked: undefined }], pick: 0 } })]); assert.equal(projectCharacters(m2, { cast }).characters.flatMap((c) => c.drift).length, 0); }); test("must-fix 5: a bare handle after an @mention is said as the shown name too; the lint judges what was SAID", async () => { const red = { anon: { realguy: "Anon 1" } }; const asked = []; const m = await manifest(); const e = { ...m.timeline[0], narration: { script: "@realguy said it. realguy, stop." } }; const t = await makeTake(project, e, { render: m.render, ask: stubAsk(asked), redaction: red }); assert.equal(asked.at(-1).text, "Anon 1 said it. Anon 1, stop."); assert.equal(t.take.said, "Anon 1 said it. Anon 1, stop."); const { anonymityProblems } = await import("umtool-report-to-video/post-anon"); const doc = JSON.parse(await readFile(path.join(DIR, "narration", "characters.json"), "utf8")); const lint = (take) => anonymityProblems({ timeline: [{ ...e, narration: { takes: [take], pick: 0 } }] }, doc).errors; assert.deepEqual(lint(t.take), [], "what it said holds no handle"); assert.equal(lint({ ...t.take, said: "Anon 1 said it. realguy, stop." }).length, 1, "a bare handle said: an error"); assert.equal(lint({ ...t.take, said: undefined }).length, 1, "a recording says its script"); }); test("must-fix 6 (ii): every take maker records where its speed came from -- the flag, the item's own", async () => { const asked = []; const m = await manifest(); const e = m.timeline[0]; assert.equal((await makeTake(project, e, { render: m.render, speed: 1.3, ask: stubAsk(asked), redaction: null })).take.speedAsked, true); assert.equal((await makeTake(project, { ...e, narration: { ...e.narration, speed: 1.1 } }, { render: m.render, ask: stubAsk(asked), redaction: null })).take.speedAsked, "item"); }); test("round 3 c: a --post-take part's words are what its source take SAID", async () => { const { threadReadPlan, postTakeOf } = await import("./postThreadRead.mjs"); const src = { file: "narration/posts/x/take-1.kokoro.wav", engine: "kokoro", voice: "am_michael", seconds: 2, script: "Thanks @RealGuy.", said: "Thanks Anon 1." }; const e = post("p-9", "host", "Host", { narration: { script: "Thanks @RealGuy.", takes: [src], pick: 0 } }); const plan = threadReadPlan(manifestOf([e]), e, { map: {}, cast: {}, postTake: postTakeOf(e, 1) }); assert.equal(plan.pieces.find((p) => p.role === "post").text, "Thanks Anon 1."); });