// The QR-origin check (lane siteorigin-check): `manifest-invalid` on // `provenance.siteOrigin` is raised only when a QR the cut draws is built from // a missing or dead origin -- the build's own link rules (lint.mjs // originQrsOf over deckQrUrl / qrUrlFor / postQrUrl), with the deck's // `qr.links: "original"` reading each clip's record page from its cue file. // A set origin that is dead still blocks whatever links it. // // 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 { originQrsOf } from "umtool-report-to-video/lint"; import { decisionsFor, summarise } from "../projects/core.mjs"; import { walkProjects } from "../projects/walk.mjs"; const RENDER = { width: 1920, height: 1080, fps: 30, transition: 0.5 }; const DECK = (deck = {}) => ({ ...RENDER, chrome: { engine: "hyperframes", layout: "deck", deck } }); const clip = (id, extra = {}) => ({ type: "clip", id, video: `vid-${id}`, start: 10, end: 20, cite: 10, ...extra }); const cited = (id) => clip(id, { citeUrl: `https://archive.example/?v=chan%2Fvid-${id}&t=10` }); /** A reports root and a channels dir; each clip's cue file names `pages[id]` (or no page). */ async function fixture() { const root = await mkdtemp(path.join(tmpdir(), "siteorigin-")); const channelsDir = path.join(root, "channels"); const reportsRoot = path.join(root, "reports"); await mkdir(reportsRoot, { recursive: true }); /** * @param {string} slug * @param {{ provenance?: object, render?: object, timeline: any[], posts?: any[], pages?: Record }} o */ const project = async (slug, { provenance = {}, render = RENDER, timeline, posts, pages = {} }) => { for (const e of timeline.filter((x) => x.type === "clip" && x.video)) { const dir = path.join(channelsDir, "chan", "data", e.video); await mkdir(dir, { recursive: true }); const page = Object.hasOwn(pages, e.id) ? pages[e.id] : `https://www.youtube.com/watch?v=${e.video}`; await writeFile( path.join(dir, "transcript.cues.json"), JSON.stringify({ title: e.video, duration: 60, ...(page ? { webpageUrl: page } : {}), cues: [{ start: 0, end: 60, text: "A whole sentence." }] }), ); } const dir = path.join(reportsRoot, slug); await mkdir(dir, { recursive: true }); const m = { schemaVersion: 1, slug, title: slug, provenance: { channelSlug: "chan", channelsDir: path.relative(dir, channelsDir), ...provenance }, render, timeline, ...(posts ? { posts } : {}), }; await writeFile(path.join(dir, "video.manifest.json"), JSON.stringify(m, null, 2)); return m; }; /** The project's siteOrigin decisions and whether its card carries the flag. */ const check = async (slug) => { const [ref] = (await walkProjects(reportsRoot)).filter((p) => p.id === slug); assert.ok(ref, `no project ${slug}`); const ds = (await decisionsFor(ref, reportsRoot)).filter((d) => d.target === "provenance.siteOrigin"); const s = await summarise(ref, reportsRoot); return { ds, flagged: s.flags.includes("dead QR origin"), attr: s.attrs["dead-origin"] ?? null }; }; return { root, project, check, done: () => rm(root, { recursive: true, force: true }) }; } test("every clip with a citeUrl: no origin is needed, so no decision and no flag", async () => { const f = await fixture(); try { await f.project("all-cited", { timeline: [cited("a"), cited("b"), cited("c")] }); assert.deepEqual(await f.check("all-cited"), { ds: [], flagged: false, attr: null }); // A card beside them under the CORNER code draws nothing, so it needs nothing either. await f.project("cited-and-card", { timeline: [cited("a"), { type: "card", id: "k1", seconds: 3 }] }); assert.deepEqual((await f.check("cited-and-card")).ds, []); } finally { await f.done(); } }); test("the deck with qr.links \"original\": a clip whose record names its page links that; one whose record names none falls back and blocks", async () => { const f = await fixture(); try { const render = DECK({ qr: { links: "original" } }); // Posts with no origin link themselves (postQrUrl), so they need none either. const posts = [{ id: "p1", attachTo: "a", url: "https://bsky.app/profile/x/post/abc", date: "2026-01-01", text: "t", platform: "bluesky" }]; await f.project("original", { render, timeline: [clip("a"), clip("b"), { type: "teaser", id: "t1", seconds: 3 }], posts }); assert.deepEqual(await f.check("original"), { ds: [], flagged: false, attr: null }); await f.project("original-gap", { render, timeline: [clip("a"), clip("nopage")], pages: { nopage: null } }); const { ds, flagged, attr } = await f.check("original-gap"); assert.equal(ds.length, 1); assert.equal(ds[0].severity, "blocking"); assert.match(ds[0].why, /^missing — 1 QR code in this cut would encode `undefined\/\?v=…` \(`nopage`\)/); assert.match(ds[0].why, /set provenance\.siteOrigin, or give those clips a citeUrl$/); assert.equal(flagged, true); assert.equal(attr, "1"); } finally { await f.done(); } }); test("one clip without a citeUrl and no origin: blocking, naming that clip and the fix", async () => { const f = await fixture(); try { await f.project("one-uncited", { timeline: [cited("a"), clip("bare"), cited("c")] }); const { ds, flagged } = await f.check("one-uncited"); assert.equal(ds.length, 1); assert.equal(ds[0].kind, "manifest-invalid"); assert.equal(ds[0].severity, "blocking"); assert.equal( ds[0].why, "missing — 1 QR code in this cut would encode `undefined/?v=…` (`bare`): set provenance.siteOrigin, or give those clips a citeUrl", ); assert.equal(flagged, true); // Many: the first three by id, then how many more. await f.project("many-uncited", { timeline: ["a", "b", "c", "d", "e"].map((id) => clip(id)) }); const [d] = (await f.check("many-uncited")).ds; assert.match(d.why, /^missing — 5 QR codes in this cut would encode `undefined\/\?v=…` \(`a`, `b`, `c` and 2 more\)/); } finally { await f.done(); } }); test("no QR at all -- render.qr false, the deck's qr.show false, a src clip -- needs no origin", async () => { const f = await fixture(); try { await f.project("qr-off", { render: { ...RENDER, qr: false }, timeline: [clip("a"), clip("b")] }); assert.deepEqual(await f.check("qr-off"), { ds: [], flagged: false, attr: null }); await f.project("deck-qr-off", { render: DECK({ qr: { show: false } }), timeline: [clip("a")] }); assert.deepEqual((await f.check("deck-qr-off")).ds, []); await f.project("src-clip", { timeline: [{ type: "clip", id: "s1", src: "media/local.mp4", start: 0, end: 5 }, cited("a")] }); assert.deepEqual((await f.check("src-clip")).ds, []); } finally { await f.done(); } }); test("a rail card with no qrLink and no origin: blocking, the card named and qrLink offered; a qrLink settles it", async () => { const f = await fixture(); try { const render = { ...RENDER, rail: { qrSize: 132 } }; const timeline = [cited("a"), { type: "card", id: "k1", seconds: 3, heading: "A card" }]; await f.project("rail-card", { render, timeline }); const { ds } = await f.check("rail-card"); assert.equal(ds.length, 1); assert.equal(ds[0].severity, "blocking"); assert.match(ds[0].why, /\(`k1`\): set provenance\.siteOrigin, or set provenance\.qrLink for the rail's other tiles$/); await f.project("rail-card-qrlink", { render, timeline, provenance: { qrLink: "https://archive.example/?q=x" } }); assert.deepEqual((await f.check("rail-card-qrlink")).ds, []); } finally { await f.done(); } }); test("a SET origin that is dead still blocks, whatever links it; a live one never does", async () => { const f = await fixture(); try { await f.project("localhost-cited", { provenance: { siteOrigin: "http://localhost:3000" }, timeline: [cited("a")] }); const [d] = (await f.check("localhost-cited")).ds; assert.equal(d.severity, "blocking"); assert.match(d.why, /^`http:\/\/localhost:3000` — resolves to nothing on anyone else's phone/); await f.project("localhost-bare", { provenance: { siteOrigin: "http://localhost:3000" }, timeline: [clip("a"), clip("b")] }); const [e] = (await f.check("localhost-bare")).ds; assert.match(e.why, /^`http:\/\/localhost:3000` — 2 QR codes in this cut \(`a`, `b`\) resolve to nothing/); assert.match(e.why, /set provenance\.siteOrigin to the public archive, or give those clips a citeUrl$/); await f.project("live", { provenance: { siteOrigin: "https://archive.example" }, timeline: [clip("a")] }); assert.deepEqual(await f.check("live"), { ds: [], flagged: false, attr: null }); } finally { await f.done(); } }); test("originQrsOf is the build's rules run on a probe origin: which codes, by entry", () => { const timeline = [cited("a"), clip("b"), { type: "card", id: "k1", seconds: 3 }, { type: "image", id: "i1", src: "x.png", citeUrl: "https://e.test/i1" }]; const ids = (m, o) => originQrsOf(m, o).map((q) => q.id); // The corner code: the uncited clip only (a card draws none, a still links its citeUrl). assert.deepEqual(ids({ render: RENDER, provenance: {}, timeline }), ["b"]); // The rail: a card's and a still's tile are qrLink ?? siteOrigin (qrUrlFor). assert.deepEqual(ids({ render: { ...RENDER, rail: {} }, provenance: {}, timeline }), ["b", "k1", "i1"]); // The deck, site links: the uncited clip; "original" with its record's page: none. assert.deepEqual(ids({ render: DECK(), provenance: {}, timeline }), ["b"]); const page = () => ({ webpageUrl: "https://www.youtube.com/watch?v=x" }); assert.deepEqual(ids({ render: DECK({ qr: { links: "original" } }), provenance: {}, timeline }, { metaOf: page }), []); // A post under "archive" depends on the origin only when one is set (else it links itself). const posts = [{ id: "p1", attachTo: "a", url: "https://bsky.app/profile/x/post/abc" }]; assert.deepEqual(originQrsOf({ render: DECK(), provenance: {}, timeline: [cited("a")], posts }), []); assert.deepEqual( originQrsOf({ render: DECK(), provenance: { siteOrigin: "http://localhost:3000" }, timeline: [cited("a")], posts }).map((q) => q.source), ["post"], ); // ...and not at all with the posts' codes off. assert.deepEqual( originQrsOf({ render: DECK({ posts: { qr: false } }), provenance: { siteOrigin: "http://localhost:3000" }, timeline: [cited("a")], posts }), [], ); });