// The finale's room (finale.mjs, deck.mjs finaleRail, chrome-finale.mjs): the // timeline taking the height its rows need (`timelineShare`), the claim // checks' words, span labels and the markers' laid so no two meet, the rail's // date labels said once and fanned with leaders when crowded, and the claims // standing in turn (`claims: "rotate"`) -- every cue stating its from. // // Run with: node --test finale-room.test.mjs import assert from "node:assert/strict"; import test from "node:test"; import { deckSchedule, estimateSchedule, finaleRail, snapWindow } from "./deck.mjs"; import { finaleCues, finaleHtml, finaleLayout } from "./chrome-finale.mjs"; import { aboveLine, aboveTop, FINALE_CLAIMS, FINALE_SHARE, fanSlots, finaleClaimSlots, finaleGeometry, placeAbove, aboveRows, railLabelLayout, textWidth, validateFinaleSettings, } from "./finale.mjs"; const PALETTE = { bg: "#101219", fg: "#f2f0ea", muted: "#979caa", accent: "#e5534b", amber: "#ffc860" }; const SEIZURES = { verdicts: { CORROBORATED: { label: "Seizures", color: "#e5534b", stampLabel: "Seizure" } } }; // The Huck walked cut in small (deck-claims.test.mjs's): dated clips in the // cut's order, his two count claims in one late clip, a goalpost, a marker. const CLIPS = [ ["arrive", "20201024"], ["meds", "20250514"], ["neuro", "20251106"], ["worst", "20260120", 1, "2026-01-19"], ["dozen", "20260824", 12, "2026-08-24"], ["ten-k", "20260826"], ["flash", "20261016"], ["rescue", "20260908", 1, "2026-09-08"], ["pill-test", "20260923"], ["costco-ok", "20261008", 1, "2026-09-22"], ["on-stream-b", "20261014", 3, "2026-10-14"], ["screenshot", "20261015"], ["blind-oct", "20261020", 1, "2026-10-20"], ["quality", "20261021"], ["less-than-ten", "20261022"], ["blend", "20261022"], ["tism", "20190613"], ["heartstrings", "20210408"], ]; const entries = (finale = ["heartstrings"]) => CLIPS.map(([id, , count, eventDate], i) => ({ type: "clip", id, video: `v${i}`, start: 100 * i, end: 100 * i + 30, ...(count ? { claim: { id, verdict: "CORROBORATED", at: 100 * i + 10, ...(count > 1 ? { count } : {}), eventDate } } : {}), ...(finale.includes(id) ? { layout: "finale" } : {}), })); const metas = () => CLIPS.map(([, up]) => ({ title: "T", uploadDate: up, channel: "C", webpageUrl: null })); const CLAIMS = [ { kind: "count", at: "less-than-ten", t: 1405, said: "“doesn't have multiple seizures a week”", window: { from: "2025-10-22", to: "2026-10-22" }, tally: "Seizures", per: "P1W", claim: { op: "<", value: 2 } }, { kind: "count", at: "less-than-ten", t: 1410, said: "“less than ten” in a year", window: { from: "2025-10-22", to: "2026-10-22" }, tally: "Seizures", claim: { op: "<", value: 10 } }, { kind: "goalpost", label: "Pill test results", steps: [ { at: "pill-test", t: 815, said: "“3–5 weeks”", from: "2026-09-23", due: ["P3W", "P5W"] }, { at: "screenshot", t: 1112, said: "“6–8 weeks”", from: "2026-10-15", due: ["P6W", "P8W"] }, ] }, ]; const MARKERS = [ { after: "quality", label: "No results after 8 wks", color: "#e5534b" }, { after: "blend", label: "MRI + neurologist Mon 26", color: "#e3b23c" }, ]; const renderWith = (deck = {}, finale = {}) => ({ width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck: { pip: { color: "verdict" }, markers: MARKERS, finale: { video: "side", ...finale }, ...deck }, factcheck: SEIZURES, }, }); const PROV = { siteOrigin: "https://example.test", channelSlug: "c" }; // The finale run: its last three clips, each `secs` long (time for the claims to take turns, or not). const built = (render, { secs = 30, finale = ["blend", "tism", "heartstrings"] } = {}) => { const es = entries(finale); return deckSchedule({ entries: es, durs: es.map((e) => (finale.includes(e.id) ? secs : 30)), D: 0.5, render, metas: metas(), provenance: PROV }); }; /** Each label's box on its row, for overlap checks: [row, left, right]. */ function claimBoxes(claims) { const out = []; for (const it of claims.items) { for (const sp of it.spans ?? []) out.push({ who: sp.label, it: it.j, row: sp.row, a: sp.left, b: sp.left + sp.w, stickX: sp.row > 0 ? sp.stickX : null }); const ls = it.kind === "count" ? [it.label] : it.steps.map((st) => st.label); for (const l of ls) out.push({ who: l.said, it: it.j, row: l.row, a: l.left, b: l.left + l.width + 8, stickX: l.stickX }); } return out; } const markerBoxes = (marks) => marks.map((mk) => ({ who: mk.label, row: mk.row + 1, a: mk.side === "left" ? mk.x - 18 - mk.max : mk.x, b: mk.side === "left" ? mk.x : mk.x + 18 + mk.max, stickX: mk.x, })); /** No two boxes in one row meet; no stick rises through a box in a row under its own. */ function assertNoneMeet(boxes, why) { for (let i = 0; i < boxes.length; i += 1) { for (let j = i + 1; j < boxes.length; j += 1) { const p = boxes[i], q = boxes[j]; if (p.row === q.row) assert.ok(p.b <= q.a || q.b <= p.a, `${why}: "${p.who}" and "${q.who}" meet in row ${p.row}`); } } for (const p of boxes) { if (p.stickX === null || p.stickX === undefined) continue; for (const q of boxes) { if (q === p || q.row >= p.row) continue; assert.ok(p.stickX < q.a || p.stickX > q.b, `${why}: the stick of "${p.who}" (row ${p.row}) crosses "${q.who}" (row ${q.row})`); } } } /** A key's value at cut second t, from the cues (linear inside a tween: enough to say on or off mid-slot). */ function valueAt({ init, cues }, k, prop, t) { let v = init[k]?.[prop] ?? 1; for (const c of cues) { if (c.k !== k || !(prop in c.to) || c.at > t) continue; const p = c.dur > 0 ? Math.min(1, (t - c.at) / c.dur) : 1; v = c.from[prop] + (c.to[prop] - c.from[prop]) * p; } return v; } test("deck.finale.timelineShare and .claims: validated, defaults auto and rotate", () => { assert.deepEqual(validateFinaleSettings({ timelineShare: "auto", claims: "all" }), []); assert.deepEqual(validateFinaleSettings({ timelineShare: 0.5, claims: "rotate" }), []); const bad = validateFinaleSettings({ timelineShare: 0.9, claims: "cycle" }); assert.ok(bad.some((e) => e.startsWith("render.chrome.deck.finale.timelineShare must be \"auto\" or a number from 0.38 to 0.6")), bad.join("\n")); assert.ok(bad.includes('render.chrome.deck.finale.claims must be "rotate", "all"'), bad.join("\n")); assert.deepEqual(validateFinaleSettings({ timelineShare: "half" }).length, 1); }); test("geometry: a taller rail shrinks the clip in its aspect and the panels to the column; the default is as it was", () => { const r = renderWith({}, { stats: [{ label: "a", value: "1" }, { label: "b", value: "2" }, { label: "c", value: "3" }, { label: "d", value: "4" }], statsTitle: "T" }); const was = finaleGeometry(r, { verdicts: 2, stats: 4, statsTitle: true }); assert.deepEqual(was.video, { x: 1104, y: 448, width: 768, height: 432 }); assert.equal(was.totals.height, 236); for (const B of [520, 560, Math.round(1080 * FINALE_SHARE.max) - 36]) { for (const video of ["side", "corner", "hidden"]) { const g = finaleGeometry(renderWith({}, { video }), { verdicts: 2, stats: 4, statsTitle: true, railBottom: B }); assert.equal(g.rail.bottom, B); if (g.video) { assert.ok(g.video.width < was.video.width || video !== "side", `${video} @${B}: ${g.video.width}`); assert.ok(Math.abs(g.video.width / g.video.height - 16 / 9) < 0.02, `${video} @${B}: the clip keeps its aspect`); assert.ok(g.qr.size >= 96, `${video} @${B}: QR ${g.qr.size}`); } for (const box of [g.totals, g.video, { ...g.qr, width: g.qr.size, height: g.qr.size }].filter(Boolean)) { assert.ok(box.y >= B && box.y + box.height <= 1080 && box.x >= 0 && box.x + box.width <= 1920, `${video} @${B}: ${JSON.stringify(box)}`); } assert.ok(g.totals.numberSize >= 96); assert.ok(g.stats.cardH >= 100, `${video} @${B}: cards ${g.stats.cardH} px`); assert.ok(g.stats.y + g.stats.titleH + g.stats.rows * g.stats.cardH + (g.stats.rows - 1) * g.stats.gap <= 1080 - 36); } } }); test("rail labels: a crowded rail says each date once and fans them -- no two meet, each joined to its pip", () => { const g = finaleGeometry(renderWith()); // 40 pips 28 px apart, dates repeating in runs and out of order (a cut is not a calendar). const days = ["24 Aug", "24 Aug", "25 Aug", "26 Aug", "26 Aug", "26 Aug", "25 Aug", "27 Aug", "22 Oct", "21 Oct", "22 Oct", "22 Oct"]; const pips = Array.from({ length: 40 }, (_, i) => ({ x: 120 + i * 28, label: `${days[i % days.length]} 2026` })); const lb = railLabelLayout(pips, g); assert.equal(lb.mode, "turned"); const labels = lb.groups.map((gr) => gr.label); assert.equal(new Set(labels).size, labels.length, "each date once"); assert.deepEqual(new Set(labels), new Set(pips.map((p) => p.label)), "every distinct date kept"); const sin = Math.sin((lb.angle * Math.PI) / 180); const block = Math.round(g.rail.labelSize * 1.15); for (let j = 1; j < lb.groups.length; j += 1) { assert.ok((lb.groups[j].lx - lb.groups[j - 1].lx) * sin >= block, `labels ${j - 1} and ${j} meet`); } assert.ok(lb.lead > 0, "a leader band under the track"); for (const gr of lb.groups) assert.ok(gr.lx >= gr.x - 0.01 || gr.lx >= lb.groups[0].x, "slots never before the rail"); // The page draws a leader per label. // Uncrowded: as it was -- no slots moved, no leaders. const few = railLabelLayout(Array.from({ length: 12 }, (_, i) => ({ x: 160 + i * 130, label: `${i + 1} Oct 2026` })), g); assert.ok(few.groups.every((gr) => (gr.lx ?? gr.x) === gr.x) && !few.lead); // fanSlots: least movement, the pitch kept, inside its bounds. const s = fanSlots([100, 101, 102, 400], 40, 90, 1000); assert.deepEqual(s.map(Math.round), [90, 130, 170, 400]); assert.deepEqual(fanSlots([500, 990, 995], 40, 0, 1000).map(Math.round), [500, 960, 1000]); }); test("the claims' words, span labels and the markers' never meet -- rotate and all", () => { for (const claims of ["rotate", "all"]) { const r = renderWith({ claims: CLAIMS }, { claims }); const s = built(r); const R = finaleRail(s, r, { railBottom: s.finale.railBottom, textScale: s.finale.textScale ?? 1 }); assert.equal(R.claims.mode, claims); const marks = markerBoxes(R.marks); if (claims === "rotate") for (const it of R.claims.items) assertNoneMeet([...marks, ...claimBoxes({ items: [it] })], `rotate, claim ${it.j}`); else assertNoneMeet([...marks, ...claimBoxes(R.claims)], "all"); // Every word on the frame; claims' words above the markers' rows. const markerTop = Math.max(...R.marks.map((mk) => mk.row + 1)); for (const b of claimBoxes(R.claims)) { assert.ok(b.a >= 0 && b.b <= 1920, `${b.who} off the frame`); if (!/^\d+ in a/.test(b.who)) assert.ok(b.row > markerTop, `${b.who} in row ${b.row}, under the markers' ${markerTop}`); } // Every row's words inside the rail's region. const topRow = Math.max(...claimBoxes(R.claims).map((b) => b.row)); assert.ok(R.Y - aboveTop(topRow, R.geo.rail.markerSize) >= R.geo.rail.top - 12, `${claims}: row ${topRow} over the panel`); } }); test("the timeline takes the room its rows need: the schedule's railBottom, the clip's smaller box, the footage moved into it", () => { const r = renderWith({ claims: CLAIMS }); const s = built(r); const f = s.finale; assert.ok(f.railBottom > 412 && f.railBottom <= Math.round(1080 * FINALE_SHARE.auto) - 36, `railBottom ${f.railBottom}`); const g = finaleGeometry(r, { railBottom: f.railBottom }); assert.deepEqual(f.box, g.video); assert.ok(f.box.width < 768); for (const mv of s.moves.filter((m) => f.segments.includes(m.segment))) assert.deepEqual(mv.to, f.box); // The page draws its hole where the schedule says, and the rail's panel to its bottom. const L = finaleLayout(s, r); assert.deepEqual(L.box, f.box); assert.equal(L.panel.bottom, f.railBottom + 12); // An estimate (umtool's preview) says the same. const est = estimateSchedule({ timeline: entries(["blend", "tism", "heartstrings"]), render: r, provenance: PROV }, { metas: metas() }); assert.ok(est.finale.railBottom > 412); // A number: that share, needed or not. const half = built(renderWith({ claims: CLAIMS }, { timelineShare: 0.5 })).finale; assert.equal(half.railBottom, 540 - 36); // No claims and nothing crowded: no new keys, the box it always had. const plain = built(renderWith()).finale; assert.ok(!("railBottom" in plain) && !("textScale" in plain)); assert.deepEqual(plain.box, { x: 1104, y: 448, width: 768, height: 432 }); }); test("claims: rotate gives each an even share of the page's time, crossfading; too little time and they stand together", () => { const fin = { at: 100, grow: 0.8, to: 160 }; const rot = finaleClaimSlots(fin, 3, "rotate"); assert.equal(rot.mode, "rotate"); assert.deepEqual(rot.slots, [[100.8, 120.533], [120.533, 140.267], [140.267, 160]]); assert.equal(finaleClaimSlots(fin, 1, "rotate").mode, "all", "one claim stands alone"); assert.equal(finaleClaimSlots(fin, 3, "all").mode, "all"); assert.equal(finaleClaimSlots({ at: 100, grow: 0.8, to: 110 }, 3, "rotate").mode, "all", `under ${FINALE_CLAIMS.minHold} s each`); assert.equal(finaleClaimSlots({ at: 100, grow: 0, to: 200, out: [130, 130.5] }, 4, "rotate").mode, "rotate", "to the run's end, not the window's"); const r = renderWith({ claims: CLAIMS }); const s = built(r); const L = finaleLayout(s, r); assert.equal(L.claims.mode, "rotate"); const cued = finaleCues(s, r, L); assert.ok(cued.cues.every((c) => Object.keys(c.to).every((p) => p in c.from)), "every cue states its from"); // Mid-slot, its claim alone stands; the rail's labels and markers stand throughout. L.claims.slots.forEach(([a, b], j) => { const mid = (a + b) / 2; L.claims.items.forEach((it, i) => { assert.equal(Math.round(valueAt(cued, `fq${it.j}`, "opacity", mid)), i === j ? 1 : 0, `slot ${j}: fq${it.j}`); }); assert.equal(valueAt(cued, "pl0", "opacity", mid), 1); }); // The last holds to the end. const last = L.claims.items[L.claims.items.length - 1]; assert.equal(valueAt(cued, `fq${last.j}`, "opacity", s.finale.to - 0.01), 1); // A short run: they stand together, the rows packed for all of them. const short = built(r, { secs: 6 }); assert.equal(finaleLayout(short, r).claims.mode, "all"); // The page renders each claim's group once. const html = finaleHtml(s, r, snapWindow({ segment: "finale", from: s.finale.from, to: s.finale.to }, { fps: 30, total: s.total }), {}); for (const it of L.claims.items) assert.equal((html.match(new RegExp(`data-k="fq${it.j}"`, "g")) ?? []).length, 1); }); test("placeAbove: a label slides along its row, or rises with its stick kept in its bracket and clear of what is under it", () => { const geo = { W: 1920, margin: 48 }; const rows = aboveRows([{ x: 1060, row: 0, side: "right", max: 300 }]); // A span label at 990 would meet the marker's stick in row 0: slid along it. const sp = placeAbove(rows, { w: 160, left: 910, align: "center", stick: { x: 990, a: 990, b: 990 }, minRow: 0, stickFrom: 1 }, geo); assert.equal(sp.row, 0); assert.ok(sp.left + 160 + 12 <= 1057, JSON.stringify(sp)); assert.ok(sp.left <= 990 && sp.left + 160 >= 990, "still over its point"); // Words whose stick would rise through the marker's label: the stick moves inside the bracket. const w = placeAbove(rows, { w: 400, left: 1100, align: "left", stick: { x: 1101, a: 900, b: 1500 }, minRow: 2, stickFrom: 0 }, geo); assert.ok(w.row >= 2); assert.ok(w.stickX < 1060 - 8 || w.stickX > 1378 + 8, JSON.stringify(w)); assert.ok(w.stickX >= w.left && w.stickX <= w.left + 400); assert.equal(aboveTop(0), 42); assert.deepEqual([1, 2, 3].map((r) => aboveTop(r)), [72, 112, 152], "the markers' rows where they always were"); assert.equal(aboveLine(), 30); assert.ok(textWidth("x", 24) > 0); }); test("a subsection on the large rail: its flag `sub` (a thinner stick, quieter words); a cut without one draws none of it", () => { const r = renderWith({ markers: [MARKERS[0], { ...MARKERS[1], level: 2 }] }); const s = built(r); const L = finaleLayout(s, r); assert.deepEqual(L.marks.map((mk) => mk.level ?? 1), [1, 2]); const win = snapWindow({ segment: "finale", from: s.finale.from, to: s.finale.to }, { fps: 30, total: s.total }); const html = finaleHtml(s, r, win, {}); assert.equal((html.match(/class="mf sub"/g) ?? []).length, 1); assert.match(html, /\.mf\.sub \.ml \{ opacity: 0\.72; \}/); const plain = finaleHtml(built(renderWith()), renderWith(), win, {}); assert.doesNotMatch(plain, /\.mf\.sub|class="mf sub"/); });