// Tests for the brand intro (`render.intro`, intro.mjs + chrome-intro.mjs + // common/lib/report/intro.mjs): the key's validation, the entry selectVariant // prepends and what it does to the cut's clock, the chapters, the beats the // page times to, and the cache key the render is kept by. // // The pixels are judged by eye: ~/reports/archilyzer-intro/variants. // // Run with: node --test umtool/report-to-video/intro.test.mjs import assert from "node:assert/strict"; import test from "node:test"; import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { mkdir } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { INTRO_BEATS, INTRO_ID, INTRO_MARKS, INTRO_SECONDS, INTRO_STANDIN_SOUND, INTRO_STYLE_MARK, INTRO_STYLES, buildIntroSegment, introAudioGraph, introEncodeArgs, introEntry, introErrors, introKey, introManifest, introOf, introRecordPath, introSoundPath, missingSoundMessage, validateIntro, } from "./intro.mjs"; import { introCues, introHtml, introPalette, lockupParts } from "./chrome-intro.mjs"; import { brandKit } from "./brand.mjs"; import { encodeArgs, foldIntroChapter, selectVariant } from "./build-video.mjs"; import { estimateSchedule, estimatedDuration, frameCount, hidesDeck, hyperframesCommand, resolveDeck, scheduleFrom } from "./deck.mjs"; import { LOOK_KEYS, applyLookPatch, validateLook } from "yt-dlp-transcript-common/lib/report/look.mjs"; import { mergePatch, patchFromSets } from "../lib/report/takeMaker.mjs"; const kit = brandKit("archilyzer-media"); const RENDER = { width: 1920, height: 1080, fps: 30, audioRate: 48000, audioChannels: 2, transition: 0.5 }; const TIMELINE = [ { id: "title", type: "card", seconds: 5 }, { id: "c1", type: "clip", video: "v1", start: 10, end: 22 }, { id: "c2", type: "card", seconds: 4 }, ]; const cut = (render) => ({ slug: "t", render: { ...RENDER, ...render }, timeline: TIMELINE.map((e) => ({ ...e })) }); // --------------------------------------------------------------------------- // Validation // --------------------------------------------------------------------------- test("render.intro: a style name or {style, ground, mark, sound, seconds}; absent and null are no intro", () => { assert.deepEqual(introErrors(undefined), []); assert.deepEqual(introErrors(null), []); for (const s of INTRO_STYLES) { assert.deepEqual(introErrors(s), [], s); assert.deepEqual(introErrors({ style: s, ground: "dark", sound: false, seconds: 5 }), [], s); for (const mark of INTRO_MARKS) assert.deepEqual(introErrors({ style: s, mark }), [], `${s} ${mark}`); } assert.deepEqual(introErrors({ style: "boot", sound: "intro.wav" }), []); assert.equal(introOf({}), null); assert.equal(introOf({ intro: null }), null); assert.deepEqual(introOf({ intro: "boot" }), { style: "boot", ground: "light", mark: "none", sound: undefined, seconds: INTRO_SECONDS }); assert.equal(introOf({ intro: "boot-dark" }).ground, "dark"); assert.equal(introOf({ intro: "boot-mark" }).ground, "dark"); assert.equal(introOf({ intro: { style: "boot-dark", ground: "light" } }).ground, "light", "a ground named beats the style's"); }); test("render.intro: an unknown style is refused by name, with the styles listed", () => { const [e] = introErrors("gameboy"); assert.match(e, /render\.intro\.style "gameboy" is not an intro style/); for (const s of INTRO_STYLES) assert.ok(e.includes(s), s); assert.match(introErrors({ ground: "dark" })[0], /style null is not an intro style/); }); test("render.intro.mark: none, draw or chime; boot-mark draws it, title-card chimes it, every other style has none", () => { assert.deepEqual([...INTRO_MARKS], ["none", "draw", "chime"]); for (const s of INTRO_STYLES) assert.equal(introOf({ intro: s }).mark, s === "boot-mark" ? "draw" : s === "title-card" ? "chime" : "none", s); assert.equal(INTRO_STYLE_MARK["boot-mark"], "draw"); assert.equal(introOf({ intro: { style: "boot-dark", mark: "chime" } }).mark, "chime", "a mark named beats the style's"); assert.equal(introOf({ intro: { style: "boot-mark", mark: "none" } }).mark, "none"); assert.match(introErrors({ style: "boot", mark: "pop" }).join(), /render\.intro\.mark must be none, draw, chime, got "pop"/); assert.match(introErrors({ style: "boot", mark: true }).join(), /render\.intro\.mark must be/); // A take sets it as one more knob, beside the style. const take = mergePatch(cut({ intro: "boot" }), patchFromSets(["render.intro.style=boot-dark", "render.intro.mark=chime"])); assert.deepEqual(validateLook(take), []); const entry = selectVariant(take).timeline[0]; assert.deepEqual([entry.style, entry.ground, entry.mark], ["boot-dark", "dark", "chime"]); assert.match(applyLookPatch(cut({}), { intro: { style: "boot", mark: "drawn" } }).errors.join(), /render\.intro\.mark must be/); }); test("render.intro: a bad ground, sound, length or key is refused, each by its name", () => { assert.match(introErrors({ style: "boot", ground: "grey" }).join(), /render\.intro\.ground must be light or dark/); assert.match(introErrors({ style: "boot", sound: 3 }).join(), /render\.intro\.sound must be/); assert.match(introErrors({ style: "boot", sound: "" }).join(), /render\.intro\.sound must be/); assert.match(introErrors({ style: "boot", seconds: 2 }).join(), /render\.intro\.seconds must be a number from 3\.5 to 8/); assert.match(introErrors({ style: "boot", seconds: 30 }).join(), /render\.intro\.seconds/); assert.match(introErrors({ style: "boot", colour: "red" }).join(), /render\.intro\.colour is not a key/); assert.match(introErrors(7).join(), /must be a style name/); }); test("render.intro is a look key: the build's validateLook refuses a bad one, the look patch writes and clears it", () => { assert.ok(LOOK_KEYS.includes("intro")); assert.deepEqual(validateLook(cut({ intro: "boot" })), []); assert.match(validateLook(cut({ intro: "nope" })).join(), /not an intro style/); assert.deepEqual(validateIntro(cut({})), []); // `umtool look

intro=boot-wipe` arrives as the text "boot-wipe". const on = applyLookPatch(cut({}), { intro: "boot-wipe" }); assert.deepEqual(on.errors, []); assert.equal(on.render.intro, "boot-wipe"); // `intro=` (null) clears it: the default, no intro. const off = applyLookPatch(cut({ intro: "boot" }), { intro: null }); assert.deepEqual(off.errors, []); assert.equal("intro" in off.render, false); const obj = applyLookPatch(cut({}), { intro: { style: "boot-cascade", ground: "dark" } }); assert.deepEqual(obj.render.intro, { style: "boot-cascade", ground: "dark" }); const bad = applyLookPatch(cut({}), { intro: "boot-tetris" }); assert.match(bad.errors.join(), /render\.intro\.style "boot-tetris" is not an intro style/); }); test("a take compares intros: --set render.intro=