// Play the cut ON A TAKE with gaps inside a clip (operator, 1 Nov 2026: a // gapped clip reported playing whole in a take's Play the cut while the take's // render left the gap out). A take plays the project's manifest NOW with its // patch (takeManifest.mjs), so a gap the project's clip carries -- written // before or after the take was made -- is in the take's view, its plan and its // sound, exactly as in the project's own: one item, one sound span per kept // piece, on the estimate's clock and on the render's edges (the cut-points // route's shape). A patch that turns the deck and its effects on (draft-21's) // changes none of that. // // Run with: pnpm test:scripts import assert from "node:assert/strict"; import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import test from "node:test"; const GAPS = [{ from: 12, to: 13 }, { from: 15, to: 15.5 }]; const manifest = () => ({ slug: "t", title: "The cut", provenance: { channelSlug: "testchan", siteOrigin: "https://archive.example" }, render: { width: 1920, height: 1080, fps: 30, transition: 0 }, timeline: [ { type: "clip", id: "a", video: "v1", start: 10, end: 18, lock: true, gaps: GAPS }, { type: "clip", id: "b", video: "v2", start: 100, end: 103, lock: true }, ], }); async function fixture() { const root = await mkdtemp(path.join(tmpdir(), "play-take-gaps-")); // Never the real corpus: the play view looks for cached windows under the channels dir. process.env.CHANNELS_DIR = path.join(root, "channels"); const dir = path.join(root, "p"); await mkdir(path.join(dir, "takes", "t1"), { recursive: true }); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(manifest())); await writeFile( path.join(dir, "takes", "t1", "take.json"), JSON.stringify({ id: "t1", group: "takes", order: 1, label: "Take one", kind: "different", preview: "preview.mp4", window: "full", // draft-21's shape: a retitle and the deck with its effects on, no timeline of its own. patch: { title: "The cut, a take", render: { chrome: { engine: "hyperframes", layout: "deck", deck: {}, fx: { zoom: {} } } } }, }), ); return { root, project: { id: "p", dir } }; } /** The render's edges as the cut-points route returns them: the cut, its gaps, the kept footage. */ const CUTS = new Map([ ["a", { cutStart: 10, cutEnd: 18, gaps: GAPS, footage: 6.5 }], ["b", { cutStart: 100, cutEnd: 103, footage: 3 }], ]); test("a take's view, plan and sound keep the project's gaps: one item, one span per kept piece", async () => { const { root, project } = await fixture(); try { const { playView } = await import("./playView.mjs"); const { playPlan } = await import("./playCut.mjs"); const { audioSpans } = await import("./playSchedule.mjs"); const pieces = (view, cuts) => audioSpans(playPlan(view.segments, view.entries, { leadIn: view.leadIn, cuts })) .filter((s) => s.id === "a") .map((s) => [s.src, s.srcTo]); const cut = await playView(project); const take = await playView(project, { take: "t1" }); assert.equal(take.take?.id, "t1"); assert.equal(take.title, "The cut, a take"); assert.equal(take.deckOn, true, "the take's patch turns the deck on"); assert.deepEqual(take.entries.find((e) => e.id === "a")?.gaps, GAPS, "the take's entry carries the project's gaps"); // The render's edges: the kept pieces, the same for the take as for the cut. const kept = [[10, 12], [13, 15], [15.5, 18]]; assert.deepEqual(pieces(take, CUTS), kept); assert.deepEqual(pieces(cut, CUTS), kept); // The estimate's clock (before the edges are measured): one span per piece too, never the whole window. const est = pieces(take, null); assert.equal(est.length, 3); assert.deepEqual(est, pieces(cut, null)); const item = playPlan(take.segments, take.entries, { leadIn: take.leadIn, cuts: CUTS }).items.find((i) => i.id === "a"); assert.deepEqual(item?.clip?.gaps, GAPS); assert.equal(Math.round((item.clip.playEnd - item.start) * 1000) / 1000, 6.5, "its footage is the kept seconds"); } finally { await rm(root, { recursive: true, force: true }); } }); test("a gap written to the project after the take was made plays in the take", async () => { const { root, project } = await fixture(); try { const m = manifest(); m.timeline[1].gaps = [{ from: 101, to: 102 }]; await writeFile(path.join(project.dir, "video.manifest.json"), JSON.stringify(m)); const { playView } = await import("./playView.mjs"); const { playPlan } = await import("./playCut.mjs"); const { audioSpans } = await import("./playSchedule.mjs"); const take = await playView(project, { take: "t1" }); const spans = audioSpans(playPlan(take.segments, take.entries, { leadIn: take.leadIn })).filter((s) => s.id === "b"); assert.deepEqual(spans.map((s) => [s.src, s.srcTo]), [[100, 101], [102, 103]]); } finally { await rm(root, { recursive: true, force: true }); } });