// The compositions' declared params (release 38 lane E, common // lib/report/fxParams.mjs) held to the validators that build them: every // declared param is accepted at its bounds and its default and refused just // past them, so a declaration cannot promise the video assistant a value the // deck's own check refuses. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import test from "node:test"; import { COMPOSITION_PARAMS, chromeWithParam, compositionOn } from "yt-dlp-transcript-common/lib/report/fxParams.mjs"; import { DECK_PARAMS, validateChrome } from "./deck.mjs"; import { STATS_PARAMS } from "./stats.mjs"; import { FX_KEYS, FX_PARAMS } from "./fx.mjs"; // Each composition on, with the one setting validateChrome needs beside it. const ON = { deck: {}, stats: { stats: {} }, "fx.kineticQuote": { fx: { kineticQuote: {} } }, "fx.redact": { fx: { redact: {} } }, "fx.odometer": { fx: { odometer: {} } }, "fx.scrubber": { fx: { scrubber: {} } }, "fx.glitch": { fx: { glitch: {} } }, "fx.thenNow": { fx: { thenNow: { pairs: [{ then: "c1", now: "c2" }] } } }, "fx.receipts": { fx: { receipts: {} } }, "fx.zoom": { fx: { zoom: {} } }, "fx.punchIn": { fx: { punchIn: {} } }, "fx.whip": { fx: { whip: {} } }, }; // A declared value that needs a setting no param can carry (a list), and that // setting: the glitch on "clips" tears into the clips its list names. const NEEDS = { "fx.glitch": { on: { clips: (fx) => ({ ...fx, glitch: { ...fx.glitch, clips: ["c1"] } }) } } }; const renderOf = (id) => ({ width: 1920, height: 1080, fps: 30, transition: 0.5, chrome: { engine: "hyperframes", layout: "deck", deck: {}, ...ON[id] } }); const errorsWith = (id, key, value) => { const render = renderOf(id); const chrome = chromeWithParam(render, id, key, value); assert.ok(chrome, `${id}.${key}: chromeWithParam gave nothing`); const need = NEEDS[id]?.[key]?.[value]; if (need) chrome.fx = need(chrome.fx); const { chrome: _c, ...rest } = render; return validateChrome(chrome, rest); }; test("the modules re-export their slice of the declarations", () => { assert.equal(DECK_PARAMS, COMPOSITION_PARAMS.deck); assert.equal(STATS_PARAMS, COMPOSITION_PARAMS.stats); assert.deepEqual(Object.keys(FX_PARAMS).sort(), Object.keys(COMPOSITION_PARAMS).filter((k) => k.startsWith("fx.")).map((k) => k.slice(3)).sort()); for (const k of Object.keys(FX_PARAMS)) assert.ok(FX_KEYS.includes(k), `${k} is an effect`); for (const id of Object.keys(COMPOSITION_PARAMS)) assert.ok(ON[id], `${id} has a fixture here`); }); test("every declared param: its default and both bounds build; just past them, the validator refuses", () => { for (const [id, params] of Object.entries(COMPOSITION_PARAMS)) { assert.ok(compositionOn(renderOf(id), id), `${id} is on in its fixture`); for (const p of params) { const where = `${id}.${p.key}`; assert.deepEqual(errorsWith(id, p.key, p.default), [], `${where} default`); if (p.kind === "enum") { for (const v of p.values) assert.deepEqual(errorsWith(id, p.key, v), [], `${where} = ${v}`); assert.ok(errorsWith(id, p.key, "nope").length, `${where} = "nope" is refused`); } else if (p.kind === "bool") { for (const v of [true, false]) assert.deepEqual(errorsWith(id, p.key, v), [], `${where} = ${v}`); assert.ok(errorsWith(id, p.key, "yes").length, `${where} = "yes" is refused`); } else if (p.kind === "text") { assert.deepEqual(errorsWith(id, p.key, "x".repeat(p.maxLength)), [], `${where} at its length`); assert.ok(errorsWith(id, p.key, "x".repeat(p.maxLength + 1)).length, `${where} past its length is refused`); } else { const eps = p.kind === "int" ? 1 : 0.01; assert.deepEqual(errorsWith(id, p.key, p.min), [], `${where} = min ${p.min}`); assert.deepEqual(errorsWith(id, p.key, p.max), [], `${where} = max ${p.max}`); assert.ok(errorsWith(id, p.key, p.min - eps).length, `${where} below min is refused`); assert.ok(errorsWith(id, p.key, p.max + eps).length, `${where} above max is refused`); } } } }); test("a composition the cut does not draw has nothing to set", () => { const plain = { width: 1920, height: 1080 }; assert.equal(compositionOn(plain, "deck"), false); assert.equal(chromeWithParam(plain, "deck", "motion.in", 0.3), null); assert.equal(compositionOn(renderOf("deck"), "fx.glitch"), false); assert.equal(chromeWithParam(renderOf("deck"), "deck", "height", 300), null, "an undeclared param"); });