// `umtool quote-check
--take ` (12 Nov 2026: the check judged the draft -- 25 blocking there -- and left the
// take unjudged). With --take the take's own clips are judged (its timeline: its patch over the draft), the rows
// go to takes//quote-check.json, and a take's refusal and `umtool check --take` read the take's rows first.
// The words and cues are the 6 Nov c43 window's (report-to-video/fixtures/rev9-a3-rumble-words.json).
//
// Run with: pnpm test:scripts
import assert from "node:assert/strict";
import test from "node:test";
import { mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { quoteCheckCommand, quoteGate, readQuoteCheck, readTakeQuoteCheck, takeQuoteCheckDir, takeQuoteDecisions, takeQuoteRefusals } from "./quoteCheck.mjs";
import { makeTake } from "./takeMaker.mjs";
const HERE = path.dirname(fileURLToPath(import.meta.url));
const FIX = JSON.parse(await readFile(path.join(HERE, "..", "..", "report-to-video", "fixtures", "rev9-a3-rumble-words.json"), "utf8"));
const C43 = FIX.clips.find((c) => c.id === "c43");
/** c43 in the draft: re-cut to seconds no window holds (no-window); in the take, where the 6 Nov fetch had it (moved). */
const DRAFT = { start: 3000, end: 3010 };
const EARLY = { start: 2119.34, end: 2127.44 };
async function project() {
const root = await mkdtemp(path.join(os.tmpdir(), "quote-check-take-"));
const dir = path.join(root, "diet");
const raw = path.join(dir, "out", "clips-raw");
await mkdir(raw, { recursive: true });
const channels = path.join(root, "channels");
await mkdir(channels, { recursive: true });
await writeFile(path.join(raw, `${C43.video}_${C43.window[0].toFixed(2)}-${C43.window[1].toFixed(2)}.mp4`), "mp4");
const c43 = { type: "clip", id: "c43", channel: C43.channel, video: C43.video, quote: C43.quote };
const manifest = {
slug: "diet",
render: { width: 640, height: 360, fps: 15, transition: 0 },
provenance: { channelSlug: "the-quartering-rumble", channelsDir: channels, channelsFallback: false },
timeline: [{ ...c43, ...DRAFT }],
};
await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(manifest));
const takeDir = path.join(dir, "takes", "t1");
await mkdir(takeDir, { recursive: true });
await writeFile(path.join(takeDir, "take.json"), JSON.stringify({ id: "t1", group: "takes", order: 0, label: "T1", kind: "different", preview: "preview.mp4", draft: true, window: "full", patch: { timeline: [{ ...c43, ...EARLY }] } }));
return { root, dir, takeDir };
}
const fakeTranscribe = async (req) => C43.words.filter((w) => w.start >= req.start - 0.01 && w.end <= req.end + 0.01);
const fakeCues = async () => C43.cues;
const run = async (p, args) => {
const out = [];
const code = await quoteCheckCommand(args, { reportsRoot: p.root, log: (l) => out.push(l), err: (l) => out.push(`ERR ${l}`), transcribe: fakeTranscribe, cuesOf: fakeCues });
return { code, text: out.join("\n") };
};
const exists = (f) => stat(f).then(() => true, () => false);
test("quote-check --take judges the take's clips into takes//quote-check.json; the draft's rows are its own", async () => {
const p = await project();
try {
// The draft: its c43 has no window to judge.
let r = await run(p, ["diet"]);
assert.equal(r.code, 0, r.text);
assert.match(r.text, /0 ok, 0 moved, 0 not found, 1 with no window/);
// The take: its c43 13 s early -- judged on ITS cut, into its own file.
r = await run(p, ["diet", "--take", "t1"]);
assert.equal(r.code, 0, r.text);
assert.match(r.text, /0 ok, 1 moved/);
assert.match(r.text, /takes\/t1\/quote-check\.json/);
const own = JSON.parse(await readFile(path.join(p.takeDir, "quote-check.json"), "utf8"));
assert.equal(own.clips.c43.status, "moved");
assert.equal(own.clips.c43.cut.from, EARLY.start);
// The draft's file is untouched by the take's run.
const draft = JSON.parse(await readFile(path.join(p.dir, "quote-check.json"), "utf8"));
assert.equal(draft.clips.c43.status, "no-window");
// --status --take: the take's rows, against the take's clips.
r = await run(p, ["diet", "--take", "t1", "--status"]);
assert.equal(r.code, 0, r.text);
assert.match(r.text, /c43 +moved/);
// A take that is not there is refused.
r = await run(p, ["diet", "--take", "nope"]);
assert.equal(r.code, 2);
assert.match(r.text, /nope/);
} finally {
await rm(p.root, { recursive: true, force: true });
}
});
test("a take's refusal and `check --take` read the take's verdicts, the project's under them", async () => {
const p = await project();
try {
assert.equal((await run(p, ["diet"])).code, 0);
assert.equal((await run(p, ["diet", "--take", "t1"])).code, 0);
const doc = await readTakeQuoteCheck(p.dir, "t1");
assert.equal(doc.own.clips.c43.status, "moved");
// check --take: the take's c43 blocks, naming the take.
const ds = await takeQuoteDecisions({ id: "diet", dir: p.dir }, "t1");
assert.deepEqual(ds.map((d) => [d.kind, d.target, d.severity]), [["clip-quote-moved", "c43", "blocking"]]);
assert.match(ds[0].fix, /--take t1/);
// The take's render refuses its moved c43 (before: only the draft's rows were read, and they say no-window).
let rendered = false;
const render = async () => {
rendered = true;
throw new Error("no render in this test");
};
await assert.rejects(makeTake(p.dir, { id: "t1", label: "T1", window: "full", patch: { timeline: JSON.parse(await readFile(path.join(p.takeDir, "take.json"), "utf8")).patch.timeline } }, { render, force: true }), /c43: its quote is heard/);
assert.equal(rendered, false);
// No take file: the project's rows still gate it (nothing loosened).
await rm(path.join(p.takeDir, "quote-check.json"));
assert.equal((await readTakeQuoteCheck(p.dir, "t1")).project.clips.c43.status, "no-window");
assert.equal(await exists(path.join(p.dir, "quote-check.json")), true);
} finally {
await rm(p.root, { recursive: true, force: true });
}
});
// Review round 1 (M1): `--take` may only ever ADD refusals to what the project's rows refuse for the same cut.
const writeRows = (dir, rows) => writeFile(path.join(dir, "quote-check.json"), JSON.stringify({ version: 1, clips: rows }));
async function bare(timelineDraft, takePatch) {
const root = await mkdtemp(path.join(os.tmpdir(), "quote-gate-take-"));
const dir = path.join(root, "p");
await mkdir(path.join(dir, "takes", "t1"), { recursive: true });
await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ slug: "p", render: { width: 640, height: 360, fps: 15 }, timeline: timelineDraft }));
await writeFile(path.join(dir, "takes", "t1", "take.json"), JSON.stringify({ id: "t1", group: "takes", order: 0, label: "T1", kind: "different", preview: "preview.mp4", draft: true, window: "full", patch: takePatch }));
return { root, dir };
}
test("a stale take row never hides the project's current refusal (the take re-set to the draft's cut)", async () => {
const c1 = { type: "clip", id: "c1", channel: "ch", video: "v", quote: "q", cutStart: 10, cutEnd: 20, start: 10, end: 20 };
const p = await bare([c1], { render: { crf: 20 } });
try {
await writeRows(p.dir, { c1: { status: "moved", offset: 3.1, cut: { from: 10, to: 20 }, quote: "q" } });
// judged when the take had c1 at 12-22 (ok); the take is back at 10-20
await writeRows(takeQuoteCheckDir(p.dir, "t1"), { c1: { status: "ok", offset: 0, cut: { from: 12, to: 22 }, quote: "q" } });
const main = quoteGate([c1], await readQuoteCheck(p.dir)).map((g) => `${g.id} ${g.status}`);
assert.deepEqual(main, ["c1 moved"]);
assert.deepEqual((await takeQuoteRefusals(p.dir, "t1", [c1])).map((g) => `${g.id} ${g.status}`), main);
} finally {
await rm(p.root, { recursive: true, force: true });
}
});
test("a take that inherits the draft's re-cut: its own row from before is stale, the project's current moved row refuses (makeTake's gate and check --take)", async () => {
const c1 = { type: "clip", id: "c1", channel: "ch", video: "v", quote: "q", start: 30, end: 40 };
const p = await bare([c1], { render: { crf: 20 } });
try {
await writeRows(takeQuoteCheckDir(p.dir, "t1"), { c1: { status: "ok", offset: 0, cut: { from: 10, to: 20 }, quote: "q" } });
await writeRows(p.dir, { c1: { status: "moved", offset: 13.1, cut: { from: 30, to: 40 }, quote: "q" } });
assert.deepEqual((await takeQuoteRefusals(p.dir, "t1", [c1])).map((g) => `${g.id} ${g.status}`), ["c1 moved"]);
assert.deepEqual((await takeQuoteDecisions({ id: "p", dir: p.dir }, "t1")).map((d) => `${d.kind} ${d.target}`), ["clip-quote-moved c1"]);
// A current take row that says ok does not take away the project's current refusal of the same cut either.
await writeRows(takeQuoteCheckDir(p.dir, "t1"), { c1: { status: "ok", offset: 0, cut: { from: 30, to: 40 }, quote: "q" } });
assert.deepEqual((await takeQuoteRefusals(p.dir, "t1", [c1])).map((g) => `${g.id} ${g.status}`), ["c1 moved"]);
} finally {
await rm(p.root, { recursive: true, force: true });
}
});
test("the project's row speaks for a take's clip only when it is the same clip: another video or channel under the same id is not judged by it (S10)", async () => {
const draft = { type: "clip", id: "c1", channel: "ch", video: "v", quote: "q", start: 30, end: 40 };
const other = { ...draft, video: "w" };
const p = await bare([draft], { timeline: [other] });
try {
await writeRows(p.dir, { c1: { status: "moved", offset: 13.1, cut: { from: 30, to: 40 }, quote: "q" } });
assert.deepEqual(await takeQuoteRefusals(p.dir, "t1", [other]), []);
assert.deepEqual(await takeQuoteRefusals(p.dir, "t1", [{ ...draft, channel: "elsewhere" }]), []);
// The same clip: refused as main refuses it.
assert.deepEqual((await takeQuoteRefusals(p.dir, "t1", [draft])).map((g) => g.id), ["c1"]);
} finally {
await rm(p.root, { recursive: true, force: true });
}
});
test("a take id is checked before anything is read (S9)", async () => {
await assert.rejects(readTakeQuoteCheck("/nowhere", "../../.."), /not a take id/);
assert.throws(() => takeQuoteCheckDir("/nowhere", "../x"), /not a take id/);
await assert.rejects(takeQuoteDecisions({ id: "p", dir: "/nowhere" }, "../x"), /not a take id/);
});