// THE LIBRARY STAYS BEHIND EVERY DOOR; THE PUBLISHED CHANNEL IS AN ORDINARY // CHANNEL (lane x-trending-publish). bin/xTrendingPrivacy.test.ts pins the // first half. This pins the second, over a temp corpus, through the real // publish, the real site writer, the real index build and the real compose: // // - a topic is published, and the channel it makes is put on a site by the // site writer (which refuses the library itself); // - the build and the composed site carry the post the OPERATOR kept; // - and NOTHING ELSE of the library: not a post an agent kept, a dropped, // later or undecided one, a post of another topic, a judgement's note, // the raw capture of a read, nor the library's slug or a file of its // name; // - `social.x.visibility` still covers the published channel (it is an X // posts channel), and no build or publisher module imports the publish or // the organise bodies. // // Run with: node_modules/.bin/tsx --test common/bin/xTrendingPublishedSite.test.ts import { after, test } from "node:test"; import assert from "node:assert/strict"; import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; const ROOT = mkdtempSync(path.join(tmpdir(), "x-trending-published-site-")); 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 { publishXTrendingTopic } = await import("../controller/publishXTrending"); const { readChannelConfig } = await import("../controller/channels"); const { main: composeSite } = await import("./compose-site"); const { writeSite } = await import("../lib/site"); const { postsVisibleTo } = await import("../lib/postsVisibility"); const { judgeXTrending } = await import("../lib/xTrending/judgements"); const { recordXTrendingRead, writeXTrendingPosts, trendingReadDir } = await import("../lib/xTrending/store"); const { X_TRENDING_NOT_ON_A_SITE } = await import("../lib/xTrending/config"); const paths = getPaths(); const LIB = "zzprivatelibraryq7"; const CHANNEL = "kettle-festival"; const READ = "tr-01JA0000000000000000000000"; const KEPT = "publishedkeptwordsmarkx3d"; const PRIVATE = { agentKept: "agentkeptwordsmarkb6t", dropped: "droppedwordsmarkc2m", later: "laterwordsmarkd9p", undecided: "undecidedwordsmarkf5r", otherTopic: "othertopicwordsmarkg1s", note: "judgenotemarkq4z", raw: "rawcapturemarkj9m", }; const quiet = () => {}; const writeJson = (file: string, value: unknown) => { mkdirSync(path.dirname(file), { recursive: true }); writeFileSync(file, JSON.stringify(value, null, 2)); }; const post = (id: string, text: string) => ({ id, slug: `${LIB}/${id}`, channelSlug: LIB, author: "teapot_news", createdAt: "2026-11-16T12:00:00.000Z", uploadDate: "20261116", text, url: `https://x.com/teapot_news/status/${id}`, platform: "twitter" as const, isReply: false, isRepost: false, links: [], }); writeJson(paths.settingsFile, {}); const libRoot = path.join(paths.channelsDir, LIB); writeJson(path.join(libRoot, "config.json"), { handling: "transcribe", sourceKind: "social", platform: "twitter", name: "A library", xTrending: {} }); await writeXTrendingPosts(libRoot, [ post("801", `the opening ${KEPT}`), post("802", PRIVATE.agentKept), post("803", PRIVATE.dropped), post("804", PRIVATE.later), post("805", PRIVATE.undecided), post("806", PRIVATE.otherTopic), ]); const ref = (n: number) => ({ trendId: `190000000000000000${n}`, url: `https://x.com/i/trending/190000000000000000${n}` }); await recordXTrendingRead(libRoot, { readId: READ, at: "2026-11-17T10:00:00.000Z", ref: ref(1), topic: "Kettle Festival", postIds: ["801", "802", "803", "804", "805"], added: 5 }); await recordXTrendingRead(libRoot, { readId: "tr-01JB0000000000000000000000", at: "2026-11-17T11:00:00.000Z", ref: ref(2), topic: "Cups", postIds: ["806"], added: 1 }); mkdirSync(trendingReadDir(libRoot, READ), { recursive: true }); writeFileSync(path.join(trendingReadDir(libRoot, READ), "responses.jsonl"), `${JSON.stringify({ n: 1, op: "Op", status: 200, body: { t: PRIVATE.raw } })}\n`); await judgeXTrending(libRoot, { by: "agent", set: [{ id: "802", state: "keep" }] }); await judgeXTrending(libRoot, { by: "operator", set: [{ id: "801", state: "keep", note: `why ${PRIVATE.note}` }, { id: "803", state: "drop" }, { id: "804", state: "later" }, { id: "806", state: "keep" }] }); const site = (channels: string[]) => ({ siteId: "pub", siteTitle: "pub", siteDescription: "fixture", headerTitle: "pub", homeTagline: "", socialLinks: [], groups: [{ id: "default", name: "All channels", selectedByDefault: true }], defaultGroupId: "default", channels: channels.map((slug) => ({ slug, groupId: "default" })), siteUrl: "https://pub.example.test", archives: false, }); 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") }); } }; if (existsSync(dir)) walk(dir); return out; } test("a published topic's channel goes on a site by the site writer, and builds the operator's kept post and nothing else of the library", async () => { const ask = { slug: LIB, topic: "kettle-festival", deriveSlug: () => CHANNEL, busy: () => false }; const dry = await publishXTrendingTopic(paths, { ...ask, dryRun: true }); assert.ok(dry.ok); assert.deepEqual(dry.result.ids, ["801"]); const done = await publishXTrendingTopic(paths, { ...ask, dryRun: false, confirm: dry.result.confirm, by: "operator" }); assert.ok(done.ok); // The site writer: the library refused as ever, the published channel taken like any channel. await assert.rejects(writeSite(site([LIB]) as never, paths), { message: X_TRENDING_NOT_ON_A_SITE(LIB) }); await writeSite(site([CHANNEL]) as never, paths); const log: string[] = []; await buildIndex({ paths, onLog: (l: string) => log.push(l) }); assert.ok(log.some((l) => l.includes(`Skipping channel ${LIB}: an X trending library`)), "the build still skips the library"); const out = console.log; const warn = console.warn; console.log = quiet; console.warn = quiet; try { await composeSite({ siteId: "pub", paths }); } finally { console.log = out; console.warn = warn; } for (const [where, dir] of [["the index", paths.exportIndexDir], ["the composed site", paths.exportPublicDir]] as const) { const files = filesUnder(dir); assert.ok(files.length > 0, `${where} was written`); // THE PUBLISHED POST IS THERE: the operator published it. assert.ok(files.some((f) => f.text.includes(KEPT)), `${where} carries the post the operator kept and published`); for (const f of files) { for (const [what, mark] of Object.entries(PRIVATE)) assert.ok(!f.text.includes(mark), `${where}: ${f.rel} carries the library's ${what}`); assert.ok(!f.text.includes(LIB), `${where}: ${f.rel} names the library`); assert.ok(!f.rel.split(path.sep).includes(LIB), `${where}: a file under ${f.rel}`); for (const name of ["judgements.json", "membership.json", "topics.json", "watch.json", "published.json", "media-index.json", "media-store", "reads"]) { assert.ok(!f.rel.split(path.sep).includes(name), `${where} wrote ${f.rel}`); } } } const composed = filesUnder(paths.exportPublicDir); for (const name of ["corpus.json", "site.json"]) { const f = composed.find((x) => x.rel === name); assert.ok(f, `${name} was composed`); assert.ok(f!.text.includes(CHANNEL), `${name} names the published channel`); } }); test("social.x.visibility covers the published channel: it is an X posts channel", async () => { const config = await readChannelConfig(paths, CHANNEL); assert.ok(config); const isPrivate = { social: { x: { visibility: "private" } } }; assert.equal(postsVisibleTo({ audience: "public" } as never, config, isPrivate), false, "X private: no public site carries it"); assert.equal(postsVisibleTo({ audience: "private" } as never, config, isPrivate), true); assert.equal(postsVisibleTo({ audience: "public" } as never, config, {}), true); // The library itself: on no site, whatever the setting. assert.equal(postsVisibleTo({ audience: "private" } as never, await readChannelConfig(paths, LIB), {}), false); }); test("no build, publisher, export, homepage or MCP module reaches the publish or the organise bodies", () => { const repo = path.resolve(path.dirname(new URL(import.meta.url).pathname), "..", ".."); const sources: { rel: string; text: string }[] = []; const walk = (d: string) => { if (!existsSync(d)) return; for (const e of readdirSync(d, { withFileTypes: true })) { if (e.name === "node_modules" || e.name.startsWith(".")) continue; const p = path.join(d, e.name); if (e.isDirectory()) walk(p); else if (/\.(ts|tsx|mjs)$/.test(e.name) && !/\.test\.|\.unit\./.test(e.name)) sources.push({ rel: path.relative(repo, p), text: readFileSync(p, "utf8") }); } }; for (const d of ["common/bin", "common/publish", "common/views", "export/app", "export/lib", "homepage/app", "homepage/lib", "mcp/src"]) walk(path.join(repo, d)); assert.ok(sources.length > 50, "the sweep read the publishing sources"); const WORDS = ["publishXTrending", "xTrending/published", "xTrending/organise", "mergeXTrendingTopics", "moveXTrendingPosts", "renameXTrendingTopic", "readXTrendingPublished", "publish-trending", "organise-trending"]; for (const f of sources) for (const word of WORDS) assert.ok(!f.text.includes(word), `${f.rel} names ${word}`); // The sweep catches what it guards against. assert.ok(WORDS.some((w) => 'import { publishXTrendingTopic } from "../controller/publishXTrending";'.includes(w))); });