// Beat reels played from a take's master (reelPlay.mjs): each beat mapped by // the trailer's own planTrailer, the beats a take cannot place said by number, // the take a reel plays chosen, the reel's cuts found. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { mkdir, mkdtemp, rm, utimes, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; import { pickReelTake, reelCutSteps, reelPlan, reelPlayView, takeMasters } from "./reelPlay.mjs"; // The trailer test's master: the brand intro, then three clips, 0.5 s dissolves. const SCHEDULE = { version: 1, kind: "deck", fps: 30, transition: 0.5, total: 40.167, segments: [ { id: "brand-intro", type: "intro", start: 0, duration: 4.167, end: 4.167 }, { id: "c1", type: "clip", start: 3.667, duration: 12, end: 15.667 }, { id: "c2", type: "clip", start: 15.167, duration: 10, end: 25.167 }, { id: "c3", type: "clip", start: 24.667, duration: 15.5, end: 40.167 }, ], }; const RECORDS = new Map([ ["c1", { id: "c1", start: 100.2, end: 112.2 }], ["c2", { id: "c2", start: 500, end: 510, gaps: [{ from: 503, to: 505 }] }], ["c3", { id: "c3", start: 2000, end: 2015.5 }], ]); const MANIFEST = { slug: "cut", render: { fps: 30 }, timeline: [{ type: "clip", id: "c1", quote: "the first" }, { type: "clip", id: "c2", quote: "the second" }, { type: "clip", id: "c3" }] }; const build = { schedule: SCHEDULE, records: RECORDS, manifest: MANIFEST }; const close = (a, b, eps = 1 / 60) => assert.ok(Math.abs(a - b) <= eps, `${a} ≉ ${b}`); test("each beat is the trailer's piece: its master span, where it lands in the reel, its asked edges and handle limits on the master", () => { const p = reelPlan(build, [{ id: "c1", start: 104.2, end: 108.2 }, { id: "c3", start: 2002, end: 2006, verdict: "confirmed" }], { xfade: 0.3 }); assert.equal(p.rows.length, 2); const [a, b] = p.rows; close(a.piece.master.start, 7.667); assert.equal(a.piece.at, 0); close(b.piece.at, 4 - 0.3); assert.equal(b.verdict, "confirmed"); assert.equal(a.quote, "the first"); close(a.asked.start, 7.667); close(a.asked.end, 11.667); // A handle stays inside the source the segment was cut from. close(a.limits.start, 3.667); close(a.limits.end, 15.667); assert.deepEqual(a.limits.source, { start: 100.2, end: 112.2 }); close(p.total, 7.7); }); test("a beat across a clip's gap maps through the record's gaps (the master's jump cut)", () => { const p = reelPlan(build, [{ id: "c2", start: 501, end: 507 }], { xfade: 0 }); const [r] = p.rows; // 501 → 15.167 + 1; 507 → 15.167 + (7 − 2) = 20.167 close(r.asked.start, 16.167); close(r.asked.end, 20.167); close(r.piece.master.duration, 4); assert.deepEqual(r.map.gaps, [{ from: 503, to: 505 }]); assert.match(p.planNotes.join("\n"), /spans a gap/); }); test("a beat the take cannot place is said by its number; the others still play; a missing intro is played without", () => { const p = reelPlan(build, [{ id: "c1", start: 104, end: 106 }, { id: "gone", start: 1, end: 2 }, { id: "c3", start: 1990, end: 2003 }, { at: 30, dur: 2 }], { intro: true }); assert.deepEqual(p.rows.map((r) => !!r.piece), [true, false, false, true]); assert.match(p.rows[1].problem, /^beat 2: no clip "gone"/); assert.match(p.rows[2].problem, /^beat 3: c3 1990–2003 is outside/); assert.ok(p.intro); close(p.rows[0].piece.at, p.intro.master.duration - p.xfade); const noIntro = reelPlan({ ...build, schedule: { ...SCHEDULE, segments: SCHEDULE.segments.slice(1) } }, [{ id: "c1", start: 104, end: 106 }], { intro: true }); assert.equal(noIntro.intro, null); assert.match(noIntro.planNotes[0], /played without the intro/); }); test("the take a reel plays: asked, else pinned, else the last cut's, else the latest master; never one rendering now", () => { const masters = [ { id: "d3", built: true, rendering: true }, { id: "d2", built: true, rendering: false }, { id: "d1", built: true, rendering: false }, { id: "d0", built: false, rendering: false }, ]; assert.deepEqual(pickReelTake({ asked: "d0", masters }), { id: "d0", why: "asked" }); assert.deepEqual(pickReelTake({ pinned: "d1", masters }), { id: "d1", why: "pinned" }); assert.deepEqual(pickReelTake({ pinned: "d0", cuts: [{ take: "d3" }, { take: "d1" }], masters }), { id: "d1", why: "last cut" }); assert.deepEqual(pickReelTake({ masters }), { id: "d2", why: "latest master" }); assert.equal(pickReelTake({ masters: [{ id: "x", built: false, rendering: false }] }), null); }); test("Cut the trailer is `umtool trailer
--reel