// Operations UI (UI notes 2026-10-30, #9 #10 #15 #18): the sites a cut's // links depend on and their deploys, the per-project link policy, the speaker // check, the render queue and a take's ETA. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { mkdir, mkdtemp, readFile, rm, utimes, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; // SITES_DIR is read when lib/paths.mjs loads: point it at this file's own // sites before anything imports it. const SITES = await mkdtemp(path.join(tmpdir(), "ui-ops-sites-")); process.env.SITES_DIR = SITES; await mkdir(path.join(SITES, "anilyzer"), { recursive: true }); await writeFile(path.join(SITES, "anilyzer", "site.json"), JSON.stringify({ siteTitle: "Anilyzer", siteUrl: "https://site.test/" })); await mkdir(path.join(SITES, "other"), { recursive: true }); await writeFile(path.join(SITES, "other", "site.json"), JSON.stringify({ siteTitle: "Other", siteUrl: "https://other.test" })); test.after(() => rm(SITES, { recursive: true, force: true })); const { dayOf, deployBehindWhy, originOf, projectSites, sitesByOrigin } = await import("./siteDeploys.mjs"); const { runLinkCheck } = await import("./linkCheck.mjs"); const { decisionsFor } = await import("../projects/core.mjs"); const { walkProjects } = await import("../projects/walk.mjs"); const SITE = "https://site.test"; const url = (chan, id, t, site = SITE) => `${site}/?v=${encodeURIComponent(`${chan}/${id}`)}&t=${t}`; const manifestOf = (timeline, extra = {}) => ({ schemaVersion: 1, slug: "cut", title: "Cut", provenance: { channelSlug: "c", siteOrigin: SITE }, render: { width: 1920, height: 1080, fps: 30 }, timeline, ...extra, }); /** A fake archive: corpus.json generatedAt 2026-10-09, channel c holding `ids`. */ function fakeSite(ids = ["v1"]) { return async (u) => { const p = new URL(String(u)).pathname; const json = (doc) => ({ ok: true, status: 200, json: async () => doc }); if (p === "/corpus.json") { return json({ spec: 5, generatedAt: "2026-10-09T10:00:00.000Z", site: { title: "Site" }, channels: [{ slug: "c", manifests: { transcripts: `${SITE}/transcripts/c/manifest.json` } }] }); } if (p === "/transcripts/c/manifest.json") return json({ pageCount: 1, slugToPage: Object.fromEntries(ids.map((i) => [i, 0])) }); if (p === "/transcripts/c/page-0000.json") return json(ids.map((id) => ({ id }))); return { ok: false, status: 404, json: async () => ({}) }; }; } /** A project in a temp root: channel c's v1..v3, each with cues and an upload date. */ async function project(timeline, { uploads = {}, landed = {}, extra = {} } = {}) { const root = await mkdtemp(path.join(tmpdir(), "ui-ops-")); const channelsDir = path.join(root, "channels"); const reportsRoot = path.join(root, "reports"); for (const v of ["v1", "v2", "v3"]) { const vdir = path.join(channelsDir, "c", "data", v); await mkdir(vdir, { recursive: true }); const cues = Array.from({ length: 200 }, (_, i) => ({ start: i, end: i + 1, text: `Line ${i}.` })); const file = path.join(vdir, "transcript.cues.json"); await writeFile(file, JSON.stringify({ cues, uploadDate: uploads[v] ?? "20260901", webpageUrl: `https://www.youtube.com/watch?v=${v}` })); const at = new Date(landed[v] ?? "2026-09-02T00:00:00Z"); await utimes(file, at, at); } const dir = path.join(reportsRoot, "cut"); await mkdir(dir, { recursive: true }); const m = manifestOf(timeline.map((e) => ({ type: "clip", channel: "c", video: "v1", lock: true, ...e })), extra); m.provenance.channelsDir = path.relative(dir, channelsDir); await writeFile(path.join(dir, "video.manifest.json"), `${JSON.stringify(m, null, 2)}\n`); const decisions = async () => { const [ref] = (await walkProjects(reportsRoot)).filter((p) => p.id === "cut"); return decisionsFor(ref, reportsRoot); }; const manifest = async () => JSON.parse(await readFile(path.join(dir, "video.manifest.json"), "utf8")); return { root, reportsRoot, dir, channelsDir, decisions, manifest, done: () => rm(root, { recursive: true, force: true }) }; } // ---- #9 the sites a cut's links depend on ----------------------------------- test("originOf, dayOf, sitesByOrigin: a site is named by the origin of its siteUrl", () => { assert.equal(originOf("https://site.test/"), "https://site.test"); assert.equal(originOf("mailto:x@y"), null); assert.equal(dayOf("20261020"), "2026-10-20"); assert.equal(dayOf("2026-10-09T10:00:00.000Z"), "2026-10-09"); assert.equal(dayOf("soon"), null); const s = sitesByOrigin(SITES); assert.deepEqual(s.get("https://site.test"), { siteId: "anilyzer", title: "Anilyzer" }); assert.equal(sitesByOrigin(path.join(SITES, "nope")).size, 0); }); test("projectSites: each origin with its deploy; videos newer than it, unless the check opened their link", () => { const m = manifestOf([ { type: "clip", id: "a", video: "v1", start: 10, end: 20 }, { type: "clip", id: "b", video: "v2", start: 10, end: 20 }, { type: "clip", id: "c", video: "v3", start: 10, end: 20 }, { type: "clip", id: "d", video: "v3", start: 30, end: 40, citeUrl: url("c", "v3", 30, "https://other.test") }, { type: "clip", id: "y", video: "yt", start: 1, end: 2, citeUrl: "https://www.youtube.com/watch?v=yt&t=1s" }, ]); const doc = { checkedAt: "2026-11-01T10:00:00.000Z", origins: { [SITE]: { state: "ok", generatedAt: "2026-10-09T10:00:00.000Z" } }, links: [ { clip: "a", url: url("c", "v1", 10), state: "ok" }, { clip: "b", url: url("c", "v2", 10), state: "dead" }, ], }; const rec = { a: { uploadDate: "20261020" }, b: { uploadDate: "20261020" }, c: { uploadDate: "20260101", landedAt: "2026-10-21T08:00:00Z" }, d: { uploadDate: "20261030" } }; const sites = projectSites(m, doc, { sites: sitesByOrigin(SITES), recordOf: (id) => rec[id] ?? null }); assert.deepEqual( sites.map((s) => [s.host, s.siteId, s.state, s.deployedAt, s.links, s.newer.map((n) => `${n.clip} ${n.why}`)]), [ // a was opened by the check: on the site, whatever its date says. ["site.test", "anilyzer", "ok", "2026-10-09T10:00:00.000Z", 3, ["b uploaded 2026-10-20", "c transcribed here 2026-10-21"]], // Never checked: no deploy date, so nothing can be newer than it. ["other.test", "other", "unchecked", null, 1, []], ], ); assert.equal( deployBehindWhy(sites[0]), "anilyzer's deploy is from 2026-10-09; 2 cited videos are newer: b (uploaded 2026-10-20), c (transcribed here 2026-10-21) — publish the site before the video ships, or link elsewhere", ); }); test("the check: site-deploy-behind, one row per site with newer videos, its settle Publish ", async () => { const p = await project( [{ id: "a", video: "v1", start: 10, end: 20, cite: 10 }, { id: "b", video: "v2", start: 10, end: 20, cite: 10 }], { uploads: { v2: "20261020" } }, ); try { // Never checked: no deploy date, no row. assert.equal((await p.decisions()).filter((d) => d.kind === "site-deploy-behind").length, 0); // The site has v1 only (built 9 Oct); v2 was uploaded on the 20th. await runLinkCheck(p.dir, await p.manifest(), { fetchImpl: fakeSite(["v1"]), cacheDir: null, gapMs: 0 }); const rows = (await p.decisions()).filter((d) => d.kind === "site-deploy-behind"); assert.equal(rows.length, 1); assert.equal(rows[0].severity, "open"); assert.equal(rows[0].target, "site.test"); assert.match(rows[0].why, /^anilyzer's deploy is from 2026-10-09; 1 cited video is newer: b \(uploaded 2026-10-20\)/); assert.deepEqual(rows[0].settle, { kind: "publish-site", siteId: "anilyzer", label: "Publish anilyzer" }); assert.equal(rows[0].fix, `pnpm ops build-deploy --json '{"siteId":"anilyzer"}'`); assert.deepEqual(rows[0].clips, ["b"]); // Redeployed with v2: the check opens it, and the row goes. await runLinkCheck(p.dir, await p.manifest(), { fetchImpl: fakeSite(["v1", "v2"]), cacheDir: null, gapMs: 0 }); assert.equal((await p.decisions()).filter((d) => d.kind === "site-deploy-behind").length, 0); } finally { await p.done(); } }); // ---- #10 the link policy ---------------------------------------------------- const { normalizeLinkPolicy, policyBreaks, policyCiteUrl, policyFixLabel } = await import("./linkPolicy.mjs"); const { addClip, insertEntry, updateLinkPolicy } = await import("./manifest.mjs"); const { linkPolicyCommand } = await import("./linksCli.mjs"); test("normalizeLinkPolicy: via an origin, direct slugs sorted; nothing is no policy; a stray key refuses", () => { assert.deepEqual(normalizeLinkPolicy({ via: "https://site.test/x", direct: ["b", "a", "a"] }), { via: "https://site.test", direct: ["a", "b"] }); assert.deepEqual(normalizeLinkPolicy({ direct: "ho, side" }), { via: null, direct: ["ho", "side"] }); assert.equal(normalizeLinkPolicy({}), null); assert.equal(normalizeLinkPolicy(null), null); assert.throws(() => normalizeLinkPolicy({ via: "ftp://x" }), /a site's http\(s\) address/); assert.throws(() => normalizeLinkPolicy({ sites: [] }), /has no key "sites"/); assert.throws(() => normalizeLinkPolicy({ direct: ["no spaces"] }), /channel slugs/); }); test("policyBreaks: a direct channel's archive link, another site's link, a platform link where the policy cites via; each with its fix", () => { const m = manifestOf( [ { type: "clip", id: "e1", channel: "ember", video: "v1", start: 10, end: 20, cite: 12 }, { type: "clip", id: "e2", channel: "ember", video: "v2", start: 10, end: 20, citeUrl: url("ember", "v2", 10, "https://other.test") }, { type: "clip", id: "e3", channel: "ember", video: "v3", start: 10, end: 20, citeUrl: "https://www.youtube.com/watch?v=v3&t=10s" }, { type: "clip", id: "h1", channel: "ho", video: "y1", start: 30, end: 40, cite: 31 }, { type: "clip", id: "h2", channel: "ho", video: "y2", start: 30, end: 40, citeUrl: "https://www.youtube.com/watch?v=y2&t=30s" }, { type: "clip", id: "h3", channel: "ho", video: "y3", start: 30, end: 40 }, { type: "clip", id: "s1", src: "media/own.mp4", start: 0, end: 4 }, ], { provenance: { channelSlug: "ember", siteOrigin: SITE, linkPolicy: { direct: ["ho"] } } }, ); const web = { y1: "https://www.youtube.com/watch?v=y1", y2: "https://www.youtube.com/watch?v=y2" }; const b = policyBreaks(m, { webpageOf: (e) => web[e.video] ?? null }); assert.deepEqual(b.map((x) => [x.clip, x.want, x.fix]), [ ["e2", "via", url("ember", "v2", 10)], ["e3", "via", url("ember", "v3", 10)], ["h1", "direct", "https://www.youtube.com/watch?v=y1&t=31s"], ["h3", "direct", null], ]); assert.match(b[0].why, /^the project's link policy cites via site\.test, but its QR opens other\.test$/); assert.match(b[3].why, /^ho links direct by the project's link policy, but its QR opens site\.test — and its record names no platform page to link/); assert.equal(policyFixLabel(b[0]), "Link via site.test"); assert.equal(policyFixLabel(b[2]), "Link its YouTube page"); // With no policy nothing breaks. assert.deepEqual(policyBreaks({ ...m, provenance: { siteOrigin: SITE } }), []); }); test("policyCiteUrl: a new clip of a direct channel gets its platform page; via another site gets that site; one that keeps it is left alone", () => { const m = manifestOf([], { provenance: { channelSlug: "c", siteOrigin: SITE, linkPolicy: { via: "https://other.test", direct: ["ho"] } } }); assert.equal(policyCiteUrl(m, { type: "clip", channel: "ho", video: "y1", start: 5, end: 9, cutStart: 6 }, "https://www.youtube.com/watch?v=y1"), "https://www.youtube.com/watch?v=y1&t=6s"); assert.equal(policyCiteUrl(m, { type: "clip", channel: "ho", video: "y1", start: 5, end: 9 }, null), null); assert.equal(policyCiteUrl(m, { type: "clip", video: "v1", start: 5, end: 9 }, null), url("c", "v1", 5, "https://other.test")); assert.equal(policyCiteUrl(m, { type: "clip", video: "v1", start: 5, end: 9, citeUrl: url("c", "v1", 5, "https://other.test") }, null), undefined); }); test("the inserters write the policy's link; the check's clip-link-policy rows and their one-press fix; the CLI", async () => { const p = await project([ { id: "a", video: "v1", start: 10, end: 20, cite: 10 }, { id: "b", video: "v2", start: 10, end: 20, cite: 12 }, ]); try { // No policy: no rows. assert.equal((await p.decisions()).filter((d) => d.kind === "clip-link-policy").length, 0); // "These channels direct": channel c links YouTube. const res = await updateLinkPolicy(p.dir, { direct: ["c"] }); assert.equal(res.changed, true); assert.deepEqual((await p.manifest()).provenance.linkPolicy, { direct: ["c"] }); assert.equal((await updateLinkPolicy(p.dir, { direct: ["c"] })).changed, false, "a no-op writes nothing"); const rows = (await p.decisions()).filter((d) => d.kind === "clip-link-policy"); assert.deepEqual(rows.map((d) => [d.target, d.severity]), [["a", "open"], ["b", "open"]]); assert.deepEqual(rows[1].settle, { kind: "patch", clip: "b", patch: { citeUrl: "https://www.youtube.com/watch?v=v2&t=12s" }, label: "Link its YouTube page" }); assert.equal(rows[1].fix, "umtool window cut b --cite-url 'https://www.youtube.com/watch?v=v2&t=12s'"); // A new clip (the strip's selection, an insert) is written by the policy. const added = await addClip(p.dir, { video: "v3", cutStart: 40, cutEnd: 44 }); assert.equal(added.entry.citeUrl, "https://www.youtube.com/watch?v=v3&t=40s"); const ins = await insertEntry(p.dir, "a", { type: "clip", video: "v1", start: 50, end: 55, citeUrl: url("c", "v1", 50) }); assert.equal(ins.entry.citeUrl, "https://www.youtube.com/watch?v=v1&t=50s", "a copied archive link that breaks the policy is replaced"); // The CLI: what breaks it, then --fix through the window writer. const lines = []; const code = await linkPolicyCommand(["cut"], { root: p.reportsRoot, out: (s) => lines.push(s), err: (s) => lines.push(s) }); assert.equal(code, 1); assert.match(lines.join("\n"), /cut: cite via provenance\.siteOrigin \(https:\/\/site\.test\); direct: c/); assert.match(lines.join("\n"), /BREAKS {2}a {2}c links direct/); const fixed = []; assert.equal(await linkPolicyCommand(["cut", "--fix"], { root: p.reportsRoot, out: (s) => fixed.push(s), err: (s) => fixed.push(s) }), 0); assert.match(fixed.join("\n"), /fixed a: https:\/\/site\.test\/\?v=c%2Fv1&t=10 -> https:\/\/www\.youtube\.com\/watch\?v=v1&t=10s/); assert.equal((await p.decisions()).filter((d) => d.kind === "clip-link-policy").length, 0); // --via by site id; --clear. assert.equal(await linkPolicyCommand(["cut", "--via", "other", "--direct", ""], { root: p.reportsRoot, out: () => {}, err: () => {}, sitesDir: SITES }), 1); assert.deepEqual((await p.manifest()).provenance.linkPolicy, { via: "https://other.test" }); assert.equal(await linkPolicyCommand(["cut", "--via", "nope"], { root: p.reportsRoot, out: () => {}, err: () => {}, sitesDir: SITES }), 2); assert.equal(await linkPolicyCommand(["cut", "--clear"], { root: p.reportsRoot, out: () => {}, err: () => {} }), 0); assert.equal("linkPolicy" in (await p.manifest()).provenance, false); } finally { await p.done(); } }); // ---- #18 a take's ETA from the project's past renders -------------------- const { etaText, parseDuration, pastRenders, projectEtas, slotWaitOf, takeEta } = await import("./takeEta.mjs"); test("parseDuration / slotWaitOf: the heavy gate's waits, read from a render's log", () => { assert.equal(parseDuration("35s"), 35); assert.equal(parseDuration("2m10s"), 130); assert.equal(parseDuration("1h02m"), 3720); assert.equal(parseDuration("soon"), null); assert.equal(slotWaitOf("heavy: waiting for memory — …\nheavy: 8879 MB available after 35s — admitted\nqueue-lock: the render let go after 2m10s — going on\n"), 165); assert.equal(slotWaitOf("take x: done (1413.3 s)"), 0, "a take's done line is the video's length, not a wait"); }); test("pastRenders: recorded renderSeconds, else the take's files' times less its log's wait; a draft or a take with no length is not one", async () => { const dir = await mkdtemp(path.join(tmpdir(), "ui-ops-eta-")); try { const take = async (id, doc, { manifestAt = null, log = null } = {}) => { const d = path.join(dir, "takes", id); await mkdir(d, { recursive: true }); await writeFile(path.join(d, "take.json"), JSON.stringify({ id, group: "takes", order: 1, label: id, kind: "reference", preview: "preview.mp4", ...doc })); if (manifestAt) { await writeFile(path.join(d, "video.manifest.json"), "{}"); await utimes(path.join(d, "video.manifest.json"), new Date(manifestAt), new Date(manifestAt)); } if (log) await writeFile(path.join(dir, `${id}.log`), log); }; await take("d1", { seconds: 600, window: "full", builtAt: "2026-10-30T10:40:00.000Z" }, { manifestAt: "2026-10-30T10:00:00.000Z", log: "heavy: 9000 MB available after 4m00s — admitted\n" }); await take("d2", { seconds: 600, window: "full", builtAt: "2026-10-31T10:00:00.000Z", renderSeconds: 900, from: "d1" }); await take("d3", { seconds: 30, window: { at: 0, dur: 30 }, builtAt: "2026-10-31T11:00:00.000Z", renderSeconds: 90 }); await take("dr", { seconds: null, draft: true, builtAt: null }); const past = await pastRenders(dir); assert.deepEqual(past.map((p) => [p.id, p.renderSeconds, p.how, p.window, p.from]), [ ["d1", 2160, "files", "full", null], ["d2", 900, "recorded", "full", "d1"], ["d3", 90, "recorded", "window", null], ]); const e = await projectEtas(dir); assert.equal(e.seconds, 600); assert.equal(e.newest, "d2"); assert.equal(e.fresh?.etaSeconds, 2160); assert.equal(e.reuse?.etaSeconds, 900); assert.equal(etaText(e.fresh?.etaSeconds), "36 min"); assert.equal(etaText(4000), "1 h 07 min"); } finally { await rm(dir, { recursive: true, force: true }); } }); test("takeEta: the median rate of the same kind, times the length; none of its kind says so and uses the others", () => { const past = [ { id: "a", seconds: 100, renderSeconds: 300, how: "recorded", window: "full", from: null, quick: false, builtAt: "1" }, { id: "b", seconds: 100, renderSeconds: 500, how: "recorded", window: "full", from: null, quick: false, builtAt: "2" }, { id: "c", seconds: 100, renderSeconds: 100, how: "recorded", window: "full", from: "b", quick: false, builtAt: "3" }, ]; const fresh = takeEta(past, { seconds: 200 }); assert.deepEqual([fresh?.etaSeconds, fresh?.rate, fresh?.basis.map((b) => b.id), fresh?.note], [800, 4, ["a", "b"], null]); const reuse = takeEta(past, { seconds: 200, from: true }); assert.deepEqual([reuse?.etaSeconds, reuse?.basis.map((b) => b.id)], [200, ["c"]]); const win = takeEta(past, { seconds: 60, window: "window" }); assert.equal(win?.etaSeconds, 180); assert.match(String(win?.note), /no past fresh take of a window — from the project's other renders/); assert.equal(takeEta([], { seconds: 60 }), null); }); // ---- #15 the speaker check ------------------------------------------------ const { execFileSync } = await import("node:child_process"); const { fileURLToPath } = await import("node:url"); const { encodeWav16 } = await import("yt-dlp-transcript-common/lib/montage/voiceMatch.mjs"); const { VOICE_A, VOICE_B, syntheticVoice, withSilence } = await import("yt-dlp-transcript-common/testing/audio/syntheticVoice.mjs"); const { PROJECT_KINDS } = await import("../projects/kinds.mjs"); const sc = await import("./speakerCheck.mjs"); const FAKE_EMBED = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "..", "common", "testing", "audio", "fakeSpeakerEmbed.mjs"); const hasFfmpeg = (() => { try { execFileSync("ffmpeg", ["-version"], { stdio: "ignore" }); return true; } catch { return false; } })(); test("speakers.json: names checked, a spec parsed, a clip added to one voice at a time", async () => { assert.deepEqual(sc.normalizeSpeakers({ speakers: [{ name: " Ember ", clips: ["e01", "e01"], videos: ["ember/abc"] }] }), [{ name: "Ember", clips: ["e01"], videos: ["ember/abc"], channels: [] }]); assert.throws(() => sc.normalizeSpeakers({ speakers: [{ name: "a/b" }] }), /no \/ = or comma/); assert.throws(() => sc.normalizeSpeakers({ speakers: [{ name: "X" }, { name: "x" }] }), /two speakers are named "x"/); assert.throws(() => sc.normalizeSpeakers({}), /speakers\.json is/); assert.deepEqual(sc.parseSpeakerSpec("Kirsche=k01,kirsche/v9,channel:kirsche"), { name: "Kirsche", clips: ["k01"], videos: ["kirsche/v9"], channels: ["kirsche"] }); const dir = await mkdtemp(path.join(tmpdir(), "ui-ops-speakers-")); try { assert.deepEqual(await sc.readSpeakers(dir), []); await sc.addClipToSpeaker(dir, "Ember", "e01"); await sc.addClipToSpeaker(dir, "Kirsche", "k01"); await sc.addClipToSpeaker(dir, "Kirsche", "e01"); assert.deepEqual((await sc.readSpeakers(dir)).map((s) => [s.name, s.clips]), [["Ember", []], ["Kirsche", ["k01", "e01"]]]); } finally { await rm(dir, { recursive: true, force: true }); } }); test("Check speaker is one job through the heavy slot, with its estimate", () => { const plan = sc.speakerCheckSteps({ id: "reports/x" }, { clip: "k04", queueLock: "/repo/scripts/queue-lock.mjs" }); assert.equal(plan.kind, "speaker-check reports/x"); const argv = plan.steps[0].argv; assert.deepEqual(argv.slice(1, 5), ["/repo/scripts/queue-lock.mjs", "--heavy", "--estimate", "800"]); assert.deepEqual(argv.slice(argv.indexOf("speaker-check")), ["speaker-check", "reports/x", "--clip", "k04", "--progress", "ndjson"]); assert.equal(sc.speakerCheckSteps({ id: "p" }, { queueLock: null }).steps[0].argv[0], "nice"); }); test("umtool speaker-check: each clip against the named voices, over a synthetic corpus; the walk's badge reads the row", { skip: !hasFfmpeg && "needs ffmpeg" }, async () => { const root = await mkdtemp(path.join(tmpdir(), "ui-ops-speaker-")); try { const chans = path.join(root, "channels"); const encode = async (x, out) => { await writeFile(`${out}.wav`, encodeWav16(x)); execFileSync("ffmpeg", ["-v", "error", "-y", "-i", `${out}.wav`, "-c:a", "aac", "-b:a", "96k", out]); await rm(`${out}.wav`); }; const timeline = []; for (const [id, voice, phase] of [["k01", VOICE_A, 0.3], ["k02", VOICE_A, 1.6], ["k03", VOICE_B, 0.8], ["k04", VOICE_A, 2.9]]) { const d = path.join(chans, "chan", "data", `v${id}`); await mkdir(path.join(d, "clips"), { recursive: true }); await writeFile(path.join(d, "transcript.cues.json"), JSON.stringify({ id: `v${id}`, cues: [{ start: 102.5, end: 104, text: "slow news day" }] })); await encode(withSilence(syntheticVoice({ ...voice, seconds: 2.5, phase }), { before: 2, after: 3.5 }), path.join(d, "clips", "100.00-108.00.mp4")); timeline.push({ type: "clip", id, channel: "chan", video: `v${id}`, start: 100, end: 108, cutStart: 102.5, cutEnd: 104, cite: 102.5, quote: "slow news day" }); } const reportsRoot = path.join(root, "reports"); const dir = path.join(reportsRoot, "cut"); await mkdir(dir, { recursive: true }); const manifest = { schemaVersion: 1, slug: "cut", title: "Cut", kind: PROJECT_KINDS.find((k) => k.makesTakes).id, provenance: { channelsDir: "../../channels", channelSlug: "chan" }, render: {}, timeline }; await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(manifest)); const out = []; const io = { reportsRoot, log: (s) => out.push(s), err: (s) => out.push(s), engine: { python: process.execPath, script: FAKE_EMBED, model: "fake.onnx" } }; // No voices yet: refused, saying how to name them. assert.equal(await sc.speakerCheckCommand(["cut"], io), 2); assert.match(out.join("\n"), /no voices to compare with: name them in speakers\.json/); assert.equal(await sc.speakerCheckCommand(["cut", "--set", "Host=k01,k02", "--set", "Guest=k03"], io), 0); out.length = 0; assert.equal(await sc.speakerCheckCommand(["cut", "--clip", "k04"], io), 0, out.join("\n")); assert.match(out.join("\n"), /k04 {3}matches Host \d\.\d\d \/ Guest 0\.\d\d/); const doc = JSON.parse(await readFile(path.join(dir, "speaker-check.json"), "utf8")); assert.deepEqual(Object.keys(doc.clips), ["chan/vk04@102.50"]); const badge = await sc.speakerBadge(dir, manifest, "k04"); assert.equal(badge.result?.label, "matches"); assert.match(badge.result?.line ?? "", /^matches Host \d\.\d\d \/ Guest 0\.\d\d$/); assert.deepEqual(badge.reference?.map((s) => [s.name, s.pieces]), [["Host", 2], ["Guest", 1]]); assert.deepEqual(badge.speakers.map((s) => s.name), ["Host", "Guest"]); // A clip with no row yet. assert.equal((await sc.speakerBadge(dir, manifest, "k02")).result, null); assert.equal(await sc.speakerCheckCommand(["cut", "--clip", "nope"], io), 2); } finally { await rm(root, { recursive: true, force: true }); } });