// A CHARACTER's ORPHEUS TUNING (lane character-tuning, S2 of plans/orpheus-retune.md): kept on the synthetic preset // through the cast's one writer (`umtool cast set` / `cast project
set`), normalised, said with every value its // reads are asked with; the resolution chain carrying it (a character without one: the entry it always was); a TRY -- // one line read with a tuning and a reading, scratch, in a short list; the reads made with other settings (stale, // never re-made); and THE PIN: keeping a tuning, or trying one, leaves the manifest and every drawn card as they were. // No editor: the tts op is a stub. Each test makes its own world (reports root, cast, project, settings): any one runs // alone. import assert from "node:assert/strict"; import { createHash } from "node:crypto"; import { mkdir, mkdtemp, readFile, readdir, rm, writeFile } from "node:fs/promises"; import { existsSync } from "node:fs"; 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 { ORPHEUS_TUNING_NAMED } from "yt-dlp-transcript-common/lib/ttsTuning.mjs"; import { castCommand } from "./castCli.mjs"; import { castFile, castWrite } from "./castStore.mjs"; import { auditionKey } from "./castAudition.mjs"; import { ORPHAN_AGE_MS, TRIES_FILE, TRY_KEEP, addTry, nextReading, readTries, tuningView } from "./characterTuning.mjs"; import { projectCharacters, resolverFor } from "./castProject.mjs"; import { effectiveCharacterTuning, presetEntryOf, tuningStale } from "umtool-report-to-video/cast"; import { readTuningOf, resolvePieceVoice } from "umtool-report-to-video/post-say"; import { postCardHtml, postItemPlan } from "umtool-report-to-video/post-item"; const BASE = await mkdtemp(path.join(tmpdir(), "umtool-tuning-")); after(() => rm(BASE, { recursive: true, force: true })); delete process.env.UMTOOL_CAST_FILE; const LIVELY = { ...ORPHEUS_TUNING_NAMED.lively }; const STEADY_KEPT = { temperature: 0.4, top_p: 0.8 }; // Steady as kept: its repeat penalty is the default's const MADE = (o = {}) => ({ temperature: 0.55, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2, takes: 4, ...o }); const LINE = "The teller says the bridge was closed for the whole of the long winter."; const TELLER = "invented_teller"; const OTHER = "invented_other"; const wavOf = async (file, seconds = 1.2) => { await mkdir(path.dirname(file), { recursive: true }); await writeFile(file, encodeWav16(withSilence(syntheticVoice({ ...VOICE_A, seconds }), { before: 0.2, after: 0.2 }))); }; /** The editor's tts op, stubbed: `out` written, the effective tuning reported as the editor reports it (Orpheus). */ const stubAsk = (asked, settingTakes = 4) => async (body) => { asked.push(body); await wavOf(body.out); return { jobId: `job-${asked.length}`, result: { wav: body.out, engine: body.engine, voice: body.voice, disclosure: `Narration: synthetic voice (${body.engine} ยท ${body.voice})`, ...(body.engine === "orpheus" ? { tuning: { ...MADE({ takes: settingTakes }), ...(body.tuning ?? {}) }, reading: body.reading ?? 0, seedBase: 1234 + 9973 * (body.reading ?? 0) } : {}), }, }; }; const take = (o) => ({ file: "narration/posts/1/take-1.orpheus-tara.wav", engine: "orpheus", voice: "tara", seconds: 1.2, script: LINE, ...o }); const post = (id, handle, o = {}) => ({ type: "post", id: `p-${id}`, post: `tellerx/${id}`, platform: "x", author: handle === TELLER ? "The Teller" : "Another One", handle, date: `2026-10-30T1${id}:00:00.000Z`, text: `${LINE} (${id})`, ...o }); // "teller" reads p-1 (an Orpheus take made with the defaults), p-2 (a take whose own line asked a tuning), p-3 (a // recorded take); "other" reads p-4 in Kokoro. const timeline = () => [ post("1", TELLER, { narration: { script: LINE, takes: [take({ tuning: MADE(), reading: 0 })], pick: 0 } }), post("2", TELLER, { narration: { script: LINE, takes: [take({ file: "narration/posts/2/take-1.orpheus-tara.wav", tuning: MADE({ temperature: 0.9 }), reading: 0, tuningAsked: true })], pick: 0 } }), post("3", TELLER, { narration: { script: LINE, takes: [{ file: "narration/posts/3/take-1.recorded.wav", engine: "recorded", voice: "operator", seconds: 1.2, script: LINE }], pick: 0 } }), post("4", OTHER, { narration: { script: "Another line.", takes: [{ file: "narration/posts/4/take-1.kokoro-af_heart.wav", engine: "kokoro", voice: "af_heart", seconds: 1, script: "Another line." }], pick: 0 } }), ]; /** * A WORLD of its own: a reports root (its cast.json), the editor's settings (tts.orpheus.takes: `settingTakes`), the * project "tuning" (its manifest), and -- unless `bare` -- the cast's teller (orpheus:tara) and other (kokoro:af_heart). */ async function world({ settingTakes = 4, bare = false } = {}) { const root = await mkdtemp(path.join(BASE, "w-")); const settings = path.join(root, "settings.json"); await writeFile(settings, JSON.stringify({ tts: { orpheus: { takes: settingTakes } } })); process.env.SETTINGS_FILE = settings; const dir = path.join(root, "tuning"); await mkdir(dir, { recursive: true }); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: "tuning", title: "Tuning", render: { width: 1920, height: 1080, fps: 30, palette: { bg: "#000000", fg: "#ffffff", muted: "#888888", accent: "#c8752a" } }, timeline: timeline(), }, null, 2)); const cast = async (args, extra = {}) => { const lines = []; const code = await castCommand(args, { reportsRoot: root, log: (s) => lines.push(s), err: (s) => lines.push(s), ...extra }); return { code, text: () => lines.join("\n"), json: () => JSON.parse(lines.join("\n")) }; }; if (!bare) { assert.equal((await cast(["add", "teller", "--name", "The Teller", "--voice", "orpheus:tara", "--handles", TELLER])).code, 0); assert.equal((await cast(["add", "other", "--name", "Another One", "--voice", "kokoro:af_heart", "--handles", OTHER])).code, 0); } const manifestText = () => readFile(path.join(dir, "video.manifest.json"), "utf8"); const BOX = { width: 1080, height: 1350 }; const drawn = async () => { const m = JSON.parse(await manifestText()); return m.timeline.map((e) => JSON.stringify([postCardHtml(e, BOX), postCardHtml(e, { ...BOX, follow: true }), postItemPlan(e, m.render)])); }; const castJson = async () => JSON.parse(await readFile(castFile(root), "utf8")); return { root, dir, cast, manifestText, drawn, castJson }; } test("cast set: a tuning on the synthetic preset -- a named starting point, the numbers over it, the defaults kept as none", async () => { const w = await world(); let r = await w.cast(["set", "teller", "--json"]); assert.deepEqual(r.json().tuning, { tuning: null, name: "default", effective: { ...MADE() }, takesFrom: "setting" }, "every value its reads are asked with: the setting's takes (4)"); r = await w.cast(["set", "teller", "--tuning", "lively", "--json"]); assert.equal(r.code, 0, r.text()); assert.deepEqual(r.json().character.synthetic.tuning, LIVELY); assert.equal(r.json().tuning.name, "lively"); assert.deepEqual(r.json().tuning.effective, effectiveCharacterTuning(LIVELY, 4)); // A number over it: custom; the others kept. r = await w.cast(["set", "teller", "--temperature", "0.8000000001", "--json"]); assert.deepEqual(r.json().character.synthetic.tuning, { ...LIVELY, temperature: 0.8 }); assert.equal(r.json().tuning.name, "custom"); // `default` takes one field off. r = await w.cast(["set", "teller", "--temperature", "default", "--json"]); assert.deepEqual(r.json().character.synthetic.tuning, { top_p: LIVELY.top_p, repeat_penalty: LIVELY.repeat_penalty }); // Takes: 5 is kept. r = await w.cast(["set", "teller", "--chunk-takes", "5", "--json"]); assert.equal(r.json().character.synthetic.tuning.takes, 5); assert.equal(r.json().tuning.takesFrom, "character"); // --tuning default puts the sampler's three back and KEEPS the takes (a name covers the sampler only). r = await w.cast(["set", "teller", "--tuning", "default", "--json"]); assert.deepEqual(r.json().character.synthetic.tuning, { takes: 5 }); // Takes 3 is Orpheus's default and is NOT kept -- and the preset says the setting's (4) is what is used. r = await w.cast(["set", "teller", "--chunk-takes", "3", "--json"]); assert.equal(r.json().character.synthetic.tuning, undefined); assert.equal(r.json().tuning.effective.takes, 4, "never a number the read would not use"); assert.match(r.json().notes[0], /takes 3 is Orpheus's default and is not kept: its reads take the editor's setting \(4\)/); await w.cast(["set", "teller", "--tuning", "steady"]); r = await w.cast(["set", "teller", "--no-tuning", "--json"]); assert.equal("tuning" in r.json().character.synthetic, false); assert.deepEqual(Object.keys((await w.castJson()).characters[0].synthetic), ["voice"], "the file keeps no empty tuning"); // Refused in the flag's words, nothing written. const before = await readFile(castFile(w.root), "utf8"); for (const [args, re] of [ [["--temperature", "9"], /--temperature must be a number from 0\.1 to 1\.5 \(got 9\)/], [["--chunk-takes", "x"], /--chunk-takes must be a whole number from 1 to 6 \(got x\)/], [["--tuning", "loud"], /--tuning is steady, default, lively \(got loud\)/], [["--no-tuning", "--temperature", "0.7"], /--no-tuning drops the whole tuning: not with --tuning, --temperature/], ]) { r = await w.cast(["set", "teller", ...args]); assert.equal(r.code, 1, args.join(" ")); assert.match(r.text(), re); } assert.equal(await readFile(castFile(w.root), "utf8"), before); // Undo puts the last one back. await w.cast(["set", "teller", "--tuning", "lively"]); await w.cast(["set", "teller", "--tuning", "steady"]); r = await w.cast(["undo", "--json"]); assert.equal(r.code, 0, r.text()); assert.deepEqual((await w.castJson()).characters[0].synthetic.tuning, LIVELY); // A Kokoro voice keeps it and ignores it (as Orpheus ignores a speed), and says so. r = await w.cast(["set", "other", "--tuning", "steady", "--json"]); assert.match(r.json().notes.join(" "), /kokoro:af_heart has no sampler: its reads ignore the tuning/); }); test("the cast's file refuses a tuning that is not a character's, whole -- a null value too (review 1 #13)", async () => { const w = await world(); for (const [tuning, re] of [ [{ top_k: 40 }, /synthetic\.tuning\.top_k is not a character's tuning field/], [{ temperature: 9 }, /synthetic\.tuning\.temperature must be a number from 0\.1 to 1\.5 \(got 9\)/], [{ temperature: null }, /synthetic\.tuning\.temperature must be a number from 0\.1 to 1\.5 \(got null\)/], [{ temperature: 0.7, takes: null }, /synthetic\.tuning\.takes must be a whole number from 1 to 6 \(got null\)/], [{}, /synthetic\.tuning names no value/], ["warm", /synthetic\.tuning must be/], ]) { await assert.rejects(castWrite(castFile(w.root), (chars) => { chars.find((c) => c.id === "teller").synthetic.tuning = tuning; }), re, JSON.stringify(tuning)); } }); test("cast project
set: the twin for this video's own character; a tuning needs a voice", async () => { const w = await world(); let r = await w.cast(["project", "tuning", "add", "visitor", "--name", "A Visitor", "--handles", "invented_visitor", "--tuning", "lively"]); assert.equal(r.code, 1); assert.match(r.text(), /a tuning is its voice's: give the character a voice too/); r = await w.cast(["project", "tuning", "add", "visitor", "--name", "A Visitor", "--voice", "orpheus:leo", "--handles", "invented_visitor", "--tuning", "steady", "--repeat-penalty", "1.3", "--json"]); assert.equal(r.code, 0, r.text()); assert.deepEqual(r.json().character.synthetic.tuning, { ...ORPHEUS_TUNING_NAMED.steady, repeat_penalty: 1.3 }); r = await w.cast(["project", "tuning", "set", "visitor", "--no-voice", "--json"]); assert.equal(r.json().character.synthetic, undefined, "no voice: no tuning either"); }); test("THE PIN: a character with no tuning is the layer entry it always was; one with a tuning carries it to the read", () => { assert.deepEqual(presetEntryOf({ id: "a", synthetic: { voice: "orpheus:tara" } }), { voice: "orpheus:tara", character: "a" }); assert.deepEqual(presetEntryOf({ id: "a", synthetic: { voice: "kokoro:am_adam", speed: 1.1 } }), { voice: "kokoro:am_adam", speed: 1.1, character: "a" }); // Defaults spelled out are no tuning at all. assert.deepEqual(presetEntryOf({ id: "a", synthetic: { voice: "orpheus:tara", tuning: { temperature: 0.55, takes: 3 } } }), { voice: "orpheus:tara", character: "a" }); const entry = presetEntryOf({ id: "a", synthetic: { voice: "orpheus:tara", tuning: LIVELY } }); assert.deepEqual(entry, { voice: "orpheus:tara", tuning: LIVELY, character: "a" }); const o = { cast: { [TELLER]: entry }, narrator: "leo", engine: "orpheus" }; assert.deepEqual(resolvePieceVoice({ handle: TELLER, role: "post" }, { ...o, self: TELLER }), { engine: "orpheus", voice: "tara", from: "cast", tuning: LIVELY, character: "a" }); // No character: no tuning key anywhere. assert.deepEqual(resolvePieceVoice({ handle: "nobody", role: "post" }, { ...o, self: "nobody" }), { engine: "orpheus", voice: "leo", from: "narrator" }); // The line's own beats the character's; an engine without a sampler has none. assert.deepEqual(readTuningOf({ preset: LIVELY, engine: "orpheus" }), { tuning: LIVELY, asked: "preset" }); assert.deepEqual(readTuningOf({ flag: { temperature: 0.9 }, preset: LIVELY, engine: "orpheus" }), { tuning: { temperature: 0.9 }, asked: true }); assert.equal(readTuningOf({ flag: {}, preset: {}, engine: "orpheus" }), null); assert.equal(readTuningOf({ preset: LIVELY, engine: "kokoro" }), null); }); // ---- stale ---------------------------------------------------------------------------------------------------------- const castOf = (tuning, voice = "orpheus:tara") => ({ format: "umtool-cast", version: 2, characters: [{ id: "teller", name: "The Teller", handles: [TELLER], synthetic: { voice, ...(tuning ? { tuning } : {}) } }] }); const manifestOf = (edit = (tl) => tl) => ({ timeline: edit(timeline()) }); const staleOf = (m, tuning, settingTakes = 4) => tuningStale(m, resolverFor({ cast: castOf(tuning) }), { settingTakes }); test("stale: a picked Orpheus read made with other settings than its character's tuning now", () => { const m = manifestOf(); assert.deepEqual(staleOf(m, null), [], "no tuning: nothing is stale (p-1 was made with the defaults; p-2 asked its own)"); // Lively: p-1 only -- p-2's tuning was its line's own, p-3 is recorded, p-4 is another character's Kokoro read. const rows = staleOf(m, LIVELY); assert.deepEqual(rows.map((r) => [r.id, r.character, r.role]), [["p-1", "teller", "post"]]); assert.deepEqual(rows[0].made, MADE()); assert.deepEqual(rows[0].want, effectiveCharacterTuning(LIVELY, 4)); // Takes: compared only when the character names them (a read with none records the setting's). assert.deepEqual(staleOf(m, { takes: 4 }), [], "4 is what it was made with"); assert.deepEqual(staleOf(m, { takes: 5 }).map((r) => r.id), ["p-1"]); // A take made with the character's tuning (tuningAsked "preset") is stale when the character changes, fresh when not. const m2 = manifestOf((tl) => { tl[0].narration.takes[0] = { ...tl[0].narration.takes[0], tuning: MADE(LIVELY), tuningAsked: "preset", reading: 2 }; return tl; }); assert.deepEqual(staleOf(m2, LIVELY), []); assert.deepEqual(staleOf(m2, STEADY_KEPT).map((r) => [r.id, r.reading]), [["p-1", 2]], "the reading is said, never compared"); // An S1 take with no provenance and a sampler value off the defaults was asked by its line: never stale. const m3 = manifestOf((tl) => { tl[0].narration.takes[0] = { ...tl[0].narration.takes[0], tuning: MADE({ top_k: 40 }) }; return tl; }); assert.deepEqual(staleOf(m3, LIVELY), []); // A read now in ANOTHER voice is drift, not stale. assert.deepEqual(tuningStale(m, resolverFor({ cast: castOf(LIVELY, "orpheus:leah") }), { settingTakes: 4 }), []); }); test("stale (review 1 #1): a changed tts.orpheus.takes does not hide a read made with the defaults", () => { // Made with the defaults while the setting was 3 (it records takes 3, says nothing of where its tuning came from); // the setting is 4 now. Its TAKES are the old setting, not its line's ask: it is stale for Lively all the same. const m = manifestOf((tl) => { tl[0].narration.takes[0] = { ...tl[0].narration.takes[0], tuning: MADE({ takes: 3 }) }; return tl; }); assert.deepEqual(staleOf(m, LIVELY, 3).map((r) => r.id), ["p-1"]); assert.deepEqual(staleOf(m, LIVELY, 4).map((r) => r.id), ["p-1"], "the same at setting 4"); assert.deepEqual(staleOf(m, null, 4), [], "a character with no tuning: nothing"); }); test("stale (review 1 #2): a thread read's part that IS another take answers as that take does", () => { // p-1's picked take is a thread read whose post part is take-1 (made with the character's Lively, tuningAsked // "preset", reading 3); the thread take itself records no tuning. const m = manifestOf((tl) => { const own = take({ tuning: MADE(LIVELY), tuningAsked: "preset", reading: 3 }); const thread = { file: "narration/posts/1/take-2.orpheus-thread.wav", engine: "orpheus", voice: "tara+leo", seconds: 3, script: LINE, read: { kind: "thread" }, parts: [{ role: "post", voice: "tara", engine: "orpheus", take: "take-1.orpheus-tara", file: own.file, text: LINE }] }; tl[0].narration = { script: LINE, takes: [own, thread], pick: 1 }; return tl; }); assert.deepEqual(staleOf(m, LIVELY), [], "made with the character's own: fresh"); const moved = staleOf(m, STEADY_KEPT); assert.deepEqual(moved.map((r) => [r.id, r.reading, r.thread]), [["p-1", 3, true]], "the character changed: stale, its source take's reading said"); assert.deepEqual(moved[0].made, MADE(LIVELY)); }); test("cast stale and the project's view list the stale reads; listing writes nothing", async () => { const w = await world(); await w.cast(["set", "teller", "--tuning", "lively"]); const before = await w.manifestText(); const view = projectCharacters(JSON.parse(before), { cast: castOf(LIVELY), settingTakes: 4 }); assert.deepEqual(view.characters.find((c) => c.character?.id === "teller").stale.map((d) => d.id), ["p-1"]); assert.deepEqual(view.tuningStale.map((d) => d.id), ["p-1"]); const r = await w.cast(["stale", "tuning", "teller", "--json"]); assert.equal(r.code, 0, r.text()); assert.deepEqual([r.json().count, r.json().items], [1, ["p-1"]]); const t = await w.cast(["stale", "tuning"]); assert.match(t.text(), /1 read made with other settings than their character's tuning now \(listed, never re-made\):\n {2}p-1 post \(teller\): made with temperature 0\.55/); assert.equal(await w.manifestText(), before); }); // ---- tries -------------------------------------------------------------------------------------------------------- test("the audition key: an untuned ask keeps the key it always had; a tuned one never collides with an untuned text (review 1 #15)", () => { const old = createHash("sha1").update(`orpheus|tara|${LINE}`).digest("hex").slice(0, 20); assert.equal(auditionKey("orpheus", "tara", LINE), old); assert.equal(auditionKey("orpheus", "tara", LINE, { tuning: { temperature: 0.55, takes: 3 }, reading: 0 }), old, "the defaults spelled out are no tuning"); const lively = auditionKey("orpheus", "tara", LINE, { tuning: LIVELY }); assert.notEqual(lively, old); assert.notEqual(auditionKey("orpheus", "tara", LINE, { tuning: LIVELY, reading: 1 }), lively); // An untuned text that spells a tuned key's old tail is another key. assert.notEqual(auditionKey("orpheus", "tara", "a", { reading: 1 }), auditionKey("orpheus", "tara", "a|{}|1")); assert.notEqual(auditionKey("orpheus", "tara", "a", { tuning: LIVELY }), auditionKey("orpheus", "tara", `a|${JSON.stringify(LIVELY)}|0`)); }); test("cast try: a line read with a tuning and a reading -- scratch, a short list, the manifest and every drawn card untouched", async () => { const w = await world(); const before = await w.manifestText(); const cards = await w.drawn(); await w.cast(["set", "teller", "--tuning", "lively"]); // The list before any try: none, and the line the page prefills (its own first line of enough words). let r = await w.cast(["try", "tuning", "teller", "--list", "--json"]); assert.equal(r.code, 0, r.text()); assert.deepEqual(r.json().tries, []); assert.deepEqual(r.json().line, { text: LINE, from: "item:p-1" }); assert.equal(r.json().character.layer, "cast"); assert.equal(r.json().character.tuning.name, "lively"); const asked = []; const ask = stubAsk(asked); // Its own tuning (no flags): asked with it, the first reading. r = await w.cast(["try", "tuning", "teller", "--json"], { ask, lanes: null }); assert.equal(r.code, 0, r.text()); assert.deepEqual(asked[0].tuning, LIVELY); assert.equal("reading" in asked[0], false); assert.equal(r.json().try.reading, 0); assert.deepEqual(r.json().try.made, MADE(LIVELY), "what the editor says it was made with"); assert.ok(existsSync(path.join(w.dir, r.json().try.rel))); // Another reading (review 1 #3): counted from what is kept -- the line as it is SAID (whitespace collapsed), not as typed. r = await w.cast(["try", "tuning", "teller", "--text", LINE.replace(/ /g, " "), "--another", "--json"], { ask, lanes: null }); assert.equal(asked[1].reading, 1); r = await w.cast(["try", "tuning", "teller", "--text", `${LINE} `, "--another", "--json"], { ask, lanes: null }); assert.equal(asked[2].reading, 2, "the next after the highest kept"); // Steady over it, typed text: its own key, its own list row (Steady's repeat penalty is the default's: not asked). r = await w.cast(["try", "tuning", "teller", "--tuning", "steady", "--text", "A line typed in.", "--json"], { ask, lanes: null }); assert.deepEqual(asked[3].tuning, STEADY_KEPT); r = await w.cast(["try", "tuning", "teller", "--list", "--json"]); assert.deepEqual(r.json().tries.map((x) => [x.text === LINE, x.reading, x.layer]), [[false, 0, "cast"], [true, 2, "cast"], [true, 1, "cast"], [true, 0, "cast"]], "newest first"); assert.equal(nextReading(r.json().tries, "teller", { voice: "orpheus:tara", text: LINE, tuning: LIVELY }, "cast"), 3); // The defaults tried: no tuning key, no reading key -- the ask an audition always made. await w.cast(["try", "tuning", "teller", "--tuning", "default", "--json"], { ask, lanes: null }); assert.deepEqual(Object.keys(asked[4]).sort(), ["engine", "out", "text", "voice"]); // Refused, each in a sentence (review 1 #12): out of range, both readings, --no-tuning, a Kokoro voice given a tuning. for (const [who, args, re] of [ ["teller", ["--reading", "-1"], /--reading must be a whole number from 0 to 99999/], ["teller", ["--reading", "2", "--another"], /--reading N or --another, not both/], ["teller", ["--no-tuning"], /cast try reads with a tuning: --tuning default for the defaults/], ["other", ["--tuning", "lively"], /a tuning and a reading are Orpheus's: kokoro:af_heart reads the same every time/], ]) { r = await w.cast(["try", "tuning", who, ...args], { ask, lanes: null }); assert.equal(r.code, 1, args.join(" ")); assert.match(r.text(), re); } assert.equal(asked.length, 5, "a refusal asks nothing"); // THE PIN: no take, no script, nothing in the manifest; every card drawn as it was. assert.equal(await w.manifestText(), before, "the manifest is byte-identical"); assert.deepEqual(await w.drawn(), cards, "every card's drawn text and structure are byte-identical"); assert.equal(existsSync(path.join(w.dir, "narration", "posts")), false, "no take file made"); }); test("the tries are a short list: the newest TRY_KEEP per character, a dropped tuned try's files swept; --clear keeps the untuned cache (review 1 #10)", async () => { const w = await world(); await w.cast(["set", "teller", "--tuning", "lively"]); const asked = []; const ask = stubAsk(asked); // An untuned try (the candidates' cache key): its file must survive every sweep. let r = await w.cast(["try", "tuning", "teller", "--tuning", "default", "--text", "Short.", "--json"], { ask, lanes: null }); const untuned = r.json().try.key; assert.equal(untuned, auditionKey("orpheus", "tara", "Short.")); for (let n = 0; n <= TRY_KEEP; n += 1) { r = await w.cast(["try", "tuning", "teller", "--reading", String(n), "--text", "Short.", "--json"], { ask, lanes: null }); assert.equal(r.code, 0, r.text()); } const list = (await w.cast(["try", "tuning", "teller", "--list", "--json"])).json().tries; assert.equal(list.length, TRY_KEEP); assert.deepEqual(list.map((x) => x.reading), Array.from({ length: TRY_KEEP }, (_, i) => TRY_KEEP - i)); const auditions = path.join(w.dir, "narration", "auditions"); assert.ok(!existsSync(path.join(auditions, `${auditionKey("orpheus", "tara", "Short.", { tuning: LIVELY, reading: 0 })}.wav`)), "the dropped tuned try's file is swept"); assert.ok(existsSync(path.join(auditions, `${untuned}.wav`)), "the dropped untuned try's file stays (the candidates' cache)"); r = await w.cast(["try", "tuning", "teller", "--clear", "--json"]); assert.equal(r.json().cleared, TRY_KEEP); assert.deepEqual((await w.cast(["try", "tuning", "teller", "--list", "--json"])).json().tries, []); const left = await readdir(auditions); assert.ok(!left.includes(`${list[0].key}.wav`), "a cleared tuned try's file is swept"); assert.ok(left.includes(`${untuned}.wav`), "--clear leaves the untuned file"); }); test("cast try --scope (review 1 #8): the cast's character and this video's own of the same id are kept apart", async () => { const w = await world(); await w.cast(["set", "teller", "--tuning", "lively"]); await w.cast(["project", "tuning", "add", "teller", "--name", "The Teller Here", "--voice", "orpheus:leo", "--handles", "invented_teller_here", "--tuning", "steady"]); let r = await w.cast(["try", "tuning", "teller", "--scope", "cast", "--list", "--json"]); assert.equal(r.code, 0, r.text()); assert.deepEqual([r.json().character.layer, r.json().character.voice, r.json().character.tuning.name], ["cast", "orpheus:tara", "lively"]); r = await w.cast(["try", "tuning", "teller", "--scope", "project", "--list", "--json"]); assert.deepEqual([r.json().character.layer, r.json().character.voice, r.json().character.tuning.name], ["project", "orpheus:leo", "steady"]); r = await w.cast(["try", "tuning", "teller", "--list", "--json"]); assert.equal(r.json().character.layer, "project", "no scope: this video's own first"); const asked = []; r = await w.cast(["try", "tuning", "teller", "--scope", "cast", "--text", "A line.", "--json"], { ask: stubAsk(asked), lanes: null }); assert.equal(r.code, 0, r.text()); assert.equal(asked[0].voice, "tara"); assert.deepEqual(asked[0].tuning, LIVELY); assert.equal((await w.cast(["try", "tuning", "teller", "--scope", "cast", "--list", "--json"])).json().tries.length, 1); assert.equal((await w.cast(["try", "tuning", "teller", "--scope", "project", "--list", "--json"])).json().tries.length, 0, "the cast's try is not this video's character's"); r = await w.cast(["try", "tuning", "teller", "--scope", "everywhere"]); assert.match(r.text(), /--scope is cast or project \(got everywhere\)/); }); test("the tries' writes hold a lock (review 1 #14): writes at once all land; a tuned file no row names is swept once old", async () => { const w = await world({ bare: true }); const row = (key, reading) => ({ key, character: "teller", layer: "cast", voice: "orpheus:tara", text: "x", tuning: LIVELY, reading, rel: `narration/auditions/${key}.wav`, at: new Date().toISOString() }); await Promise.all([addTry(w.dir, row("a".repeat(20), 0)), addTry(w.dir, row("b".repeat(20), 1)), addTry(w.dir, row("c".repeat(20), 2))]); assert.deepEqual((await readTries(w.dir)).map((r) => r.key).sort(), ["a", "b", "c"].map((c) => c.repeat(20))); // Orphans: a tuned ask's files no row names -- swept once ORPHAN_AGE_MS old; a young one (a try still being kept) // and an untuned candidate's stay. A tries.json that does not parse loses its rows; the sweep tidies their files. const auditions = path.join(w.dir, "narration", "auditions"); const meta = async (key, o) => { await writeFile(path.join(auditions, `${key}.json`), JSON.stringify({ key, engine: "orpheus", voice: "tara", text: "x", ...o })); await writeFile(path.join(auditions, `${key}.wav`), "RIFF"); }; const old = new Date(Date.now() - ORPHAN_AGE_MS - 60_000).toISOString(); await meta("d".repeat(20), { at: old, asked: { tuning: LIVELY, reading: 0 } }); await meta("e".repeat(20), { at: new Date().toISOString(), asked: { tuning: LIVELY, reading: 1 } }); await meta("f".repeat(20), { at: old }); await writeFile(path.join(w.dir, ...TRIES_FILE.split("/")), "{ not json"); const r = await addTry(w.dir, row("9".repeat(20), 0)); assert.deepEqual(r.removed, ["d".repeat(20)]); const left = await readdir(auditions); for (const k of ["e", "f"]) assert.ok(left.includes(`${k.repeat(20)}.wav`), `${k}: kept`); assert.ok(!left.includes(`${"d".repeat(20)}.wav`)); assert.ok(!left.some((f) => f.endsWith(".lock")), "the lock is let go"); }); test("tuningView: the takes the editor will use, said", () => { assert.deepEqual(tuningView(null, 3), { tuning: null, name: "default", effective: { temperature: 0.55, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2, takes: 3 }, takesFrom: "setting" }); assert.equal(tuningView({ takes: 3 }, 5).effective.takes, 5, "takes 3 is not kept: the setting's"); assert.equal(tuningView({ takes: 2 }, 5).effective.takes, 2); });