// Integration (lane/local-media re-review B1): a local recording's transcript // is composed only into a PRIVATE-audience site, through the REAL index build // and the REAL site compose, over a temp corpus — and stays out of a public // site's tree whatever site composed into public/ before it. // // One channel holding an online record and a local recording, on a public site // P and a private site V. public/transcripts/ is ONE directory every site // composes into in turn; P must never ship the private tree V left there // (compose P, V, P), and V must never ship the shared tree P left (V, P, V). // // Run with: node_modules/.bin/tsx --test common/bin/compose-site.localMedia.test.ts import { after, test } from "node:test"; import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; const ROOT = mkdtempSync(path.join(tmpdir(), "compose-local-media-")); 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"), EDITOR_CHANGELOG_FILE: path.join(ROOT, "editor-CHANGELOG.md"), EXPORT_CHANGELOG_FILE: path.join(ROOT, "export-CHANGELOG.md"), CHARTS_CONFIG_FILE: path.join(ROOT, "chart-templates.json"), SEARCH_ALIASES_FILE: path.join(ROOT, "transcripts", "search-aliases.json"), CURATED_TAGS_FILE: path.join(ROOT, "transcripts", "tags.json"), ARCHILYZER_CONFIG_DIR: path.join(ROOT, "config"), ARCHILYZER_SOURCE_SCRATCH: path.join(ROOT, "source-scratch"), }); after(() => rmSync(ROOT, { recursive: true, force: true })); const { getPaths } = await import("../lib/paths"); const { buildIndex } = await import("../controller/buildIndex"); const { main: composeSite } = await import("./compose-site"); const { prepareManualLocalRecordingMetadata } = await import("../lib/localRecordingMetadata"); const paths = getPaths(); const CH = "mixed"; const LOCAL = "local-" + "7".repeat(32); const quiet = () => {}; const writeJson = (file: string, value: unknown) => { mkdirSync(path.dirname(file), { recursive: true }); writeFileSync(file, JSON.stringify(value, null, 2)); }; writeJson(paths.settingsFile, {}); writeJson(path.join(paths.channelsDir, CH, "config.json"), { handling: "youtube", name: "Mixed", url: "https://www.youtube.com/@mixed/videos", localMedia: { sourceId: "library-1", directory: path.join(ROOT, "library") }, }); const vtt = (text: string) => `WEBVTT\n\n00:00:01.000 --> 00:00:03.000\n${text}\n`; const online = path.join(paths.channelsDir, CH, "data", "onlinevideo"); writeJson(path.join(online, "metadata.info.json"), { id: "onlinevideo", title: "Online", upload_date: "20260601", duration: 120, webpage_url: "https://www.youtube.com/watch?v=onlinevideo", extractor_key: "Youtube", }); writeFileSync(path.join(online, "transcript.en.vtt"), vtt("an online cue")); const local = path.join(paths.channelsDir, CH, "data", LOCAL); writeJson(path.join(local, "metadata.info.json"), prepareManualLocalRecordingMetadata({ id: LOCAL, filename: "talk.mp4", title: "A private talk" })); writeFileSync(path.join(local, "transcript.en.vtt"), vtt("a private local cue")); const site = (siteId: string, extra: Record = {}) => writeJson(path.join(paths.sitesDir, siteId, "site.json"), { siteId, siteTitle: siteId, siteDescription: "fixture", headerTitle: siteId, homeTagline: "", socialLinks: [], groups: [{ id: "default", name: "All channels", selectedByDefault: true }], defaultGroupId: "default", channels: [{ slug: CH, groupId: "default" }], siteUrl: `https://${siteId}.example.test`, archives: false, ...extra, }); site("pub"); site("priv", { audience: "private" }); await buildIndex({ paths, onLog: quiet }); // Every file under public/transcripts/, read whole: a local id or its cue // anywhere in it (a page, the manifest's slugToPage) is a leak. function transcriptTree(): string { const dir = path.join(paths.exportTranscriptsDir, CH); return readdirSync(dir).map((f) => readFileSync(path.join(dir, f), "utf8")).join("\n"); } async function compose(siteId: string): Promise { const log = console.log; console.log = quiet; try { await composeSite({ siteId, paths }); } finally { console.log = log; } return transcriptTree(); } const assertPublic = (tree: string, when: string) => { assert.doesNotMatch(tree, new RegExp(LOCAL), `${when}: no local id in the public site's tree`); assert.doesNotMatch(tree, /a private local cue/, `${when}: no local cue`); assert.match(tree, /an online cue/, `${when}: the online record is there`); }; const assertPrivate = (tree: string, when: string) => { assert.match(tree, new RegExp(LOCAL), `${when}: the private site carries the local recording`); assert.match(tree, /a private local cue/, `${when}: and its cue`); assert.match(tree, /an online cue/, `${when}: and the online record`); }; test("compose P, V, P: the public site never ships the private tree the private site left", async () => { assertPublic(await compose("pub"), "P first"); assertPrivate(await compose("priv"), "then V"); assertPublic(await compose("pub"), "P again, shared tree unchanged"); assertPublic(await compose("pub"), "P a third time, its own compose last"); }); test("compose V, P, V: the private site never ships the shared tree the public site left", async () => { assertPrivate(await compose("priv"), "V first"); assertPublic(await compose("pub"), "then P"); assertPrivate(await compose("priv"), "V again, private tree unchanged"); });