// `window-overlap` is about footage that PLAYS twice. Two shapes on the shelf // overlapped on paper and repeated nothing, and made 22 of its 25 cards: // // - a crossfade seam: the next clip in the timeline starts one transition // before this one ends, so the fade lays the same seconds over themselves // (make-videos.py's unoverlap(), every hasan-leads polemic); // - two extents that overlap while the cuts that play do not // (quartering-slow-news s51/s52). // // 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"; import { decisionsFor } from "../projects/core.mjs"; import { walkProjects } from "../projects/walk.mjs"; async function overlapsOf(timeline, render = {}) { const root = await mkdtemp(path.join(tmpdir(), "window-overlap-")); try { const channelsDir = path.join(root, "channels"); const reportsRoot = path.join(root, "reports"); const vdir = path.join(channelsDir, "chan", "data", "vid"); await mkdir(vdir, { recursive: true }); // Punctuated cues covering everything, every one closing a sentence, so the // only decisions about these clips are the overlaps. const cues = Array.from({ length: 200 }, (_, i) => ({ start: i, end: i + 1, text: `Line ${i}.` })); await writeFile(path.join(vdir, "transcript.cues.json"), JSON.stringify({ cues })); const dir = path.join(reportsRoot, "cut"); await mkdir(dir, { recursive: true }); await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify({ schemaVersion: 1, slug: "cut", title: "Cut", provenance: { channelSlug: "chan", channelsDir: path.relative(dir, channelsDir), siteOrigin: "https://example.test" }, render: { width: 1920, height: 1080, fps: 30, ...render }, timeline: timeline.map((e) => ({ type: "clip", video: "vid", cite: Math.floor(e.start), lock: true, ...e })), }, null, 2)); const [ref] = (await walkProjects(reportsRoot)).filter((p) => p.id === "cut"); return (await decisionsFor(ref, reportsRoot)) .filter((d) => d.kind === "window-overlap") .map((d) => `${d.target}: ${d.why}`); } finally { await rm(root, { recursive: true, force: true }); } } test("a crossfade seam between back-to-back clips is not an overlap", async () => { // b starts exactly one transition (0.5 s) before a ends, and follows it. assert.deepEqual( await overlapsOf([{ id: "a", start: 10, end: 20 }, { id: "b", start: 19.5, end: 30 }], { transition: 0.5 }), [], ); // The default transition is the build's: 0.5. assert.deepEqual(await overlapsOf([{ id: "a", start: 10, end: 20 }, { id: "b", start: 19.5, end: 30 }]), []); }); test("more than a transition, a clip not next in the timeline, a hard cut, a montage: still overlaps", async () => { assert.deepEqual( await overlapsOf([{ id: "a", start: 10, end: 20 }, { id: "b", start: 18, end: 30 }], { transition: 0.5 }), ["a: overlaps b by 2.0s"], ); assert.deepEqual( await overlapsOf( [{ id: "a", start: 10, end: 20 }, { id: "x", start: 50, end: 60 }, { id: "b", start: 19.5, end: 30 }], { transition: 0.5 }, ), ["a: overlaps b by 0.5s"], ); // b plays BEFORE a: the fade into a is not the seam with b. assert.deepEqual( await overlapsOf([{ id: "b", start: 19.5, end: 30 }, { id: "a", start: 10, end: 20 }], { transition: 0.5 }), ["a: overlaps b by 0.5s"], ); assert.deepEqual( await overlapsOf([{ id: "a", start: 10, end: 20 }, { id: "b", start: 19.5, end: 30 }], { transition: 0 }), ["a: overlaps b by 0.5s"], ); // A montage joins its segments hard, whatever `transition` says. assert.deepEqual( await overlapsOf([{ id: "a", start: 10, end: 20 }, { id: "b", start: 19.5, end: 30 }], { transition: 0.5, montage: {} }), ["a: overlaps b by 0.5s"], ); }); test("judged on the cuts that play when a clip has the pair", async () => { // Extents overlap by 1.8 s; the cuts are 3 s apart (quartering-slow-news s51/s52). assert.deepEqual( await overlapsOf( [ { id: "s51", start: 89.18, end: 99.14, cutStart: 91.68, cutEnd: 96.64 }, { id: "s52", start: 97.34, end: 107.82, cutStart: 99.84, cutEnd: 105.32 }, ], { transition: 0 }, ), [], ); // Half a pair renders the whole extent, so the extent is what is judged. assert.deepEqual( await overlapsOf( [ { id: "s51", start: 89.18, end: 99.14, cutStart: 91.68 }, { id: "s52", start: 97.34, end: 107.82 }, ], { transition: 0 }, ), ["s51: overlaps s52 by 1.8s"], ); }); test("a deliberate repeat (repeatOf) is not an overlap, either way round; an undeclared one still is", async () => { // tr3z re-plays the tail of tr3 as a closing callback (EmberParadox, 30 Oct). const tr3 = { id: "tr3", start: 100, end: 130, lockEnd: true }; const tr3z = { id: "tr3z", start: 123, end: 129, lockEnd: true }; assert.deepEqual(await overlapsOf([tr3, { id: "x", start: 150, end: 160 }, { ...tr3z, repeatOf: "tr3" }]), []); assert.deepEqual(await overlapsOf([{ ...tr3, repeatOf: "tr3z" }, { id: "x", start: 150, end: 160 }, tr3z]), []); assert.deepEqual( await overlapsOf([tr3, { id: "x", start: 150, end: 160 }, tr3z]), ["tr3: overlaps tr3z by 7.0s and has lockEnd, so nothing will trim it"], ); }); test("repeatOf: the writer keeps a clip of the cut, refuses itself or a stranger, and clears on empty", async () => { const { patchClipEntry } = await import("./manifest.mjs"); const manifest = () => ({ timeline: [ { type: "clip", id: "tr3", video: "v", start: 100, end: 130 }, { type: "card", id: "c1" }, { type: "clip", id: "tr3z", video: "v", start: 123, end: 129 }, ], }); const m = manifest(); patchClipEntry(m, "tr3z", { repeatOf: "tr3" }); assert.equal(m.timeline[2].repeatOf, "tr3"); patchClipEntry(m, "tr3z", { repeatOf: "" }); assert.equal("repeatOf" in m.timeline[2], false); assert.throws(() => patchClipEntry(manifest(), "tr3z", { repeatOf: "tr3z" }), /itself/); assert.throws(() => patchClipEntry(manifest(), "tr3z", { repeatOf: "nope" }), /not a clip of the cut/); assert.throws(() => patchClipEntry(manifest(), "tr3z", { repeatOf: "c1" }), /not a clip of the cut/); });