// Run with: // pnpm -C editor exec tsx --test "app/api/ops/_speakers.test.ts" // // `pnpm ops lane` for the Speakers lane — its `operations` narrowing, its // `order`, its one control (`speakers`: work | pause) — and `pnpm ops get // speakers`, against the route handlers over a temp corpus. Never the live // editor's settings. import { test } from "node:test"; import assert from "node:assert/strict"; import { writeFileSync } from "node:fs"; import path from "node:path"; import { callGet, callPost, setupOpsCorpus } from "./_testCorpus"; const corpus = await setupOpsCorpus(null); const RENDER_STATE = path.join(corpus.root, "render-priority.json"); process.env.RENDER_PRIORITY_FILE = RENDER_STATE; const { POST } = await import("./lane/route"); const { GET } = await import("./speakers/route"); const { getSettings } = await import("yt-dlp-transcript-common/lib/settings"); test.after(() => corpus.cleanup()); const DIARIZATION = { enabled: true, segModel: "/m/seg.onnx", embModel: "/m/emb.onnx", }; test("lane: operations narrows the Speakers lane (and null widens it), order takes \"space\"; bad values are 400s", async () => { await corpus.writeSettings({ minFreeDiskGB: 0, diarization: DIARIZATION, attribution: { enabled: true, textOnlyEnabled: true, diarizedEnabled: true } }); const ok = await callPost(POST!, { lane: "backfill", operations: ["diarization"], order: "space" }); assert.equal(ok.status, 200, JSON.stringify(ok.body)); assert.deepEqual(getSettings().autoQueue.backfill.operations, ["diarization"]); assert.equal(getSettings().autoQueue.backfill.order, "space"); const unknown = await callPost(POST!, { lane: "backfill", operations: ["no-such-op"] }); assert.equal(unknown.status, 400); assert.match(String(unknown.body.error), /Not an enabled operation on the backfill lane: no-such-op/); assert.equal((await callPost(POST!, { lane: "backfill", order: "biggest" })).status, 400); assert.equal((await callPost(POST!, { lane: "backfill", operations: "diarization" })).status, 400); assert.equal((await callPost(POST!, { lane: "digest", speakers: "work" })).status, 400); const widened = await callPost(POST!, { lane: "backfill", operations: null }); assert.equal(widened.status, 200, JSON.stringify(widened.body)); assert.equal(getSettings().autoQueue.backfill.operations, undefined); assert.equal(getSettings().autoQueue.backfill.order, "space", "order untouched by an operations write"); }); // `speakers: "work" | "pause"` goes through the lane actions, which revalidate // pages and so need a request: the e2e suite drives them (speakers-run.spec, // backfill.spec). Here: what `get speakers` says about a held lane. test("get speakers: the line, the lane's state and the two capture settings", async () => { await corpus.writeSettings({ minFreeDiskGB: 0, diarization: { ...DIARIZATION, cleanAfterCapture: true }, autoQueue: { ...getSettings().autoQueue, backfill: { ...getSettings().autoQueue.backfill, enabled: false, held: true } }, }); const got = await callGet(GET!, "http://localhost/api/ops/speakers"); assert.equal(got.status, 200, JSON.stringify(got.body)); const lane = got.body.lane as { held: boolean; armed: boolean; cleanAfterCapture: boolean; requireVoiceprints: boolean }; assert.deepEqual( { held: lane.held, armed: lane.armed, cleanAfterCapture: lane.cleanAfterCapture, requireVoiceprints: lane.requireVoiceprints }, { held: true, armed: false, cleanAfterCapture: true, requireVoiceprints: true }, ); assert.equal(got.body.line, "waiting: 0 B in 0 videos · freed this run: 0 B · nothing left"); assert.deepEqual(got.body.channels, []); }); test("lane speakers:work refuses an un-narrowed lane, and a lane a render holds — writing nothing", async () => { await corpus.writeSettings({ minFreeDiskGB: 0, diarization: DIARIZATION, attribution: { enabled: true, textOnlyEnabled: true, diarizedEnabled: true }, autoQueue: { ...getSettings().autoQueue, backfill: { ...getSettings().autoQueue.backfill, enabled: false, held: true, operations: undefined } }, }); const wide = await callPost(POST!, { lane: "backfill", speakers: "work" }); assert.equal(wide.status, 400); assert.match(String(wide.body.error), /not narrowed to speaker diarization/); assert.match(String(wide.body.error), /"operations":\["diarization"\]/); assert.equal(getSettings().autoQueue.backfill.held, true); assert.equal(getSettings().autoQueue.backfill.enabled, false); await corpus.writeSettings({ minFreeDiskGB: 0, diarization: DIARIZATION, autoQueue: { ...getSettings().autoQueue, backfill: { ...getSettings().autoQueue.backfill, enabled: false, held: true, operations: ["diarization"] } }, }); writeFileSync( RENDER_STATE, JSON.stringify({ version: 1, token: "tok", since: new Date().toISOString(), until: null, holder: { pid: process.pid, cmd: "umtool take ember --id t1" }, lanesHeld: ["backfill"], editor: "http://localhost:3001", }), ); const rendering = await callPost(POST!, { lane: "backfill", speakers: "work" }); assert.equal(rendering.status, 400); assert.match(String(rendering.body.error), /A render holds the Speakers lane \(umtool take ember --id t1\)/); assert.equal(getSettings().autoQueue.backfill.held, true, "the render's hold stands"); });