// `umtool set`, `umtool look`, `umtool variants` and the knobs `umtool show` // prints (plans/video-knobs-ui.md): the same writers the UI uses, from a // terminal; the encoder stubbed (e2e/fixtures/variants.e2e.mjs). // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; const ROOT = await mkdtemp(path.join(tmpdir(), "umtool-knobs-cli-")); process.env.REPORTS_DIR = ROOT; const { knobsLines, knobsOf, lookCommand, parseAssignments, setCommand, variantsCommand } = await import("./knobsCli.mjs"); const STUB = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "..", "e2e", "fixtures", "variants.e2e.mjs"); const MANIFEST = { schemaVersion: 1, slug: "huck", title: "Huck", provenance: { siteOrigin: "https://example.test", channelSlug: "chan" }, render: { width: 1920, height: 1080, fps: 30, chrome: { engine: "hyperframes", layout: "deck" } }, timeline: [ { type: "clip", id: "c01", video: "v1", start: 10, end: 20, claim: { id: "k1", verdict: "CONTRADICTED" } }, { type: "clip", id: "c02", video: "v2", start: 30, end: 41 }, ], }; async function project(name) { const dir = path.join(ROOT, name); await mkdir(dir, { recursive: true }); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(MANIFEST, null, 2) + "\n"); return dir; } const read = async (dir) => JSON.parse(await readFile(path.join(dir, "video.manifest.json"), "utf8")); const runner = (fn) => { const lines = []; return { lines, run: (...args) => fn(args, { root: ROOT, out: (s) => lines.push(s), err: (s) => lines.push(`ERR ${s}`) }) }; }; test.after(() => rm(ROOT, { recursive: true, force: true })); test("parseAssignments: JSON when it parses, text otherwise, empty clears", () => { assert.deepEqual(parseAssignments(["a=2", "b=true", "c=SEIZURE", "d=", 'e=[{"x":1}]']), [["a", 2], ["b", true], ["c", "SEIZURE"], ["d", null], ["e", [{ x: 1 }]]]); assert.throws(() => parseAssignments(["nope"]), /not key=value/); }); test("umtool set chat=on|off|true|false writes the clip's chat flag; chat= clears it; anything else is refused", async () => { const dir = await project("chat"); const { lines, run } = runner(setCommand); assert.equal(await run("chat", "c02", "chat=on"), 0); assert.equal((await read(dir)).timeline[1].chat, true); assert.match(lines.at(-1), /chat on/); assert.equal(await run("chat", "c02", "chat=off"), 0); assert.equal((await read(dir)).timeline[1].chat, false); assert.equal(await run("chat", "c02", "chat=true"), 0); assert.equal((await read(dir)).timeline[1].chat, true); assert.equal(await run("chat", "c02", "chat="), 0); assert.equal("chat" in (await read(dir)).timeline[1], false); assert.equal(await run("chat", "c02", "chat=maybe"), 2); assert.match(lines.at(-1), /on or off/); // The look: render.chrome.chat through `umtool look`, checked by the build's rules. const look = runner(lookCommand); assert.equal(await look.run("chat", "chat.position=left", "chat.lines=8"), 0); assert.deepEqual((await read(dir)).render.chrome.chat, { position: "left", lines: 8 }); assert.notEqual(await look.run("chat", "chat.lines=99"), 0); assert.deepEqual((await read(dir)).render.chrome.chat, { position: "left", lines: 8 }); }); test("umtool set hideModules=diet,streak: the modules hidden over an entry's span, any entry; --take writes the take's patch", async () => { const dir = await project("hide"); const m = await read(dir); m.timeline.push({ type: "post", id: "x01", item: "123" }); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(m, null, 2) + "\n"); const { lines, run } = runner(setCommand); assert.equal(await run("hide", "c02", "hideModules=streak,diet"), 0); assert.deepEqual((await read(dir)).timeline[1].hideModules, ["diet", "streak"], "in the modules' order"); assert.match(lines.at(-1), /hideModules diet, streak \(hidden over its span\)/); assert.equal(await run("hide", "x01", 'hideModules=["promise"]'), 0, lines.join("\n")); assert.deepEqual((await read(dir)).timeline[2].hideModules, ["promise"], "a post item too"); assert.equal(await run("hide", "c02", "hideModules=dial"), 1); assert.match(lines.at(-1), /dial cannot be hidden per entry/); assert.equal(await run("hide", "c02", "hideModules="), 0); assert.equal("hideModules" in (await read(dir)).timeline[1], false); // --take: the take's patch, an undo point of the take's; the project's manifest untouched. const { draftTake } = await import("./takeMaker.mjs"); const { resolveTakeManifest } = await import("./takeManifest.mjs"); await draftTake(dir, { id: "panel", label: "Panel", patch: {} }); const before = await readFile(path.join(dir, "video.manifest.json"), "utf8"); assert.equal(await run("hide", "c02", "hideModules=diet,streak", "--take", "panel"), 0, lines.join("\n")); assert.match(lines.join("\n"), /c02 \(take panel\): hideModules diet, streak/); assert.equal(await readFile(path.join(dir, "video.manifest.json"), "utf8"), before); assert.deepEqual((await resolveTakeManifest(dir, "panel")).manifest.timeline[1].hideModules, ["diet", "streak"]); assert.equal(await run("hide", "c02", "claim.count=2", "--take", "panel"), 2); assert.match(lines.at(-1), /--take sets a take's entry knobs/); }); test("umtool set shelfNote='…': a line on the shelf over an entry's span, any entry; --take writes the take's patch", async () => { const dir = await project("note"); const m = await read(dir); m.timeline.push({ type: "post", id: "x01", item: "123" }); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(m, null, 2) + "\n"); const { lines, run } = runner(setCommand); assert.equal(await run("note", "c02", "shelfNote= Weighed in on camera "), 0, lines.join("\n")); assert.equal((await read(dir)).timeline[1].shelfNote, "Weighed in on camera", "trimmed"); assert.match(lines.at(-1), /c02: shelfNote "Weighed in on camera" \(on the shelf over its span\)/); assert.equal(await run("note", "x01", "shelfNote=2026"), 0, lines.join("\n")); assert.equal((await read(dir)).timeline[2].shelfNote, "2026", "a post item too; words whatever they parse as"); assert.equal(await run("note", "c02", `shelfNote=${"x".repeat(81)}`), 1); assert.match(lines.at(-1), /shelfNote is 81 characters \(at most 80\)/); assert.equal(await run("note", "c02", "shelfNote="), 0); assert.equal("shelfNote" in (await read(dir)).timeline[1], false); const { draftTake } = await import("./takeMaker.mjs"); const { resolveTakeManifest } = await import("./takeManifest.mjs"); await draftTake(dir, { id: "panel", label: "Panel", patch: {} }); const before = await readFile(path.join(dir, "video.manifest.json"), "utf8"); assert.equal(await run("note", "c02", "shelfNote=Day 41", "hideModules=diet", "--take", "panel"), 0, lines.join("\n")); assert.equal(await readFile(path.join(dir, "video.manifest.json"), "utf8"), before); const t = (await resolveTakeManifest(dir, "panel")).manifest.timeline[1]; assert.deepEqual([t.shelfNote, t.hideModules], ["Day 41", ["diet"]]); }); test("umtool set: claim and audio knobs through the writers; key= clears; a bad key or value is refused", async () => { const dir = await project("set"); const { lines, run } = runner(setCommand); assert.equal(await run("set", "c01", "claim.at=15.5", "claim.count=2", "claim.label=2 SEIZURES", "audio.offset=-40"), 0); let c = (await read(dir)).timeline[0]; assert.deepEqual(c.claim, { id: "k1", verdict: "CONTRADICTED", at: 15.5, count: 2, label: "2 SEIZURES" }); assert.deepEqual(c.audio, { offset: -40 }); assert.equal(await run("set", "c01", "claim.count=", "audio.offset="), 0); c = (await read(dir)).timeline[0]; assert.deepEqual(c.claim, { id: "k1", verdict: "CONTRADICTED", at: 15.5, label: "2 SEIZURES" }); assert.equal("audio" in c, false); assert.equal(await run("set", "c01", "claim.colour=1"), 2); assert.match(lines.at(-1), /not a clip knob/); assert.equal(await run("set", "c01", "claim.at=99"), 1); assert.match(lines.at(-1), /is outside the clip's window/); assert.equal(await run("set", "c02", "claim.count=2"), 1); assert.match(lines.at(-1), /carries no claim/); assert.equal(await run("set"), 2); // The deck's finale layout for a clip: finale, or clip (the default: the key removed). assert.equal(await run("set", "c02", "layout=finale"), 0); assert.equal((await read(dir)).timeline[1].layout, "finale"); assert.equal(await run("set", "c02", "layout=clip"), 0); assert.equal("layout" in (await read(dir)).timeline[1], false); assert.equal(await run("set", "c02", "layout=wide"), 1); assert.match(lines.at(-1), /layout must be/); // The finale is one run of the last clips: c01 alone would have c02 after it (finale.mjs). assert.equal(await run("set", "c01", "layout=finale"), 1); assert.match(lines.at(-1), /no clip may follow the finale/); assert.equal("layout" in (await read(dir)).timeline[0], false); }); test("umtool set claim=: the clip's claim pin off on the draft; claim=none too; a value or --take is refused", async () => { const dir = await project("claimoff"); const { lines, run } = runner(setCommand); assert.equal(await run("claimoff", "c01", "claim=x"), 2); assert.match(lines.at(-1), /claim= \(or claim=none\) takes the clip's claim off; to add one, mark\.add=/); assert.deepEqual((await read(dir)).timeline[0].claim, { id: "k1", verdict: "CONTRADICTED" }, "untouched"); // A version (L3): refused, with the way there -- nothing written to the take or the draft. const { draftTake } = await import("./takeMaker.mjs"); await draftTake(dir, { id: "v1", label: "Version 1", patch: {} }); const takeBefore = await readFile(path.join(dir, "takes", "v1", "take.json"), "utf8"); assert.equal(await run("claimoff", "c01", "claim=", "--take", "v1"), 2); assert.match(lines.at(-1), /open it in the draft first \(umtool takes open claimoff v1\)/); assert.equal(await readFile(path.join(dir, "takes", "v1", "take.json"), "utf8"), takeBefore); assert.deepEqual((await read(dir)).timeline[0].claim, { id: "k1", verdict: "CONTRADICTED" }); // The draft: the pin comes off. assert.equal(await run("claimoff", "c01", "claim="), 0, lines.join("\n")); assert.equal("claim" in (await read(dir)).timeline[0], false); assert.match(lines.at(-1), /c01: no claim \(its pin taken off\)/); // A clip of two marks: claim=none takes both (claims), as marks= would. const m = await read(dir); m.timeline[1].claims = [{ id: "a", verdict: "CONTRADICTED", at: 32 }, { id: "b", verdict: "CONTRADICTED", at: 38 }]; await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(m, null, 2) + "\n"); assert.equal(await run("claimoff", "c02", "claim=none", "--json"), 0, lines.join("\n")); const c2 = (await read(dir)).timeline[1]; assert.equal("claims" in c2 || "claim" in c2, false); assert.deepEqual(JSON.parse(lines.at(-1)).marks, []); }); test("umtool look: the fact-check's stamp, a verdict's stamp word, markers, layout, the ladder, a look key", async () => { const dir = await project("look"); const { lines, run } = runner(lookCommand); assert.equal(await run("look", "factcheck.stamp.scale=1.3", "factcheck.stamp.motion=pop", "factcheck.verdicts.CONTRADICTED.stampLabel=SEIZURE"), 0); let m = await read(dir); assert.deepEqual(m.render.chrome.factcheck, { stamp: { scale: 1.3, motion: "pop" }, verdicts: { CONTRADICTED: { stampLabel: "SEIZURE" } } }); assert.equal(await run("look", "factcheck.stamp.scale=", "factcheck.stamp.motion="), 0); m = await read(dir); assert.deepEqual(m.render.chrome.factcheck, { verdicts: { CONTRADICTED: { stampLabel: "SEIZURE" } } }); assert.equal(await run("look", 'deck.markers=[{"after":"c01","label":"Arrival","align":"left"}]', "deck.markerLayout=truncate"), 0); m = await read(dir); assert.deepEqual(m.render.chrome.deck, { markers: [{ after: "c01", label: "Arrival", align: "left" }], markerLayout: "truncate" }); assert.equal(await run("look", 'variants=[{"name":"master"},{"name":"480p","height":480,"crf":26}]', "transition=0.3"), 0); m = await read(dir); assert.deepEqual(m.render.variants, [{ name: "master" }, { name: "480p", height: 480, crf: 26 }]); assert.equal(m.render.transition, 0.3); assert.equal(await run("look", "factcheck.stamp.motion=spin"), 1); assert.match(lines.at(-1), /stamp\.motion/); // The tally's cells on their first count: for every cell, or one verdict's; an unknown value refused by name. assert.equal(await run("look", "factcheck.tally.showAt=first"), 0, lines.join("\n")); assert.deepEqual((await read(dir)).render.chrome.factcheck.tally, { showAt: "first" }); assert.equal(await run("look", "factcheck.tally.showAt.PARTLY=first"), 0, lines.join("\n")); assert.deepEqual((await read(dir)).render.chrome.factcheck.tally, { showAt: { PARTLY: "first" } }); assert.equal(await run("look", "factcheck.tally.showAt=later"), 1); assert.match(lines.at(-1), /tally\.showAt must be "always" or "first"/); assert.equal(await run("look", "factcheck.tally.showAt="), 0); assert.equal("tally" in ((await read(dir)).render.chrome.factcheck ?? {}), false); // Any of the deck's own keys, checked by the build's rules (an unknown one is refused in its words). assert.equal(await run("look", 'deck.pip={"color":"verdict"}'), 0, lines.join("\n")); assert.deepEqual((await read(dir)).render.chrome.deck.pip, { color: "verdict" }); assert.equal(await run("look", "deck.nope=1"), 1); assert.match(lines.at(-1), /nope/); assert.equal(await run("look", "deck=1"), 2); assert.equal(await run("look", "nope=1"), 2); // what `umtool show` prints const k = knobsOf(m); assert.equal(k.markers.length, 1); assert.deepEqual(k.stampLabels, { CONTRADICTED: "SEIZURE" }); assert.ok(knobsLines(m).some((l) => /variants\s+master, 480p$/.test(l))); }); test("umtool look deck..: one field set, the rest kept; the subtitle's second line refused until the footage fits", async () => { const dir = await project("look-nested"); const { lines, run } = runner(lookCommand); assert.equal(await run("look-nested", 'deck.subtitle={"parts":["channel","title","date","clock"]}'), 0, lines.join("\n")); // 0.82 leaves the footage 4 px over a 190 px deck: one more line does not fit, and the refusal says what does. assert.equal(await run("look-nested", "deck.subtitle.lines=2"), 1); assert.match(lines.at(-1), /subtitle\.lines 2.*footageScale at most 0\.787/); assert.deepEqual((await read(dir)).render.chrome.deck.subtitle, { parts: ["channel", "title", "date", "clock"] }); assert.equal(await run("look-nested", "deck.subtitle.lines=2", "deck.footageScale=0.78"), 0, lines.join("\n")); let deck = (await read(dir)).render.chrome.deck; assert.deepEqual(deck.subtitle, { parts: ["channel", "title", "date", "clock"], lines: 2 }); assert.equal(deck.footageScale, 0.78); assert.equal(await run("look-nested", "deck.subtitle.lines=3"), 1); assert.match(lines.at(-1), /subtitle\.lines must be 1 or 2/); // key= clears one field; the object goes when nothing is left in it. assert.equal(await run("look-nested", "deck.subtitle.lines=", "deck.subtitle.parts="), 0, lines.join("\n")); deck = (await read(dir)).render.chrome.deck; assert.equal("subtitle" in deck, false); assert.equal(await run("look-nested", "deck.subtitle..lines=2"), 2); }); test("umtool variants: refuses an unbuilt cut; makes the ladder (stub encoder) and lists it with the sync report", async () => { const dir = await project("vars"); const { lines, run } = runner((args, o) => variantsCommand(args, { ...o, env: { ...process.env, E2E_UMTOOL_VARIANTS_SCRIPT: STUB } })); assert.equal(await run("vars"), 2); assert.match(lines.at(-1), /not been built/); await mkdir(path.join(dir, "out", "sourced"), { recursive: true }); await writeFile(path.join(dir, "out", "huck.mp4"), Buffer.alloc(4096, 1)); await writeFile(path.join(dir, "out", "sourced", "sync.json"), JSON.stringify({ fps: 30, items: [{ id: "c01", start: 0, lagMs: -68, peak: 0.9 }] })); lines.length = 0; assert.equal(await run("vars"), 0); assert.ok(lines.some((l) => /^ {2}fit24 /.test(l)), lines.join("\n")); assert.ok(lines.some((l) => /c01 +-68 ms/.test(l)), lines.join("\n")); lines.length = 0; assert.equal(await run("vars", "--list", "--json"), 0); const s = JSON.parse(lines.join("\n")); assert.deepEqual(s.made.items.map((i) => i.name), ["master", "1080p", "720p", "fit24"]); assert.equal(s.sync.items[0].flagged, true); }); test("umtool variants --take: a finished take whose render is only its preview.mp4 gets its ladder", async () => { const dir = await project("take-vars"); const takeDir = path.join(dir, "takes", "final-1026"); await mkdir(path.join(takeDir, "out"), { recursive: true }); await writeFile(path.join(takeDir, "video.manifest.json"), JSON.stringify(MANIFEST, null, 2) + "\n"); await writeFile(path.join(takeDir, "preview.mp4"), Buffer.alloc(4096, 2)); await writeFile(path.join(takeDir, "take.json"), JSON.stringify({ id: "final-1026", group: "takes", order: 1, label: "Final", kind: "different", preview: "preview.mp4" })); const { lines, run } = runner((args, o) => variantsCommand(args, { ...o, env: { ...process.env, E2E_UMTOOL_VARIANTS_SCRIPT: STUB } })); assert.equal(await run("take-vars", "--take", "final-1026"), 0, lines.join("\n")); assert.ok(lines.some((l) => /making the variants of its preview\.mp4/.test(l)), lines.join("\n")); assert.ok(lines.some((l) => /--source .*preview\.mp4/.test(l)), lines.join("\n")); lines.length = 0; assert.equal(await run("take-vars", "--take", "final-1026", "--list", "--json"), 0); const s = JSON.parse(lines.join("\n")); assert.equal(s.built.from, "preview"); assert.deepEqual(s.made.items.map((i) => [i.name, i.exists]), [["master", true], ["1080p", true], ["720p", true], ["fit24", true]]); assert.equal((await readFile(path.join(takeDir, "out", "huck.master.mp4"))).length, 4096); }); test("umtool set blur.*: on, caption (text whatever it parses as), strength, a span; blur.on= clears it all; render.blur=off by umtool look", async () => { const dir = await project("blur"); const { lines, run } = runner(setCommand); assert.equal(await run("blur", "c02", "blur.on=true", "blur.caption=Blurred here for TOS", "blur.strength=8", "blur.from=31.5", "blur.to=40"), 0, lines.join("\n")); assert.deepEqual((await read(dir)).timeline[1].blur, { on: true, caption: "Blurred here for TOS", strength: 8, from: 31.5, to: 40 }); assert.match(lines.at(-1), /^c02: blur \{"on":true,"caption":"Blurred here for TOS"/); assert.equal(await run("blur", "c02", "blur.caption=2025", "blur.from=", "blur.to="), 0); assert.deepEqual((await read(dir)).timeline[1].blur, { on: true, caption: "2025", strength: 8 }); assert.equal(await run("blur", "c02", "blur.strength=40"), 1); assert.match(lines.at(-1), /strength must be a number from 2 to 15/); assert.equal(await run("blur", "c02", "blur.to=99"), 1); assert.match(lines.at(-1), /must lie inside the clip's window 30–41/); assert.equal(await run("blur", "c02", "blur.sigma=3"), 2); assert.match(lines.at(-1), /not a clip knob/); // what `umtool show` prints const m = await read(dir); assert.deepEqual(knobsOf(m).clips.find((c) => c.id === "c02").blur, { on: true, caption: "2025", strength: 8 }); assert.ok(knobsLines(m).some((l) => /c02\s.*blur caption="2025" strength=8/.test(l)), knobsLines(m).join("\n")); // The uncensored variant: render.blur off, through the look's writer. const look = runner(lookCommand); assert.equal(await look.run("blur", "blur=off"), 0, look.lines.join("\n")); assert.equal((await read(dir)).render.blur, "off"); assert.ok(knobsLines(await read(dir)).some((l) => /blur\s+off \(render\.blur/.test(l))); assert.equal(await look.run("blur", "blur=on"), 0); assert.equal("blur" in (await read(dir)).render, false); // blur.on= clears the whole key. assert.equal(await run("blur", "c02", "blur.on="), 0); assert.equal("blur" in (await read(dir)).timeline[1], false); assert.match(lines.at(-1), /c02: blur none/); }); test("umtool look chrome.layout=deck --unset render.: the deck turned on and the legacy keys dropped in ONE write, an undo point first", async () => { const dir = path.join(ROOT, "legacy"); await mkdir(dir, { recursive: true }); const legacy = { ...MANIFEST, slug: "legacy", render: { width: 1920, height: 1080, fps: 30, rail: { width: 680 }, chromeEngine: "hyperframes", railEngine: "table", chromeRegions: ["panel"], claimSchedule: "pinned", wordmark: "X", title: { size: 1 }, finale: { open: 1 }, cut: { a: 1 } }, }; await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(legacy, null, 2) + "\n"); const { lines, run } = runner(lookCommand); // The deck beside the old rail is refused (the build's own sentence); the manifest untouched. assert.equal(await run("legacy", "chrome.layout=deck"), 1); assert.match(lines.join("\n"), /render\.chrome \(the deck\) and render\.rail cannot both be set/); assert.equal((await read(dir)).render.chrome, undefined); // A key that is not a legacy one is refused, and named. assert.equal(await run("legacy", "--unset", "render.palette"), 2); assert.match(lines.at(-1), /legacy render keys only/); // In one write: the rail and the old engine keys gone, the deck on (render.chrome created). assert.equal(await run("legacy", "chrome.layout=deck", ...["rail", "chromeEngine", "railEngine", "chromeRegions", "claimSchedule", "wordmark", "title", "finale", "cut"].flatMap((k) => ["--unset", `render.${k}`])), 0, lines.join("\n")); const m = await read(dir); assert.deepEqual(m.render, { width: 1920, height: 1080, fps: 30, chrome: { engine: "hyperframes", layout: "deck", deck: {} } }); assert.match(lines.at(-1), /unset render\.rail, render\.chromeEngine.*chrome\.layout: deck \(render\.chrome created.*undo point: revisions\//); const { readdir } = await import("node:fs/promises"); assert.ok((await readdir(path.join(dir, "revisions"))).some((f) => /render-keys/.test(f)), "an undo point of its own"); // deck.* keys in the same command land after the chrome exists. const fresh = path.join(ROOT, "fresh"); await mkdir(fresh, { recursive: true }); await writeFile(path.join(fresh, "video.manifest.json"), JSON.stringify({ ...MANIFEST, slug: "fresh", render: { width: 1920, height: 1080, fps: 30 } }, null, 2) + "\n"); assert.equal(await run("fresh", "chrome.layout=deck", "deck.sectionTitle=true"), 0, lines.join("\n")); assert.deepEqual((await read(fresh)).render.chrome.deck, { sectionTitle: true }); }); test("umtool look deck.=… --take : the take's patch, an undo point of the take's, the project's manifest untouched; deck keys only", async () => { const dir = await project("looktake"); const { lines, run } = runner(lookCommand); const { draftTake } = await import("./takeMaker.mjs"); const { resolveTakeManifest } = await import("./takeManifest.mjs"); await draftTake(dir, { id: "a9", label: "A9", patch: {} }); const before = await readFile(path.join(dir, "video.manifest.json"), "utf8"); assert.equal(await run("looktake", "deck.goals.base=true", "deck.goals.baseMaxDays=365", "--take", "a9"), 0, lines.join("\n")); assert.match(lines.join("\n"), /deck\.goals: \{"base":true,"baseMaxDays":365\}/); assert.match(lines.at(-1), /take a9: written to its patch \(undo: umtool timeline looktake --take a9 undo\)/); assert.equal(await readFile(path.join(dir, "video.manifest.json"), "utf8"), before); assert.deepEqual((await resolveTakeManifest(dir, "a9")).manifest.render.chrome.deck.goals, { base: true, baseMaxDays: 365 }); // One field off again keeps the rest. assert.equal(await run("looktake", "deck.goals.baseMaxDays=", "--take", "a9"), 0, lines.join("\n")); assert.deepEqual((await resolveTakeManifest(dir, "a9")).manifest.render.chrome.deck.goals, { base: true }); // The build's rules still refuse; other knobs and a take that is not there are refused. assert.equal(await run("looktake", "deck.goals.baseMaxDays=-3", "--take", "a9"), 1); assert.match(lines.at(-1), /baseMaxDays must be null \(every base counts\) or whole days/); assert.equal(await run("looktake", "transition=0.3", "--take", "a9"), 2); assert.match(lines.at(-1), /--take sets a take's deck keys/); assert.equal(await run("looktake", "deck.goals.baseMaxDays=365", "--take", "nope"), 1); assert.match(lines.at(-1), /has no take nope/); assert.equal(await readFile(path.join(dir, "video.manifest.json"), "utf8"), before); }); test("umtool set chapter='…': an entry's name in the chapter list, any entry; chapter= clears; --take writes the take's patch", async () => { const dir = await project("chapter"); const m = await read(dir); m.timeline.push({ type: "post", id: "x01", item: "123" }); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(m, null, 2) + "\n"); const { lines, run } = runner(setCommand); assert.equal(await run("chapter", "c02", "chapter= The weigh-in "), 0, lines.join("\n")); assert.equal((await read(dir)).timeline[1].chapter, "The weigh-in", "trimmed"); assert.match(lines.at(-1), /c02: chapter "The weigh-in" \(its name in the chapter list\)/); assert.equal(await run("chapter", "x01", "chapter=2026"), 0, lines.join("\n")); assert.equal((await read(dir)).timeline[2].chapter, "2026", "a post item too; words whatever they parse as"); // Beside a clip's other knobs in one command. assert.equal(await run("chapter", "c01", "chapter=Arrival", "audio.gain=2"), 0, lines.join("\n")); assert.deepEqual([(await read(dir)).timeline[0].chapter, (await read(dir)).timeline[0].audio], ["Arrival", { gain: 2 }]); assert.equal(await run("chapter", "c02", `chapter=${"x".repeat(101)}`), 1); assert.match(lines.at(-1), /chapter is 101 characters \(at most 100\)/); assert.equal((await read(dir)).timeline[1].chapter, "The weigh-in", "a refused write changes nothing"); assert.equal(await run("chapter", "c02", "chapter="), 0); assert.equal("chapter" in (await read(dir)).timeline[1], false); assert.match(lines.at(-1), /c02: chapter none/); const { draftTake } = await import("./takeMaker.mjs"); const { resolveTakeManifest } = await import("./takeManifest.mjs"); await draftTake(dir, { id: "a9", label: "A9", patch: {} }); const before = await readFile(path.join(dir, "video.manifest.json"), "utf8"); assert.equal(await run("chapter", "c02", "chapter=Day 41", "--take", "a9"), 0, lines.join("\n")); assert.match(lines.join("\n"), /c02 \(take a9\): chapter "Day 41"/); assert.equal(await readFile(path.join(dir, "video.manifest.json"), "utf8"), before); assert.equal((await resolveTakeManifest(dir, "a9")).manifest.timeline[1].chapter, "Day 41"); assert.equal(await run("chapter", "x01", "chapter=", "--take", "a9"), 0, lines.join("\n")); assert.equal("chapter" in (await resolveTakeManifest(dir, "a9")).manifest.timeline[2], false); }); test("umtool set channelTitle=…: the clip's own channel name, trimmed; `channelTitle=` clears it; a control character or > 60 is refused", async () => { const dir = await project("chantitle"); const { lines, run } = runner(setCommand); assert.equal(await run("chantitle", "c02", "channelTitle= Synth Channel "), 0, lines.join("\n")); assert.equal((await read(dir)).timeline[1].channelTitle, "Synth Channel", "trimmed"); assert.match(lines.at(-1), /c02: channelTitle "Synth Channel"/); assert.equal(await run("chantitle", "c02", "channelTitle=2031"), 0, lines.join("\n")); assert.equal((await read(dir)).timeline[1].channelTitle, "2031", "words whatever they parse as"); assert.equal(await run("chantitle", "c02", "channelTitle=Synth\u0007Channel"), 1); assert.match(lines.at(-1), /control character/); assert.equal(await run("chantitle", "c02", "channelTitle=Synth\nChannel"), 1); assert.match(lines.at(-1), /control character/); assert.equal(await run("chantitle", "c02", `channelTitle=${"x".repeat(61)}`), 1); assert.match(lines.at(-1), /at most 60/); assert.equal((await read(dir)).timeline[1].channelTitle, "2031", "a refused write changes nothing"); assert.equal(await run("chantitle", "c02", "channelTitle="), 0); assert.equal("channelTitle" in (await read(dir)).timeline[1], false); assert.match(lines.at(-1), /c02: channelTitle none/); }); test("umtool look channelNames.=…: one channel's name for the whole cut; `channelNames.=` clears one, `channelNames=` all", async () => { const dir = await project("channames"); const m = await read(dir); m.timeline.push({ type: "clip", id: "c03", channel: "guest-chan", video: "v3", start: 1, end: 5 }); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(m, null, 2) + "\n"); const { lines, run } = runner(lookCommand); assert.equal(await run("channames", "channelNames.chan=Synth Channel"), 0, lines.join("\n")); assert.deepEqual((await read(dir)).render.channelNames, { chan: "Synth Channel" }); assert.equal(await run("channames", "channelNames.guest-chan=2031"), 0, lines.join("\n")); assert.deepEqual((await read(dir)).render.channelNames, { chan: "Synth Channel", "guest-chan": "2031" }, "merged; words whatever they parse as"); // A slug no clip of the cut uses: written, and warned about. assert.equal(await run("channames", "channelNames.other-chan=Nobody"), 0, lines.join("\n")); assert.equal((await read(dir)).render.channelNames["other-chan"], "Nobody"); assert.match(lines.join("\n"), /WARN .*other-chan/); // A control character: refused, nothing written. assert.notEqual(await run("channames", "channelNames.chan=Synth\u0000Channel"), 0); assert.match(lines.at(-1), /control character/); assert.equal((await read(dir)).render.channelNames.chan, "Synth Channel"); assert.equal(await run("channames", "channelNames.other-chan="), 0, lines.join("\n")); assert.deepEqual((await read(dir)).render.channelNames, { chan: "Synth Channel", "guest-chan": "2031" }); // The JSON form, and clearing the lot. assert.equal(await run("channames", 'channelNames={"chan":null}'), 0, lines.join("\n")); assert.deepEqual((await read(dir)).render.channelNames, { "guest-chan": "2031" }); assert.ok(knobsLines(await read(dir)).some((l) => /channels\s+guest-chan="2031"$/.test(l)), "umtool show prints them"); assert.equal(await run("channames", "channelNames="), 0, lines.join("\n")); assert.equal("channelNames" in ((await read(dir)).render ?? {}), false); });