// The basic preset and `umtool preset apply --replace` (lane output-modes): // the built-in `basic` is one key, render.mode; --replace clears the // manifest's own value of every key a preset sets, after an undo point, so the // preset's renders; the mode a writer sees is the look's (`umtool look
// mode=basic`), and a basic cut's chrome is not checked. Synthetic. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { mkdtemp, readdir, 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, leafPaths, renderLessPreset, updatePreset, updateRender } from "./manifest.mjs"; import { listPresets, loadPreset } from "umtool-report-to-video/presets"; import { presetCommand } from "./modulesCli.mjs"; import { lookCommand } from "./knobsCli.mjs"; async function project(doc) { const root = await mkdtemp(path.join(tmpdir(), "umtool-preset-replace-")); const dir = path.join(root, "p"); await import("node:fs/promises").then((fs) => fs.mkdir(dir, { recursive: true })); await writeFile(path.join(dir, MANIFEST_NAME), JSON.stringify(doc, null, 2) + "\n"); return { root, dir }; } const read = async (dir) => JSON.parse(await readFile(path.join(dir, MANIFEST_NAME), "utf8")); const base = (render) => ({ schemaVersion: 1, slug: "p", provenance: { channelSlug: "ch" }, render, timeline: [{ type: "clip", id: "c1", video: "v", start: 1, end: 3 }] }); test("the built-in presets: plain-deck, huck-deck, ember-deck, archive-catalog and basic (render.mode basic, nothing else)", () => { const names = listPresets().map((p) => p.name); for (const n of ["plain-deck", "huck-deck", "ember-deck", "archive-catalog", "basic"]) assert.ok(names.includes(n), n); assert.deepEqual(loadPreset("basic").render, { mode: "basic" }); }); test("leafPaths and renderLessPreset: every leaf the preset sets goes from the manifest, an emptied object with it", () => { assert.deepEqual(leafPaths({ a: 1, b: { c: 2, d: { e: [1] } }, f: {} }), [["a"], ["b", "c"], ["b", "d", "e"], ["f"]]); const { render, cleared } = renderLessPreset( { mode: "deck", crf: 19, palette: { bg: "#000", accent: "#f00" }, chrome: { deck: { qr: { links: "x" }, markers: [{ after: "c1" }] } }, intro: "boot" }, { mode: "basic", palette: { bg: "#111" }, chrome: { deck: { qr: { links: "original", show: true } } }, intro: { style: "boot-dark" } }, ); assert.deepEqual(render, { crf: 19, palette: { accent: "#f00" }, chrome: { deck: { markers: [{ after: "c1" }] } } }, "the cut's own content stays"); assert.deepEqual(cleared.sort(), ["render.chrome.deck.qr.links", "render.intro", "render.mode", "render.palette.bg"]); }); test("preset apply basic --replace: an undo point first, the manifest's mode cleared, the cut renders basic; its deck chrome is not checked", async () => { const p = await project(base({ mode: "deck", crf: 21, chrome: { layout: "deck", engine: "hyperframes", deck: { nonsense: true } } })); try { // Without --replace the manifest's own "deck" beats the preset's basic -- and its broken chrome is checked. await assert.rejects(updatePreset(p.dir, "basic"), /nonsense/); const r = await updatePreset(p.dir, "basic", { replace: true }); assert.equal(r.preset, "basic"); assert.deepEqual(r.cleared, ["render.mode"]); assert.match(r.snapshot.rel, /^revisions\/.*-auto-before-preset-replace\.manifest\.json$/); const m = await read(p.dir); assert.equal(m.preset, "basic"); assert.equal(m.render.mode, undefined); assert.equal(m.render.crf, 21); const before = JSON.parse(await readFile(path.join(p.dir, r.snapshot.rel), "utf8")); assert.equal(before.render.mode, "deck", "the undo point is the file as it was"); await assert.rejects(updatePreset(p.dir, null, { replace: true }), /name the preset/); } finally { await rm(p.root, { recursive: true, force: true }); } }); test("umtool preset apply … --replace and umtool look
mode=basic|deck, from a terminal", async () => { const p = await project(base({ mode: "deck" })); const lines = []; const opts = { reportsRoot: p.root, log: (s) => lines.push(s), err: (s) => lines.push(s) }; try { assert.equal(await presetCommand(["apply", "basic", p.dir, "--replace"], opts), 0); assert.match(lines.join("\n"), /stands on the preset basic[\s\S]*cleared the manifest's own render\.mode[\s\S]*undo point: revisions\//); assert.ok((await readdir(path.join(p.dir, "revisions"))).length >= 1); assert.equal(await presetCommand(["apply", "none", p.dir, "--replace"], opts), 2); const out = []; assert.equal(await lookCommand([p.dir, "mode=deck"], { root: p.root, out: (s) => out.push(s), err: (s) => out.push(s) }), 0); assert.equal((await read(p.dir)).render.mode, "deck", "over a preset, deck is written: it must beat the preset's basic"); assert.equal(await lookCommand([p.dir, "mode=basic", "basic={\"fade\":{\"video\":0.5}}"], { root: p.root, out: (s) => out.push(s), err: (s) => out.push(s) }), 0); const m = await read(p.dir); assert.equal(m.render.mode, "basic"); assert.deepEqual(m.render.basic, { fade: { video: 0.5 } }); assert.equal(await lookCommand([p.dir, "mode=plain"], { root: p.root, out: (s) => out.push(s), err: (s) => out.push(s) }), 1); assert.match(out.join("\n"), /render\.mode must be "deck"/); // The writer's door alone: deck on a cut with no preset is no key. await updatePreset(p.dir, null); await updateRender(p.dir, { mode: "deck" }); assert.equal((await read(p.dir)).render.mode, undefined); } finally { await rm(p.root, { recursive: true, force: true }); } });