Archilyzer · Source

archilyzer

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

commit 3c91f59ca726ed8f949da093fa16a056eafe9513
parent 123f2f78da4717653467c1ec13a61bdfb99a7761
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 11:30:57 -0500

compose: a channel tree is trusted by what its destination was copied from

Re-review blocker B1. public/<tree>/<slug> is one directory every site
composes into in turn, but reconcileChannelTree trusted a destination by THIS
site's cache (`prev[slug] === sig`). Since a private-audience site copies a
channel's full transcript tree (local recordings included) where a public one
copies the shared tree, composing public P, then private V, then P again
(shared tree unchanged) skipped the copy: P was built with V's private tree,
every local recording's transcript and the manifest naming it.

reconcileChannelTree now keeps a ledger, .export-index/compose-trees.json
(never in public/), of the source dir and signature each destination was last
copied from. A destination is trusted only when that record matches this
compose's source; a copy in progress is recorded first, so a cut-short copy is
never trusted. A destination with no record predates the ledger and was copied
from the shared tree (nothing else existed): `prev` decides, and only when this
compose's source is the shared tree. Every copied tree (transcripts, subs,
posts, digests) uses it. Subs, posts and digests had the same cache shape but
one source for every site, so they were not leaking; the ledger keeps them
right if they ever get a second one.

Test (compose-site.localMedia.test.ts, real index build and compose): P, V, P
-- no local id or cue anywhere in P's transcript tree; V, P, V -- V still
carries them. Both fail without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Diffstat:
Acommon/bin/compose-site.localMedia.test.ts | 116+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcommon/bin/compose-site.ts | 71++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 178 insertions(+), 9 deletions(-)

diff --git a/common/bin/compose-site.localMedia.test.ts b/common/bin/compose-site.localMedia.test.ts @@ -0,0 +1,116 @@ +// 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/<slug> 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<string, unknown> = {}) => + 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/<CH>, 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<string> { + 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"); +}); diff --git a/common/bin/compose-site.ts b/common/bin/compose-site.ts @@ -21,6 +21,7 @@ // reports, site.json (no channels) and corpus.json (`site.scope: "cited"`) — // see composeCitedSite. +import { writeJsonAtomic } from "../lib/jsonFile-server"; import { isLocalRecord } from "../lib/localMedia"; import path from "node:path"; import { cp, link, mkdir, rm, readdir, access, readFile, writeFile, stat, rename } from "node:fs/promises"; @@ -728,6 +729,15 @@ async function writeComposeCache(p: string, cache: ComposeCache): Promise<void> // under a constant signature and the contract stays unconditional. export const MANIFEST_ONLY_SIGNATURE = "manifest-only"; +// A ledger entry for a destination being copied right now (reconcileChannelTree). +const COPY_IN_PROGRESS = "copy in progress"; + +// The ledger of what each public/<tree>/<slug> was last copied from: beside the +// index, never in public/ (it names staging paths). +export function composeTreesLedgerPath(paths: Pick<Paths, "exportIndexDir">): string { + return path.join(paths.exportIndexDir, "compose-trees.json"); +} + // WHICH TRANSCRIPT TREE A SITE COPIES (lane/local-media slice 1 ruling). The // shared tree leaves local recordings out; a channel that holds one also has a // full tree under sharedPrivateTranscriptsDir. A PRIVATE-audience site copies @@ -753,19 +763,42 @@ export async function reconcileChannelTree( memberSlugs: string[], prev: Record<string, string>, log: (m: string) => void, - // Where one member's tree comes from, when not `srcRoot/<slug>`: the - // transcripts of a private-audience site (transcriptsSourceFor). - srcFor?: (slug: string) => Promise<string>, + opts: { + // Where one member's tree comes from, when not `srcRoot/<slug>`: the + // transcripts of a private-audience site (transcriptsSourceFor). + srcFor?: (slug: string) => Promise<string>; + // WHAT EACH DESTINATION HOLDS (lane/local-media re-review B1). public/<tree> + // is ONE directory every site composes into in turn, while `prev` is THIS + // site's cache: once two sites copy a channel from different sources (the + // shared tree, a private site's full tree), `prev` cannot say what another + // site left there — a public site would trust, and ship, the private tree. + // The ledger records, per destination, the source dir and signature it was + // last copied from (outside public/, never published); a destination is + // trusted only when that record matches this compose's source. A copy in + // progress is recorded as such first, so a cut-short copy is never trusted. + // A destination with no record was copied before the ledger existed, from + // the shared tree (no other source existed): `prev` decides, and only when + // this compose's source is the shared tree too. + ledgerFile?: string; + } = {}, ): Promise<Record<string, string>> { + const { srcFor, ledgerFile } = opts; // A linked tree (a worktree's public/<tree> → the primary's) becomes this // checkout's own before anything is copied into or pruned from it. await ownDir(destRoot); + const ledger: Record<string, string> | null = ledgerFile + ? await readFile(ledgerFile, "utf8").then((raw) => JSON.parse(raw) as Record<string, string>, () => ({})) + : null; + const persistLedger = async () => { + if (ledgerFile && ledger) await writeJsonAtomic(ledgerFile, ledger); + }; const next: Record<string, string> = {}; const memberSet = new Set(memberSlugs); let copied = 0; let skipped = 0; for (const slug of memberSlugs) { - const src = srcFor ? await srcFor(slug) : path.join(srcRoot, slug); + const sharedSrc = path.join(srcRoot, slug); + const src = srcFor ? await srcFor(slug) : sharedSrc; const dest = path.join(destRoot, slug); // Exclude the per-channel manifest.json — its `generatedAt` churns every // mutation build; the page files capture real content changes. @@ -776,15 +809,27 @@ export async function reconcileChannelTree( if (sig === "") { // No source for this member — ensure no stale dest survives. await rm(dest, { recursive: true, force: true }); + if (ledger) delete ledger[dest]; continue; } - if (prev[slug] === sig && (await exists(dest))) { + const copiedFrom = `${src}\0${sig}`; + const trusted = + (await exists(dest)) && + (ledger && dest in ledger + ? ledger[dest] === copiedFrom + : prev[slug] === sig && src === sharedSrc); + if (trusted) { next[slug] = sig; skipped++; continue; } + if (ledger) { + ledger[dest] = COPY_IN_PROGRESS; + await persistLedger(); + } await rm(dest, { recursive: true, force: true }); await cp(src, dest, { recursive: true }); + if (ledger) ledger[dest] = copiedFrom; next[slug] = sig; copied++; } @@ -799,8 +844,10 @@ export async function reconcileChannelTree( for (const e of entries) { if (e.isDirectory() && !memberSet.has(e.name)) { await rm(path.join(destRoot, e.name), { recursive: true, force: true }); + if (ledger) delete ledger[path.join(destRoot, e.name)]; } } + await persistLedger(); log(`[compose] ${kind}: ${copied} copied, ${skipped} unchanged.`); return next; } @@ -865,9 +912,12 @@ export async function main( // last (it is written below, every compose); another name, or none, and the // site's own stages (summaries, stats, duplicates) are composed afresh. // - // The per-channel tree signatures stay trusted: those trees are copies of - // the SHARED trees, the same bytes whichever site copied them, and a - // channel another site pruned is re-copied because its directory is gone. + // The per-channel trees are trusted by what each destination was last + // copied FROM (reconcileChannelTree's ledger), not by this site's cache: a + // private-audience site copies a channel's FULL transcript tree where a + // public one copies the shared tree (transcriptsSourceFor), so the same + // destination can hold either; a channel another site pruned is re-copied + // because its directory is gone. const cachePath = composeCachePath(paths, siteId); const lastComposed = builtSiteIdIn(paths.exportPublicDir); const cached = await readComposeCache(cachePath); @@ -934,7 +984,7 @@ export async function main( memberSlugs, cache.transcripts, console.log, - transcriptsSourceFor(paths, isPrivateSite(site)), + { srcFor: transcriptsSourceFor(paths, isPrivateSite(site)), ledgerFile: composeTreesLedgerPath(paths) }, ); cache.subs = await reconcileChannelTree( "subs", @@ -943,6 +993,7 @@ export async function main( memberSlugs, cache.subs, console.log, + { ledgerFile: composeTreesLedgerPath(paths) }, ); // The social-post corpus: same shared-tree shape, same incremental reconcile. // Only social member channels have a source dir; reconcileChannelTree treats a @@ -963,6 +1014,7 @@ export async function main( postsListed ? memberSlugs.filter((slug) => postsListed.has(slug)) : memberSlugs, cache.posts ?? {}, console.log, + { ledgerFile: composeTreesLedgerPath(paths) }, ); // The AI-digest corpus: same shared-tree shape again. Sparse — only channels // with at least one digest have a source dir, and reconcileChannelTree treats @@ -974,6 +1026,7 @@ export async function main( memberSlugs, cache.digests ?? {}, console.log, + { ledgerFile: composeTreesLedgerPath(paths) }, ); // Subs also carries a per-site manifest.json (tiny — copied every build). const subsManifestSrc = path.join(