// THE RECORDING'S END at window / insert time (lane window-end): a clip whose // padded fetch window runs past a whole saved recording's end is said to be // cut from the saved video, clamped there; a clip far from the end, or a // partial recording, says nothing. // // Run with: node --test lib/report/recordingEndNote.test.mjs import assert from "node:assert/strict"; import test from "node:test"; import path from "node:path"; import os from "node:os"; import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; import { recordingEndLine, recordingEndOf } from "./recordingEndNote.mjs"; async function tree(meta) { const root = await mkdtemp(path.join(os.tmpdir(), "umtool-recend-")); const channelsDir = path.join(root, "channels"); const videoDir = path.join(channelsDir, "synth-chan", "data", "vid1"); const storeDir = path.join(root, "store"); await mkdir(videoDir, { recursive: true }); await mkdir(storeDir, { recursive: true }); await writeFile(path.join(storeDir, "source-media.mp4"), Buffer.alloc(16, 1)); await writeFile(path.join(videoDir, "saved-video.json"), JSON.stringify({ storedAt: "2026-11-21T00:00:00Z", dir: storeDir, file: "source-media.mp4", bytes: 16 })); if (meta) await writeFile(path.join(videoDir, "metadata.info.json"), JSON.stringify(meta)); const project = { dir: path.join(root, "proj") }; await mkdir(project.dir, { recursive: true }); const manifest = { provenance: { channelsDir, channelSlug: "synth-chan" }, render: { fetchPad: 3 } }; return { root, project, manifest }; } const clip = (start, end) => ({ type: "clip", id: "last", video: "vid1", start, end }); const probe = async () => ({ duration: 300.5 }); test("a clip ending 1 s before a whole recording's end, pad 3: said, and the line names the clamp", async () => { const t = await tree({ id: "vid1", duration: 300 }); try { const r = await recordingEndOf(t.project, t.manifest, clip(290, 299.5), { probe }); assert.deepEqual(r, { recordingEnd: 300.5, from: 287, to: 302.5, clipEndPast: false, source: "saved-video" }); assert.match(recordingEndLine(r), /runs past the saved recording's end \(300\.50 s, known whole\) — cut from the saved video, clamped there; nothing is fetched$/); // Its end itself past the recording's: it plays to the end. const past = await recordingEndOf(t.project, t.manifest, clip(295, 301.5), { probe }); assert.equal(past.clipEndPast, true); assert.match(recordingEndLine(past), /it plays to 300\.50$/); } finally { await rm(t.root, { recursive: true, force: true }); } }); test("far from the end nothing is probed; a partial recording says nothing", async () => { const t = await tree({ id: "vid1", duration: 300 }); try { let probed = 0; const counting = async () => (probed++, { duration: 300.5 }); assert.equal(await recordingEndOf(t.project, t.manifest, clip(100, 110), { probe: counting }), null); assert.equal(probed, 0); } finally { await rm(t.root, { recursive: true, force: true }); } const p = await tree({ id: "vid1", duration: 3600 }); try { assert.equal(await recordingEndOf(p.project, p.manifest, clip(290, 299.5), { probe }), null); } finally { await rm(p.root, { recursive: true, force: true }); } assert.equal(recordingEndLine(null), null); });