// THE QUEUE's READ IS THE BENCH's (lane reads-find, the orchestrator's ruling 3): a post's read made by the re-read // queue (makeTake with the bench's slur rule) asks the editor EXACTLY what the bench's take op asks // (postTakeAsk.mjs: the one module both build from) -- the slur case included: a cut that beeps a slur has it left // out of a bench read, and out of the queue's. Temp dirs, a stub tts, invented people. import "./noLiveEditor.mjs"; import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; 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 { encodeWav16 } from "yt-dlp-transcript-common/lib/montage/voiceMatch.mjs"; import { VOICE_B, syntheticVoice, withSilence } from "yt-dlp-transcript-common/testing/audio/syntheticVoice.mjs"; import { makeTake } from "./postNarrationCli.mjs"; import { askBody, benchTakeAskOf } from "./postTakeAsk.mjs"; import { projectRedaction } from "./postRedaction.mjs"; const LIST = JSON.parse(readFileSync(new URL("../../report-to-video/slurs.json", import.meta.url), "utf8")); const F = LIST.entries.find((e) => e.id === "f-slur").word; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-bench-parity-")); after(() => rm(ROOT, { recursive: true, force: true })); delete process.env.UMTOOL_CAST_FILE; const item = (o = {}) => ({ type: "post", id: "p-1", post: "ferry-x/1", platform: "x", author: "Ferry Teller", handle: "invented_ferry", date: "2026-10-30T10:00:00.000Z", text: "post one", ...o }); async function project(name, timeline, render = {}) { const dir = path.join(ROOT, name, "p"); await mkdir(dir, { recursive: true }); await mkdir(path.join(ROOT, name, ".umtool"), { recursive: true }); await writeFile(path.join(ROOT, name, ".umtool", "cast.json"), JSON.stringify({ format: "umtool-cast", version: 2, characters: [{ id: "ferry", name: "Ferry Teller", handles: ["invented_ferry"], synthetic: { voice: "orpheus:tara", tuning: { temperature: 0.75 } } }] })); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: name, title: name, render: { width: 1920, height: 1080, fps: 30, postNarration: { engine: "orpheus", voice: "zac" }, ...render }, timeline }, null, 2)); return { id: name, dir }; } const manifest = async (p) => JSON.parse(await readFile(path.join(p.dir, "video.manifest.json"), "utf8")); const asker = (asked) => async (body) => { asked.push(body); await mkdir(path.dirname(body.out), { recursive: true }); await writeFile(body.out, encodeWav16(withSilence(syntheticVoice({ ...VOICE_B, seconds: 0.6 }), { before: 0.1, after: 0.1 }))); return { jobId: `job-${asked.length}`, result: { wav: body.out, engine: body.engine, voice: body.voice } }; }; /** The bench's take op's body for one press: through the route's OWN builder (benchTakeAskOf, from the POST's body). */ async function benchBody(p, press) { const m = await manifest(p); const e = m.timeline[0]; const red = await projectRedaction(p.dir, m); const a = await benchTakeAskOf(p, e, { manifest: m, script: String(press.script ?? e.narration.script), body: { ...(press.speed !== undefined ? { speed: press.speed } : {}) }, tuning: press.tuning ?? null, reading: press.reading ?? null, red }); return askBody(a, "OUT"); } async function queueBody(p, press) { const asked = []; const r = await makeTake(p, (await manifest(p)).timeline[0], { ask: asker(asked), benchSlurs: true, keepPick: true, ...press, askOp: async () => { throw new Error("the queue's read is never word-timed"); } }); assert.equal(asked.length, 1, "one ask, never a second for a beep"); return { body: { ...asked[0], out: "OUT" }, take: r.take }; } test("the same press, the same ask: the character's tuning, the line's own over it, a reading", async () => { for (const [name, press] of [["plain", {}], ["own", { tuning: { temperature: 0.9, takes: 5 } }], ["reading", { reading: 2 }]]) { const p = await project(`same-${name}`, [item({ narration: { script: "The ferry runs at noon." } })]); const want = await benchBody(p, press); const got = await queueBody(p, press); assert.deepEqual(got.body, want, name); } }); test("THE SLUR CASE: a cut that beeps -- the bench leaves the slur out, and so does the queue's read (no word timing)", async () => { const script = `Hello, you ${F}. Welcome.`; const p = await project("beep", [item({ narration: { script } })], { posts: { slurs: { voice: "beep" } } }); const want = await benchBody(p, {}); assert.equal(want.text, "Hello, you. Welcome."); const got = await queueBody(p, {}); assert.deepEqual(got.body, want); assert.equal(got.take.slurs, "skip"); assert.equal(got.take.words, undefined); }); // REVIEW 1, a nit: the UNTUNED bench ask is byte-identical to the one the route made before this lane -- its keys in // their order, a speed only when it is a number (never NaN, never 0), none for Orpheus. test("the untuned bench ask, byte for byte as before: Orpheus (no speed), Kokoro with the item's speed, a speed that is no number", async () => { const p = await project("bytes", [item({ narration: { script: "The ferry runs at noon." } })]); // No character for a handle that is not the cast's: the narrator, Orpheus zac. const m = await manifest(p); const e = { ...m.timeline[0], handle: "invented_nobody" }; const red = await projectRedaction(p.dir, m); const old = (spoken, engine, voice, speed, tuning, reading) => JSON.stringify({ text: spoken, engine, voice, out: "OUT", ...(speed ? { speed } : {}), ...(tuning ? { tuning } : {}), ...(reading !== null ? { reading } : {}) }); // `old` is the pre-lane route's own body expression (4e42b042f, app/api/report/post-narration/route.ts:460), and the // literals below are what it made for these asks: the pin holds both. let a = await benchTakeAskOf(p, e, { manifest: m, script: e.narration.script, body: {}, red }); assert.equal(JSON.stringify(askBody(a, "OUT")), old("The ferry runs at noon.", "orpheus", "zac", undefined, null, null)); assert.equal(JSON.stringify(askBody(a, "OUT")), '{"text":"The ferry runs at noon.","engine":"orpheus","voice":"zac","out":"OUT"}'); const k = { ...e, narration: { ...e.narration, engine: "kokoro", voice: "af_heart", speed: 1.1 } }; a = await benchTakeAskOf(p, k, { manifest: m, script: k.narration.script, body: {}, red }); assert.equal(JSON.stringify(askBody(a, "OUT")), old("The ferry runs at noon.", "kokoro", "af_heart", 1.1, null, null)); assert.equal(JSON.stringify(askBody(a, "OUT")), '{"text":"The ferry runs at noon.","engine":"kokoro","voice":"af_heart","out":"OUT","speed":1.1}'); a = await benchTakeAskOf(p, k, { manifest: m, script: k.narration.script, body: { speed: "fast" }, red }); assert.equal(JSON.stringify(askBody(a, "OUT")), old("The ferry runs at noon.", "kokoro", "af_heart", undefined, null, null), "a speed that is no number is left out"); assert.equal(JSON.stringify(askBody(a, "OUT")), '{"text":"The ferry runs at noon.","engine":"kokoro","voice":"af_heart","out":"OUT"}'); a = await benchTakeAskOf(p, k, { manifest: m, script: k.narration.script, body: { speed: 0 }, red }); assert.equal(JSON.stringify(askBody(a, "OUT")), '{"text":"The ferry runs at noon.","engine":"kokoro","voice":"af_heart","out":"OUT"}', "a speed of 0 is left out, as the route left it"); });