// The clip kit's keys written (lane clip-kit): `umtool set`'s and the clip editor's writer (manifest.mjs updateClip) // takes a clip's `qr` (whole or one field) and its batch `name`, refuses what the build would, and clears with null. 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 { MANIFEST_NAME, updateClip } from "./manifest.mjs"; const manifest = () => ({ schemaVersion: 1, slug: "kit", provenance: { channelSlug: "chan", siteOrigin: "" }, render: { width: 640, height: 360, fps: 15 }, timeline: [{ type: "clip", id: "w01", video: "01a1d292-6d30", start: 10, end: 20, citeUrl: "https://kick.com/somechan/videos/01a1d292-6d30" }], }); const read = async (dir) => JSON.parse(await readFile(path.join(dir, MANIFEST_NAME), "utf8")).timeline[0]; test("updateClip: a clip's qr (whole or one field) and name; refused in the build's words; null clears", async () => { const dir = await mkdtemp(path.join(tmpdir(), "umtool-kit-")); try { await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(manifest(), null, 2) + "\n"); await updateClip(dir, "w01", { "qr.corner": "tl" }); assert.deepEqual((await read(dir)).qr, { corner: "tl" }); await updateClip(dir, "w01", { "qr.links": "moment" }); assert.deepEqual((await read(dir)).qr, { corner: "tl", links: "moment" }); await updateClip(dir, "w01", { "qr.corner": null }); assert.deepEqual((await read(dir)).qr, { links: "moment" }); await updateClip(dir, "w01", { qr: false }); assert.equal((await read(dir)).qr, false); await updateClip(dir, "w01", { qr: null }); assert.equal("qr" in (await read(dir)), false); await updateClip(dir, "w01", { name: " toms-toast " }); assert.equal((await read(dir)).name, "toms-toast"); await assert.rejects(updateClip(dir, "w01", { "qr.corner": "middle" }), /w01\.qr\.corner is one of br, bl, tr, tl/); await assert.rejects(updateClip(dir, "w01", { name: "x".repeat(61) }), /name is a file name of 1 to 60/); // A refused write leaves the file as it was. assert.deepEqual(await read(dir), { ...manifest().timeline[0], name: "toms-toast" }); await updateClip(dir, "w01", { name: "" }); assert.equal("name" in (await read(dir)), false); } finally { await rm(dir, { recursive: true, force: true }); } }); import { updateRender } from "./manifest.mjs"; test("the channel promo written: the look's (checked by the build's rules) and a clip's own (false, or its timing)", async () => { const dir = await mkdtemp(path.join(tmpdir(), "umtool-promo-")); try { await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(manifest(), null, 2) + "\n"); // A code linking the channel needs the channel's page first. await assert.rejects(updateRender(dir, { qr: { links: "channel" } }), /set render\.promo\.url/); const r = await updateRender(dir, { promo: { name: ["Synth", "Live"], url: "https://kick.com/somechan" } }); assert.deepEqual(r.look.promo, { name: ["Synth", "Live"], url: "https://kick.com/somechan" }); await assert.rejects(updateRender(dir, { promo: { name: "Synth", url: "kick.com" } }), /render\.promo\.url is the channel's page/); await updateClip(dir, "w01", { promo: false }); assert.equal((await read(dir)).promo, false); await updateClip(dir, "w01", { "promo.hold": 2 }); assert.deepEqual((await read(dir)).promo, { hold: 2 }); await assert.rejects(updateClip(dir, "w01", { "promo.hold": 9 }), /w01\.promo\.hold is 0–5 seconds/); await updateClip(dir, "w01", { promo: null }); assert.equal("promo" in (await read(dir)), false); // The render's promo removed: none again. await updateRender(dir, { promo: null }); assert.equal(JSON.parse(await readFile(path.join(dir, MANIFEST_NAME), "utf8")).render.promo, undefined); } finally { await rm(dir, { recursive: true, force: true }); } }); test("a clip's zooms written: whole, checked against its window and each other; [] or null clears", async () => { const dir = await mkdtemp(path.join(tmpdir(), "umtool-zooms-")); try { await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(manifest(), null, 2) + "\n"); await updateClip(dir, "w01", { zooms: [{ at: 12, scale: 1.5, focus: [0.7, 0.3] }] }); assert.deepEqual((await read(dir)).zooms, [{ at: 12, scale: 1.5, focus: [0.7, 0.3] }]); await assert.rejects(updateClip(dir, "w01", { zooms: [{ at: 19 }] }), /w01\.zooms\[0\] \(19–21\.3 s\) runs outside the clip's window \(10–20\)/); await assert.rejects(updateClip(dir, "w01", { zooms: [{ at: 11 }, { at: 12 }] }), /starts before the one at 11 s is out again/); await updateClip(dir, "w01", { zooms: [] }); assert.equal("zooms" in (await read(dir)), false); // Written, a zoom is checked against the CUT: one inside the window the cut does not play is refused. const m = manifest(); Object.assign(m.timeline[0], { cutStart: 12, cutEnd: 17 }); await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(m, null, 2) + "\n"); await assert.rejects(updateClip(dir, "w01", { zooms: [{ at: 16 }] }), /w01\.zooms\[0\] \(16–18\.3 s\) runs outside the clip's cut \(12–17\)/); await assert.rejects(updateClip(dir, "w01", { zooms: [{ at: 11 }] }), /runs outside the clip's cut \(12–17\)/); await updateClip(dir, "w01", { zooms: [{ at: 12.5 }] }); await assert.rejects(updateRender(dir, { zooms: { soften: 2 } }), /soften is 1–1\.3/); assert.deepEqual((await updateRender(dir, { zooms: { soften: 1.3 } })).look.zooms, { soften: 1.3 }); } finally { await rm(dir, { recursive: true, force: true }); } }); test("a clip's cold open written: both fields in one patch, inside its cut, 1-4 s; null clears", async () => { const dir = await mkdtemp(path.join(tmpdir(), "umtool-coldopen-")); try { await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(manifest(), null, 2) + "\n"); await updateClip(dir, "w01", { "coldOpen.from": 17, "coldOpen.to": 19.5 }); assert.deepEqual((await read(dir)).coldOpen, { from: 17, to: 19.5 }); await assert.rejects(updateClip(dir, "w01", { "coldOpen.to": 25 }), /w01\.coldOpen is 8 s: a cold open is 1–4 s/); await assert.rejects(updateClip(dir, "w01", { coldOpen: { from: 19, to: 21 } }), /outside the clip's cut \(10–20\)/); // Across a gap, or the whole cut: refused at write time, naming the clip and the gap. const m = manifest(); Object.assign(m.timeline[0], { cutStart: 12, cutEnd: 15, gaps: [{ from: 13.5, to: 14 }] }); await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(m, null, 2) + "\n"); await assert.rejects(updateClip(dir, "w01", { coldOpen: { from: 13, to: 14.5 } }), /w01\.coldOpen \(13–14\.5\) runs across w01's gap 13\.5–14 s/); await assert.rejects(updateClip(dir, "w01", { coldOpen: { from: 12, to: 15 } }), /w01\.coldOpen \(12–15\) is the whole cut/); await assert.doesNotReject(updateClip(dir, "w01", { coldOpen: { from: 12, to: 13.4 } })); await updateClip(dir, "w01", { coldOpen: null }); assert.equal("coldOpen" in (await read(dir)), false); } finally { await rm(dir, { recursive: true, force: true }); } }); import { censorCommand } from "./censorCli.mjs"; test("hidden regions written: a clip's own (dotted fields), a recording's through umtool censor; refused in the build's words", async () => { const root = await mkdtemp(path.join(tmpdir(), "umtool-censor-")); const dir = path.join(root, "reports", "proj"); try { await mkdir(dir, { recursive: true }); await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(manifest(), null, 2) + "\n"); await updateClip(dir, "w01", { "censor.boxes": [[0, 0, 0.2, 0.2]], "censor.style": "black" }); assert.deepEqual((await read(dir)).censor, { boxes: [[0, 0, 0.2, 0.2]], style: "black" }); await assert.rejects(updateClip(dir, "w01", { "censor.style": "smudge" }), /censor\.style is one of blur, black, pixelate/); await updateClip(dir, "w01", { censor: false }); assert.equal((await read(dir)).censor, false); const out = []; const code = await censorCommand(["proj", "--video", "01a1d292-6d30", "--box", "0.75,0,0.25,1", "--box", "0,0.6,0.3,0.4@12-14", "--style", "pixelate"], { reportsRoot: path.join(root, "reports"), log: (s) => out.push(s), err: (s) => out.push(s) }); assert.equal(code, 0, out.join("\n")); const m = JSON.parse(await readFile(path.join(dir, MANIFEST_NAME), "utf8")); assert.deepEqual(m.render.censor, [{ video: "01a1d292-6d30", boxes: [[0.75, 0, 0.25, 1], { box: [0, 0.6, 0.3, 0.4], from: 12, to: 14 }], style: "pixelate" }]); const bad = []; assert.equal(await censorCommand(["proj", "--video", "x", "--box", "0.9,0,0.3,1"], { reportsRoot: path.join(root, "reports"), log: () => {}, err: (s) => bad.push(s) }), 2); assert.match(bad.join(), /boxes\[0\] is \[x, y, w, h\]/); assert.equal(await censorCommand(["proj", "--video", "01a1d292-6d30", "--clear"], { reportsRoot: path.join(root, "reports"), log: () => {}, err: () => {} }), 0); assert.equal(JSON.parse(await readFile(path.join(dir, MANIFEST_NAME), "utf8")).render.censor, undefined); } finally { await rm(root, { recursive: true, force: true }); } });