// The measure's instruments (instruments.mjs, chrome-instruments.mjs, // modules/dial|odometer|trail|dial-finale.mjs): their settings, the frame they // make room in, the pages and their frame keys -- and that a cut without them // draws exactly what it drew before they existed. import assert from "node:assert/strict"; import { createHash } from "node:crypto"; import { readFileSync } from "node:fs"; import path from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; import { deckGeometry, estimateSchedule, instrumentsGeometry, postsGeometry, resolveDeck, validateChrome } from "./deck.mjs"; import { deckHtml } from "./chrome-deck.mjs"; import { dialFinaleGeometry, dialFinaleHandoff, dialFinaleHtml, dialHtml, finaleNumbers, odometerHtml, trailHtml } from "./chrome-instruments.mjs"; import { frameKeys } from "./frame-keys.mjs"; import { instrumentsOn, resolveDial, validateDial } from "./instruments.mjs"; import { dialAngle, fmtDate, fmtSigned, measureTrack, wheelDigits, wheelRoll } from "./measure-draw.mjs"; import { deckOverlays, moduleById, moduleProblems, playModules, scheduleSlices } from "./modules/index.mjs"; import { slotRect } from "./modules/layout.mjs"; const HERE = path.dirname(fileURLToPath(import.meta.url)); const MEASURE = JSON.parse(readFileSync(path.join(HERE, "fixtures", "measure-dial", "measure.json"), "utf8")); const FPS = 30; const chromeWith = (deck = {}) => ({ engine: "hyperframes", layout: "deck", deck }); const RENDER = { width: 1920, height: 1080, fps: FPS, transition: 0.4, palette: { bg: "#0F1312", fg: "#EDF0EC", muted: "#98A29B", accent: "#22AB83", amber: "#E8A33F" }, chrome: chromeWith({ dial: true, odometer: true, trail: true, qr: { show: false }, finale: { video: "side", totals: false } }), }; /** A deck cut long enough for the fixture's 62 s, its last clip the finale, with the measure in its schedule. */ function cut(render = RENDER) { const timeline = Array.from({ length: 9 }, (_, i) => ({ type: "clip", id: `c${i + 1}`, video: "vidx", start: 10 * i, end: 10 * i + (i === 8 ? 14 : 8), cite: 1, section: 0, quote: "q", onscreen: { title: `Clip ${i + 1}` }, ...(i === 8 ? { layout: "finale" } : {}), })); const manifest = { slug: "m", title: "M", provenance: {}, render, timeline }; return { manifest, schedule: { ...estimateSchedule(manifest), measure: MEASURE } }; } // --------------------------------------------------------------------------- // A cut without them is the cut it was. // --------------------------------------------------------------------------- // What the release 28 kit's manifests drew on main before the instruments (c05e5314): the estimate's // schedule, the deck's page, the frame and every whole-cut overlay's region, hashed. Unchanged. // Re-pinned on lane/band-shelf (6 Nov): the automatic subtitle's parts by token -- the schedule equal but for // `subtitleParts`, the frame and the regions equal, the deck's page differing only in the parts' `data-p`, a // segment's `data-sub`, the token CSS and the live preview's restore (chrome-deck.mjs subtitleMarkup). // full was 0eeb6303e621af4b88c8e0eaae2eca7228da0e3dbae997c60fd45fdd5744e18a, flips // 565472d4e03834bdf8f2fdd656d76f48d1bca37019be27f33422c0f27d6f270e. const BEFORE = { full: "a072b99f19faefe264655cf34899ea86807d2bbe42fdb06d6455ec6393467fda", flips: "ae320afa4c16e51f8d4b283b69304b078f8e79f30eb82d21b9c4b84427ba0ada", }; test("a cut without the instruments draws exactly what it drew before them (the release 28 kit's manifests)", () => { for (const name of ["full", "flips"]) { const m = JSON.parse(readFileSync(path.join(HERE, "../../common/testing/draft/manifests", `${name}.video.manifest.json`), "utf8")); const s = estimateSchedule(m); const render = m.render; const html = deckHtml(s, render, { fonts: { regular: "assets/r.ttf", bold: "assets/b.ttf" } }); const regions = deckOverlays().filter((mod) => mod.on(s, render) && mod.kind === "overlay-whole").map((mod) => [mod.id, mod.regions(s, { render, outDir: "/o" })]); const doc = { s, html, g: deckGeometry(render), regions, slices: Object.keys(scheduleSlices(s)).sort() }; assert.equal(createHash("sha256").update(JSON.stringify(doc)).digest("hex"), BEFORE[name], name); assert.ok(!regions.some(([id]) => ["dial", "odometer", "trail"].includes(id))); assert.equal(instrumentsOn(render), false); } }); test("the deck's frame is moved only when an instrument is asked for", () => { const plain = { width: 1920, height: 1080, chrome: chromeWith({}) }; assert.deepEqual(deckGeometry(plain).footage, { x: 173, y: 2, width: 1574, height: 886 }); for (const off of [{ dial: false }, { odometer: false, trail: false }]) { assert.deepEqual(deckGeometry({ ...plain, chrome: chromeWith(off) }).footage, deckGeometry(plain).footage); } const g = deckGeometry(RENDER); assert.deepEqual(g.footage, { x: 24, y: 94, width: 1248, height: 702 }); const ig = instrumentsGeometry(RENDER); assert.deepEqual(ig.column, { x: 1296, y: 24, width: 600, height: 842 }); assert.deepEqual([ig.dial.height, ig.odometer.height, ig.trail.height], [540, 140, 138]); assert.equal(ig.trail.y + ig.trail.height, g.deck.y - 24); assert.deepEqual(slotRect("instruments", RENDER), ig.column); // The dial alone takes a square face; an instrument that is off has no region. const one = instrumentsGeometry({ ...RENDER, chrome: chromeWith({ odometer: true }) }); assert.equal(one.dial, null); assert.equal(one.odometer.y, 24); }); test("with the instruments the posts stay in the footage box: posts.shift does not apply", () => { assert.ok(resolveDeck({ chrome: chromeWith({}) }).posts.shift); assert.equal(resolveDeck(RENDER).posts.shift, false); const p = postsGeometry(RENDER); const f = deckGeometry(RENDER).footage; assert.ok(p.x + p.width <= f.x + f.width, "the posts column is inside the footage, clear of the instruments"); }); // --------------------------------------------------------------------------- // Settings. // --------------------------------------------------------------------------- test("the instruments' settings: true, an object of known keys, or off; the side panel and the feed refused beside them", () => { assert.deepEqual(validateChrome(RENDER.chrome, RENDER), []); assert.deepEqual(validateChrome(chromeWith({ dial: { mark: 300, needle: "#ff0000", finale: false } }), {}), []); assert.match(validateChrome(chromeWith({ dial: { marks: 3 } }), {})[0], /deck\.dial\.marks is not a setting of it/); assert.match(validateChrome(chromeWith({ odometer: "yes" }), {})[0], /deck\.odometer must be true, false or/); assert.match(validateChrome(chromeWith({ trail: { mark: "300" } }), {})[0], /deck\.trail\.mark must be a weight/); assert.deepEqual(validateDial({ label: "x".repeat(41) }), ["render.chrome.deck.dial.label is 41 characters (at most 40)"]); const feed = validateChrome(chromeWith({ dial: true, posts: { layout: "feed" } }), {}); assert.ok(feed.some((e) => /need the popup posts, not the feed/.test(e)), feed.join("\n")); const side = validateChrome({ ...chromeWith({ trail: true }), threads: { list: [{ id: "a", label: "A" }] } }, {}); assert.ok(side.some((e) => /render\.chrome\.threads and render\.chrome\.deck\.trail both need the frame/.test(e)), side.join("\n")); assert.deepEqual(resolveDial(RENDER), { mark: 300, ghosts: true, goal: true, needle: "#ff5a4e", finale: true, label: "HE SAYS HE WEIGHS", placement: "column", size: 340, corner: "bottom-right", motion: "spring", finaleEnd: "auto", rememberedAs: "needle", flash: null, }); assert.match(validateDial({ placement: "left" })[0], /placement must be "column" or "corner"/); assert.match(validateDial({ size: 100 })[0], /size must be a whole number of pixels from 200 to 540/); assert.match(validateDial({ motion: "bounce" })[0], /motion must be "spring" or "ease"/); assert.match(validateDial({ finaleEnd: "net" })[0], /finaleEnd must be "auto" or "odometer" or "promise"/); assert.equal(resolveDial({ chrome: chromeWith({ dial: false }) }), null); assert.deepEqual(moduleProblems({ render: { ...RENDER, chrome: chromeWith({ dial: { ghost: true } }) } }).dial, ["render.chrome.deck.dial.ghost is not a setting of it (mark, ghosts, goal, needle, finale, label, placement, size, corner, motion, finaleEnd, rememberedAs, flash)"]); }); // --------------------------------------------------------------------------- // The slice and the modules. // --------------------------------------------------------------------------- test("the measure is a slice only when the schedule has one; each instrument is on with its setting and the measure", () => { const { schedule } = cut(); const { measure: _m, ...bare } = schedule; assert.equal(scheduleSlices(schedule).measure, MEASURE); assert.equal("measure" in scheduleSlices(bare), false); for (const id of ["dial", "odometer", "trail"]) { const m = moduleById(id); assert.equal(m.on(schedule, RENDER), true, id); assert.equal(m.on(bare, RENDER), false, id); assert.equal(m.on(schedule, { ...RENDER, chrome: chromeWith({}) }), false, id); assert.match(m.check(bare, RENDER), /needs a schedule with a measure/); assert.equal(m.regions(schedule, { render: RENDER, outDir: "/o" })[0].frames, `/o/chrome/${id}-frames`); assert.ok(playModules().includes(m), id); } const fin = moduleById("dial-finale"); assert.equal(fin.on(schedule, RENDER), true); assert.equal(fin.on(schedule, { ...RENDER, chrome: chromeWith({ dial: { finale: false } }) }), false); const [r] = fin.regions(schedule, { render: RENDER, outDir: "/o" }); assert.deepEqual([r.x, r.y, r.width, r.height], [48, 448, 1008, 596]); assert.equal(r.offset, r.window.from); // Stats cards fill the finale's lower column: no room, and it says so. const crowded = { ...RENDER, chrome: chromeWith({ dial: true, finale: { video: "side", stats: [{ label: "A", value: "1" }] } }) }; assert.equal(dialFinaleGeometry(schedule, crowded), null); assert.match(fin.check(schedule, crowded), /needs the finale's lower column clear/); }); // --------------------------------------------------------------------------- // The measure, read. // --------------------------------------------------------------------------- test("measureTrack: the stated weights, the ghosts, a goal, and an odometer that only goes up", () => { const t = measureTrack(MEASURE); assert.equal(t.current[0].value, null); assert.deepEqual(t.current.slice(1, 3).map((c) => [c.value, c.qualifier]), [[240, ">"], [300, ">"]]); // A stated weight with an as-of is dated by its weighing: 291.5 "on Friday". assert.equal(t.current.at(-1).date, "2026-10-23"); assert.equal(t.remembered.length, MEASURE.state.at(-1).remembered.length); for (let i = 1; i < t.lost.length; i += 1) assert.ok(t.lost[i].total >= t.lost[i - 1].total); // The cut's own total: the rows no clip shows yet are the record's (totals.lost), not the odometer's. assert.equal(t.lost.at(-1).total, MEASURE.state.at(-1).lost.total); assert.deepEqual(t.under.map((u) => u.row), ["w115", "w118"]); assert.equal(t.stated.length, 13); // A loss that would lower the total holds it at its highest. const lower = { ...MEASURE, state: [...MEASURE.state, { ...MEASURE.state.at(-1), t: 61, lost: { total: 100, runs: MEASURE.state.at(-1).lost.runs } }] }; assert.equal(measureTrack(lower).lost.at(-1).total, MEASURE.state.at(-1).lost.total); }); test("the dial's angles, the odometer's wheels, the words", () => { const scale = { min: 220, max: 400 }; assert.deepEqual([dialAngle(220, scale), dialAngle(310, scale), dialAngle(400, scale), dialAngle(500, scale)], [-135, 0, 135, 135]); assert.deepEqual(wheelDigits(212.8, 3), [2, 1, 2, 8]); // 90.4 -> 122.9: the hundreds 0 -> 1, the tens 9 through 0 to 2, the lower wheels a turn more. assert.deepEqual(wheelRoll(90.4, 122.9, 3), [ { from: 0, to: 1, settle: null }, { from: 9, to: 12, settle: 2 }, { from: 0, to: 12, settle: 2 }, { from: 4, to: 19, settle: 9 }, ]); assert.equal(fmtDate("2026-10-26"), "26 OCT 2026"); assert.equal(fmtDate("2025-02-01"), "FEB 2025"); assert.equal(fmtSigned(-76.5), "−76.5"); }); // --------------------------------------------------------------------------- // The pages: cue interpreters the frame keys model. // --------------------------------------------------------------------------- const fonts = { DeckSans: "assets/DeckSans.ttf", DeckSansBold: "assets/DeckSansBold.ttf" }; test("the dial's page: the needle swings on each stated weight and is keyed once at rest", () => { const { schedule } = cut(); const html = dialHtml(schedule, RENDER, { fonts }); assert.match(html, /data-composition-id="dial"/); assert.match(html, /dial:ready/); assert.match(html, />>240LB<\/i>/); assert.match(html, /HE SAYS HE WEIGHS/); // The state before any weight is up from the cut's first instant (the dash's block in init). const data = JSON.parse(/