// Tests for the brand intro's site swap (`render.intro.site`, `swap`, `url`, // `urlPlace`): the key's validation, how "auto" and a site id resolve, the // prefix rule, the page with no site being the page it always was (so cached // intros still hit), the cues landing on the chime and staying seek-safe, the // colours and the URLs. // // The pixels are judged by eye: ~/reports/archilyzer-intro/variants/site. // // Run with: node --test umtool/report-to-video/intro-site.test.mjs import assert from "node:assert/strict"; import test from "node:test"; import { createHash } from "node:crypto"; import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { INTRO_BEATS, INTRO_MARKS, INTRO_SECONDS, INTRO_STYLES, INTRO_SWAPS, introEntry, introErrors, introKey, introManifest, introOf, introSiteKnobs, introSitePrefix, introUrlText, resolveIntroSite, } from "./intro.mjs"; import { PROJECT_URL_TEXT, SWAP_SECONDS, contrast, introAccent, introCues, introHtml, introPalette, lockupParts, swapPlan, } from "./chrome-intro.mjs"; import { brandKit } from "./brand.mjs"; import { encodeArgs, selectVariant } from "./build-video.mjs"; import { frameCount } from "./deck.mjs"; import { validateLook } from "yt-dlp-transcript-common/lib/report/look.mjs"; import { mergePatch, patchFromSets } from "../lib/report/takeMaker.mjs"; const HERE = path.dirname(fileURLToPath(import.meta.url)); const kit = brandKit("archilyzer-media"); const parts = lockupParts(kit); const RENDER = { width: 1920, height: 1080, fps: 30, audioRate: 48000, audioChannels: 2, transition: 0.5 }; const HUCK_ORIGIN = "https://jeralyzer.pages.dev"; const JERA = { name: "Jeralyzer", lead: "Jer", accent: "brass", url: "jeralyzer.pages.dev" }; /** A sites dir like the corpus's: site.json files with the keys the intro reads (and one it must not). */ function sitesFixture() { const dir = mkdtempSync(path.join(tmpdir(), "intro-sites-")); const site = (id, j) => { mkdirSync(path.join(dir, id), { recursive: true }); writeFileSync(path.join(dir, id, "site.json"), JSON.stringify(j)); }; site("hasanalyzer", { siteTitle: "Hasanalyzer", wordmarkLead: "Hasan", accent: "violet", siteUrl: "https://hasanalyzer.pages.dev" }); site("jeralyzer", { siteTitle: "Jeralyzer", wordmarkLead: "Jer", accent: "brass", siteUrl: "https://jeralyzer.pages.dev", cloudflareProject: "secret" }); site("jeralyzer-private", { siteTitle: "Jeralyzer", wordmarkLead: "Jer", accent: "brass", audience: "private" }); mkdirSync(path.join(dir, "_homepage")); return dir; } const cut = (intro, provenance) => ({ slug: "t", render: { ...RENDER, intro }, ...(provenance ? { provenance } : {}), timeline: [{ id: "c1", type: "card", seconds: 5 }], }); // --------------------------------------------------------------------------- // The key // --------------------------------------------------------------------------- test("render.intro.site: auto, none, a site id or {name, lead, accent, url}; swap, url and urlPlace beside it", () => { for (const site of ["auto", "none", "jeralyzer", "hasanalyzer-private", JERA, { name: "Jeralyzer" }, { name: "Foo", accent: "#a1b2c3", url: false }]) { assert.deepEqual(introErrors({ style: "boot-dark", site }), [], JSON.stringify(site)); } for (const swap of INTRO_SWAPS) assert.deepEqual(introErrors({ style: "boot-dark", site: "auto", swap }), [], swap); for (const url of [true, false, "both", "site", "project"]) assert.deepEqual(introErrors({ style: "boot-dark", site: "auto", url }), [], String(url)); for (const urlPlace of ["under", "replace"]) assert.deepEqual(introErrors({ style: "boot-dark", site: "auto", urlPlace }), []); assert.deepEqual([...INTRO_SWAPS], ["swipe-down", "roll", "wipe"]); // Read with the defaults: the operator's swipe-down, both URLs, under MEDIA. const o = introOf({ intro: { style: "boot-dark", mark: "chime", site: "auto" } }); assert.deepEqual([o.site, o.swap, o.url, o.urlPlace], ["auto", "swipe-down", "both", "under"]); assert.equal(introOf({ intro: { style: "boot", site: "auto", url: false } }).url, "none"); assert.equal(introOf({ intro: { style: "boot", site: "auto", url: true } }).url, "both"); }); test("render.intro.site: bad values are refused, each by its name", () => { const e = (v) => introErrors({ style: "boot-dark", ...v }).join("\n"); assert.match(e({ site: "Jera lyzer!" }), /render\.intro\.site "Jera lyzer!" is not auto, none, a site id/); assert.match(e({ site: 7 }), /render\.intro\.site must be auto, none, a site id or an object/); assert.match(e({ site: { name: "X", colour: "red" } }), /render\.intro\.site\.colour is not a key \(name, lead, accent, url\)/); assert.match(e({ site: { accent: "brass" } }), /render\.intro\.site\.name must be the site's name/); assert.match(e({ site: { name: "Jeralyzer", lead: "Hasan" } }), /render\.intro\.site\.lead must be how the name starts/); assert.match(e({ site: { name: "Jeralyzer", accent: "gold" } }), /render\.intro\.site\.accent must be an accent \(signal, brass/); assert.match(e({ site: { name: "Jeralyzer", url: 5 } }), /render\.intro\.site\.url must be the site's URL/); assert.match(e({ site: "auto", swap: "slide" }), /render\.intro\.swap must be swipe-down, roll, wipe, got "slide"/); assert.match(e({ site: "auto", url: "all" }), /render\.intro\.url must be both, site, project, true \(both\) or false \(none\), got "all"/); assert.match(e({ site: "auto", urlPlace: "over" }), /render\.intro\.urlPlace must be under or replace, got "over"/); // A take's patch goes through the same door. const take = mergePatch(cut({ style: "boot-dark" }), patchFromSets(["render.intro.site=auto", "render.intro.swap=roll", "render.intro.url=false"])); assert.deepEqual(validateLook(take), []); assert.match(validateLook(mergePatch(cut({ style: "boot-dark" }), patchFromSets(["render.intro.swap=flip"]))).join(), /render\.intro\.swap must be/); }); // --------------------------------------------------------------------------- // Resolving the site // --------------------------------------------------------------------------- test("site auto: the Huck cut's siteOrigin (https://jeralyzer.pages.dev) resolves to Jeralyzer, read for its title, lead, accent and URL only", () => { const sitesDir = sitesFixture(); try { const site = resolveIntroSite("auto", { siteOrigin: HUCK_ORIGIN, sitesDir }); assert.deepEqual(site, { id: "jeralyzer", name: "Jeralyzer", lead: "Jer", accent: "brass", url: "jeralyzer.pages.dev" }); assert.ok(!JSON.stringify(site).includes("secret"), "no other site.json key is carried"); // An origin with a path or a trailing slash, or in capitals, is the same site. assert.equal(resolveIntroSite("auto", { siteOrigin: "https://Jeralyzer.pages.dev/pages/x/", sitesDir }).id, "jeralyzer"); // Through the cut's one door: selectVariant -> introManifest, provenance read off the manifest. const m = introManifest(cut({ style: "boot-dark", mark: "chime", site: "auto" }, { siteOrigin: HUCK_ORIGIN }), { sitesDir }); const entry = m.timeline[0]; assert.equal(entry.site.name, "Jeralyzer"); assert.deepEqual([entry.swap, entry.url, entry.urlPlace], ["swipe-down", "both", "under"]); assert.deepEqual(introSiteKnobs(entry), { site: entry.site, swap: "swipe-down", url: "both", urlPlace: "under" }); // A site id names one outright. assert.equal(resolveIntroSite("hasanalyzer", { sitesDir }).lead, "Hasan"); // A private copy has no URL: it swaps the name, and only the project's URL can show. assert.equal(resolveIntroSite("jeralyzer-private", { sitesDir }).url, undefined); } finally { rmSync(sitesDir, { recursive: true, force: true }); } }); test("site auto with no match (no provenance, another archive): no swap, the plain intro's entry exactly", () => { const sitesDir = sitesFixture(); try { const plain = introEntry({ intro: { style: "boot-dark", mark: "chime" } }); assert.deepEqual(introEntry({ intro: { style: "boot-dark", mark: "chime", site: "auto" } }, { sitesDir }), plain); assert.deepEqual(introEntry({ intro: { style: "boot-dark", mark: "chime", site: "auto", swap: "roll" } }, { provenance: { siteOrigin: "https://elsewhere.example" }, sitesDir }), plain); assert.deepEqual(introEntry({ intro: { style: "boot-dark", mark: "chime", site: "none" } }, { sitesDir }), plain); assert.equal(introSiteKnobs(plain), null); } finally { rmSync(sitesDir, { recursive: true, force: true }); } }); test("site : one that is not there is refused by name, with the sites that are", () => { const sitesDir = sitesFixture(); try { assert.throws(() => resolveIntroSite("rekietalyzer", { sitesDir }), /render\.intro\.site "rekietalyzer" is not a site in .* — one of hasanalyzer, jeralyzer, jeralyzer-private, or "auto"/); assert.throws(() => introManifest(cut({ style: "boot", site: "nope" }), { sitesDir }), /render\.intro\.site "nope" is not a site/); } finally { rmSync(sitesDir, { recursive: true, force: true }); } }); test("site {object}: kept as written, its URL without a scheme", () => { assert.deepEqual(resolveIntroSite({ name: " Jeralyzer ", accent: "brass", url: "https://jeralyzer.pages.dev/" }), { name: "Jeralyzer", accent: "brass", url: "jeralyzer.pages.dev" }); assert.deepEqual(resolveIntroSite({ name: "Jeralyzer", url: false }), { name: "Jeralyzer", url: false }); assert.equal(introUrlText("http://a.b/"), "a.b"); }); // --------------------------------------------------------------------------- // The prefix rule // --------------------------------------------------------------------------- test("the prefix: the name minus the shared 'lyzer' (the whole name when it does not end in it); the lead says which letters are heavy", () => { assert.equal(introSitePrefix("Jeralyzer"), "Jera"); assert.equal(introSitePrefix("Rekietalyzer"), "Rekieta"); assert.equal(introSitePrefix("Hasanalyzer"), "Hasana"); assert.equal(introSitePrefix("Foo"), "Foo"); assert.equal(introSitePrefix("lyzer"), "lyzer", "never an empty prefix"); const plan = (site) => swapPlan({ parts, site }); const jera = plan(JERA); assert.equal(jera.prefix, "Jera"); assert.deepEqual(jera.out, [0, 1, 2, 3, 4], "Archi goes, lyzer stays"); assert.deepEqual(jera.glyphs.map((g) => `${g.ch}:${g.role}`), ["J:lead", "e:lead", "r:lead", "a:suffix"], "Jer|alyzer, as the site's header splits it"); // The new prefix ends where Archi did: right up to the kept "l", the word's own spacing. const l = parts.letters[5]; assert.ok(jera.glyphs.at(-1).box.x1 < l.box.x0 && l.box.x0 - jera.glyphs.at(-1).box.x1 < 12, "no gap opened, no overlap"); // A narrower name re-centres the word by half the difference. assert.ok(jera.recenter < 0 && Math.abs(jera.recenter - ((jera.oldL + 531.65) / 2 - (jera.newL + jera.newR) / 2)) < 1); // No lead: the whole prefix heavy. assert.ok(plan({ name: "Jeralyzer" }).glyphs.every((g) => g.role === "lead")); // A lead that runs into "lyzer" (Bonnell|yzer) takes its letters with it. const bon = plan({ name: "Bonnellyzer", lead: "Bonnell" }); assert.equal(bon.prefix, "Bonnell"); assert.deepEqual(bon.out, [0, 1, 2, 3, 4, 5], "Archil goes, yzer stays"); // A name not ending in lyzer swaps the whole word. assert.deepEqual(plan({ name: "Ani" }).out, [...Array(10).keys()]); // MEDIA is spread to the new word's width. const wide = plan({ name: "Rekietalyzer", lead: "Rekieta" }); assert.ok(Math.abs((wide.mediaBox.x1 - wide.mediaBox.x0) - (wide.newR - wide.newL)) < 1); // A letter the table does not have is refused, naming it. assert.throws(() => plan({ name: "Jéralyzer" }), /the intro cannot draw "é"/); }); // --------------------------------------------------------------------------- // No site: the page it always was // --------------------------------------------------------------------------- // sha256 (first 16) of every plain page as it was before the site swap // existed. A cached intro's key is its page's hash: if one of these moves, // every cached intro of that style re-renders. Update them only on purpose. const PLAIN_PAGES = { "boot/light/none": "a314e2a3b32667dc", "boot/light/draw": "7ccd0e5de3926525", "boot/light/chime": "6d5db33e755a60d9", "boot/dark/none": "dd8a7c5e89d92502", "boot/dark/draw": "aefd5b4522ce885c", "boot/dark/chime": "de884a858d799c82", "boot-wipe/light/none": "eef28861f737445c", "boot-wipe/light/draw": "84a5fc523220cf70", "boot-wipe/light/chime": "24305243b63ef0f9", "boot-wipe/dark/none": "2560d4c6fef528f2", "boot-wipe/dark/draw": "713499595d48cffd", "boot-wipe/dark/chime": "92667f9fd80e039a", "boot-dark/light/none": "1e7d1a13ae92c5d6", "boot-dark/light/draw": "f6f39f7dc92490f3", "boot-dark/light/chime": "109f770bc7166bc9", "boot-dark/dark/none": "5649d73cb258aa0a", "boot-dark/dark/draw": "5663f66716f9b3bd", "boot-dark/dark/chime": "4821a2a9109caff7", "boot-cascade/light/none": "66702393b4898a2c", "boot-cascade/light/draw": "0ae2a60ed6f50784", "boot-cascade/light/chime": "11650c9d299010ae", "boot-cascade/dark/none": "e6688e3b824d0264", "boot-cascade/dark/draw": "bf4442b27759e9d8", "boot-cascade/dark/chime": "c28a423b4b7d3713", "boot-mark/light/none": "8dd36eca63449b09", "boot-mark/light/draw": "ccce2bdc9e2a1c92", "boot-mark/light/chime": "0816d90979a7d62a", "boot-mark/dark/none": "8c56b66e319ddea8", "boot-mark/dark/draw": "06936a62572f6c88", "boot-mark/dark/chime": "89e4e087e67af811", // title-card (lane intro-play, 9 Nov) without words: boot-mark's motion, its own page. "title-card/light/none": "ed845730c051db8f", "title-card/light/draw": "d2d697471f1279d7", "title-card/light/chime": "1537771013ccc805", "title-card/dark/none": "e23fdccbff88e8d5", "title-card/dark/draw": "3ebb9262c1f4a897", "title-card/dark/chime": "88d148cf54d71096", }; test("no site (absent, none, or an auto that matched nothing): every page is byte-identical to before, so cached intros still hit", () => { const hash = (html) => createHash("sha256").update(html).digest("hex").slice(0, 16); for (const style of INTRO_STYLES) { for (const ground of ["light", "dark"]) { for (const mark of INTRO_MARKS) { const html = introHtml({ style, ground, mark, seconds: INTRO_SECONDS, kit }); assert.equal(hash(html), PLAIN_PAGES[`${style}/${ground}/${mark}`], `${style}/${ground}/${mark}`); assert.equal(introHtml({ style, ground, mark, seconds: INTRO_SECONDS, kit, site: null, swap: "roll", url: "site" }), html); } } } // site: "none" builds the plain entry, so the same page and the same key. const sitesDir = sitesFixture(); try { const a = selectVariant(cut({ style: "boot-dark", mark: "chime" })).timeline[0]; const b = introManifest(cut({ style: "boot-dark", mark: "chime", site: "none" }), { sitesDir }).timeline[0]; assert.deepEqual(a, b); } finally { rmSync(sitesDir, { recursive: true, force: true }); } }); test("the cache key: the site, the swap, the URLs and where they go each change it", () => { const key = (o = {}) => introKey({ html: introHtml({ style: "boot-dark", ground: "dark", mark: "chime", seconds: INTRO_SECONDS, kit, ...o }), soundSha: "s", encode: encodeArgs(RENDER), fps: 30, frames: frameCount(INTRO_SECONDS, 30), version: "hf", }); const keys = [ key(), key({ site: JERA }), key({ site: JERA, swap: "roll" }), key({ site: JERA, swap: "wipe" }), key({ site: JERA, url: "none" }), key({ site: JERA, url: "site" }), key({ site: JERA, urlPlace: "replace" }), key({ site: { ...JERA, accent: "green" } }), key({ site: { name: "Hasanalyzer", lead: "Hasan", accent: "violet" } }), ]; assert.equal(new Set(keys).size, keys.length); assert.equal(key({ site: JERA }), key({ site: { ...JERA } })); }); // --------------------------------------------------------------------------- // The cues // --------------------------------------------------------------------------- const PROPS = (c) => Object.keys(c.to).flatMap((p) => (p === "scale" ? ["scaleX", "scaleY"] : p === "attr" ? Object.keys(c.to.attr).map((a) => `attr.${a}`) : [p])); const siteCues = ({ style = "boot-dark", ground = "dark", mark = "chime", swap = "swipe-down", site = JERA, url = "both", urlPlace = "under" } = {}) => { const palette = introPalette(ground, kit); const withMark = mark !== "none"; const plan = swapPlan({ parts, site, url, urlPlace, markX: withMark ? parts.mark.x : null }); const markShapes = mark === "draw" ? [{ kind: "ground", fill: "#151b20" }, { kind: "bar", fill: "#5fa8a0", lit: true }] : []; return { plan, ...introCues({ style, ground, mark, seconds: INTRO_SECONDS, parts: { ...parts, markShapes }, palette, swap: { plan, kind: swap, accent: introAccent(site.accent, ground, palette), lift: -20 } }) }; }; test("the swap lands with the chime: nothing of it before the chime, the prefix changed within ~0.5 s, the mark's pop and MEDIA on the same beat", () => { const T = INTRO_BEATS.chime.from; for (const swap of INTRO_SWAPS) { const { cues, init } = siteCues({ swap }); const own = cues.filter((c) => /^(n\d|nf\d|swapclip|swapin|bar|recenter|mshift|u\d|lift)/.test(c.k)); assert.ok(own.length, swap); for (const c of own) assert.ok(c.at >= T - 1e-9, `${swap}: ${c.k} at ${c.at}, before the chime`); const ends = own.filter((c) => /^(n\d|recenter)/.test(c.k)).map((c) => c.at + c.dur); assert.ok(Math.max(...ends) <= T + 0.55, `${swap}: the new prefix lands by ${Math.max(...ends)}`); // The old prefix moves only on the chime; the new one is out of sight until then. for (const i of [0, 1, 2, 3, 4]) { const late = cues.filter((c) => c.k === `w${i}` && c.at >= T - 1e-9); if (swap !== "wipe") assert.ok(late.length, `${swap}: Archi's letter ${i} goes on the chime`); } if (swap === "swipe-down") { assert.ok(init.n0.y < 0, "the new prefix waits above its line"); assert.equal(init.swapclip.attr.height, 10000, "the line clips nothing until the chime (the tumble flies through it)"); const ns = cues.filter((c) => /^n\d$/.test(c.k)); assert.ok(ns.every((c) => c.to.y === 0 && c.ease === "power3.inOut")); const end = Math.max(...ns.map((c) => c.at + c.dur)) - T; assert.ok(end > SWAP_SECONDS - 0.03 && end <= SWAP_SECONDS + 1e-6, `swipe-down takes the swap's ~0.35 s (${end})`); } if (swap === "roll") assert.equal(init.n0.scaleY, 0); if (swap === "wipe") assert.equal(init.swapin.attr.height, 0); } }); test("every swap cue list is seek-safe: no two cues run on one property at once, and each starts where the one before it ended", () => { for (const style of INTRO_STYLES) { for (const mark of INTRO_MARKS) { for (const swap of INTRO_SWAPS) { for (const urlPlace of ["under", "replace"]) { const { cues } = siteCues({ style, mark, swap, urlPlace, ground: style === "boot-dark" ? "dark" : "light" }); const last = new Map(); for (const c of [...cues].sort((a, b) => a.at - b.at)) { for (const p of PROPS(c)) { const k = `${c.k}.${p}`; const prev = last.get(k); if (prev) { assert.ok(c.at >= prev.at + prev.dur - 1e-6, `${style}/${mark}/${swap}: ${k} at ${c.at} starts before ${prev.at}+${prev.dur} ends`); const val = (o) => (p.startsWith("attr.") ? o.attr?.[p.slice(5)] : p === "scaleY" || p === "scaleX" ? (o[p] ?? o.scale) : o[p]); if (val(c.from) !== undefined && val(prev.to) !== undefined) { assert.deepEqual(val(c.from), val(prev.to), `${style}/${mark}/${swap}: ${k} at ${c.at} starts from ${val(c.from)}, not where ${prev.at} left it`); } } last.set(k, c); } } } } } } }); test("URLs in MEDIA's place: MEDIA never comes in; under MEDIA it does, spread to the new word", () => { const nW = 10; const media = (cues) => cues.filter((c) => /^w1[0-4]$/.test(c.k) || c.k === "mwipe"); const under = siteCues({ urlPlace: "under" }); assert.ok(media(under.cues).length); const replace = siteCues({ urlPlace: "replace" }); assert.equal(media(replace.cues).length, 0); for (let j = 0; j < 5; j++) assert.equal(replace.init[`w${nW + j}`].opacity, 0); // With no URL to show, MEDIA stays even with urlPlace: replace. assert.ok(media(siteCues({ urlPlace: "replace", url: "none" }).cues).length); }); // --------------------------------------------------------------------------- // Colours and URLs on the page // --------------------------------------------------------------------------- test("the site's colours: its accent on the letters, MEDIA, the mark's lit line and its URL; the project's URL in the brand's own", () => { for (const ground of ["dark", "light"]) { const palette = introPalette(ground, kit); for (const id of ["signal", "brass", "vermilion", "violet", "sakura", "blue", "green"]) { const a = introAccent(id, ground, palette); assert.ok(contrast(a.ink, palette.ground) >= 3, `${id} on ${ground}: ${contrast(a.ink, palette.ground)}`); assert.ok(contrast(a.mark, "#151b20") >= 3, `${id}'s lit line on the mark's square`); } // A custom hex too dark (or light) for the ground is fitted to it. for (const hex of ["#202830", "#e0e8f0"]) assert.ok(contrast(introAccent(hex, ground, palette).ink, palette.ground) >= 4.5, `${hex} on ${ground}`); } assert.equal(introAccent(undefined, "dark", introPalette("dark", kit)).ink, "#5fa8a0", "no accent: Signal, the family default"); const html = introHtml({ style: "boot-dark", ground: "dark", mark: "chime", seconds: INTRO_SECONDS, kit, site: JERA }); assert.match(html, /data-k="u0" fill="#e3b15c"/, "the site's URL in brass"); assert.match(html, /data-k="u1" fill="#5fa8a0"/, "the project's in Signal"); assert.match(html, //); assert.match(html, //); assert.match(html, //); const data = JSON.parse(html.match(/