// A TAKE OF A PROJECT WHOSE STAMP HOLDS A NO-RECORD SOURCE (lane source-status-nulls). // // A take's manifest is the project's with its look preset laid under it: composeTake -> // presets.mjs resolvePresetLayers, which lays the MANIFEST over `{ render: preset.render }` // as a merge patch, so every explicit null in it is dropped. A stamp's no-record entry // (`now: null, …`) arrived at the build as `{ evidence, from, recordsAt }`, and the // validator refused the whole take, the status switch on or off. Here the take-shaped // manifest is made by composeTake itself, never imitated. Synthetic names only. // // Run with: node --test umtool/lib/report/sourceStatusTake.test.mjs 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 ROOT = await mkdtemp(path.join(tmpdir(), "umtool-source-status-take-")); process.env.REPORTS_DIR = path.join(ROOT, "reports"); process.env.CHANNELS_DIR = path.join(ROOT, "channels"); process.env.UMTOOL_PRESETS_DIR = path.join(ROOT, "presets"); test.after(() => rm(ROOT, { recursive: true, force: true })); const { checkSpec, composeTake } = await import("./takeMaker.mjs"); const { estimateSchedule } = await import("../../report-to-video/deck.mjs"); const { clipSourceStatus, sourceStatusNotes, validateSourceStatus } = await import("../../report-to-video/source-status.mjs"); const PALETTE = { bg: "#12101a", fg: "#f4f1ea", muted: "#9a93ad", accent: "#a97bff", amber: "#ffc860" }; await mkdir(process.env.UMTOOL_PRESETS_DIR, { recursive: true }); await writeFile(path.join(process.env.UMTOOL_PRESETS_DIR, "synth-look.json"), JSON.stringify({ name: "synth-look", description: "A synthetic deck look.", render: { width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck: { subtitle: { parts: ["channel", "date", "clock"], status: "end" } } }, }, })); const clip = (id, video, start) => ({ id, type: "clip", video, start, end: start + 10, cite: start + 2, quote: "a synthetic line", onscreen: { title: `Moment ${id}` } }); const META = (n) => ({ title: `Synthetic stream ${n}`, uploadDate: "20310301", channel: "Synth Channel", webpageUrl: `https://video.example.test/${n}` }); const STAMP = { refreshedAt: "2031-03-02T00:00:00.000Z", sources: { // No record, as refresh wrote it before this lane: every nullable field an explicit null. "synth-channel/synthvid001": { now: null, since: null, asOf: null, first: null, firstAt: null, firstWhen: null, evidence: [], from: "corpus", recordsAt: "2031-03-01T00:00:00.000Z" }, "synth-channel/synthvid002": { now: "private", since: "2031-03-01T20:00:00Z", asOf: "2031-03-01T20:00:00Z", first: "public", firstAt: "2031-03-01T10:05:00Z", firstWhen: "live", from: "corpus", evidence: [] }, // No record, as refresh writes it now. "synth-channel/synthvid003": { evidence: [], from: "corpus", recordsAt: "2031-03-01T00:00:00.000Z" }, // An archive reading with no state the line names (its deleted is the loose class). "synth-channel/synthvid004": { now: null, since: null, asOf: "2031-03-01T20:00:00Z", first: null, firstAt: null, firstWhen: null, from: "archive", evidence: [{ kind: "archive", at: null, availability: "deleted", counts: false, why: "synthetic" }] }, }, }; let n = 0; /** A project naming the preset, its manifest's own render under the switch given, and a take of it composed. */ async function takeOf(status) { const dir = path.join(process.env.REPORTS_DIR, `snt${++n}`); await mkdir(dir, { recursive: true }); const manifest = { schemaVersion: 1, slug: `snt${n}`, title: "Synthetic cut", preset: "synth-look", provenance: { channelSlug: "synth-channel", channel: "Synth Channel", siteOrigin: "https://archive.example.test" }, render: status ? { chrome: { deck: { subtitle: { status } } } } : {}, timeline: [clip("c01", "synthvid001", 600), clip("c02", "synthvid002", 1200), clip("c03", "synthvid003", 1800), clip("c04", "synthvid004", 2400)], sourceStatus: STAMP, }; await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(manifest, null, 2) + "\n"); // A take's patch, as a real draft carries one ("No intro"). const c = await composeTake(dir, checkSpec({ id: "draft-1", label: "draft 1", window: "full", patch: { render: { intro: null } } })); return { manifest, take: c.renderDoc }; } test("the take's manifest has lost the stamp's nulls (the cause), and the build's validator passes it, the switch on or off", async () => { for (const status of [null, "end", "off"]) { const { manifest, take } = await takeOf(status); assert.equal(take.presetApplied, "synth-look"); assert.deepEqual(Object.keys(take.sourceStatus.sources["synth-channel/synthvid001"]), ["evidence", "from", "recordsAt"], "the preset's layering dropped the nulls"); assert.ok(!("now" in take.sourceStatus.sources["synth-channel/synthvid004"])); assert.deepEqual(validateSourceStatus(take), [], `switch ${status ?? "(the preset's)"}: the take validates`); assert.deepEqual(validateSourceStatus(manifest), [], "and the project's own manifest, nulls and all"); } }); test("the take's deck: nothing for a no-record source, the words for a private one", async () => { const { take } = await takeOf(null); const s = estimateSchedule(take, { metas: [META(1), META(2), META(3), META(4)] }); const seg = (id) => s.segments.find((x) => x.id === id); assert.equal(seg("c02").subtitle, "Synth Channel · Mar 1, 2031 · 20:02 · now private (public when streamed)"); for (const id of ["c01", "c03", "c04"]) { assert.ok(seg(id).subtitleParts.every(([k]) => k !== "status"), `${id}: no status part`); assert.doesNotMatch(seg(id).subtitle, /now /); } assert.equal(clipSourceStatus(take.timeline[0], take.sourceStatus, take.provenance), ""); // The build's notes: a no-record source is not listed as stale, null or absent. const notes = sourceStatusNotes(take, { now: Date.parse("2031-04-30T00:00:00Z") }); assert.equal(notes.length, 1); assert.doesNotMatch(notes[0], /synthvid001|synthvid003/); // The switch off in the take: the line is what it always was. const off = (await takeOf("off")).take; const so = estimateSchedule(off, { metas: [META(1), META(2), META(3), META(4)] }); assert.equal(so.segments.find((x) => x.id === "c02").subtitle, "Synth Channel · Mar 1, 2031 · 20:02"); });