// migrateManifest (modules/migrate.mjs): the fact-check verdicts and tally // into the counter's named series -- pure, idempotent, and the pages it draws // the bytes they were. import { test } from "node:test"; import assert from "node:assert/strict"; import { migrateManifest, MIGRATIONS } from "./migrate.mjs"; import { estimateSchedule, snapWindow, validateChrome } from "../deck.mjs"; import { validateClaims } from "../factcheck.mjs"; import { deckHtml } from "../chrome-deck.mjs"; import { stampHtml } from "../chrome-stamp.mjs"; import { finaleHtml } from "../chrome-finale.mjs"; const PALETTE = { bg: "#101219", fg: "#f2f0ea", muted: "#979caa", accent: "#e5534b", amber: "#ffc860" }; /** A Huck-shaped cut: one verdict relabelled, a per-verdict showAt, marks, a count claim by label, a finale. */ function huckish({ tally = { show: true, position: "right", showAt: { PARTLY: "first" } } } = {}) { return { provenance: {}, posts: [], render: { width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE, fontBold: "/usr/share/fonts/TTF/FiraSans-Bold.ttf", chrome: { engine: "hyperframes", layout: "deck", deck: { pip: { color: "verdict" }, finale: { totals: true }, claims: [{ kind: "count", at: "b", t: 4, said: "“less than ten”", window: { from: "2026-01-01", to: "2026-12-31" }, tally: "Seizures" }], }, factcheck: { verdicts: { CORROBORATED: { label: "Seizures", color: "#e5534b", stampLabel: "Seizure" }, PARTLY: { label: "Huck's Blend pitches", tallyLabel: "Pitches" } }, stamp: { seconds: 3, position: "top-left", show: true }, ...(tally ? { tally } : {}), }, }, }, timeline: [ { type: "clip", id: "a", video: "v1", start: 0, end: 10, date: "2026-03-01", claim: { id: "s1", verdict: "CORROBORATED" } }, { type: "clip", id: "b", video: "v2", start: 0, end: 12, date: "2026-04-01", claims: [{ id: "p1", verdict: "PARTLY", at: 2 }, { id: "s2", verdict: "CORROBORATED", at: 8 }] }, { type: "clip", id: "c", video: "v3", start: 0, end: 10, date: "2026-05-01", layout: "finale", claim: { id: "s3", verdict: "CORROBORATED" } }, ], }; } function pages(m) { const s = estimateSchedule(m); const r = m.render; return { schedule: JSON.stringify(s), deck: deckHtml(s, r, {}), stamp: stampHtml(s, r, {}), finale: finaleHtml(s, r, snapWindow({ segment: "finale", from: s.finale.from, to: s.finale.to }, { fps: 30, total: s.total }), {}), }; } test("the migration moves the verdicts and the tally into deck.counter, and the claim names its series by id", () => { const before = huckish(); const frozen = JSON.stringify(before); const { manifest, changes } = migrateManifest(before); assert.equal(JSON.stringify(before), frozen, "the manifest given is not touched"); const c = manifest.render.chrome; assert.deepEqual(c.deck.counter, { series: [ { id: "CORROBORATED", label: "Seizures", color: "#e5534b", stampLabel: "Seizure" }, { id: "PARTLY", label: "Huck's Blend pitches", tallyLabel: "Pitches", showAt: "first" }, { id: "CONTRADICTED" }, { id: "NOT_FOUND" }, { id: "UNTESTABLE" }, ], }); assert.deepEqual(c.factcheck, { stamp: { seconds: 3, position: "top-left", show: true } }); assert.equal(c.deck.claims[0].tally, "CORROBORATED"); assert.equal(changes.length, 3); assert.match(changes.join("\n"), /factcheck\.verdicts -> render\.chrome\.deck\.counter\.series/); assert.deepEqual(validateChrome(c, manifest.render), []); assert.deepEqual(validateClaims(manifest), []); assert.equal(MIGRATIONS[0].id, "counter-series"); }); test("the migrated cut draws the same pages, byte for byte", () => { for (const tally of [undefined, { show: true, position: "left", showAt: "first" }, { showAt: { PARTLY: "first" } }]) { const before = huckish({ tally }); const a = pages(before); const b = pages(migrateManifest(before).manifest); for (const k of Object.keys(a)) assert.equal(b[k], a[k], `${k} (tally ${JSON.stringify(tally)})`); } }); test("idempotent; nothing to count is nothing to do", () => { const once = migrateManifest(huckish()).manifest; const twice = migrateManifest(once); assert.deepEqual(twice.changes, []); assert.deepEqual(twice.manifest, once); const plain = { render: { chrome: { engine: "hyperframes", layout: "deck", deck: {} } }, timeline: [{ type: "clip", id: "a" }] }; assert.deepEqual(migrateManifest(plain), { manifest: plain, changes: [] }); assert.deepEqual(migrateManifest({ render: {}, timeline: [] }).changes, []); assert.throws(() => migrateManifest(null), /a manifest is an object/); });