// Tests for the deck-counts lane (plans/deck-counts.md): the stamps off with // the tally still counting (`factcheck.stamp.show`), no QR on the post cards // (`deck.posts.qr`), pips in their claim's verdict colour and shape // (`deck.pip.color: "verdict"`), and flags on the pip track // (`deck.markers`). Each is optional, and a deck without them is as it was. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; import { DECK_DEFAULTS, deckLayout, deckMarkers, deckSchedule, MARKER_BAND, MARKER_LIMITS, pipSegments, pipXs, postWindows, resolveDeck, snapWindow, validateChrome, validateDeckMarkers, } from "./deck.mjs"; import { deckCues, deckHtml, MARKER_POP } from "./chrome-deck.mjs"; import { postsHtml, windowPosts } from "./chrome-posts.mjs"; import { feedHtml, feedLayout } from "./chrome-feed.mjs"; import { FACTCHECK_DEFAULTS, resolveFactcheck, stampsDrawn, tallyCues, validateFactcheck, VERDICT_SHAPES, VERDICTS, } from "./factcheck.mjs"; import { validatorErrors } from "./lint.mjs"; const PALETTE = { bg: "#12101a", fg: "#f4f1ea", muted: "#9a93ad", accent: "#a97bff", amber: "#ffc860" }; const CHROME = { engine: "hyperframes", layout: "deck" }; const BASE = { width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE }; const renderWith = (deck = {}, factcheck = undefined) => ({ ...BASE, chrome: { ...CHROME, deck, ...(factcheck ? { factcheck } : {}) } }); const PROV = { siteOrigin: "https://example.test", channelSlug: "chan" }; // Four clips and a card: c1 PARTLY, c2 CONTRADICTED, c4 CORROBORATED, c3 none. const ENTRIES = [ { id: "c1", type: "clip", video: "a", start: 0, end: 10, date: "2024-09-05", claim: { id: "k1", verdict: "PARTLY" } }, { id: "c2", type: "clip", video: "b", start: 0, end: 20, date: "2024-10-01", claim: { id: "k2", verdict: "CONTRADICTED" } }, { id: "t1", type: "card", seconds: 4, heading: "Three weeks later" }, { id: "c3", type: "clip", video: "c", start: 0, end: 6, date: "2025-12-08" }, { id: "c4", type: "clip", video: "d", start: 0, end: 9, date: "2025-12-09", claim: { id: "k4", verdict: "CORROBORATED" } }, ]; const DURS = [10, 20, 4, 6, 9]; const POST = (id, date, extra = {}) => ({ id, platform: "x", author: "Someone", handle: "someone", date, text: `words of ${id}`, url: `https://x.com/someone/status/${id}`, ...extra, }); const POSTS = [POST("p1", "2024-10-02", { attachTo: "c2" }), POST("p2", "2024-10-03", { attachTo: "c2" })]; const sched = (render, posts = []) => deckSchedule({ entries: ENTRIES, durs: DURS, D: 0.5, render, provenance: PROV, posts }); const FONTS = { regular: "assets/DeckSans.ttf", bold: "assets/DeckSansBold.ttf" }; // ---- F1: the stamp off, the tally still counting ------------------------------ test("stamp.show: a setting, default on; refused when not a boolean", () => { assert.equal(FACTCHECK_DEFAULTS.stamp.show, true); assert.equal(resolveFactcheck(renderWith()).stamp.show, true); assert.equal(resolveFactcheck(renderWith({}, { stamp: { show: false } })).stamp.show, false); assert.deepEqual(validateFactcheck({ stamp: { show: false, seconds: 2 } }), []); assert.match(validateFactcheck({ stamp: { show: "no" } }).join(" "), /stamp\.show must be true or false/); assert.deepEqual(validateChrome({ ...CHROME, factcheck: { stamp: { show: false } } }, BASE), []); }); test("stamp.show false: the schedule keeps its stamps, nothing is drawn, and the tally counts at the same seconds", () => { const on = renderWith(); const off = renderWith({}, { stamp: { show: false } }); const a = sched(on), b = sched(off); // The schedule is the same: the stamps are when the tally steps. assert.deepEqual(b, a); assert.equal(a.factcheck.stamps.length, 3); assert.equal(stampsDrawn(a, on), true); assert.equal(stampsDrawn(b, off), false); assert.equal(stampsDrawn({ segments: [] }, on), false); // The tally's cues -- each count and its flash -- are exactly the stamps-on ones. const tally = (r, s) => deckCues(s, r).cues.filter((c) => c.k.startsWith("ty.")); assert.deepEqual(tally(off, b), tally(on, a)); assert.ok(tally(off, b).some((c) => c.k === "ty.CONTRADICTED.flash"), "the flash fires"); const steps = tallyCues(b.factcheck.stamps).events.filter((e) => e.k.endsWith(".n1")); assert.deepEqual(steps.map((e) => e.at).sort(), b.factcheck.stamps.map((s) => s.landed).sort()); // The deck page itself is identical: the stamp is another region. assert.equal(deckHtml(b, off, { fonts: FONTS }), deckHtml(a, on, { fonts: FONTS })); }); test("compose-chrome: no stamp region when the stamps are off", async () => { const dir = mkdtempSync(path.join(tmpdir(), "deck-counts-stamp-")); const env = process.env.HYPERFRAMES_BIN; try { const stub = path.join(dir, "hf-stub.mjs"); writeFileSync(stub, "#!/usr/bin/env node\nprocess.exit(1);\n"); chmodSync(stub, 0o755); process.env.HYPERFRAMES_BIN = stub; const font = path.join(dir, "face.ttf"); writeFileSync(font, "face"); const render = { ...renderWith({}, { stamp: { show: false } }), fontRegular: font, fontBold: font }; const mp = path.join(dir, "video.manifest.json"); writeFileSync(mp, JSON.stringify({ slug: "f", render, timeline: ENTRIES })); const out = path.join(dir, "out", "sourced"); mkdirSync(out, { recursive: true }); writeFileSync(path.join(out, "schedule.json"), JSON.stringify(sched(render))); const { composeChrome } = await import("./compose-chrome.mjs"); await assert.rejects(composeChrome({ manifestPath: mp, region: "stamp" }), /the stamps are off/); } finally { if (env === undefined) delete process.env.HYPERFRAMES_BIN; else process.env.HYPERFRAMES_BIN = env; rmSync(dir, { recursive: true, force: true }); } }); // ---- F2: no QR on the posts --------------------------------------------------- test("posts.qr: a setting, default on; refused when not a boolean", () => { assert.equal(DECK_DEFAULTS.posts.qr, true); assert.equal(resolveDeck(renderWith({ posts: { qr: false } })).posts.qr, false); assert.deepEqual(validateChrome({ ...CHROME, deck: { posts: { qr: false } } }, BASE), []); assert.match(validateChrome({ ...CHROME, deck: { posts: { qr: 0 } } }, BASE).join(" "), /posts\.qr must be true or false/); }); test("posts.qr false, popup: no code and no cell; the words take the width; the deck's own QR stays", () => { const on = renderWith(); const off = renderWith({ posts: { qr: false } }); const qrSrcs = { p1: "assets/pqr0.png", p2: "assets/pqr1.png" }; const page = (r) => { const s = sched(r, POSTS); const win = snapWindow(postWindows(s)[0], { fps: 30, total: s.total }); assert.deepEqual(windowPosts(s, win.segment).map((p) => p.id), ["p1", "p2"]); return postsHtml(s, r, win, { fonts: FONTS, qrSrcs, logoSrcs: { p2: "assets/logo.png" } }); }; const withQr = page(on); assert.ok(withQr.includes('/g) ?? []).length, 1); assert.match(without, /\.post\.no-plate \.body \{ width: 594px; \}/, "600 less the rail"); assert.match(without, /\.post \{ min-height: 0; \}/); // The clip's deck QR is the deck's: untouched. const s = sched(off, POSTS); assert.equal(deckHtml(s, off, { qrSrcs: { c2: "assets/qr1.png" } }), deckHtml(sched(on, POSTS), on, { qrSrcs: { c2: "assets/qr1.png" } })); }); test("posts.qr false, feed: no code, no cell, the body the stack's width less the rail", () => { const off = renderWith({ posts: { layout: "feed", qr: false } }); const on = renderWith({ posts: { layout: "feed" } }); assert.equal(feedLayout(off).card.plate, 0); assert.equal(feedLayout(on).card.plate, 120 + 28); const qrSrcs = { p1: "assets/pqr0.png", p2: "assets/pqr1.png" }; const html = feedHtml(sched(off, POSTS), off, { qrSrcs }); assert.doesNotMatch(html, /pqr\d\.png/); assert.doesNotMatch(html, /
/); const lay = feedLayout(off); assert.ok(html.includes(`.body { position: relative; width: ${lay.stack.width - lay.card.rail}px;`)); assert.ok(feedHtml(sched(on, POSTS), on, { qrSrcs }).includes(' { assert.equal(DECK_DEFAULTS.pip.color, "accent"); assert.deepEqual(validateChrome({ ...CHROME, deck: { pip: { color: "verdict" } } }, BASE), []); assert.match(validateChrome({ ...CHROME, deck: { pip: { color: "red" } } }, BASE).join(" "), /pip\.color must be "accent" or "verdict"/); }); test("VERDICT_SHAPES: one distinct shape per verdict, in VERDICTS order", () => { assert.deepEqual(Object.keys(VERDICT_SHAPES), [...VERDICTS]); assert.equal(new Set(Object.values(VERDICT_SHAPES)).size, VERDICTS.length); assert.deepEqual(Object.values(VERDICT_SHAPES), ["circle", "diamond", "square", "triangle", "ring"]); }); test("pip.color verdict: a claimed pip lit in its verdict's colour (relabels included) and shape; an unclaimed one as before", () => { const r = renderWith({ pip: { color: "verdict" } }, { verdicts: { PARTLY: { color: "#ff00aa" } } }); const s = sched(r); const { pips } = deckCues(s, r); assert.deepEqual(pips.map((p) => [p.id, p.verdict ?? null]), [["c1", "PARTLY"], ["c2", "CONTRADICTED"], ["c3", null], ["c4", "CORROBORATED"]]); const html = deckHtml(s, r, {}); const lit = (k) => new RegExp(`
]*>`).exec(html)[0]; assert.match(lit(0), /data-verdict="PARTLY" data-shape="diamond"/); assert.match(lit(0), /background:#ff00aa/, "the override's colour"); assert.match(lit(0), /transform:rotate\(45deg\)/); assert.match(lit(1), /data-shape="square"/); assert.match(lit(1), /background:#e5534b/); assert.match(lit(3), /data-shape="circle"/); assert.match(lit(3), /background:#3fbf7f/); assert.equal(lit(2), `
`, "unclaimed: as it always was"); // The tally cell is the same colour, and carries the same shape. const cell = /
]*>.*?
(.*?)<\/div>/s.exec(html); assert.match(cell[0], /--vc:#ff00aa/); assert.match(cell[0], /
]*background:#ff00aa/); assert.equal(cell[1], "Partly true", "the label keeps its width: the shape is in the cell's corner"); // The pips still light as they did: one opacity cue each, same times. const plain = renderWith({}, { verdicts: { PARTLY: { color: "#ff00aa" } } }); const cuesOf = (rr) => deckCues(s, rr).cues.filter((c) => c.k.startsWith("pip")); assert.deepEqual(cuesOf(r), cuesOf(plain)); // Accent (the default): no verdict pips, no shape in the tally. const accent = deckHtml(s, plain, {}); assert.doesNotMatch(accent, /vpip|tshape/); }); // ---- F4: markers ---------------------------------------------------------------- const MARKS = [{ after: "c2", label: "3 to 5 weeks pass" }, { after: "c4", label: "promise lapses", color: "#e5534b" }]; test("markers: shape refused in sentences -- unknown keys, labels, colours, count", () => { const bad = (markers) => validateChrome({ ...CHROME, deck: { markers } }, BASE).join(" "); assert.equal(bad(MARKS), ""); assert.match(bad("c2"), /markers must be a list/); assert.match(bad([{ after: "c2", label: "x", note: 1 }]), /markers\[0\]\.note is not a marker setting/); assert.match(bad([{ after: "", label: "x" }]), /markers\[0\]\.after must name a clip's id/); // No label (or a blank one) is a marker with no words: a tick. assert.equal(bad([{ after: "c2", label: " " }]), ""); assert.equal(bad([{ after: "c2" }]), ""); assert.match(bad([{ after: "c2", label: 3 }]), /markers\[0\]\.label must be a word or two/); assert.match(bad([{ after: "c2", label: "x".repeat(MARKER_LIMITS.label + 1) }]), /is 25 characters \(at most 24\)/); assert.equal(bad([{ after: "c2", label: "x".repeat(MARKER_LIMITS.label) }]), ""); assert.match(bad([{ after: "c2", label: "a\nb" }]), /must be one line/); assert.match(bad([{ after: "c2", label: "x", color: "red" }]), /color must be a #hex colour/); assert.equal(bad([{ after: "c2", label: "x", color: "amber" }]), ""); // The count is the one shared constant (marker-limits.mjs): 32 since 2026-11-01, not 12. assert.equal(MARKER_LIMITS.count, 32); assert.equal(bad(Array.from({ length: 32 }, () => ({ after: "c2", label: "x" }))), ""); assert.match(bad(Array.from({ length: 33 }, () => ({ after: "c2", label: "x" }))), /33 markers \(at most 32\)/); // `level`: 1 (a section, the default) or 2 (a subsection); nothing else. assert.equal(bad([{ after: "c2", label: "x", level: 1 }, { after: "c4", label: "y", level: 2 }]), ""); assert.match(bad([{ after: "c2", label: "x", level: 3 }]), /markers\[0\]\.level must be 1 \(a section\) or 2 \(a subsection\)/); assert.match(bad([{ after: "c2", label: "x", level: "2" }]), /level must be 1/); }); test("markers: `after` must name a clip in the timeline -- the build's, the lint's and the writer's check", () => { const m = (markers, timeline = ENTRIES) => ({ timeline, render: renderWith({ markers }) }); assert.deepEqual(validateDeckMarkers(m(MARKS)), []); assert.match(validateDeckMarkers(m([{ after: "zz", label: "x" }])).join(" "), /names zz, which is not in the timeline/); assert.match(validateDeckMarkers(m([{ after: "t1", label: "x" }])).join(" "), /names t1, a card: a marker follows a clip/); // The shape too, for the lint, which does not run validateChrome. assert.match(validateDeckMarkers(m([{ after: "c2", label: ["x"] }])).join(" "), /label must be a word or two/); assert.deepEqual(validateDeckMarkers(m([{ after: "c2" }])), []); assert.match(validatorErrors(m([{ after: "zz", label: "x" }])).join(" "), /not in the timeline/); // Without the deck, or without markers, nothing to say. assert.deepEqual(validateDeckMarkers({ timeline: ENTRIES, render: BASE }), []); assert.deepEqual(validateDeckMarkers({ timeline: ENTRIES, render: renderWith() }), []); }); test("markers: a band above the track only when there are some; the code and the tally keep clear of it", () => { const plain = deckLayout(renderWith(), { tally: ["PARTLY"] }); const marked = deckLayout(renderWith({ markers: MARKS }), { tally: ["PARTLY"] }); assert.equal(plain.pipTrack.y, 16); assert.equal(plain.markerBand, undefined); assert.equal(marked.pipTrack.y, 16 + MARKER_BAND); assert.deepEqual(marked.markerBand, { y: 3, height: MARKER_BAND + 6 }); // The labels' band ends above everything in the body. const bandEnd = marked.markerBand.y + 14; assert.ok(marked.qr.y >= marked.pipTrack.y + 12 && marked.qr.y + marked.qr.size <= 190, `qr ${marked.qr.y}`); assert.ok(marked.tally.y > bandEnd && marked.text.titleY > bandEnd); }); test("markers: placed between the pip they follow and the next; time spacing at the hand-over; boxes never meet", () => { const r = renderWith({ markers: MARKS }); const s = sched(r); const lay = deckLayout(r); const pipped = pipSegments(s); const xs = pipXs(pipped.length, lay.pipTrack.x0, lay.pipTrack.x1, "even"); const ms = deckMarkers(s, r, xs, pipped, lay); assert.deepEqual(ms.map((m) => [m.after, m.k]), [["c2", 1], ["c4", 3]]); assert.equal(ms[0].x, (xs[1] + xs[2]) / 2); assert.equal(ms[1].x, (xs[3] + lay.pipTrack.x1) / 2, "after the last pip: toward the track's end"); assert.equal(ms[0].color, PALETTE.amber, "the default colour is the palette's amber"); assert.equal(ms[1].color, "#e5534b"); for (const m of ms) assert.ok(m.box[0] <= m.x && m.box[1] >= m.x && m.box[1] - m.box[0] <= 360); // Time spacing: at the next segment's mid-dissolve, in the cut's clock. const rt = renderWith({ markers: MARKS, pip: { spacing: "time" } }); const st = sched(rt); const tl = deckLayout(rt); const tp = pipSegments(st); const txs = pipXs(tp.length, tl.pipTrack.x0, tl.pipTrack.x1, "time", { total: st.total, segments: tp }); const [m0] = deckMarkers(st, rt, txs, tp, tl); const next = st.segments[st.segments.findIndex((x) => x.id === "c2") + 1]; assert.ok(Math.abs(m0.x - (tl.pipTrack.x0 + ((tl.pipTrack.x1 - tl.pipTrack.x0) * (next.start + 0.25)) / st.total)) < 0.01); assert.ok(m0.x > txs[1] && m0.x < txs[2]); // Crowded flags: each label stops short of halfway to its neighbour. const crowd = renderWith({ markers: [{ after: "c1", label: "a long label of a flag" }, { after: "c2", label: "another long label" }, { after: "c3", label: "third" }] }); const cs = sched(crowd); const cl = deckLayout(crowd); const cp = pipSegments(cs); const cx = pipXs(cp.length, cl.pipTrack.x0, cl.pipTrack.x1, "even"); const placed = deckMarkers(cs, crowd, cx, cp, cl); for (let j = 1; j < placed.length; j += 1) assert.ok(placed[j - 1].box[1] < placed[j].box[0], `boxes ${j - 1} and ${j} meet`); }); test("markers: hidden until the fuse reaches the flag, then a pop, lit for the rest; drawn in the page", () => { const r = renderWith({ markers: MARKS }); const s = sched(r); const { init, cues, markers } = deckCues(s, r); assert.equal(markers.length, 2); assert.deepEqual(init.mk0, { autoAlpha: 0, scale: MARKER_POP.from }); const mk0 = cues.filter((c) => c.k === "mk0"); assert.equal(mk0.length, 1, "one cue: it pops in and stays"); assert.deepEqual(mk0[0].from, { autoAlpha: 0, scale: MARKER_POP.from }); assert.deepEqual(mk0[0].to, { autoAlpha: 1, scale: 1 }); // The fuse from pip 1 (c2) toward pip 2 (c3) passes the midpoint halfway // through its burn: c2's rest, from its arrival to the deck sliding away. const fuse = cues.find((c) => c.k === "fuse" && c.why === "fuse c2"); assert.ok(Math.abs(mk0[0].at - (fuse.at + fuse.dur / 2)) < 0.01, `${mk0[0].at} vs fuse ${fuse.at}+${fuse.dur}`); assert.ok(mk0[0].at > s.segments[1].start && mk0[0].at < s.segments[1].end); // After the last pip: a second before its clip ends. const c4 = s.segments.find((x) => x.id === "c4"); const mk1 = cues.find((c) => c.k === "mk1"); assert.ok(Math.abs(mk1.at - (c4.end - 1)) < 0.01); // The page: a flag per marker, its label escaped, in the band. const html = deckHtml(s, r, {}); assert.equal((html.match(/class="mflag"/g) ?? []).length, 2); assert.match(html, /data-k="mk0" data-after="c2"[^>]*--mc:#ffc860/); assert.match(html, /
]*>3 to 5 weeks pass<\/div>/); assert.match(html, new RegExp(`\\.mlabel \\{ position: absolute; top: ${3 - (16 + MARKER_BAND)}px;`), "the band, above the track"); assert.match(html, /text-overflow: ellipsis; font-family: 'DeckSansBold'/); const esc = renderWith({ markers: [{ after: "c2", label: "x & y" }] }); assert.match(deckHtml(sched(esc), esc, {}), /><b>x<\/b> & y