// A LOOKOUT'S PRIVATE FILES NEVER LEAVE (lane/lookout slice 2, acceptance 2b): // a video's `reading-notes.json` (what the model found reading it) and // everything under `transcripts/.lookouts/` (runs, ideas, verdicts, traces) // are planted in a temp corpus with a marker in every one, then each consumer // that enumerates the corpus's files runs FOR REAL and its whole output is // searched — file names and contents — for the names and the markers. A // positive control in each (the video's own public cue) proves the consumer // did read the video. // // the index build (controller/buildIndex.ts: export index files + LMDB) // the site compose (bin/compose-site.ts: the public dir) // the archive bundles (controller/archiveTranscripts.ts: the ZIP) // the editor's reader (controller/videoCues.ts readVideoCues — what // `pnpm ops get transcript` and the MCP's editor-side // transcript ask read) // The MCP's own readers are mcp/src/lookoutPrivacy.test.ts (over this same // kind of composed dir), the source mirror publish/source.test.ts. // // Run with: node_modules/.bin/tsx --test common/bin/lookoutPrivacy.test.ts import { after, test } from "node:test"; import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { execa } from "execa"; const ROOT = mkdtempSync(path.join(tmpdir(), "lookout-privacy-")); 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"), }); delete process.env.ARCHILYZER_INDEX_ALLOW_HELD; 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 { archiveTranscripts } = await import("../controller/archiveTranscripts"); const { readVideoCues } = await import("../controller/videoCues"); const { READING_NOTES_FILENAME } = await import("../lib/readingNotes-server"); const { LOOKOUTS_DIRNAME } = await import("../lib/lookoutStore"); const { open } = await import("lmdb"); const paths = getPaths(); const CH = "alpha-news"; const VIDEO = "PublicVid01"; const PUBLIC_CUE = "an ordinary public cue about the weather"; // One marker per private file, so a leak names its source. const NOTES_MARK = "notesmarkerq7x"; const RUN_MARK = "runmarkerz4k"; const VERDICT_MARK = "verdictmarkerw2p"; const TRACE_MARK = "tracemarkerj9m"; const MARKS = [NOTES_MARK, RUN_MARK, VERDICT_MARK, TRACE_MARK]; const NAMES = [READING_NOTES_FILENAME, LOOKOUTS_DIRNAME, "verdicts.json", "trace.jsonl"]; 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: "Alpha News", url: "https://www.youtube.com/@alpha-news/videos" }); const video = path.join(paths.channelsDir, CH, "data", VIDEO); writeJson(path.join(video, "metadata.info.json"), { id: VIDEO, title: "A public video", upload_date: "20261103", timestamp: 1793750000, duration: 120, webpage_url: `https://www.youtube.com/watch?v=${VIDEO}`, extractor_key: "Youtube", }); writeFileSync(path.join(video, "transcript.en.vtt"), `WEBVTT\n\n00:00:01.000 --> 00:00:04.000\n${PUBLIC_CUE}\n`); writeJson(path.join(video, "transcript.cues.json"), { version: 2, id: VIDEO, title: "A public video", uploadDate: "20261103", duration: 120, platform: "youtube", webpageUrl: `https://www.youtube.com/watch?v=${VIDEO}`, cues: [{ start: 1, end: 4, text: PUBLIC_CUE }], }); // The private files, as a lookout run writes them. writeJson(path.join(video, READING_NOTES_FILENAME), { version: 1, provenance: { model: "stub-local:1b", promptVersion: 1, chunkChars: 7000, cues: { size: 1, mtimeMs: 1 } }, chunkCount: 1, chunks: [{ index: 0, from: 1, to: 1, covers: `covers ${NOTES_MARK}`, items: [{ kind: "claim", quote: `a quote ${NOTES_MARK}`, start: 1, end: 4, why: "why", voice: "own", people: [] }], dropped: 0 }], complete: true, updatedAt: "2026-11-11T12:00:00.000Z", }); const store = path.join(paths.transcriptsDir, LOOKOUTS_DIRNAME, "example-week"); writeJson(path.join(store, "runs", "20261111T120000Z-abcd.json"), { version: 1, lookoutId: "example-week", runId: "20261111T120000Z-abcd", ideas: [{ workingTitle: RUN_MARK }] }); writeFileSync(path.join(store, "runs", "20261111T120000Z-abcd.trace.jsonl"), `${JSON.stringify({ t: TRACE_MARK })}\n`); writeJson(path.join(store, "verdicts.json"), { version: 1, ideas: { "FAKE-TEST-VALUE": { verdict: "make", at: "x", note: VERDICT_MARK } } }); writeJson(path.join(paths.sitesDir, "pub", "site.json"), { siteId: "pub", siteTitle: "pub", siteDescription: "fixture", headerTitle: "pub", homeTagline: "", socialLinks: [], groups: [{ id: "default", name: "All channels", selectedByDefault: true }], defaultGroupId: "default", channels: [{ slug: CH, groupId: "default" }], siteUrl: "https://pub.example.test", archives: false, }); /** Every file under `dir`: its path relative to `dir`, and its bytes as text. */ function filesUnder(dir: string): { rel: string; text: string }[] { const out: { rel: string; text: string }[] = []; const walk = (d: string) => { for (const e of readdirSync(d, { withFileTypes: true })) { const p = path.join(d, e.name); if (e.isDirectory()) walk(p); else if (e.isFile() || (e.isSymbolicLink() && statSync(p).isFile())) out.push({ rel: path.relative(dir, p), text: readFileSync(p).toString("latin1") }); } }; walk(dir); return out; } function assertNoLeak(files: { rel: string; text: string }[], where: string) { for (const f of files) { for (const name of NAMES) assert.ok(!f.rel.split(path.sep).includes(name) && !f.rel.endsWith(name), `${where}: a file named ${f.rel}`); for (const mark of MARKS) assert.ok(!f.text.includes(mark), `${where}: ${f.rel} holds ${mark}`); for (const name of [READING_NOTES_FILENAME, LOOKOUTS_DIRNAME]) assert.ok(!f.text.includes(name), `${where}: ${f.rel} names ${name}`); } } const hasPublicCue = (files: { text: string }[]) => files.some((f) => f.text.includes(PUBLIC_CUE)); test("the index build: neither the export index files nor any LMDB record carries a lookout's file", async () => { await buildIndex({ paths, onLog: quiet }); const files = filesUnder(paths.exportIndexDir); assert.ok(hasPublicCue(files), "control: the video's cue is in the index"); assertNoLeak(files, "export index"); // Every record of every sub-database, keys and values (LMDB compresses, so // the bytes on disk are not searched; the records are). const root = open({ path: paths.lmdbPath, maxDbs: 18, compression: true }); try { let seenCue = false; for (const name of ["sums", "cues", "subs", "alts", "mtimes", "byChannel", "pageHashes", "subPageHashes", "channelStats", "posts", "postPageHashes", "channelPostsStats", "digests", "digestPageHashes", "channelDigestStats", "videoState", "meta"]) { const db = root.openDB({ name, encoding: "msgpack" }); for (const { key, value } of db.getRange()) { const text = JSON.stringify([key, value]); if (text.includes(PUBLIC_CUE)) seenCue = true; for (const mark of MARKS) assert.ok(!text.includes(mark), `LMDB ${name}: a record holds ${mark}`); for (const n of [READING_NOTES_FILENAME, LOOKOUTS_DIRNAME]) assert.ok(!text.includes(n), `LMDB ${name}: a record names ${n}`); } } assert.ok(seenCue, "control: the cue is in LMDB"); } finally { await root.close(); } }); test("the site compose: nothing in the public dir carries a lookout's file", async () => { await buildIndex({ paths, onLog: quiet }); const log = console.log; console.log = quiet; try { await composeSite({ siteId: "pub", paths }); } finally { console.log = log; } const files = filesUnder(paths.exportPublicDir); assert.ok(hasPublicCue(files), "control: the video's cue is composed"); assertNoLeak(files, "public dir"); }); test("the archive bundles: a channel's ZIP, with metadata, holds the cues and the channel and nothing of a lookout's", async () => { for (const includeMetadata of [true, false]) { const result = await archiveTranscripts({ paths, channelSlugs: [CH], build: { format: "zip", includeMetadata }, onLog: quiet }); assert.equal(result.archives.length, 1); const archive = result.archives[0]!.archivePath; const names = (await execa("unzip", ["-Z1", archive])).stdout.split(/\r?\n/).filter((n) => n && !n.endsWith("/")); const files = await Promise.all(names.map(async (rel) => ({ rel, text: (await execa("unzip", ["-p", archive, rel])).stdout }))); assert.ok(hasPublicCue(files), "control: the cue is in the ZIP"); assertNoLeak(files, `ZIP (metadata=${includeMetadata})`); } }); test("the editor's transcript reader: a video's cues, never its reading notes", async () => { const out = await readVideoCues(paths, { slug: CH, id: VIDEO }); const text = JSON.stringify(out); assert.ok(text.includes(PUBLIC_CUE), text.slice(0, 400)); for (const mark of MARKS) assert.ok(!text.includes(mark), mark); assert.ok(!text.includes(READING_NOTES_FILENAME)); }); test("the search itself catches a leak: a planted name or marker fails it", () => { assert.throws(() => assertNoLeak([{ rel: path.join("transcripts", CH, READING_NOTES_FILENAME), text: "" }], "x")); assert.throws(() => assertNoLeak([{ rel: path.join(LOOKOUTS_DIRNAME, "a"), text: "" }], "x")); for (const mark of MARKS) assert.throws(() => assertNoLeak([{ rel: "page-0001.json", text: `{"q":"${mark}"}` }], "x")); assert.doesNotThrow(() => assertNoLeak([{ rel: "page-0001.json", text: PUBLIC_CUE }], "x")); });