Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 456c582e0134571a76d79b257b13a3bbb0855631
parent ba9d84cdceac9abacc2181eec4e4291a0006ce91
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Fri, 23 Oct 2026 02:22:47 -0400

Merge lane/siteorigin-check: the siteOrigin decision blocks only when a drawn QR is built from the origin

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

# Conflicts:
#	editor/CHANGELOG.md

Diffstat:
Meditor/CHANGELOG.md | 1+
Mplans/FACTS.md | 7++++---
Aplans/siteorigin-check.md | 38++++++++++++++++++++++++++++++++++++++
Mumtool/docs/authoring.md | 3++-
Mumtool/docs/inbox.md | 2+-
Mumtool/docs/report-video.md | 12++++++++++--
Mumtool/lib/projects/report.mjs | 104++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
Aumtool/lib/report/siteorigin-check.test.mjs | 198+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/lint.mjs | 62+++++++++++++++++++++++++++++++++++++++++++++++++++-----------
9 files changed, 384 insertions(+), 43 deletions(-)

diff --git a/editor/CHANGELOG.md b/editor/CHANGELOG.md @@ -4,6 +4,7 @@ - **A clip in a fact-check video can stamp and count more than once.** The clip editor's **Count & stamp** box is now **Marks**, on every clip: a list of the clip's marks, each its own stamp and its own step of the tally at its own second — its verdict picked by this cut's words (Episodes, Grift…), when it lands (**Set at playhead**, Shift+S for the selected mark), how long it stays, whether it is drawn, how much it counts, what it says, **Remove**. **Add mark at playhead** (Shift+M) adds one under a new id; **Clear** removes them all. Two stamps on one clip that would sit on each other are refused, saying where the second may land. From a terminal: `umtool set <project> <clip> mark.add=Episodes@190.2`, `mark.remove=<id>`, `mark.verdict=…`, `marks=<json>`; `umtool show` lists them. A clip with one mark is written as before, so an existing video renders the same. - **Walk a report video's clips in umtool's clip editor with the on-screen chrome drawn over them, no build.** Under the clip editor's player, **Live preview** draws the cut's deck over the playing clip, in step with the playhead: the clip's date title and subtitle, the timeline with its pip and flags, the tally as it stands at that moment (stepping when a stamp lands), the stamp, the posts, the QR, and the finale's page on the last clip. A trimmed edge, a moved stamp or new words show about a second after they are saved; an unsaved nudge moves the picture at once. **Title** and **Subtitle** under the picture edit the clip's on-screen words, shown as they are typed. A line under the picture says what the preview does not do (the build snaps each edge to a silence and crossfades the clips). **Render this clip** makes the clip with its chrome exactly as the build would, in a minute or two, and plays it in place (`node umtool/report-to-video/build-video.mjs <manifest> --skip-fetch --clip-preview <id>`). The On-screen preview now draws the finale too. Needs a restart of umtool. - **A long report video with on-screen chrome is no longer stopped partway through its build.** umtool gave a build two minutes per clip (a whole-cut take one minute), which a 36-clip, 25-minute cut with its panel, posts column and stamps outruns: drawing those alone takes over half an hour. A build or take of a cut with on-screen chrome now gets five times the cut's length when that is longer. Needs a restart of umtool. +- **A report video with no site origin is blocked only when one of its QR codes needs it.** umtool's "Fix the manifest" call on `provenance.siteOrigin` used to block every cut with no origin, even when no code was built from it. It is now raised only for the codes that would read `undefined/?v=…`: a clip with no `citeUrl` whose code links the archive, a deck clip under `qr.links: "original"` whose source names no page of its own, and a rail card or still with no `provenance.qrLink`. A cut whose codes all link something else (each clip's `citeUrl`, each source's own page) or that draws none (`render.qr` off, the deck's QR off) has no call. The call says how many codes, names the first few entries and the fix: set `provenance.siteOrigin`, or give those clips a `citeUrl`. An origin that is set but points at localhost or a private address is still blocked. Needs a restart of umtool. - **A video attached from a local archive gets its date when the archive writes it as 2019-10-31.** `attach-media` with `createRecords` read a folder's "Published on …" line only as "July 13th 2018" or "March 1, 2019"; it now reads "2019-10-31" and "2019/10/31" too, and a date that is not on the calendar is no date. Records it made before without a date can be dated now: `"fillDates": true` on `pnpm ops attach-media` (`--fill-dates` on `archilyzer media attach`) gives a held record that attach-media made, and that has no upload date, the date from its folder's description.txt — recorded in its metadata history. A record that has a date, or that attach-media did not make, is never touched. The log and the summary list them as "dated"; with `"dryRun": true` it only lists them. - **A report video's sound stays with its picture from the first clip to the last.** A clip whose sound started late (its cut reached back before the fetched window's media) or had a gap in it (a seam in the source's stream) used to pull that clip's sound, and every later clip's, early — on a 20-minute cut by half a second from the 13th minute on. Each clip's sound is now laid on its own clock before the clips are joined, and every build writes `sync.json` beside its schedule saying where each clip's sound landed against its picture; the build log names any clip more than a frame off. A video's manifest can now also set when a fact-check stamp lands and the count steps (`claim.at`, a second of the source), how long it stays, a count of more than one, a stamp that counts without showing, the stamp's words, size, entrance and opacity; nudge a clip's sound against its picture, its volume and fades (`audio`); align a timeline flag's label and lay crowded labels in two rows; and `node umtool/report-to-video/variants.mjs <take out dir>` makes smaller copies of a finished cut — 1080p, 720p and one under 24 MiB by default (`render.variants`). Needs a rebuild of the video. - **A fact-check video can count without the stamp, colour its timeline by verdict, flag the moments time passes, and leave the QR off posts.** In umtool's fact-check form, **stamp effect** off draws no verdict stamp over the footage, while the tally in the panel still counts each claim at the second its stamp would have landed. The On-screen settings have **colour** under timeline: **verdict** lights each clip that carries a claim in its verdict's colour — the tally's colour — with a shape per verdict (circle, diamond, square, triangle, ring), and the tally's cells carry the same shapes. **qr codes** under posts off leaves the QR off every post card, popup or feed, and the words take its width; each clip's own QR stays. A video's manifest can flag moments on the timeline (`render.chrome.deck.markers`: "3 to 5 weeks pass" after a clip), each popping in as the timeline reaches it and staying lit. Needs a restart of umtool. diff --git a/plans/FACTS.md b/plans/FACTS.md @@ -10823,9 +10823,10 @@ parsed to 0 cues, indexing the video textless) is CLOSED by `200a3105` (transcri moves; a kept clip with no citeUrl gains it; a citeUrl that is not the derived one for its cite is never touched. The seed then sets `render` to `SITELESS_LOOK` (`umtool/lib/projects/scaffold.mjs`: headerHeight 0, footerHeight 0, qr false, transition 0.5, transitionStyle "fadeblack", loudness {target: -16}) instead of `transition: 0`, and - `provenance.channel` from metadata `channel` (else `uploader`) whenever it was empty. `report.mjs` `originUnused(m)`: - an EMPTY siteOrigin with every clip carrying an http(s) citeUrl and no card or post is no "dead QR origin" flag or - blocking decision. Nothing in lint/build refuses an unknown render key (verified: `lintManifest(…, {validators: + `provenance.channel` from metadata `channel` (else `uploader`) whenever it was empty. An EMPTY siteOrigin + is a "dead QR origin" flag / blocking decision only when a QR the cut draws is built from it (`report.mjs` + `deadOriginQrsOf` → `lint.mjs` `originQrsOf`; lane siteorigin-check, `plans/siteorigin-check.md` — it replaced + `originUnused`). Nothing in lint/build refuses an unknown render key (verified: `lintManifest(…, {validators: true})` on a seeded site-less manifest gives no render error). - **`/api/report/clips`** POST: `routeCaller(authorization, agentToken())` (`umtool/lib/annotations/agentAuth.mjs`) — no header = the page, `Bearer <umtool's WORKER_TOKEN>` = the editor, else 401 `{error}`; every POST answers `jobId` diff --git a/plans/siteorigin-check.md b/plans/siteorigin-check.md @@ -0,0 +1,38 @@ +# The QR-origin check — exact (lane `lane/siteorigin-check`) + +Asked by the operator on 2026-10-23: "Am I good to click 'fix manifest' on the huck video in umtool? And why do I +have to click it for everything?" → "queue it" (fix the check). + +## Findings + +- `umtool decisions` (read-only, 2026-10-23, before): 30 `manifest-invalid` rows on `provenance.siteOrigin`, every + one "missing — every QR in this cut encodes `undefined/?v=…`". 28 are deck cuts with `qr.links: "original"` whose + every clip's cue file names its page (`webpageUrl`); one has the deck's `qr.show: false`; one has `render.qr: false`. + None of them draws a code built from the origin. +- "Fix the manifest" (lib/inbox/groups.mjs `ACTION_LABEL`) is a link: the decision's `href`, the project's Overview, + whose decision row prints the decision's sentence. It changes nothing on disk. + +## Rulings + +1. `lint.mjs` `originQrsOf(manifest, { metaOf })` is the one answer to "which codes are built from + `provenance.siteOrigin`": it runs `qrsOf` — the build's `deckQrUrl`, `qrUrlFor`, `postQrUrl` — with the origin set to + a probe and keeps the codes whose link starts with it. A post counts only when an origin is set (with none, + `postQrUrl` links the post itself). +2. `qrsOf` takes `metaOf(entry)` (the clip's record `{ webpageUrl }`) for the deck's `qr.links: "original"`, honours + the deck's `posts.qr: false`, and tags each code with its entry/post `id` and `source`. +3. `report.mjs` `deadOriginQrsOf(dir, m)` reads each uncited deck clip's `webpageUrl` from its cue file (the record the + build reads; memoised, the same files `sourcesOf` reads) only when the origin is missing or dead and the deck shows + its QR under `"original"`; otherwise `originQrsOf` alone. The summary carries `deadOriginQrs` for the decision pass. +4. A MISSING (or blank) origin is a defect — the "dead QR origin" flag, the `dead-origin` attr, the blocking + `manifest-invalid` — only when at least one code is built from it. With none, nothing is added (no info row). +5. A SET origin that is dead (localhost, a LAN address — `isDeadOrigin`) blocks whatever links it, as before. +6. The sentence names the count and up to three ids ("`a`, `b`, `c` and 2 more") and the fix: set + `provenance.siteOrigin` (to the public archive, for a set dead one); give those clips a `citeUrl` when clips are + among them; set `provenance.qrLink` when a rail card's or still's tile is; give those posts a `siteUrl` when posts are. +7. The action stays "Fix the manifest", linking the Overview, where the sentence carries the fix. +8. `originUnused` is removed; `originQrsOf` replaces it. + +## Counts + +`node umtool/bin/umtool.mjs decisions --json` over the real projects (run with every fs write refused): before 30 +siteOrigin rows (1,147 blocking of 1,360); after 0 (1,117 of 1,330). No other row changed. diff --git a/umtool/docs/authoring.md b/umtool/docs/authoring.md @@ -25,7 +25,8 @@ README listing every `?v=` citation as a checklist. **This is the field that shipped broken twice.** One manifest has no `siteOrigin` at all — 19 QR codes encoding `undefined/?v=…` — and one has `http://localhost:3000`, a finished video whose codes resolve to nothing on -anybody's phone. `umtool check` blocks until it is set to something real. +anybody's phone. `umtool check` blocks while any QR the cut draws is built from +it and it is not something real (a localhost origin blocks whatever links it). ## 2. Turn each citation into a WINDOW diff --git a/umtool/docs/inbox.md b/umtool/docs/inbox.md @@ -59,7 +59,7 @@ on (`decisionTab`, `songTabOfSection`). | kind | severity | trigger | action | |---|---|---|---| -| `manifest-invalid` | blocking | missing or `localhost` `siteOrigin`, missing `channelSlug`, duplicate ids, `section` out of range | Fix the manifest | +| `manifest-invalid` | blocking | a `localhost`/private `siteOrigin`; a missing one only when a QR the cut draws is built from it (its count and first ids named — lint.mjs `originQrsOf`); missing `channelSlug`, duplicate ids, `section` out of range | Fix the manifest | | `clip-no-cues` | blocking | no `transcript.cues.json` — the build dies there | Fix the cue source | | `clip-unfetchable` | blocking | the last preflight says the source is gone | Replace the source | | `clip-mid-sentence` | open | the cut lands inside a cue that does not close a sentence, and `lockEnd` is unset | Trim to the sentence | diff --git a/umtool/docs/report-video.md b/umtool/docs/report-video.md @@ -600,7 +600,14 @@ fields are load-bearing: this**, and two real videos shipped broken: `quartering-employee-count` has no `siteOrigin` at all (19 QR codes encoding `undefined/?v=…`) and `ferret-rescue` has `http://localhost:3000` (codes that resolve to nothing on a phone). This is - the single best reason to run `umtool check` before every build. + the single best reason to run `umtool check` before every build. A + localhost/private origin always blocks; a MISSING one blocks only when a code + the cut draws is built from it — the build's own rules, `lint.mjs` + `originQrsOf`: a clip's `citeUrl` wins, the deck's `qr.links: "original"` + links the source's own page (its cue file's `webpageUrl`), a rail card or + still links `provenance.qrLink` first, and `render.qr: false`, the deck's + `qr.show: false` and a `src` clip with no `citeUrl` draw nothing. The + decision names how many codes and the first ids. - **`channelSlug`** — the default archived channel for cue lookups, overridable per clip. - **`availabilityCheckedOn`** — when sources were last confirmed fetchable. Stale in @@ -1146,7 +1153,8 @@ writes `provenance.channel` from the metadata and the look chosen for a one-video cut: `render` `headerHeight: 0, footerHeight: 0, qr: false, transition: 0.22, transitionStyle: "blurslide", loudness: {target: -16}, room: {tail: true, head: true}` (lane E; before it, 0.5 s `"fadeblack"`). With -every clip linked, an empty `siteOrigin` is not a blocking decision. +every clip linked, an empty `siteOrigin` is not a blocking decision (nor with +any cut whose codes are none of them built from it — see `siteOrigin` above). **From the editor** (release 36): `POST /api/report/clips {mode: "new", slug, from: "<channel>/<id>", target?, scope? ("auto", the default | "all" | [from, diff --git a/umtool/lib/projects/report.mjs b/umtool/lib/projects/report.mjs @@ -18,7 +18,8 @@ import { resolveVideoDirSync } from "yt-dlp-transcript-common/lib/videoDir-serve import { deliverablesState, finishCommand, outDirState, leftoversOf } from "../report/storage.mjs"; import { CHANNELS_DIR, inside } from "../paths.mjs"; import { channelName, cleanTitle } from "umtool-report-to-video/attribution"; -import { teaserTitle } from "umtool-report-to-video/deck"; +import { deckOn, resolveDeck, teaserTitle } from "umtool-report-to-video/deck"; +import { originQrsOf } from "umtool-report-to-video/lint"; import { DRAFTS_REVIEW_FILE, NARRATION_REVIEW_FILE } from "umtool-report-to-video/drafts-review"; /** @@ -91,20 +92,72 @@ const DEAD_ORIGIN = export const isDeadOrigin = (o) => !o || typeof o !== "string" || DEAD_ORIGIN.test(o); +const originSet = (m) => typeof m?.provenance?.siteOrigin === "string" && m.provenance.siteOrigin.trim() !== ""; + /** - * A cut with NO siteOrigin whose every clip carries its own `citeUrl` (release - * 36: a site-less reactions cut links each clip's platform page), with no - * card and no post that would need the archive: no QR is built from the - * origin, so its absence is not a defect. A dead origin that IS set (localhost) - * still is one. + * The QR codes this cut draws from `provenance.siteOrigin`, when that origin is + * missing or dead -- `[]` when it is live, since then none of them is wrong. + * + * WHICH codes is the build's own rule, not a guess here: lint.mjs originQrsOf + * runs qrsOf (deckQrUrl, qrUrlFor, postQrUrl). A clip with a `citeUrl` links + * that; under the deck with `qr.links: "original"` a clip links its record's + * page (`webpageUrl`, read from its cue file -- the record the build reads), + * and only one whose record names none falls back to the archive; no code is + * drawn with `render.qr: false`, the deck's `qr.show: false`, or for a `src` + * clip with no `citeUrl`; a rail card links `provenance.qrLink` before the + * origin. + * + * @returns {Promise<{ where: string, id: string|null, source: "entry"|"post" }[]>} */ -export const originUnused = (m) => { - if (m?.provenance?.siteOrigin) return false; - const tl = Array.isArray(m?.timeline) ? m.timeline : []; - const clips = tl.filter((e) => e?.type === "clip"); - return clips.length > 0 && clips.every((c) => typeof c.citeUrl === "string" && /^https?:\/\//.test(c.citeUrl)) && !tl.some((e) => e?.type === "card") && !(Array.isArray(m?.posts) && m.posts.length); -}; -const originDead = (m) => isDeadOrigin(m?.provenance?.siteOrigin) && !originUnused(m); +export async function deadOriginQrsOf(dir, m, { channelsDir = null } = {}) { + if (!m || !isDeadOrigin(m.provenance?.siteOrigin)) return []; + const render = m.render ?? {}; + let metaOf = null; + if (deckOn(render) && resolveDeck(render).qr?.show && resolveDeck(render).qr?.links === "original") { + const root = channelsDir ?? channelsDirFor(dir, m, { shadowExists: await hasShadowChannels(dir) }); + const metas = new Map(); + for (const e of clipsOf(m)) { + if (e.citeUrl || e.src != null || !e.video) continue; + const file = cuePathFor(m, e, root); + const doc = file ? await readCues(file) : null; + metas.set(e, doc?.webpageUrl ? { webpageUrl: doc.webpageUrl } : null); + } + metaOf = (e) => metas.get(e) ?? null; + } + return originQrsOf(m, { metaOf }); +} + +/** + * Is the QR origin a defect? A SET origin that is dead (localhost, a LAN + * address) always is: it is the archive the cut names, whatever links it + * today. A MISSING one only when a code the cut draws is built from it + * (`qrs`, deadOriginQrsOf) -- a cut whose every code links something of its + * own (a citeUrl, a record's page, qrLink) or that draws none needs no origin. + */ +export const originDeadFor = (m, qrs) => (originSet(m) ? isDeadOrigin(m.provenance.siteOrigin) : qrs.length > 0); + +/** Up to three ids, then how many more: "`a`, `b`, `c` and 4 more". */ +const someIds = (ids) => + ids.slice(0, 3).map((id) => `\`${id}\``).join(", ") + (ids.length > 3 ? ` and ${ids.length - 3} more` : ""); + +/** The siteOrigin decision's sentence: how many codes, the first few, the fix. */ +export function deadOriginWhy(m, qrs) { + const origin = m?.provenance?.siteOrigin; + const n = qrs.length; + const codes = `${n} QR code${n === 1 ? "" : "s"}`; + const ids = someIds(qrs.map((q) => (q.source === "post" ? `post ${q.id ?? "?"}` : q.id ?? "?"))); + const types = new Map((m?.timeline ?? []).filter((e) => e?.id).map((e) => [e.id, e.type])); + const entries = qrs.filter((q) => q.source === "entry"); + const fixes = [originSet(m) ? "set provenance.siteOrigin to the public archive" : "set provenance.siteOrigin"]; + if (entries.some((q) => types.get(q.id) === "clip")) fixes.push("give those clips a citeUrl"); + // A rail tile that is not a clip's (a card's, a still's) links qrLink first. + if (entries.some((q) => types.get(q.id) !== "clip")) fixes.push("set provenance.qrLink for the rail's other tiles"); + if (qrs.some((q) => q.source === "post")) fixes.push("give those posts a siteUrl"); + const fix = fixes.length > 1 ? `${fixes.slice(0, -1).join(", ")}, or ${fixes[fixes.length - 1]}` : fixes[0]; + if (!originSet(m)) return `missing — ${codes} in this cut would encode \`undefined/?v=…\` (${ids}): ${fix}`; + if (!n) return `\`${origin}\` — resolves to nothing on anyone else's phone, and it is the archive this cut names: ${fix}`; + return `\`${origin}\` — ${codes} in this cut (${ids}) resolve to nothing on anyone else's phone: ${fix}`; +} const stat0 = (p) => stat(p).then((s) => s, () => null); @@ -671,6 +724,10 @@ export async function summariseReport(ctx) { const sourcesDead = src.rows.filter((r) => r.availability && !r.availability.ok && r.availability.state !== "no-cues").length; const sourcesMissing = src.rows.filter((r) => r.cues === "missing").length; const cueGaps = src.rows.filter((r) => r.coverageGap).length; + // The codes a missing or dead origin would break (deadOriginQrsOf): the + // same cue files sourcesOf just read, memoised. + const deadOriginQrs = m ? await deadOriginQrsOf(dir, m) : []; + const originDead = m ? originDeadFor(m, deadOriginQrs) : false; const state = !m ? "draft" @@ -697,7 +754,7 @@ export async function summariseReport(ctx) { if (build.built) facts.push(`${(build.finalSize / 1e6).toFixed(0)} MB`); const flags = []; - if (originDead(m)) flags.push("dead QR origin"); + if (originDead) flags.push("dead QR origin"); if (!m?.provenance?.channelSlug) flags.push("no channelSlug"); if (build.stale) flags.push("older than its manifest"); if (sourcesDead) flags.push(`${sourcesDead} dead source${sourcesDead === 1 ? "" : "s"}`); @@ -741,12 +798,13 @@ export async function summariseReport(ctx) { ...(sourcesMissing ? { "sources-missing": String(sourcesMissing) } : {}), ...(cueGaps ? { "cue-gaps": String(cueGaps) } : {}), ...(build.built ? { built: "1", "final-bytes": String(build.finalSize + build.fullSize) } : {}), - ...(originDead(m) ? { "dead-origin": "1" } : {}), + ...(originDead ? { "dead-origin": "1" } : {}), }, // Kept for the project page and the decisions pass, so neither re-reads. manifest: m, build, sources: src, + deadOriginQrs, }; } @@ -841,16 +899,12 @@ export async function reportDecisions(ctx, summary) { (await stat(path.join(dir, "make-shadow-channels.sh")).then(() => true, () => false)); // --- the manifest itself ------------------------------------------------- - const origin = m.provenance?.siteOrigin; - if (originDead(m)) { - add( - "manifest-invalid", - "provenance.siteOrigin", - origin - ? `\`${origin}\` — every QR in this cut resolves to nothing on anyone else's phone` - : "missing — every QR in this cut encodes `undefined/?v=…`", - "blocking", - ); + // Only the codes that are built from the origin: a cut whose every code + // links something of its own (or that draws none) is not blocked by a + // missing one. A set origin that is dead blocks whatever links it. + const deadOriginQrs = s.deadOriginQrs ?? (await deadOriginQrsOf(dir, m, { channelsDir })); + if (originDeadFor(m, deadOriginQrs)) { + add("manifest-invalid", "provenance.siteOrigin", deadOriginWhy(m, deadOriginQrs), "blocking"); } if (!m.provenance?.channelSlug) { add( diff --git a/umtool/lib/report/siteorigin-check.test.mjs b/umtool/lib/report/siteorigin-check.test.mjs @@ -0,0 +1,198 @@ +// 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<string, string|null> }} 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 }), + [], + ); +}); diff --git a/umtool/report-to-video/lint.mjs b/umtool/report-to-video/lint.mjs @@ -142,14 +142,21 @@ function postQrUrlForLint(post, provenance, links) { } /** - * Every QR the cut will draw, as `{ where, url, px, perModule }` -- `px` the - * drawn width on the frame, or null for the corner code, which is `perModule` - * native pixels per module, unresized. + * Every QR the cut will draw, as `{ where, id, source, url, px, perModule }` + * -- `id` the timeline entry's (or the post's), `source` "entry" or "post", + * `px` the drawn width on the frame, or null for the corner code, which is + * `perModule` native pixels per module, unresized. + * + * `metaOf(entry)` is a clip's record metadata (`{ webpageUrl }`) when the + * caller has it: under the deck's `qr.links: "original"` a clip with no + * `citeUrl` links its record's own page, and falls back to the archive link + * only when the record names none (deckQrUrl). Without it the archive link is + * measured, as before. * * @param {any} manifest a cut, as selectVariant returns it - * @param {{ only?: string|null }} [opts] + * @param {{ only?: string|null, metaOf?: ((entry: any) => ({ webpageUrl?: string|null } | null)) | null }} [opts] */ -export function qrsOf(manifest, { only = null } = {}) { +export function qrsOf(manifest, { only = null, metaOf = null } = {}) { const render = manifest.render ?? {}; const provenance = manifest.provenance ?? {}; const timeline = (manifest.timeline ?? []).filter((e) => e && (!only || e.id === only)); @@ -158,15 +165,16 @@ export function qrsOf(manifest, { only = null } = {}) { const d = resolveDeck(render); if (d.qr?.show) { for (const e of timeline) { - const url = deckQrUrl(e, provenance, { links: d.qr.links }); - if (url) out.push({ where: `timeline ${e.id} (the deck's QR)`, url, px: Number(d.qr.size) }); + const url = deckQrUrl(e, provenance, { links: d.qr.links, meta: metaOf?.(e) ?? null }); + if (url) out.push({ where: `timeline ${e.id} (the deck's QR)`, id: e.id, source: "entry", url, px: Number(d.qr.size) }); } } - if (d.posts?.show && Array.isArray(manifest.posts)) { + // `posts.qr: false` draws no code on any post card. + if (d.posts?.show && d.posts.qr !== false && Array.isArray(manifest.posts)) { for (const p of manifest.posts) { if (!p || (only && p.attachTo !== only)) continue; const url = postQrUrlForLint(p, provenance, d.posts.links); - if (url) out.push({ where: `posts ${p.id ?? "?"} (its QR)`, url, px: Number(d.posts.qrSize) }); + if (url) out.push({ where: `posts ${p.id ?? "?"} (its QR)`, id: p.id ?? null, source: "post", url, px: Number(d.posts.qrSize) }); } } return out; @@ -178,7 +186,7 @@ export function qrsOf(manifest, { only = null } = {}) { const px = Number(render.rail.qrSize ?? 132); for (const e of timeline) { const url = qrUrlFor(e, provenance); - if (url) out.push({ where: `timeline ${e.id} (its rail QR)`, url, px }); + if (url) out.push({ where: `timeline ${e.id} (its rail QR)`, id: e.id, source: "entry", url, px }); } return out; } @@ -194,11 +202,43 @@ export function qrsOf(manifest, { only = null } = {}) { } else if (e.type === "image" && e.citeUrl) { url = e.citeUrl; } - if (url) out.push({ where: `timeline ${e.id} (its corner QR)`, url, px: null, perModule: scale }); + if (url) out.push({ where: `timeline ${e.id} (its corner QR)`, id: e.id, source: "entry", url, px: null, perModule: scale }); } return out; } +// A stand-in archive origin no real link starts with: what originQrsOf puts in +// `provenance.siteOrigin` to see which links the real rules build from it. +const ORIGIN_PROBE = "https://site-origin.probe.invalid"; + +/** + * The QRs the cut draws whose link is built from `provenance.siteOrigin`: the + * ones an absent origin turns into `undefined/?v=…` (or, a rail card's, an + * empty code) and a localhost one into a link that resolves nowhere. Every + * other code links something of its own -- a clip's `citeUrl`, its record's + * page under the deck's `qr.links: "original"`, a still's `citeUrl`, a card's + * `provenance.qrLink` -- or is not drawn (`render.qr: false`, the deck's + * `qr.show: false`, a `src` clip with no `citeUrl`, `posts.qr: false`). + * + * Not a second copy of the link rules: it runs qrsOf -- the build's own + * deckQrUrl, qrUrlFor and postQrUrl -- with the origin set to a probe, and + * keeps the codes whose link begins with it. A post is the one exception: with + * NO origin its code links the post itself (postQrUrl), so a post depends on + * the origin only when one is set. + * + * @param {any} manifest + * @param {{ only?: string|null, metaOf?: ((entry: any) => ({ webpageUrl?: string|null } | null)) | null }} [opts] + * @returns {{ where: string, id: string|null, source: "entry"|"post" }[]} + */ +export function originQrsOf(manifest, { only = null, metaOf = null } = {}) { + const provenance = manifest?.provenance ?? {}; + const origin = typeof provenance.siteOrigin === "string" ? provenance.siteOrigin.trim() : ""; + const probe = { ...manifest, provenance: { ...provenance, siteOrigin: ORIGIN_PROBE } }; + return qrsOf(probe, { only, metaOf }) + .filter((q) => String(q.url).startsWith(ORIGIN_PROBE) && (origin || q.source !== "post")) + .map(({ where, id, source }) => ({ where, id, source })); +} + /** * Every picture the cut reads from beside the manifest, as `{ where, src }`. * Posts' shots and logos only under the deck, the one place posts are drawn.