// The Twitch join, option (b), in a site's evidence read (release 23 F1): a // report cites a Twitch record by its `v`, and the media, duration and // availability are read from its `data//`. The citation's id is reported // as cited — never rewritten. Synthetic ids; no ffmpeg (nothing is cut). // // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test publish/reportMediaTwitch.test.ts import { after, test } from "node:test"; import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; const ROOT = mkdtempSync(path.join(tmpdir(), "report-media-twitch-")); Object.assign(process.env, { TRANSCRIPTS_DIR: path.join(ROOT, "transcripts"), SAVED_VIDEOS_DIR: path.join(ROOT, "saved-videos"), SITES_DIR: path.join(ROOT, "transcripts", "sites"), SETTINGS_FILE: path.join(ROOT, "settings.json"), EXPORT_PUBLIC_DIR: path.join(ROOT, "public"), EXPORT_INDEX_DIR: path.join(ROOT, ".export-index"), EXPORT_BUILDS_DIR: path.join(ROOT, ".export-builds"), ARCHILYZER_CONFIG_DIR: path.join(ROOT, "config"), }); after(() => rmSync(ROOT, { recursive: true, force: true })); const { getPaths } = await import("../lib/paths"); const { missingEvidenceWindows } = await import("./reportMedia"); const paths = getPaths(); const SITE = "demo-site"; const CH = "example-twitch"; const GONE = "2700000001"; const HELD = "2700000002"; const OPEN = "2700000003"; const writeJson = (file: string, value: unknown) => { mkdirSync(path.dirname(file), { recursive: true }); writeFileSync(file, JSON.stringify(value, null, 2)); }; const dataDir = (id: string) => path.join(paths.channelsDir, CH, "data", id); writeJson(path.join(paths.channelsDir, CH, "config.json"), { handling: "transcribe", name: "Example", url: "https://www.twitch.tv/example", }); for (const id of [GONE, HELD, OPEN]) { writeJson(path.join(dataDir(id), "metadata.info.json"), { id: `v${id}`, duration: 600 }); } writeJson(path.join(dataDir(GONE), "availability.json"), { availability: "deleted", checkedAt: "2026-10-01T00:00:00Z" }); // A window file is only listed, never probed, by the corpus-window tier. mkdirSync(path.join(dataDir(HELD), "clips"), { recursive: true }); writeFileSync(path.join(dataDir(HELD), "clips", "0.00-60.00.mp4"), "mp4"); writeJson(path.join(paths.sitesDir, SITE, "site.json"), { title: "Demo", channels: [{ slug: CH }], search: false, reports: ["r1"], }); writeJson(path.join(paths.sitesDir, SITE, "reports", "r1", "report.json"), { format: "archilyzer-report", version: 1, id: "r1", kind: "sweep", title: "Report r1", citations: { c01: { kind: "video", channel: CH, id: `v${GONE}`, start: 10, end: 12, quote: "one" }, c02: { kind: "video", channel: CH, id: `v${HELD}`, start: 10, end: 12, quote: "two" }, c03: { kind: "video", channel: CH, id: `v${OPEN}`, start: 10, end: 12, quote: "three" }, }, sections: [{ id: "s1", title: "One", body: "[c01](cite:c01) [c02](cite:c02) [c03](cite:c03)" }], }); test("missingEvidenceWindows reads a Twitch v citation's media and availability from data//", async () => { const r = await missingEvidenceWindows(paths, SITE); assert.deepEqual(r.problems, []); // The held window is on disk (data//clips/). assert.equal(r.onDisk, 1); // The deleted one is gone, read from data//availability.json. assert.deepEqual( r.unfetchable.map((w) => [w.id, w.why]), [[`v${GONE}`, "gone"]], ); // The open one is missing, and named by the id the report cites. assert.deepEqual(r.missing.map((w) => w.id), [`v${OPEN}`]); });