Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit dcd0107e2a4a11f68c7221d7afae06c2e7c639ff
parent 7af86a77074c78a374cf91f26994f434eb3e3cf1
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 17 Nov 2026 10:25:15 -0500

Voices tuning review 1: Another reading counted by the CLI, honest job polls, one press one job

- Another reading posts another:true; the CLI counts from the line as it is
  said (whitespace, paragraphs, masked words), never the typed text.
- A job poll that is not the job's (404, unreachable) is a failed read, never
  "made"; only the finished job's own try plays.
- A press waiting for its answer holds the buttons (a ref: a double click is
  one job).
- The preset editor is not remounted by Keep (its tuning is out of its key):
  unsaved edits above stay.
- Keep says the CLI's notes and sets the takes field to what is stored; the
  form compares with the STORED tuning, so takes equal to the setting can be
  pinned.
- try/tries carry the preset's scope; the route refuses a who that is not an
  id or @handle, and a tuning value that is not a number.
- The fixture's handle is an obviously invented one.

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mumtool/app/api/report/voices/route.ts | 31++++++++++++++++++++++---------
Mumtool/components/projects/CharacterPresets.tsx | 3++-
Mumtool/components/projects/CharacterTuning.tsx | 162+++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------
Mumtool/components/projects/VoicesPanel.tsx | 2+-
Mumtool/e2e/character-tuning.spec.ts | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
Mumtool/e2e/fixtures/tuning-fixture.mjs | 12++++++------
6 files changed, 207 insertions(+), 88 deletions(-)

diff --git a/umtool/app/api/report/voices/route.ts b/umtool/app/api/report/voices/route.ts @@ -29,10 +29,11 @@ export const dynamic = "force-dynamic"; // engines and their stock voices, the job running // GET ?project&who&voices=a,b[&text|&item] an audition as it is kept (auditionView: nothing asked) // GET ?job=<id>[&since&sinceEvent] that job -// GET ?project&tries=<who> a character's TRIES (umtool cast try <p> <who> --list): its tuning, +// GET ?project&tries=<who>[&scope=cast|project] a character's TRIES (umtool cast try <p> <who> --list): its tuning, // the line the page prefills, the tries kept (newest first) -// POST { project, op: "try", who, text, tuning: { temperature, top_p, repeat_penalty, takes? }, reading } a JOB: one -// line read in the character's voice with that tuning and reading +// POST { project, op: "try", who, scope?, text, tuning: { temperature, top_p, repeat_penalty, takes? }, reading | another: true } +// a JOB: one line read in the character's voice (of that layer) with +// that tuning and reading -- or the next after the highest kept // (umtool cast try: the editor's tts; scratch, no take, no draft) // POST { project, op: "audition", who, voices: [..], text?, item? } a JOB: the editor's tts for the candidates not // kept, then (with a reference) their closeness to the real voice @@ -131,7 +132,11 @@ function tuningArgs(t: unknown): string[] { if (!t || typeof t !== "object" || Array.isArray(t)) throw new TuningAskError("a tuning is { temperature, top_p, repeat_penalty, takes }"); const o = t as Record<string, unknown>; for (const k of Object.keys(o)) { - if (k in TUNING_FIELD_FLAGS) continue; + if (k in TUNING_FIELD_FLAGS) { + const v = o[k]; + if (v !== undefined && v !== null && v !== "" && !(typeof v === "number" && Number.isFinite(v))) throw new TuningAskError(`tuning.${k} is a number (got ${JSON.stringify(v)})`); + continue; + } const dflt = (ORPHEUS_TUNING_DEFAULTS as Record<string, number>)[k]; if (dflt !== undefined && (o[k] === null || o[k] === undefined || Number(o[k]) === dflt)) continue; throw new TuningAskError(`a character keeps temperature, top_p, repeat penalty and takes (not ${k})`); @@ -145,6 +150,11 @@ function tuningArgs(t: unknown): string[] { } class TuningAskError extends Error {} +/** A character as an argv word: its id, or an @handle -- never a flag. */ +const whoOk = (v: string) => /^[a-z0-9][a-z0-9_-]{0,47}$/.test(v) || /^@[a-z0-9_.-]{1,64}$/i.test(v); +/** The layer a try's character is looked up in: "cast", "project", or none (this video's own first). */ +const scopeArgs = (v: unknown): string[] => (v === "cast" || v === "project" ? ["--scope", v] : []); + /** The checkout's heavy-slot CLI, when this umtool sits in the checkout (speakerCheck.mjs's rule). */ function queueLockScript() { const file = path.join(/* turbopackIgnore: true */ UMTOOL_DIR, "..", "scripts", "queue-lock.mjs"); @@ -170,7 +180,8 @@ export async function GET(request: Request) { const tries = url.searchParams.get("tries"); try { if (tries) { - const r = await cli(["try", project.id, tries, "--list"]); + if (!whoOk(tries)) return Response.json({ error: "a character's id, or @handle" }, { status: 400 }); + const r = await cli(["try", project.id, tries, ...scopeArgs(url.searchParams.get("scope")), "--list"]); return Response.json(r.code === 0 ? r.json : { error: r.error }, { status: r.code === 0 ? 200 : 400, headers }); } if (who) { @@ -241,9 +252,11 @@ export async function POST(request: Request) { // ONE LINE read in the character's voice with a tuning and a reading: the CLI's own command as a job (scratch). const who = s("who"); const text = s("text"); - if (!who) return Response.json({ error: "a try is of a character" }, { status: 400 }); + if (!who || !whoOk(who)) return Response.json({ error: "a try is of a character: its id, or @handle" }, { status: 400 }); if (!text) return Response.json({ error: "type the line to read" }, { status: 400 }); - const reading = b.reading === undefined || b.reading === null || b.reading === "" ? 0 : Number(b.reading); + // Another reading: the CLI counts the next one from what it keeps (the line as it is said, not as typed). + const another = b.another === true; + const reading = another || b.reading === undefined || b.reading === null || b.reading === "" ? 0 : b.reading; const readingError = ttsReadingError(reading); if (readingError) return Response.json({ error: readingError }, { status: 400 }); let tuning: string[]; @@ -257,8 +270,8 @@ export async function POST(request: Request) { const running = runningJob(); if (running) return Response.json({ error: `another job is running (${running.kind}): Read it is open again when it ends`, busy: true, running: jobView(running) }, { status: 409 }); const cliPath = path.join(/* turbopackIgnore: true */ UMTOOL_DIR, "bin", "umtool.mjs"); - const argv = [process.execPath, cliPath, "cast", "try", project.id, who, "--text", text, ...tuning, "--reading", String(reading), "--progress", "ndjson"]; - const job = startJob(`cast-try ${project.id}`, [{ label: `${who}: the line read (the editor's tts), reading ${reading}`, argv, cwd: path.join(/* turbopackIgnore: true */ UMTOOL_DIR, ".."), env: {}, ndjson: true, timeoutMs: 45 * 60 * 1000 }], { project: project.id }); + const argv = [process.execPath, cliPath, "cast", "try", project.id, who, ...scopeArgs(b.scope), "--text", text, ...tuning, ...(another ? ["--another"] : ["--reading", String(reading)]), "--progress", "ndjson"]; + const job = startJob(`cast-try ${project.id}`, [{ label: `${who}: the line read (the editor's tts), ${another ? "another reading" : `reading ${reading}`}`, argv, cwd: path.join(/* turbopackIgnore: true */ UMTOOL_DIR, ".."), env: {}, ndjson: true, timeoutMs: 45 * 60 * 1000 }], { project: project.id }); return Response.json({ ok: true, job: jobView(job) }, { headers }); } if (op === "use") { diff --git a/umtool/components/projects/CharacterPresets.tsx b/umtool/components/projects/CharacterPresets.tsx @@ -126,7 +126,8 @@ export function PresetEditor({ /** The reads by this character made with other settings than its tuning now (cast.mjs tuningStale). */ stale?: StaleRead[]; }) { - // (The panel keys this editor by the character as it is stored: another one opened, or this one saved, is a new form.) + // (The panel keys this editor by the character as it is stored: another one opened, or this one saved, is a new form. + // Its Orpheus tuning is left out of the key: Keep these settings must not throw away unsaved edits above it.) const [f, setF] = useState<Form>(() => formOf(c)); const set = <K extends keyof Form>(k: K, v: Form[K]) => setF((x) => ({ ...x, [k]: v })); const follows = f.convertPitch === "source" || f.convertPitch === "contour"; diff --git a/umtool/components/projects/CharacterTuning.tsx b/umtool/components/projects/CharacterTuning.tsx @@ -22,9 +22,9 @@ import { ORPHEUS_TUNING_NAMED, ORPHEUS_TUNING_NAMES, TTS_TUNING_RANGES, ttsTunin export type TuningFields = { temperature?: number; top_p?: number; repeat_penalty?: number; takes?: number }; export type StaleRead = { id: string; role: string; character: string; reading: number; made: Record<string, number>; want: Record<string, number> }; type TuningView = { tuning: TuningFields | null; name: string; effective: Record<string, number>; takesFrom: "character" | "setting" }; -type TryRow = { key: string; character: string; voice: string; text: string; tuning: TuningFields; reading: number; rel: string; seconds: number | null; lufs: number | null; at: string }; +type TryRow = { key: string; character: string; layer?: string | null; voice: string; text: string; tuning: TuningFields; reading: number; rel: string; seconds: number | null; lufs: number | null; at: string }; type Tries = { character: { id: string; name: string; layer: string | null; voice: string | null; tuning: TuningView }; line: { text: string; from: string }; settingTakes: number; tries: TryRow[] }; -type JobPoll = { id: string; state: "running" | "done" | "failed"; error: string | null; kind?: string }; +type JobPoll = { id: string; state: "running" | "done" | "failed"; error: string | null; kind?: string; events?: { ev?: string; phase?: string; key?: string; reading?: number }[] }; type PostFn = (body: Record<string, unknown>) => Promise<Record<string, unknown> | null>; const FIELDS = [ @@ -57,8 +57,9 @@ function numbersOf(f: Form): { ok: true; t: TuningFields } | { ok: false; field: } return { ok: true, t }; } -const sameTuning = (a: TuningFields, b: TuningFields, dflt: number) => - (["temperature", "top_p", "repeat_penalty"] as const).every((k) => (a[k] ?? ORPHEUS_TUNING_NAMED.default[k]) === (b[k] ?? ORPHEUS_TUNING_NAMED.default[k])) && (a.takes ?? dflt) === (b.takes ?? dflt); +/** The form's numbers the same as the tuning KEPT: the sampler's three (unsaid: the default) and takes as stored (none: none). */ +const sameAsStored = (a: TuningFields, stored: TuningFields) => + (["temperature", "top_p", "repeat_penalty"] as const).every((k) => (a[k] ?? ORPHEUS_TUNING_NAMED.default[k]) === (stored[k] ?? ORPHEUS_TUNING_NAMED.default[k])) && (a.takes ?? null) === (stored.takes ?? null); const numbersWords = (t: TuningFields, settingTakes: number) => `temperature ${t.temperature ?? ORPHEUS_TUNING_NAMED.default.temperature} · top_p ${t.top_p ?? ORPHEUS_TUNING_NAMED.default.top_p} · repeat penalty ${t.repeat_penalty ?? ORPHEUS_TUNING_NAMED.default.repeat_penalty} · takes ${t.takes ?? settingTakes}`; @@ -76,32 +77,48 @@ export function CharacterTuning({ const [renderWait, setRenderWait] = useState<string | null>(null); const [error, setError] = useState<string | null>(null); const [status, setStatus] = useState<string | null>(null); + const [notes, setNotes] = useState<string[]>([]); + // A press sent and not answered yet: a second press waits (no second job, no second follow). + const [pending, setPending] = useState(false); + // The same, read synchronously: two clicks inside one render both see `pending` false. + const pendingRef = useRef(false); const timer = useRef<ReturnType<typeof setTimeout> | null>(null); - const newest = useRef<HTMLAudioElement | null>(null); - const playNext = useRef(false); + const audios = useRef<Map<string, HTMLAudioElement>>(new Map()); + // The try a finished job made: it plays when the list is read again, and only it. + const playKey = useRef<string | null>(null); const load = useCallback(async () => { - const r = await fetch(`/api/report/voices?project=${encodeURIComponent(project)}&tries=${encodeURIComponent(id)}`, { cache: "no-store" }); - const j = (await r.json().catch(() => null)) as (Tries & { error?: string }) | null; + let r: Response; + let j: (Tries & { error?: string }) | null = null; + try { + r = await fetch(`/api/report/voices?project=${encodeURIComponent(project)}&tries=${encodeURIComponent(id)}&scope=${scope}`, { cache: "no-store" }); + j = (await r.json().catch(() => null)) as (Tries & { error?: string }) | null; + } catch (e) { + playKey.current = null; + setError(`the tries could not be read: ${e instanceof Error ? e.message : String(e)}`); + return; + } if (!r.ok || !j) { + playKey.current = null; setError(j?.error ?? `HTTP ${r.status}`); return; } setData(j); setForm((f) => f ?? formOf(j.character.tuning.tuning, j.character.tuning.effective)); setText((t) => t ?? j.line.text); - }, [project, id]); + }, [project, id, scope]); useEffect(() => { void load(); return () => { if (timer.current) clearTimeout(timer.current); }; }, [load]); - // A new try plays when its job ends (the list re-read, its row first). + // A new try plays when its job ends: the row of the key that job made, once the list is read again. useEffect(() => { - if (!playNext.current || !newest.current) return; - playNext.current = false; - void newest.current.play().catch(() => undefined); + const k = playKey.current; + if (!k) return; + playKey.current = null; + void audios.current.get(k)?.play().catch(() => undefined); }, [data]); const settingTakes = data?.settingTakes ?? 3; @@ -109,67 +126,91 @@ export function CharacterTuning({ const tuning = nums?.ok ? nums.t : null; const named = tuning ? ttsTuningNameOf(tuning) : "custom"; const kept = data?.character.tuning.tuning ?? {}; - const isKept = !!tuning && sameTuning(tuning, kept, settingTakes); + const isKept = !!tuning && sameAsStored(tuning, kept); const running = job?.state === "running"; - const off = busy || running || !!blocked || !orpheus; + const off = busy || running || pending || !!blocked || !orpheus; - /** Follow a job to its end; while it runs, say when render mode holds the machine. */ + /** + * Follow a job to its end; while it runs, say when render mode holds the machine. An answer that is not the job's + * (umtool restarted: no such job) or a poll that cannot reach umtool ends it as failed -- never as made. + */ const follow = useCallback((jobId: string, then: (j: JobPoll) => void) => { + if (timer.current) clearTimeout(timer.current); const tick = async () => { - const r = await fetch(`/api/report/voices?job=${encodeURIComponent(jobId)}`, { cache: "no-store" }); - const j = (await r.json().catch(() => null)) as JobPoll | null; + let j: JobPoll; + try { + const r = await fetch(`/api/report/voices?job=${encodeURIComponent(jobId)}`, { cache: "no-store" }); + const body = (await r.json().catch(() => null)) as (JobPoll & { error?: string }) | null; + j = r.ok && body && typeof body.state === "string" ? body : { id: jobId, state: "failed", error: body?.error ?? `HTTP ${r.status}` }; + } catch (e) { + j = { id: jobId, state: "failed", error: `the job could not be followed: ${e instanceof Error ? e.message : String(e)}` }; + } const rm = (await fetch("/api/render-mode", { cache: "no-store" }).then((x) => x.json()).catch(() => null)) as { held?: boolean; what?: string | null } | null; - setRenderWait(rm?.held ? `Waiting for the render (${rm.what ?? "render mode is on"}): the read is made when it lets go.` : null); - if (!j || j.state === "running") { + setRenderWait(j.state === "running" && rm?.held ? `Waiting for the render (${rm.what ?? "render mode is on"}): the read is made when it lets go.` : null); + if (j.state === "running") { timer.current = setTimeout(() => void tick(), 1000); return; } - setRenderWait(null); then(j); }; void tick(); }, []); - const read = async (reading: number) => { - if (!tuning || !text?.trim()) return; + const read = async (ask: { reading: number } | { another: true }) => { + if (!tuning || !text?.trim() || pendingRef.current) return; + pendingRef.current = true; + setPending(true); setError(null); setStatus(null); - const r = await fetch("/api/report/voices", { - method: "POST", headers: { "content-type": "application/json" }, - body: JSON.stringify({ project, op: "try", who: id, text: text.trim(), tuning: { ...tuning, takes: tuning.takes ?? null }, reading }), - }); - const j = (await r.json().catch(() => ({}))) as { job?: JobPoll; error?: string; running?: JobPoll }; - if (r.status === 409 && j.running) { - // Another job holds umtool's runner: said here, the buttons open again when it ends. - setBlocked(`Another job is running (${j.running.kind ?? "a job"}): Read it is open again when it ends.`); - follow(j.running.id, () => setBlocked(null)); - return; - } - if (!r.ok || !j.job) { - setError(j.error ?? `HTTP ${r.status}`); - return; - } - setJob(j.job); - follow(j.job.id, (done) => { - setJob(done); - if (done.state === "failed") setError(`the read failed: ${done.error ?? "see the job's log on /jobs"}`); - else { - playNext.current = true; - setStatus(`reading ${reading} made`); + try { + let r: Response; + let j: { job?: JobPoll; error?: string; running?: JobPoll }; + try { + r = await fetch("/api/report/voices", { + method: "POST", headers: { "content-type": "application/json" }, + body: JSON.stringify({ project, op: "try", who: id, scope, text: text.trim(), tuning: { ...tuning, takes: tuning.takes ?? null }, ...ask }), + }); + j = (await r.json().catch(() => ({}))) as typeof j; + } catch (e) { + setError(`umtool could not be reached: ${e instanceof Error ? e.message : String(e)}`); + return; } - void load(); - }); - }; - const another = () => { - if (!tuning || !text) return; - const mine = (data?.tries ?? []).filter((t) => t.voice === voice && t.text === text.trim() && sameTuning(t.tuning ?? {}, tuning, settingTakes)); - void read(mine.length ? Math.max(...mine.map((t) => t.reading)) + 1 : 1); + if (r.status === 409 && j.running) { + // Another job holds umtool's runner: said here, the buttons open again when it ends. + setBlocked(`Another job is running (${j.running.kind ?? "a job"}): Read it is open again when it ends.`); + follow(j.running.id, () => setBlocked(null)); + return; + } + if (!r.ok || !j.job) { + setError(j.error ?? `HTTP ${r.status}`); + return; + } + setJob(j.job); + follow(j.job.id, (done) => { + setJob(done); + const made = (done.events ?? []).find((ev) => ev?.ev === "cast-try" && ev.phase === "done" && typeof ev.key === "string"); + if (done.state !== "done" || !made) setError(`the read failed: ${done.error ?? "see the job's log on /jobs"}`); + else { + playKey.current = made.key ?? null; + setStatus(`reading ${made.reading ?? 0} made`); + } + void load(); + }); + } finally { + pendingRef.current = false; + setPending(false); + } }; const keep = async () => { if (!tuning) return; - const j = await post({ op: "character-set", scope, id, tuning: { ...tuning, takes: tuning.takes ?? null } }); + setNotes([]); + const j = (await post({ op: "character-set", scope, id, tuning: { ...tuning, takes: tuning.takes ?? null } })) as { notes?: string[]; tuning?: TuningView } | null; if (j) { onKept(`${name}: Orpheus tuning kept (${NAME_LABEL[named]}) ${scope === "cast" ? "in the cast (every project)" : "for this video only"}`); + // What the CLI said beside it (takes 3 not kept, a voice that ignores it), and the takes field as it is stored. + setNotes(Array.isArray(j.notes) ? j.notes : []); + const storedTakes = j.tuning?.tuning?.takes; + setForm((f) => (f ? { ...f, takes: typeof storedTakes === "number" ? String(storedTakes) : "" } : f)); void load(); } }; @@ -223,13 +264,13 @@ export function CharacterTuning({ data-tuning-text="" aria-label="the line to try" value={text ?? ""} onChange={(e) => setText(e.target.value)} rows={2} maxLength={400} className={cn(input, "min-w-[18rem] flex-1")} disabled={!orpheus} /> - <button type="button" data-tuning-read="" aria-label="Read the line with these settings" disabled={off || !tuning || !text?.trim()} onClick={() => void read(0)} className={buttonVariants({ variant: "outline", size: "sm" })}> + <button type="button" data-tuning-read="" aria-label="Read the line with these settings" disabled={off || !tuning || !text?.trim()} onClick={() => void read({ reading: 0 })} className={buttonVariants({ variant: "outline", size: "sm" })}> Read it </button> - <button type="button" data-tuning-another="" aria-label="Read the same line again, the next reading" disabled={off || !tuning || !text?.trim()} onClick={another} className={buttonVariants({ variant: "outline", size: "sm" })}> + <button type="button" data-tuning-another="" aria-label="Read the same line again, the next reading" disabled={off || !tuning || !text?.trim()} onClick={() => void read({ another: true })} className={buttonVariants({ variant: "outline", size: "sm" })}> Another reading </button> - <button type="button" data-tuning-keep="" aria-label={`Keep these settings for ${name} (${scope === "cast" ? "the cast" : "this video"})`} disabled={busy || running || !tuning || isKept || !orpheus} onClick={() => void keep()} className={buttonVariants({ variant: "go", size: "sm" })}> + <button type="button" data-tuning-keep="" aria-label={`Keep these settings for ${name} (${scope === "cast" ? "the cast" : "this video"})`} disabled={busy || running || pending || !tuning || isKept || !orpheus} onClick={() => void keep()} className={buttonVariants({ variant: "go", size: "sm" })}> Keep these settings </button> </div> @@ -237,12 +278,17 @@ export function CharacterTuning({ {renderWait && <p className="m-0 mt-1 text-[11.5px] text-doubt-text" data-tuning-render-wait="">{renderWait}</p>} {blocked && <p className="m-0 mt-1 text-[11.5px] text-doubt-text" data-tuning-blocked="">{blocked}</p>} {status && <p className="m-0 mt-1 text-[11.5px] text-text-2" data-tuning-status="">{status}</p>} + {notes.map((n) => ( + <p key={n} className="m-0 mt-1 text-[11.5px] text-doubt-text" data-tuning-note=""> + note: {n} + </p> + ))} {error && <p role="alert" className="m-0 mt-1 text-[11.5px] text-reject-text" data-tuning-error="">{error}</p>} {data && data.tries.length > 0 && ( <table className="mt-2 w-full border-collapse text-[11.5px]" data-tuning-tries={data.tries.length}> <tbody> - {data.tries.map((t, i) => ( + {data.tries.map((t) => ( <tr key={t.key} data-tuning-try={t.reading} data-tuning-try-key={t.key} className="align-top"> <td className="border-t border-seam px-1.5 py-1 text-text-2">{t.text.length > 70 ? `${t.text.slice(0, 70)}…` : t.text}</td> <td className="border-t border-seam px-1.5 py-1 font-mono text-[11px]" data-tuning-try-numbers=""> @@ -250,7 +296,7 @@ export function CharacterTuning({ </td> <td className="border-t border-seam px-1.5 py-1 whitespace-nowrap">reading {t.reading}</td> <td className="border-t border-seam px-1.5 py-1 w-[16rem]"> - <audio ref={i === 0 ? (a) => { newest.current = a; } : undefined} controls preload="none" src={fileUrl(project, t.rel, t.key)} className="w-full" aria-label={`play reading ${t.reading}`} data-tuning-try-audio="" /> + <audio ref={(a) => { if (a) audios.current.set(t.key, a); else audios.current.delete(t.key); }} controls preload="none" src={fileUrl(project, t.rel, t.key)} className="w-full" aria-label={`play reading ${t.reading}`} data-tuning-try-audio="" /> {t.lufs !== null && <span className="text-[10.5px] text-muted" title="every try is brought to one loudness, so they compare by ear, not by level">{t.lufs.toFixed(1)} LUFS</span>} </td> <td className="border-t border-seam px-1.5 py-1 whitespace-nowrap"> diff --git a/umtool/components/projects/VoicesPanel.tsx b/umtool/components/projects/VoicesPanel.tsx @@ -424,7 +424,7 @@ export default function VoicesPanel({ project, posts, initialWho = null }: { pro {/* --- one character's presets --------------------------------------------------- */} {preset && presetOf && ( <> - <PresetEditor key={`${preset.scope}:${preset.id}:${JSON.stringify([presetOf.name, presetOf.shown, presetOf.synthetic, presetOf.recorded])}`} c={presetOf} scope={preset.scope} engines={view.engines} convertEngines={view.convertEngines} busy={busy} post={post} onSaved={changed} onClose={() => setPreset(null)} project={project} stale={(view.tuningStale ?? []).filter((d) => d.character === preset.id)} /> + <PresetEditor key={`${preset.scope}:${preset.id}:${JSON.stringify([presetOf.name, presetOf.shown, { ...presetOf.synthetic, tuning: undefined }, presetOf.recorded])}`} c={presetOf} scope={preset.scope} engines={view.engines} convertEngines={view.convertEngines} busy={busy} post={post} onSaved={changed} onClose={() => setPreset(null)} project={project} stale={(view.tuningStale ?? []).filter((d) => d.character === preset.id)} /> {preset.scope === "cast" && !own.some((c) => c.id === preset.id) && ( <p className="m-0 -mt-3 text-[11.5px] text-text-2"> <button type="button" data-character-keep={preset.id} disabled={busy} onClick={() => void keepHere(preset.id, presetOf.name)} className="ink-link"> diff --git a/umtool/e2e/character-tuning.spec.ts b/umtool/e2e/character-tuning.spec.ts @@ -13,10 +13,12 @@ import { TUNING_LINE } from "./fixtures/tuning-fixture.mjs"; // three reads of it (made with the defaults; with its line's own tuning; recorded). Every step a press: // // Lively fills the numbers; a number edited is "custom" -// the line it reads in this project, prefilled; Read it -> a job (the stub editor's tts) -> a try, reading 0; -// Another reading -> reading 1, the same numbers -// another job running: said in place, the buttons open again when it ends -// Keep these settings -> umtool cast project <p> set: the preset says the tuning kept +// the line it reads in this project, prefilled; Read it (pressed twice: one job) -> a job (the stub editor's tts) +// -> a try, reading 0; Another reading -> reading 1, then 2 -- counted from the line as it is said, not as typed +// another job running: said in place, the buttons open again when it ends; a job umtool no longer knows: failed +// Keep these settings (takes 3 typed) -> umtool cast project <p> set: the preset says the tuning kept, the note +// beside it, the takes field as stored; an unsaved edit above it stays +// the route refuses a flag as a character and a tuning value that is not a number // the read made with the defaults is now one made with other settings (listed, never re-made) // and nothing the cut shows changed: the manifest, every drawn card, no take // --------------------------------------------------------------------------- @@ -84,25 +86,34 @@ test("a character's tuning: Lively, Read it, Another reading, Keep -- its stale await tune.locator('[data-tuning-pick="lively"]').click(); await expect(tune.locator("[data-tuning-custom]")).toHaveCount(0); - // Read it: a job (the stub editor's tts, asked with the numbers), a try at reading 0 in the list. - await tune.getByRole("button", { name: "Read the line with these settings" }).click(); + // The line typed with doubled spaces: what is SAID collapses them (Another reading counts from that, review 1 #3). + const typed = TUNING_LINE.replace(/ /g, " "); + await tune.locator("[data-tuning-text]").fill(typed); + // Read it, pressed twice at once (review 1 #5): one job, one ask, nothing "already running". + await tune.getByRole("button", { name: "Read the line with these settings" }).dblclick(); await expect(tune.locator('[data-tuning-try="0"]')).toBeVisible({ timeout: 60_000 }); let asks = ttsAsks().slice(asksBefore); expect(asks).toHaveLength(1); expect(asks[0].tuning).toEqual({ temperature: 0.75, top_p: 0.92, repeat_penalty: 1.25 }); expect(asks[0].reading).toBeUndefined(); expect(asks[0].text).toBe(TUNING_LINE); + await expect(tune.locator("[data-tuning-blocked]")).toHaveCount(0); await expect(tune.locator('[data-tuning-try="0"] [data-tuning-try-numbers]')).toContainText("Lively · temperature 0.75 · top_p 0.92 · repeat penalty 1.25"); await expect(tune.locator('[data-tuning-try="0"] [data-tuning-try-audio]')).toHaveAttribute("src", /narration%2Fauditions%2F[0-9a-f]{20}\.wav/); - // Another reading: the same line and numbers, reading 1. - await tune.getByRole("button", { name: "Read the same line again, the next reading" }).click(); + // Another reading: the same line and numbers, reading 1; and again, reading 2. + const another = tune.getByRole("button", { name: "Read the same line again, the next reading" }); + await another.click(); await expect(tune.locator('[data-tuning-try="1"]')).toBeVisible({ timeout: 60_000 }); + await expect(another).toBeEnabled({ timeout: 60_000 }); + await another.click(); + await expect(tune.locator('[data-tuning-try="2"]')).toBeVisible({ timeout: 60_000 }); asks = ttsAsks().slice(asksBefore); - expect(asks).toHaveLength(2); - expect(asks[1].reading).toBe(1); + expect(asks).toHaveLength(3); + expect(asks.map((a) => a.reading)).toEqual([undefined, 1, 2]); expect(asks[1].tuning).toEqual(asks[0].tuning); - await expect(tune.locator("[data-tuning-tries]")).toHaveAttribute("data-tuning-tries", "2"); + await expect(tune.locator("[data-tuning-tries]")).toHaveAttribute("data-tuning-tries", "3"); + await expect(tune.locator("[data-tuning-status]")).toContainText("reading 2 made"); // Another job running: said in place, Read it closed until it ends (umtool runs one job at a time). let busy = true; @@ -124,7 +135,51 @@ test("a character's tuning: Lively, Read it, Another reading, Keep -- its stale await expect(tune.locator("[data-tuning-read]")).toBeEnabled(); await page.unroute(tryPost); await page.unroute(busyJob); - expect(ttsAsks().slice(asksBefore), "the refused press asked nothing").toHaveLength(2); + expect(ttsAsks().slice(asksBefore), "the refused press asked nothing").toHaveLength(3); + + // A job umtool no longer knows (restarted: 404 on its poll) is a failed read -- never "made", nothing played (review 1 #4). + const goneJob = (u: URL) => u.pathname === "/api/report/voices" && u.searchParams.get("job") === "gone-1"; + await page.route(tryPost, async (route) => { + const body = route.request().postDataJSON() as { op?: string } | null; + if (route.request().method() === "POST" && body?.op === "try") return route.fulfill({ contentType: "application/json", body: JSON.stringify({ ok: true, job: { id: "gone-1", state: "running", error: null } }) }); + return route.continue(); + }); + await page.route(goneJob, (route) => route.fulfill({ status: 404, contentType: "application/json", body: JSON.stringify({ error: "no such job" }) })); + await tune.locator("[data-tuning-read]").click(); + await expect(tune.locator("[data-tuning-error]")).toContainText("the read failed: no such job"); + await expect(tune.locator("[data-tuning-status]")).toHaveCount(0); + await expect(tune.locator("[data-tuning-read]")).toBeEnabled(); + await page.unroute(tryPost); + await page.unroute(goneJob); + + // The route: a flag is never a character; a tuning value is a number (review 1 #16). + const refused = await page.evaluate(async (project) => { + const ask = async (body: Record<string, unknown>) => { + const r = await fetch("/api/report/voices", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ project, ...body }) }); + return [r.status, ((await r.json()) as { error?: string }).error ?? ""]; + }; + return [ + await ask({ op: "try", who: "--project", text: "x", tuning: { temperature: 0.7 }, reading: 0 }), + await ask({ op: "character-set", scope: "project", id: "teller", tuning: { temperature: [0.7] } }), + ]; + }, P); + expect(refused[0]).toEqual([400, "a try is of a character: its id, or @handle"]); + expect(refused[1]).toEqual([400, "tuning.temperature is a number (got [0.7])"]); + + // An edit above the tuning, not saved yet: Keep must not throw it away (review 1 #6). + await ed.locator("[data-preset-direction]").fill("slower, warmer"); + // Takes 3 typed: not what is stored (none), so Keep is open (review 1 #17); the CLI's note is said beside it, and the + // field shows what is stored -- none, the setting's (review 1 #7). The note is the CLI's when the setting is not 3; + // here it is laid on the route's answer, as the CLI words it. + await tune.locator('[data-tuning-field="takes"]').fill("3"); + const keepSet = (u: URL) => u.pathname === "/api/report/voices" && !u.search; + await page.route(keepSet, async (route) => { + const body = route.request().postDataJSON() as { op?: string } | null; + if (route.request().method() !== "POST" || body?.op !== "character-set") return route.continue(); + const res = await route.fetch(); + const j = (await res.json()) as Record<string, unknown>; + return route.fulfill({ response: res, json: { ...j, notes: ["takes 3 is Orpheus's default and is not kept: its reads take the editor's setting (4)"] } }); + }); // Keep these settings: the CLI's own command; the preset says it is kept; the read made with the defaults is stale. await tune.getByRole("button", { name: /Keep these settings for The Teller \(this video\)/ }).click(); @@ -132,6 +187,10 @@ test("a character's tuning: Lively, Read it, Another reading, Keep -- its stale const kept = (JSON.parse(readFileSync(CHARACTERS, "utf8")) as { characters: { id: string; synthetic?: { tuning?: Record<string, number> } }[] }).characters.find((c) => c.id === "teller"); expect(kept?.synthetic?.tuning).toEqual({ temperature: 0.75, top_p: 0.92, repeat_penalty: 1.25 }); const tune2 = page.locator('[data-preset-editor="teller"] [data-tuning="teller"]'); + await expect(tune2.locator("[data-tuning-note]")).toContainText("note: takes 3 is Orpheus's default and is not kept"); + await expect(tune2.locator('[data-tuning-field="takes"]')).toHaveValue(""); + await expect(ed.locator("[data-preset-direction]")).toHaveValue("slower, warmer"); + await page.unroute(keepSet); await expect(tune2).toHaveAttribute("data-tuning-kept", "yes"); await expect(tune2.locator("[data-tuning-effective]")).toContainText("kept: Lively · temperature 0.75 · top_p 0.92 · repeat penalty 1.25"); await expect(tune2.locator("[data-tuning-stale]")).toHaveAttribute("data-tuning-stale", "1"); @@ -139,7 +198,7 @@ test("a character's tuning: Lively, Read it, Another reading, Keep -- its stale await expect(tune2.locator("[data-tuning-stale-item]")).toHaveCount(1); await expect(row.locator("[data-voice-stale]")).toHaveAttribute("data-voice-stale", "1"); // The tries are still there after the keep (scratch, the project's). - await expect(tune2.locator("[data-tuning-tries]")).toHaveAttribute("data-tuning-tries", "2"); + await expect(tune2.locator("[data-tuning-tries]")).toHaveAttribute("data-tuning-tries", "3"); // Nothing the cut shows changed: the manifest byte for byte, every card as drawn, no take made, no script written. expect(readFileSync(MANIFEST, "utf8")).toBe(manifestBefore); diff --git a/umtool/e2e/fixtures/tuning-fixture.mjs b/umtool/e2e/fixtures/tuning-fixture.mjs @@ -2,9 +2,9 @@ // `cast set|try|stale`): one character of this video's own, "teller" (orpheus · tara), and the reads it makes -- // // reports/tuning-fixture/ -// p-1 @teller its picked take orpheus · tara, made with the DEFAULTS (a 262 Hz tone): stale once a tuning is kept -// p-2 @teller its picked take made with its line's OWN tuning (temperature 0.9): never stale -// p-3 @teller its picked take RECORDED: never stale +// p-1 @invented_teller_fixture its picked take orpheus · tara, made with the DEFAULTS (a 262 Hz tone): stale once a tuning is kept +// p-2 @invented_teller_fixture its picked take made with its line's OWN tuning (temperature 0.9): never stale +// p-3 @invented_teller_fixture its picked take RECORDED: never stale // narration/characters.json teller, no tuning yet // // The cast (<fixture>/.umtool/cast.json) is not used: the character is this video's own. The editor is the suite's @@ -25,8 +25,8 @@ export function makeTuningFixture({ reports, manifest, ff }) { const dir = path.join(reports, TUNING); const made = (o = {}) => ({ temperature: 0.55, top_p: 0.85, top_k: 50, min_p: 0, repeat_penalty: 1.2, takes: 3, ...o }); const post = (id, text, take) => ({ - type: "post", id: `p-${id}`, post: `tuningx/${id}`, platform: "x", author: "The Teller", handle: "teller", date: `2026-10-30T1${id}:00:00.000Z`, text, - url: `https://x.com/teller/status/${id}`, engagement: { likes: 1 }, section: 0, + type: "post", id: `p-${id}`, post: `tuningx/${id}`, platform: "x", author: "The Teller", handle: "invented_teller_fixture", date: `2026-10-30T1${id}:00:00.000Z`, text, + url: `https://x.com/invented_teller_fixture/status/${id}`, engagement: { likes: 1 }, section: 0, narration: { script: text, takes: [{ seconds: 2, script: text, at: "2026-11-02T00:00:00.000Z", ...take }], pick: 0 }, }); const tone = (rel) => { @@ -42,7 +42,7 @@ export function makeTuningFixture({ reports, manifest, ff }) { write(dir, "video.manifest.json", manifest(TUNING, "The Tuning Fixture", {}, timeline)); write(path.join(dir, "narration"), "characters.json", { format: "umtool-project-characters", version: 1, - characters: [{ id: "teller", name: "The Teller", handles: ["teller"], synthetic: { voice: "orpheus:tara" } }], + characters: [{ id: "teller", name: "The Teller", handles: ["invented_teller_fixture"], synthetic: { voice: "orpheus:tara" } }], }); return dir; }