// The source status on the deck's source line (lane source-status): the words from // one table, the part placed by the switch or by `parts`, read from the manifest's // stamp alone -- and a cut with the switch off, or on with no stamp, draws the // schedule and the deck page it always did, byte for byte. // // Run with: node --test umtool/report-to-video/deck-source-status.test.mjs import assert from "node:assert/strict"; import { createHash } from "node:crypto"; import test from "node:test"; import { deckSubtitleLinesParts, deckSubtitleParts } from "./attribution.mjs"; import { deckHtml, scheduleHasStatus, subtitleMarkup } from "./chrome-deck.mjs"; import { finaleHtml, titleLastParts } from "./chrome-finale.mjs"; import { estimateSchedule } from "./deck.mjs"; import { finaleRegions, measureChromeSchedule } from "./build-video.mjs"; import { validateSubtitleSettings } from "./modules/settings.mjs"; import { SOURCE_STATUS_NOW, SOURCE_STATUS_WORDS, clipSourceStatus, sourceStatusNotes, sourceStatusText, statusSourceKeys, subtitleStatusOn, validateSourceStatus, } from "./source-status.mjs"; import { AVAILABILITIES } from "yt-dlp-transcript-common/lib/sourceStatus.mjs"; const PALETTE = { bg: "#12101a", fg: "#f4f1ea", muted: "#9a93ad", accent: "#a97bff", amber: "#ffc860" }; const FONTS = { regular: "assets/DeckSans.ttf", bold: "assets/DeckSansBold.ttf" }; const clip = (id, video, start, extra = {}) => ({ id, type: "clip", video, start, end: start + 10, cite: start + 2, quote: "a synthetic line", ...extra }); /** A synthetic cut: four clips of one made-up channel. */ function manifest({ subtitle = null, stamp = undefined, timeline = null } = {}) { return { title: "Synthetic cut", provenance: { channelSlug: "synth-channel", channel: "Synth Channel", siteOrigin: "https://archive.example.test" }, render: { width: 1920, height: 1080, fps: 30, transition: 0.5, palette: PALETTE, chrome: { engine: "hyperframes", layout: "deck", deck: subtitle ? { subtitle } : {} }, }, timeline: timeline ?? [ clip("c01", "synthvid001", 600, { onscreen: { title: "The first moment" } }), clip("c02", "synthvid002", 1200, { onscreen: { title: "The second moment" } }), clip("c03", "synthvid003", 1800, { onscreen: { title: "The third moment" } }), clip("c04", "synthvid004", 2400, { onscreen: { title: "The fourth moment" } }), ], ...(stamp !== undefined ? { sourceStatus: stamp } : {}), }; } const META = (n) => ({ title: `Synthetic stream ${n}`, uploadDate: "20310301", channel: "Synth Channel", webpageUrl: `https://video.example.test/${n}` }); const METAS = [META(1), META(2), META(3), META(4)]; const STAMP = { refreshedAt: "2031-03-02T00:00:00.000Z", sources: { "synth-channel/synthvid001": { now: "members_only", 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: [] }, "synth-channel/synthvid002": { now: "private", since: null, asOf: "2031-03-01T20:00:00Z", first: "public", firstAt: "2031-02-01T00:00:00Z", firstWhen: "other", from: "corpus", evidence: [] }, "synth-channel/synthvid003": { now: "deleted", since: null, asOf: "2031-03-01T20:00:00Z", first: null, firstAt: null, firstWhen: null, from: "archive", evidence: [] }, "synth-channel/synthvid004": { now: "public", since: null, asOf: "2031-03-01T20:00:00Z", first: null, firstAt: null, firstWhen: null, from: "corpus", evidence: [] }, }, }; const scheduleOf = (m) => estimateSchedule(m, { metas: METAS }); const pageOf = (m) => deckHtml(scheduleOf(m), m.render, { fonts: FONTS }); const sha = (s) => createHash("sha256").update(s).digest("hex"); const seg = (s, id) => s.segments.find((x) => x.id === id); // THE BYTES MAIN DRAWS for this cut (no switch, no stamp), computed from main's // own modules at the lane's base (bbe528138) with this lane's changes stashed. const MAIN_SCHEDULE_SHA = "c70ee12800800ea78e724d4633b43893abcfb2beea4a86a7681a5b6d7f295f51"; const MAIN_PAGE_SHA = "19cc5f822e220de5db9131fbe0cac60c8368aa8c801f7b28449577337e8ba093"; test("the words: one table, each state with and without its parenthesis", () => { const w = (now, first = null, firstWhen = null) => sourceStatusText({ now, first, firstWhen }); assert.equal(w("private", "public", "live"), "now private (public when streamed)"); assert.equal(w("private", "public", "other"), "now private (was public)"); assert.equal(w("private"), "now private"); assert.equal(w("members_only", "public", "live"), "now members-only (public when streamed)"); assert.equal(w("members_only", "public", "other"), "now members-only (was public)"); assert.equal(w("members_only"), "now members-only"); assert.equal(w("deleted", "public", "live"), "now deleted (public when streamed)"); assert.equal(w("deleted", "public", "other"), "now deleted (was public)"); assert.equal(w("deleted"), "now deleted"); for (const quiet of ["public", "unlisted", "needs_auth", "error", "maybe_missing", null]) assert.equal(w(quiet, "public", "live"), "", `${quiet} draws nothing`); assert.equal(sourceStatusText(null), ""); // Every string the part can draw is in the table. assert.deepEqual(Object.keys(SOURCE_STATUS_WORDS.now).sort(), ["deleted", "members_only", "private"]); }); test("a clip's words from the stamp: hidden per clip, none for a src clip or an unstamped source", () => { const prov = { channelSlug: "synth-channel" }; assert.equal(clipSourceStatus(clip("a", "synthvid002", 0), STAMP, prov), "now private (was public)"); assert.equal(clipSourceStatus(clip("a", "synthvid002", 0, { sourceStatus: false }), STAMP, prov), ""); assert.equal(clipSourceStatus(clip("a", "synthvid002", 0, { src: "clips/own.mp4" }), STAMP, prov), ""); assert.equal(clipSourceStatus(clip("a", "synthvid009", 0), STAMP, prov), ""); assert.equal(clipSourceStatus(clip("a", "synthvid002", 0, { channel: "other-synth" }), STAMP, prov), ""); assert.equal(clipSourceStatus(clip("a", "synthvid002", 0), null, prov), ""); }); test("the subtitle parts: status after the last with the switch, where named in parts, on the second of two lines", () => { const parts = { channel: "Synth Channel", title: "Synthetic stream", date: "2031-03-01", at: 2100, status: "now private (public when streamed)" }; assert.deepEqual(deckSubtitleParts(parts, { parts: ["channel", "date", "clock"], status: "end" }).map(([k]) => k), ["channel", "date", "clock", "status"]); assert.deepEqual(deckSubtitleParts(parts, { parts: ["channel", "status", "date"] }).map(([k]) => k), ["channel", "status", "date"]); // Off: the part is not drawn even with words; on with no words: dropped. assert.deepEqual(deckSubtitleParts(parts, {}).map(([k]) => k), ["title", "date"]); assert.deepEqual(deckSubtitleParts({ ...parts, status: "" }, { status: "end" }).map(([k]) => k), ["title", "date"]); const [one, two] = deckSubtitleLinesParts(parts, { parts: ["channel", "title", "date", "clock"], status: "end", lines: 2 }); assert.deepEqual(one.map(([k]) => k), ["title"]); assert.deepEqual(two.map(([k]) => k), ["channel", "date", "clock", "status"]); }); test("the schedule: each clip's line ends in its status; a public source's line is the line it was", () => { const s = scheduleOf(manifest({ subtitle: { parts: ["channel", "date", "clock"], status: "end" }, stamp: STAMP })); assert.equal(seg(s, "c01").subtitle, "Synth Channel · Mar 1, 2031 · 10:02 · now members-only (public when streamed)"); assert.deepEqual(seg(s, "c01").subtitleParts.at(-1), ["status", "now members-only (public when streamed)"]); assert.equal(seg(s, "c02").subtitle, "Synth Channel · Mar 1, 2031 · 20:02 · now private (was public)"); assert.equal(seg(s, "c03").subtitle, "Synth Channel · Mar 1, 2031 · 30:02 · now deleted"); assert.equal(seg(s, "c04").subtitle, "Synth Channel · Mar 1, 2031 · 40:02"); assert.ok(seg(s, "c04").subtitleParts.every(([k]) => k !== "status")); // The page: the part by token, its quiet accent only because one is drawn. assert.ok(scheduleHasStatus(s)); const html = deckHtml(s, manifest().render, { fonts: FONTS }); assert.match(html, /now members-only \(public when streamed\)<\/span>/); assert.match(html, /now deleted<\/span>/, "no parenthesis: no short form to carry"); assert.match(html, /\.deck-sub \.part\[data-p="status"\] \{ color: /); assert.equal(subtitleMarkup("a · b", [["title", "a"], ["status", "b"]]), 'a·b'); }); test("BYTE FOR BYTE: the switch off, or on with no stamp, draws main's schedule and page", () => { const base = manifest({ subtitle: { parts: ["channel", "date", "clock"] } }); const baseSchedule = JSON.stringify(scheduleOf(base), null, 2); const basePage = pageOf(base); assert.equal(sha(baseSchedule), MAIN_SCHEDULE_SHA, "the schedule main writes"); assert.equal(sha(basePage), MAIN_PAGE_SHA, "the deck page main draws"); for (const [why, m] of [ ["the switch on, no stamp", manifest({ subtitle: { parts: ["channel", "date", "clock"], status: "end" } })], ["a stamp, the switch off", manifest({ subtitle: { parts: ["channel", "date", "clock"] }, stamp: STAMP })], ["a stamp, the switch off explicitly", manifest({ subtitle: { parts: ["channel", "date", "clock"], status: "off" }, stamp: STAMP })], ]) { const s = scheduleOf(m); assert.equal(JSON.stringify(s, null, 2), baseSchedule, `${why}: the schedule`); assert.equal(scheduleHasStatus(s), false); // The page reads render.chrome.deck; the switch alone may not change a byte of it. assert.equal(deckHtml(s, m.render, { fonts: FONTS }), basePage, `${why}: the page`); } }); // THE BYTES MAIN DRAWS for more of the surfaces (review 1, item 12): a cut whose subtitle is // `auto`, one of two lines, a finale page, and measureChromeSchedule's schedule -- each with no // switch and no stamp, computed from main's own modules at the lane's base (bbe528138, the lane's // changes stashed) with the same fixtures. const MAIN = { auto: { schedule: "2562917695a31e711f682f7d83c99ba6277163d768e3cc346856a849ce72bb5a", page: "e8866263a8f9772994fc1e32521e09f96d85c979b1c46a6d86b3e85d5ecef45d" }, lines2: { schedule: "ba5087e52fed6c6c69df62a27b8857439ef55e7e7edd260c6f747f13a97a5fee", page: "f304f54383a9d3304b6ebf881546b3ad5d36e5cd2c3e88cc167bf664909667de" }, finale: { schedule: "46d35ab16a28eaed128e735e1da81b2a06ec6b92c1b9ce8c1e5a36e57bdb20b1", page: "e3520445bc3ee328081505aa3e285ff30c94d345f12ee9ddf7a2cfd810353c31" }, measure: { schedule: "9f8bbe2885447273a660d5d7d0eaf20b86aa67be2c208872febd9f9efe98cb5c" }, }; /** The cut with `deck` as its deck settings, a stamp or not, its last clip the finale's or not. */ function cut(deck, { stamp = undefined, finale = false } = {}) { const m = manifest({ stamp }); m.render.chrome.deck = deck; if (finale) m.timeline[3] = { ...m.timeline[3], layout: "finale" }; return m; } /** The three ways the part must draw nothing: the switch on with no stamp, a stamp with it off, and "off" said. */ const QUIET = (deck) => [ ["the switch on, no stamp", { ...deck, subtitle: { ...deck.subtitle, status: "end" } }, undefined], ["a stamp, the switch off", deck, STAMP], ["a stamp, the switch off explicitly", { ...deck, subtitle: { ...deck.subtitle, status: "off" } }, STAMP], ["a stamp, status named in parts, the switch off", { ...deck, subtitle: { ...deck.subtitle, ...(Array.isArray(deck.subtitle.parts) ? { parts: [...deck.subtitle.parts, "status"] } : {}), status: "off" } }, STAMP], ]; for (const [name, deck] of [["auto", { subtitle: {} }], ["lines2", { subtitle: { parts: ["channel", "title", "date", "clock"], lines: 2 } }]]) { test(`BYTE FOR BYTE (${name === "auto" ? "parts: auto" : "lines: 2"}): main's schedule and page, and the same with the part quiet`, () => { const base = cut(deck); const s = scheduleOf(base); assert.equal(sha(JSON.stringify(s, null, 2)), MAIN[name].schedule, "the schedule main writes"); assert.equal(sha(deckHtml(s, base.render, { fonts: FONTS })), MAIN[name].page, "the deck page main draws"); for (const [why, d, stamp] of QUIET(deck)) { const m = cut(d, { stamp }); const q = scheduleOf(m); assert.equal(sha(JSON.stringify(q, null, 2)), MAIN[name].schedule, `${why}: the schedule`); assert.equal(sha(deckHtml(q, m.render, { fonts: FONTS })), MAIN[name].page, `${why}: the page`); } }); } test("BYTE FOR BYTE (the finale page): main's, and the same with the part quiet", () => { const deck = { subtitle: { parts: ["channel", "title", "date", "clock"] }, finale: {} }; const page = (m) => { const s = scheduleOf(m); return [sha(JSON.stringify(s, null, 2)), sha(finaleHtml(s, m.render, finaleRegions(m.render, "/nowhere", s)[0].window, {}))]; }; assert.deepEqual(page(cut(deck, { finale: true })), [MAIN.finale.schedule, MAIN.finale.page]); for (const [why, d, stamp] of QUIET(deck)) assert.deepEqual(page(cut(d, { stamp, finale: true })), [MAIN.finale.schedule, MAIN.finale.page], why); // On, with a stamp: the finale's copies of the line carry the status and the page its fit. const gone = { ...STAMP, sources: { ...STAMP.sources, "synth-channel/synthvid004": STAMP.sources["synth-channel/synthvid001"] } }; const on = cut({ ...deck, subtitle: { ...deck.subtitle, status: "end" } }, { stamp: gone, finale: true }); const s = scheduleOf(on); const html = finaleHtml(s, on.render, finaleRegions(on.render, "/nowhere", s)[0].window, {}); assert.match(html, /data-p="status" data-short="now members-only">now members-only \(public when streamed\) { const deck = { subtitle: { parts: ["channel", "date", "clock"] } }; const measured = async (m) => sha(JSON.stringify(await measureChromeSchedule({ manifest: m, entries: m.timeline, segments: [], D: 0.5, durs: [12, 12, 12, 12] }), null, 2)); assert.equal(await measured(cut(deck)), MAIN.measure.schedule); for (const [why, d, stamp] of QUIET(deck)) assert.equal(await measured(cut(d, { stamp })), MAIN.measure.schedule, why); // On, with a stamp: the build's schedule carries it (the stamp alone, no corpus, no network). const on = cut({ subtitle: { ...deck.subtitle, status: "end" } }, { stamp: STAMP }); const s = await measureChromeSchedule({ manifest: on, entries: on.timeline, segments: [], D: 0.5, durs: [12, 12, 12, 12] }); assert.deepEqual(seg(s, "c01").subtitleParts.at(-1), ["status", "now members-only (public when streamed)"]); }); test("an explicit off wins over status named in the parts (review 1, nit 11)", () => { assert.equal(subtitleStatusOn({ parts: ["channel", "status"], status: "off" }), false); assert.equal(subtitleStatusOn({ parts: ["channel", "status"] }), true); assert.equal(subtitleStatusOn({ status: "end" }), true); const parts = { channel: "Synth Channel", date: "2031-03-01", status: "now private" }; assert.deepEqual(deckSubtitleParts(parts, { parts: ["channel", "status", "date"], status: "off" }).map(([k]) => k), ["channel", "date"]); }); test("a stamp cannot draw what is not a state: 'constructor' and its kin draw nothing and fail validation (review 1, finding 8)", () => { for (const now of ["constructor", "toString", "__proto__", "hasOwnProperty", "maybe_missing", "gone"]) { assert.equal(sourceStatusText({ now }), "", now); assert.equal(sourceStatusText({ now: "private", first: "public", firstWhen: now }), "now private", `firstWhen ${now}`); const errors = validateSourceStatus(manifest({ stamp: { refreshedAt: STAMP.refreshedAt, sources: { "a/b": { now } } } })); assert.match(errors[0] ?? "", /now must be one of/, now); } assert.deepEqual(validateSourceStatus(manifest({ stamp: { refreshedAt: STAMP.refreshedAt, sources: { "a/b": { now: null, asOf: null } } } })), []); // The two lists of states, umtool's and common's, are one list. assert.deepEqual(SOURCE_STATUS_NOW, AVAILABILITIES); }); test("the notes and check name the same sources: platform clips that are not hidden (review 1, finding 7c)", () => { const m = manifest({ timeline: [ clip("c01", "synthvid001", 0), clip("c02", "synthvid002", 0, { sourceStatus: false }), clip("c03", "synthvid003", 0, { src: "clips/own.mp4" }), clip("c04", "synthvid001", 50), ], }); m.ledger = [{ id: "k1", video: "synthvid009" }]; assert.deepEqual(statusSourceKeys(m), ["synth-channel/synthvid001"]); }); test("the build's notes leave out a source with no record at all (no state, no reading): nothing to recheck (review 1, finding 7b)", () => { const stamp = { refreshedAt: STAMP.refreshedAt, sources: { ...STAMP.sources, "synth-channel/synthvid004": { now: null, asOf: null, first: null, from: "corpus", evidence: [] } } }; const notes = sourceStatusNotes(manifest({ subtitle: { status: "end" }, stamp }), { now: Date.parse("2031-04-30T00:00:00Z") }); assert.equal(notes.length, 1); assert.doesNotMatch(notes[0], /synthvid004|never read/); assert.match(notes[0], /synthvid001/); }); // Review 1, nit 11: the design said status last. In the finale's caption the LAST part is the // one that wraps and is clamped at two lines (the title, titleLastParts), so a status after a long // title would be the part cut or pushed out of sight; before it, it stays whole (the page's fit // drops it whole if even that cannot hold). So the status stays before the title there. test("the finale's copy of the line keeps the title last, the status before it", () => { const tok = [["channel", "Synth Channel"], ["title", "Synthetic stream"], ["date", "Mar 1, 2031"], ["status", "now private"]]; const line = tok.map(([, v]) => v).join(" · "); assert.deepEqual(titleLastParts(line, tok).map(([k]) => k), ["channel", "date", "status", "title"]); }); test("the build's notes: once that refresh has not been run, and a status older than 14 days", () => { const on = manifest({ subtitle: { status: "end" } }); assert.deepEqual(sourceStatusNotes(on, { now: Date.parse("2031-03-03T00:00:00Z") }).length, 1); assert.match(sourceStatusNotes(on)[0], /source-status

refresh` has not been run/); const stamped = manifest({ subtitle: { status: "end" }, stamp: STAMP }); assert.deepEqual(sourceStatusNotes(stamped, { now: Date.parse("2031-03-10T00:00:00Z") }), []); const late = sourceStatusNotes(stamped, { now: Date.parse("2031-03-20T00:00:00Z") }); assert.equal(late.length, 1); assert.match(late[0], /older than 14 days: synth-channel\/synthvid001 \(2031-03-01\)/); const partial = manifest({ subtitle: { status: "end" }, stamp: { ...STAMP, sources: { "synth-channel/synthvid001": STAMP.sources["synth-channel/synthvid001"] } } }); assert.match(sourceStatusNotes(partial, { now: Date.parse("2031-03-03T00:00:00Z") })[0], /3 source\(s\) not in the stamp/); }); test("validation: the switch's values, the status token, the stamp's shape, a clip's hide", () => { const v = (subtitle) => validateSubtitleSettings({ subtitle }, { where: "deck" }); assert.deepEqual(v({ status: "end" }), []); assert.deepEqual(v({ parts: ["channel", "status"] }), []); assert.match(v({ status: "on" })[0], /subtitle\.status must be "off" or "end"/); assert.deepEqual(validateSourceStatus(manifest({ stamp: STAMP })), []); assert.deepEqual(validateSourceStatus(manifest()), []); assert.match(validateSourceStatus(manifest({ stamp: { sources: {} } }))[0], /refreshedAt/); assert.match(validateSourceStatus(manifest({ stamp: { refreshedAt: STAMP.refreshedAt, sources: { "a/b": { now: "private", first: "public" } } } }))[0], /firstWhen/); assert.match(validateSourceStatus(manifest({ timeline: [clip("c01", "synthvid001", 0, { sourceStatus: true })] }))[0], /may only be false/); }); // Lane source-status-nulls: a manifest with its look preset laid under it (every take's) has lost // every null (presets.mjs lays the manifest over the preset as a merge patch). Absent reads as null. test("validation: an absent field reads exactly as null -- an entry's, the stamp's, a clip's", () => { const ok = (sources) => validateSourceStatus(manifest({ stamp: { refreshedAt: STAMP.refreshedAt, sources } })); assert.deepEqual(ok({ "a/b": { evidence: [], from: "corpus", recordsAt: "2031-03-01T00:00:00.000Z" } }), [], "a no-record entry with its nulls dropped"); assert.deepEqual(ok({ "a/b": { now: null, since: null, asOf: null, first: null, firstAt: null, firstWhen: null, evidence: [], from: "corpus" } }), [], "and with them"); assert.deepEqual(ok({ "a/b": { now: "private", from: "corpus", evidence: [] } }), [], "a state, every other field absent"); assert.match(ok({ "a/b": { now: "gone", from: "corpus" } })[0], /\.now must be one of/, "a bad state still fails"); assert.deepEqual(validateSourceStatus(manifest({ stamp: null })), [], "a null stamp is no stamp"); assert.deepEqual(validateSourceStatus(manifest({ timeline: [clip("c01", "synthvid001", 0, { sourceStatus: null })] })), [], "a clip's null is no hide"); // The words: absent is null there too. assert.equal(sourceStatusText({ evidence: [], from: "corpus" }), ""); assert.equal(sourceStatusText({ now: "private" }), "now private"); assert.equal(clipSourceStatus(clip("c01", "synthvid001", 0, { sourceStatus: null }), STAMP, { channelSlug: "synth-channel" }), "now members-only (public when streamed)"); });