// `--clip-preview ` (umtool's "Render this clip", plans/live-preview.md): // the heavy slot, the one segment's join, its own directory, and the finale // page's live-preview hook (the clip editor seeks it in the cut's seconds). // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import path from "node:path"; import test from "node:test"; import { CLIP_PREVIEW_DIR, clipPreviewDir, clipPreviewJoin, finaleRegions, takesHeavySlot } from "./build-video.mjs"; import { finaleHtml } from "./chrome-finale.mjs"; import { deckSchedule } from "./deck.mjs"; const PALETTE = { bg: "#101219", fg: "#f2f0ea", muted: "#979caa", accent: "#e5534b", amber: "#ffc860" }; const render = (deck = {}, extra = {}) => ({ width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck, factcheck: { verdicts: { CONTRADICTED: { label: "Grift" } } } }, ...extra, }); const PROV = { siteOrigin: "https://example.test", channelSlug: "chan" }; const clips = (n, { finale = null } = {}) => Array.from({ length: n }, (_, i) => ({ id: `c${i}`, type: "clip", video: `v${i}`, start: 100, end: 130, ...(i === 1 ? { claim: { id: "k1", verdict: "CONTRADICTED" } } : {}), ...(finale === i ? { layout: "finale" } : {}), })); test("--clip-preview renders, so it takes the heavy slot; --only does not", () => { assert.equal(takesHeavySlot({ opts: { clipPreview: "c1" } }), true); assert.equal(takesHeavySlot({ opts: {}, only: "c1" }), false); }); test("its own directory under the variant's out dir, never the build's chrome/", () => { assert.equal(CLIP_PREVIEW_DIR, "clip-preview"); assert.equal(clipPreviewDir("/p/out/sourced"), path.join("/p/out/sourced", "clip-preview")); }); test("clipPreviewJoin: the schedule's hold and footage move for that one segment; nothing else to join is null", async () => { const r = render(); const entries = clips(3); const s = deckSchedule({ entries, durs: [30, 30, 30], D: 0.5, render: r, provenance: PROV }); // No hold, no move, no mute, not the last with an end fade: nothing. assert.equal(await clipPreviewJoin({ schedule: s, entries, i: 1, seg: "/nope.mp4", render: r }), null); // A hold and a move on the segment (a carrying clip's posts) are this join's. const move = { segment: "c1", at: 50, segmentAt: 20, seconds: 0.8, from: { x: 0, y: 0, width: 100, height: 50 }, to: { x: 10, y: 10, width: 50, height: 25 } }; const held = { ...s, segments: s.segments.map((x) => (x.id === "c1" ? { ...x, hold: 2 } : x)), moves: [move] }; assert.deepEqual(await clipPreviewJoin({ schedule: held, entries, i: 1, seg: "/nope.mp4", render: r }), { hold: 2, move }); assert.equal(await clipPreviewJoin({ schedule: held, entries, i: 0, seg: "/nope.mp4", render: r }), null); }); test("the finale page answers the live preview: `finale:ready`, seeked in the cut's seconds", () => { const r = render({ finale: {} }); const entries = clips(4, { finale: 3 }); const s = deckSchedule({ entries, durs: [30, 30, 30, 30], D: 0.5, render: r, provenance: PROV }); const win = finaleRegions(r, "/tmp/x", s)[0].window; const html = finaleHtml(s, r, win, {}); assert.match(html, /params\.get\("preview"\) === "1"/); assert.match(html, /type: "finale:ready"/); assert.match(html, /m\.type === "deck:seek"\) tl\.seek\(Math\.max\(0, Math\.min\(F\.dur, \(Number\(m\.t\) \|\| 0\) - F\.from\)\), false\)/); });