Archilyzer · Source

archilyzer

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

commit 24b70f3818de7cade05dffb9affa0df9f25bf23d
parent 55ee52ba31d02a60e1ede78f7bbcd9bce4951cee
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 17 Nov 2026 21:09:04 -0500

x-trending review 1 (MUST 1): the report door is shut on a library; its posts live under trending/

An article cites any channel of the corpus and a draft resolves an X URL to whichever
channel holds the post, so a library's post could be composed into the homepage.

- Both report hosts' citableProblem refuse a library (X_TRENDING_NOT_CITABLE);
  composeReports and reportMedia refuse one beside the visibility rule, and
  postsVisibleTo answers false for a library on every site, private ones included.
- diskPostChannelOf skips libraries and diskPostOf reads none; a research run's
  channel list (editorChannelsOf) leaves them out.
- Structural: a library's posts are written to channels/<lib>/trending/posts/ and
  trending/posts-archive (the posts-channel format, one directory down), not to
  channels/<lib>/posts/. Every reader of a posts channel — reports, drafts, research,
  availability checks, the index, umtool's post search, Add posts and reels — looks
  in the old place and so finds a library empty; only the library's own store reads
  the new one.
- The marker alone decides isXTrendingChannel (kind and platform no longer part of it).
- compose writes no tombstone for a library a hand-written site.json names (it would
  publish the slug).

Tests: publish/xTrendingReportDoor.test.ts (an article citing a library post is
refused for both audiences and nothing of it is written; a draft's X URL never
resolves to a library; hosts, visibility rule, research list), with the post also
planted where an ordinary channel keeps posts; umtool/lib/report/xTrendingLibrary.test.mjs.

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

Diffstat:
Mcommon/bin/compose-site.ts | 7++++++-
Mcommon/bin/xTrendingPrivacy.test.ts | 8++++++--
Mcommon/controller/readXTrending.test.ts | 13++++++-------
Mcommon/controller/readXTrending.ts | 9+++++----
Mcommon/controller/reportDraft.ts | 7+++++--
Mcommon/lib/postsVisibility.ts | 6+++++-
Mcommon/lib/report/convert-server.ts | 6++++++
Mcommon/lib/xTrending/config.test.ts | 12++++++++----
Mcommon/lib/xTrending/config.ts | 17+++++++++++------
Acommon/lib/xTrending/library-server.ts | 28++++++++++++++++++++++++++++
Mcommon/lib/xTrending/store.test.ts | 12++++++------
Mcommon/lib/xTrending/store.ts | 35+++++++++++++++++++++++++++++++----
Mcommon/publish/composeReports.ts | 8++++++++
Mcommon/publish/reportHost.ts | 22++++++++++++++++++++--
Mcommon/publish/reportMedia.ts | 9+++++++++
Acommon/publish/xTrendingReportDoor.test.ts | 186+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Meditor/app/api/ops/read-x-trending/route.test.ts | 6+++---
Meditor/e2e/x-trending.spec.ts | 6+++++-
Mmcp/src/xTrendingPrivacy.test.ts | 8++++++--
Aumtool/lib/report/xTrendingLibrary.test.mjs | 43+++++++++++++++++++++++++++++++++++++++++++
20 files changed, 403 insertions(+), 45 deletions(-)

diff --git a/common/bin/compose-site.ts b/common/bin/compose-site.ts @@ -22,6 +22,7 @@ // see composeCitedSite. import { writeJsonAtomic } from "../lib/jsonFile-server"; +import { isXTrendingChannel } from "../lib/xTrending/config"; 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"; @@ -1120,7 +1121,11 @@ export async function main( const tombstones = await writePostsTombstones({ postsDir: paths.exportPostsDir, sharedPostsDir: paths.exportSharedPostsDir, - slugs: site.channels.map((c) => c.slug).filter((slug) => !memberSet.has(slug)), + // Not an X trending library (lane x-trending): no site ever served one, so + // there is nothing to replace — and a tombstone would publish its slug. + slugs: site.channels + .map((c) => c.slug) + .filter((slug) => !memberSet.has(slug) && !isXTrendingChannel(configs.get(slug))), }); // --- tombstones for the channels that left this site's pool (release 24 H1) --- // Every per-channel tree the site's last bundle served that this compose does diff --git a/common/bin/xTrendingPrivacy.test.ts b/common/bin/xTrendingPrivacy.test.ts @@ -47,7 +47,7 @@ const { buildIndex } = await import("../controller/buildIndex"); const { main: composeSite } = await import("./compose-site"); const { getSite, writeSite } = await import("../lib/site"); const { writePosts } = await import("../lib/posts-server"); -const { recordXTrendingRead, trendingReadDir, listXTrending } = await import("../lib/xTrending/store"); +const { recordXTrendingRead, writeXTrendingPosts, trendingReadDir, listXTrending } = await import("../lib/xTrending/store"); const { X_TRENDING_NOT_ON_A_SITE } = await import("../lib/xTrending/config"); const { open } = await import("lmdb"); @@ -94,7 +94,11 @@ const libRoot = path.join(paths.channelsDir, LIB); writeJson(path.join(libRoot, "config.json"), { handling: "transcribe", sourceKind: "social", platform: "twitter", name: "Trending", xTrending: {}, }); -await writePosts(libRoot, [post(LIB, "1900000000000006001", HANDLE_MARK, `a trending post ${POST_MARK}`)]); +const libPosts = [post(LIB, "1900000000000006001", HANDLE_MARK, `a trending post ${POST_MARK}`)]; +// Where a library keeps them, AND where an ordinary posts channel would (a +// hand copy): neither may reach a build. +await writeXTrendingPosts(libRoot, libPosts); +await writePosts(libRoot, libPosts); await recordXTrendingRead(libRoot, { readId: READ, at: "2026-11-17T10:00:00.000Z", diff --git a/common/controller/readXTrending.test.ts b/common/controller/readXTrending.test.ts @@ -9,8 +9,7 @@ import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, import { tmpdir } from "node:os"; import path from "node:path"; import type { Paths } from "../lib/paths"; -import { readAllPosts } from "../lib/posts-server"; -import { listXTrending, readXTrendingReadRecord } from "../lib/xTrending/store"; +import { listXTrending, readXTrendingPosts, readXTrendingReadRecord } from "../lib/xTrending/store"; import { fakeTrendingPage, type FakeTrendingPage } from "../social/fakeXProfileBrowser"; import { FIXTURE_TIMELINE_OP, @@ -123,7 +122,7 @@ test("a read writes the page's posts, records the read against a topic, and says ); // A clean request was noted; no alert. assert.deepEqual(notes, [{ url: FIXTURE_TREND_URL, channel: "trending" }]); - const posts = await readAllPosts(root(paths)); + const posts = await readXTrendingPosts(root(paths)); assert.deepEqual(posts.map((p) => p.id).sort(), [ "1900000000000001001", "1900000000000001002", @@ -182,7 +181,7 @@ test("a probe saves the capture and its summary, writes no post, and a reparse w assert.match(result.sentence, /^Probe saved \(trending\/reads\/tr-01JA0000000000000000000000\/\): 4 answers — /); assert.match(result.sentence, /The parser finds 4 posts in it\. No post was written/); assert.deepEqual(notes, []); - assert.equal((await readAllPosts(root(paths))).length, 0); + assert.equal((await readXTrendingPosts(root(paths))).length, 0); assert.deepEqual((await listXTrending(root(paths))).topics, []); assert.equal(existsSync(path.join(root(paths), "trending", "reads", READ_1, "responses.jsonl")), true); @@ -193,7 +192,7 @@ test("a probe saves the capture and its summary, writes no post, and a reparse w assert.equal(reparsed.mode, "reparse"); assert.deepEqual(reparsed.posts, { onPage: 4, added: 4 }); assert.match(reparsed.sentence, /X was asked nothing\.$/); - assert.equal((await readAllPosts(root(paths))).length, 4); + assert.equal((await readXTrendingPosts(root(paths))).length, 4); const listing = await listXTrending(root(paths)); // The read keeps the time it was made, not the time it was parsed. assert.equal(listing.topics[0].sources[0].lastReadAt, "2026-11-17T10:00:00.000Z"); @@ -235,7 +234,7 @@ test("a login wall fails with its sentence, writes no post and raises the X aler assert.equal(notes.length, 1); assert.equal(notes[0].kind, "auth-failure"); assert.ok(typeof notes[0].challengeLine === "string"); - assert.equal((await readAllPosts(root(paths))).length, 0); + assert.equal((await readXTrendingPosts(root(paths))).length, 0); }); test("a 429 fails with its sentence, keeps what was read, and raises no alert", async () => { @@ -252,7 +251,7 @@ test("a 429 fails with its sentence, keeps what was read, and raises no alert", assert.match(result.sentence, /3 posts read before it were kept \(3 new\)\./); assert.match(result.sentence, /nothing retries by itself/); assert.deepEqual(notes, []); - assert.equal((await readAllPosts(root(paths))).length, 3); + assert.equal((await readXTrendingPosts(root(paths))).length, 3); }); test("a page X no longer has, and a page that did not load, each fail with a sentence", async () => { diff --git a/common/controller/readXTrending.ts b/common/controller/readXTrending.ts @@ -7,8 +7,9 @@ // - the page is opened in the connected X profile's browser and what the // page itself fetched is saved raw (social/xTrendingRead.ts); // - the posts are then parsed FROM THE SAVED FILE (social/xTrendingParse.ts) -// and written as the library's posts (lib/posts-server.ts writePosts: -// month shards, deduped by id), and the read is recorded against a topic +// and written as the library's posts (month shards, deduped by id, under +// the library's own trending/ — store.ts xTrendingPostsRoot says why not +// where a posts channel keeps them), and the read is recorded against a topic // (lib/xTrending/store.ts). A re-read adds posts and never drops one; // - nothing else is fetched: no media, no thread, no screenshot of a post. // Archiving a post is a separate step (slice 2). @@ -27,7 +28,6 @@ import path from "node:path"; import type { Paths } from "../lib/paths"; -import { writePosts } from "../lib/posts-server"; import { noteXServiceOutcome } from "../lib/serviceCookies-server"; import { isXTrendingChannel, @@ -47,6 +47,7 @@ import { TRENDING_READS_DIRNAME, TRENDING_RESPONSES_FILENAME, trendingReadDir, + writeXTrendingPosts, writeXTrendingReadRecord, type XTrendingReadOperation, type XTrendingReadOutcome, @@ -216,7 +217,7 @@ async function ingestCapture(o: { const parsed = parseTrendingCapture(lines, o.slug); const base = { operations: parsed.operations, responses: parsed.responses, onPage: parsed.posts.length }; if (!o.write || parsed.posts.length === 0) return { ...base, added: 0 }; - const written = await writePosts(o.channelRoot, parsed.posts); + const written = await writeXTrendingPosts(o.channelRoot, parsed.posts); const recorded = await recordXTrendingRead(o.channelRoot, { readId: o.readId, at: o.at, diff --git a/common/controller/reportDraft.ts b/common/controller/reportDraft.ts @@ -89,6 +89,7 @@ import { } from "../lib/report/iterations"; import { diskPostChannelOf } from "../lib/report/convert-server"; import { readAllPosts } from "../lib/posts-server"; +import { isXTrendingChannel } from "../lib/xTrending/config"; import { runTask, type TaskDeps, type TaskInput, type TaskResult, pickCorpusBuild, siteOriginOf } from "../lib/report/draft/tasks/index"; import { corpusCuesOf } from "../lib/report/draft/tasks/corpusCues"; import { loadDeckChecks, type DeckChecks } from "../lib/report/draft/tasks/deckChecks"; @@ -628,11 +629,13 @@ export type ReportDraftDeps = { }; // The editor's channels, as a research run lists them. -async function editorChannelsOf(paths: Paths): Promise<EditorChannel[]> { +export async function editorChannelsOf(paths: Pick<Paths, "channelsDir">): Promise<EditorChannel[]> { // A remote-only channel (demo epic D1) is no channel of the editor's own — // it holds an archive's clip windows — so a research run never lists it, or // imports into it. - return (await listChannelConfigs(paths)).filter(({ config }) => !isRemoteOnlyChannel(config)).map(({ slug, config }) => { + // Nor is an X trending library (lane x-trending): private, so a research + // run never lists it, reads it or imports into it. + return (await listChannelConfigs(paths as Paths)).filter(({ config }) => !isRemoteOnlyChannel(config) && !isXTrendingChannel(config)).map(({ slug, config }) => { const c = config as Record<string, unknown>; const s = (k: string) => (typeof c[k] === "string" && c[k] ? (c[k] as string) : undefined); const kind = s("sourceKind") ?? (s("postFetcher") ? "posts" : s("handling")); diff --git a/common/lib/postsVisibility.ts b/common/lib/postsVisibility.ts @@ -33,11 +33,12 @@ import { isPrivateSite, type Site } from "./siteSchema"; import type { XPostsVisibility } from "../social/xCookieSource"; import { isWaybackPagesChannel } from "./waybackPages/config"; import { isXTargetUrl } from "./waybackPages/urls"; +import { isXTrendingChannel } from "./xTrending/config"; // What the rule reads of a config: its kind and platform, and for a Wayback // pages channel its scope. type VisibilityConfig = Pick<ChannelConfig, "sourceKind" | "platform"> & - Partial<Pick<ChannelConfig, "url" | "wayback">>; + Partial<Pick<ChannelConfig, "url" | "wayback" | "xTrending">>; // An X channel: the posts of a social channel whose platform is X — and // (release 37) a Wayback pages channel whose scope is on X (a target on @@ -73,6 +74,9 @@ export function postsVisibleTo( config: VisibilityConfig | null | undefined, settings: { social?: { x?: { visibility?: unknown } } }, ): boolean { + // An X trending library (lane x-trending) is private: NO site carries it, + // a private one included, whatever the X visibility setting says. + if (isXTrendingChannel(config)) return false; if (!isXPostsChannel(config)) return true; if (xPostsVisibility(settings) === "public") return true; return isPrivateSite(site); diff --git a/common/lib/report/convert-server.ts b/common/lib/report/convert-server.ts @@ -15,6 +15,7 @@ import { assertChannelTextReadable } from "../channelMedia"; import { resolveVideoDir } from "../videoDir-server.mjs"; import { isSafeChannelSegment, isSafeIdSegment } from "../citations/moments"; import { readAllPosts, readSeenPostIds } from "../posts-server"; +import { isXTrendingLibrary } from "../xTrending/library-server"; import type { Post } from "../posts"; import type { Cue, CuesOf, PostChannelOf } from "./convertShared"; import type { PostOf, PostRecord } from "./convertManifest"; @@ -84,6 +85,9 @@ export function diskPostChannelOf(channelsDir: string): PostChannelOf { const build = async () => { const byId = new Map<string, string[]>(); for (const slug of await channelSlugs(channelsDir)) { + // Never an X trending library (lane x-trending): a draft's X URL must + // not resolve to a private library because only it holds the post. + if (await isXTrendingLibrary(channelsDir, slug)) continue; for (const id of await readSeenPostIds(path.join(channelsDir, slug))) { byId.set(id, [...(byId.get(id) ?? []), slug]); } @@ -104,6 +108,8 @@ export function diskPostOf(channelsDir: string): PostOf { const channels = new Map<string, Promise<Map<string, Post>>>(); return async (channel, id) => { if (!isSafeChannelSegment(channel)) return null; + // A library's post is no record a report may read. + if (await isXTrendingLibrary(channelsDir, channel)) return null; let p = channels.get(channel); if (!p) { p = readAllPosts(path.join(channelsDir, channel)).then( diff --git a/common/lib/xTrending/config.test.ts b/common/lib/xTrending/config.test.ts @@ -43,7 +43,7 @@ test("the marker is an object; its caps are kept only in range", () => { for (const bad of [undefined, null, true, "yes", 1, []]) assert.equal(coerceXTrendingConfig(bad), undefined); }); -test("a library is a posts channel on X carrying the marker, and its config survives a parse", () => { +test("a library is a channel carrying the marker — the marker alone — and its config survives a parse", () => { const config = parseChannelConfig({ handling: "transcribe", sourceKind: "social", @@ -54,9 +54,13 @@ test("a library is a posts channel on X carrying the marker, and its config surv assert.ok(config); assert.deepEqual(config!.xTrending, { maxPosts: 40 }); assert.equal(isXTrendingChannel(config), true); - assert.equal(isXTrendingChannel({ sourceKind: "social", platform: "twitter" }), false); - assert.equal(isXTrendingChannel({ sourceKind: "video", platform: "twitter", xTrending: {} }), false); - assert.equal(isXTrendingChannel({ sourceKind: "social", platform: "bluesky", xTrending: {} }), false); + assert.equal(isXTrendingChannel({ sourceKind: "social", platform: "twitter" } as never), false); + // THE MARKER ALONE DECIDES: a library whose kind or platform was changed is + // still a library (and still private). + assert.equal(isXTrendingChannel({ sourceKind: "video", platform: "twitter", xTrending: {} } as never), true); + assert.equal(isXTrendingChannel({ sourceKind: "social", platform: "bluesky", xTrending: {} } as never), true); + assert.equal(isXTrendingChannel({ xTrending: { maxPosts: 3 } }), true); + for (const none of [undefined, null, false, true, "yes", 1, []]) assert.equal(isXTrendingChannel({ xTrending: none }), false); assert.equal(isXTrendingChannel(null), false); }); diff --git a/common/lib/xTrending/config.ts b/common/lib/xTrending/config.ts @@ -58,14 +58,19 @@ export function coerceXTrendingConfig(v: unknown): XTrendingConfig | undefined { return out; } -// An X trending library: a posts channel on platform "twitter" carrying the -// marker. Structural, so this leaf needs no import of the config's type. -export function isXTrendingChannel( - config: { sourceKind?: string; platform?: string; xTrending?: unknown } | null | undefined, -): boolean { - return config?.sourceKind === "social" && config.platform === "twitter" && Boolean(config.xTrending); +// An X trending library: a channel carrying the marker. THE MARKER ALONE +// DECIDES (review 1): were the kind or the platform part of the test, a config +// edit that changed either would switch the privacy off while the posts stayed. +// The marker is an object (coerceXTrendingConfig); anything else is none. +export function isXTrendingChannel(config: { xTrending?: unknown } | null | undefined): boolean { + const m = config?.xTrending; + return Boolean(m) && typeof m === "object" && !Array.isArray(m); } +export const X_TRENDING_NOT_CITABLE = (slug: string) => + `"${slug}" is an X trending library: it is private, and a report cannot cite its posts. ` + + `Publish the posts out of it into a posts channel first.`; + export const X_TRENDING_NOT_ON_A_SITE = (slug: string) => `${slug} is an X trending library: it is private, and never put on a site.`; diff --git a/common/lib/xTrending/library-server.ts b/common/lib/xTrending/library-server.ts @@ -0,0 +1,28 @@ +// "IS THIS CHANNEL AN X TRENDING LIBRARY?", asked of the disk by the doors a +// library is kept behind (lane x-trending, review 1): the report hosts, the +// draft's post resolver, a research run's channel list. One small read of the +// channel's config.json; the MARKER ALONE decides (lib/xTrending/config.ts +// isXTrendingChannel), so a library whose kind or platform was edited by hand +// is still one. SERVER-ONLY (node:fs). + +import path from "node:path"; +import { readJsonFile, readJsonFileSync } from "../jsonFile-server"; +import { isXTrendingChannel } from "./config"; + +const SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]*$/; + +function marked(value: unknown): boolean { + return isXTrendingChannel(value && typeof value === "object" ? (value as { xTrending?: unknown }) : null); +} + +export function isXTrendingLibrarySync(channelsDir: string | undefined, slug: string): boolean { + if (!channelsDir || !SLUG.test(slug)) return false; + const raw = readJsonFileSync(path.join(channelsDir, slug, "config.json")); + return raw.ok && marked(raw.value); +} + +export async function isXTrendingLibrary(channelsDir: string | undefined, slug: string): Promise<boolean> { + if (!channelsDir || !SLUG.test(slug)) return false; + const raw = await readJsonFile(path.join(channelsDir, slug, "config.json")); + return raw.ok && marked(raw.value); +} diff --git a/common/lib/xTrending/store.test.ts b/common/lib/xTrending/store.test.ts @@ -8,11 +8,11 @@ import { readXTrendingMembership, readXTrendingTopics, recordXTrendingRead, + writeXTrendingPosts, topicIdFromTitle, topicTitleProblem, trendingReadDir, } from "./store"; -import { writePosts } from "../posts-server"; import type { Post } from "../posts"; const TMP = mkdtempSync(path.join(tmpdir(), "x-trending-store-")); @@ -64,7 +64,7 @@ test("a topic id comes from its title; a title is refused when empty or too long test("the first read of a page makes a topic named for it; a re-read adds posts, keeps old ones, appends the read", async () => { const dir = root("reread"); - await writePosts(dir, [post("101", "teapot_news", "one"), post("102", "saucer_fan", "two")]); + await writeXTrendingPosts(dir, [post("101", "teapot_news", "one"), post("102", "saucer_fan", "two")]); const first = await recordXTrendingRead(dir, { readId: READ_A, at: "2026-11-17T10:00:00.000Z", @@ -78,7 +78,7 @@ test("the first read of a page makes a topic named for it; a re-read adds posts, placed: 2, kept: 0, }); - await writePosts(dir, [post("103", "lid_watch", "three")]); + await writeXTrendingPosts(dir, [post("103", "lid_watch", "three")]); const second = await recordXTrendingRead(dir, { readId: READ_B, at: "2026-11-17T11:00:00.000Z", @@ -119,7 +119,7 @@ test("the first read of a page makes a topic named for it; a re-read adds posts, test("a named topic is found by id or title, else made; a second page merges into it; a placed post keeps its topic", async () => { const dir = root("named"); - await writePosts(dir, [post("201", "a", "one"), post("202", "b", "two"), post("203", "c", "three")]); + await writeXTrendingPosts(dir, [post("201", "a", "one"), post("202", "b", "two"), post("203", "c", "three")]); const made = await recordXTrendingRead(dir, { readId: READ_A, at: "2026-11-17T10:00:00.000Z", @@ -161,7 +161,7 @@ test("a named topic is found by id or title, else made; a second page merges int test("the listing gives each post's words, author, media, reads and topic — and nothing of the raw capture", async () => { const dir = root("listing"); - await writePosts(dir, [post("301", "teapot_news", "The kettle festival opens today."), post("302", "saucer_fan", "Second.")]); + await writeXTrendingPosts(dir, [post("301", "teapot_news", "The kettle festival opens today."), post("302", "saucer_fan", "Second.")]); mkdirSync(trendingReadDir(dir, READ_A), { recursive: true }); await recordXTrendingRead(dir, { readId: READ_A, @@ -220,7 +220,7 @@ test("an empty library lists nothing", async () => { test("a row carries its first captured picture and its judgement, once there are any", async () => { const dir = root("captured"); - await writePosts(dir, [post("401", "a", "one"), post("402", "b", "two"), post("403", "c", "three")]); + await writeXTrendingPosts(dir, [post("401", "a", "one"), post("402", "b", "two"), post("403", "c", "three")]); await recordXTrendingRead(dir, { readId: READ_A, at: "2026-11-17T10:00:00.000Z", ref: REF, topic: "T", postIds: ["401", "402", "403"], added: 3 }); // 401: a capture with an attached image and a shot; 402: a shot alone; 403: none. for (const [id, files] of [["401", ["shot.png", "401_2.jpg", "401_1.jpg", "capture.json", "shot-thread.png"]], ["402", ["shot.png", "capture.json", "402_1.mp4"]]] as const) { diff --git a/common/lib/xTrending/store.ts b/common/lib/xTrending/store.ts @@ -1,6 +1,8 @@ -// AN X TRENDING LIBRARY'S OWN FILES (lane x-trending, slice 1), beside its -// posts (the channel's ordinary month shards, lib/posts-server.ts): +// AN X TRENDING LIBRARY'S OWN FILES (lane x-trending, slice 1): // +// channels/<lib>/trending/posts/<YYYY-MM>.jsonl its posts (a posts +// channels/<lib>/trending/posts-archive channel's format, kept +// HERE: see xTrendingPostsRoot) // channels/<lib>/trending/topics.json the operator's topics, each with // the trending pages read into it // and every read's id and time @@ -39,7 +41,7 @@ import path from "node:path"; import { readdir } from "node:fs/promises"; import { POSTS_MEDIA_DIRNAME, SHOT_FILENAME } from "../../social/postCapture"; import { readJsonFile, withJsonFileLock, writeJsonAtomic } from "../jsonFile-server"; -import { readAllPosts } from "../posts-server"; +import { readAllPosts, readSeenPostIds, writePosts, type WritePostsResult } from "../posts-server"; import type { Post } from "../posts"; import type { XTrendingRef } from "./config"; @@ -53,6 +55,31 @@ export function trendingDir(channelRoot: string): string { return path.join(channelRoot, TRENDING_DIRNAME); } +// WHERE A LIBRARY'S POSTS LIVE (review 1): `channels/<lib>/trending/posts/` +// and `trending/posts-archive` — a posts channel's own shard and archive +// format, one directory down. NOT `channels/<lib>/posts/`: every reader of a +// posts channel (reports and drafts, research, umtool's post search and reels, +// the index, the availability checks) looks there, and a library must be +// offered to none of them until someone publishes posts out of it on purpose. +// So to all of those a library is a channel with no posts, by construction; +// the library's own readers and writers below are the only way in. +export function xTrendingPostsRoot(channelRoot: string): string { + return trendingDir(channelRoot); +} + +export function readXTrendingPosts(channelRoot: string): Promise<Post[]> { + return readAllPosts(xTrendingPostsRoot(channelRoot)); +} + +export function readXTrendingPostIds(channelRoot: string): Promise<Set<string>> { + return readSeenPostIds(xTrendingPostsRoot(channelRoot)); +} + +// Month shards, deduped by id against the library's archive, as writePosts does. +export function writeXTrendingPosts(channelRoot: string, posts: ReadonlyArray<Post>): Promise<WritePostsResult> { + return writePosts(xTrendingPostsRoot(channelRoot), posts); +} + const READ_ID = /^tr-[0-9A-Z]{26}$/; export function isXTrendingReadId(id: unknown): id is string { @@ -479,7 +506,7 @@ export async function listXTrending( listXTrendingReadIds(channelRoot), readXTrendingJudgements(channelRoot), ]); - const archived = new Map((opts.posts ?? (await readAllPosts(channelRoot))).map((p) => [p.id, p])); + const archived = new Map((opts.posts ?? (await readXTrendingPosts(channelRoot))).map((p) => [p.id, p])); const count = new Map<string, number>(); for (const [id, m] of Object.entries(membership)) { if (archived.has(id)) count.set(m.topic, (count.get(m.topic) ?? 0) + 1); diff --git a/common/publish/composeReports.ts b/common/publish/composeReports.ts @@ -80,6 +80,7 @@ import { type Site } from "../lib/site"; import { storeReportDir } from "../lib/report/store"; import { getSettings } from "../lib/settings"; import { postsVisibleTo } from "../lib/postsVisibility"; +import { isXTrendingChannel, X_TRENDING_NOT_CITABLE } from "../lib/xTrending/config"; import { assertChannelTextReadable } from "../lib/channelMedia"; import type { ChannelConfig } from "../lib/channelConfig"; import { readChannelConfig } from "../controller/channels"; @@ -631,6 +632,13 @@ export async function resolveReports(opts: ResolveReportsOptions): Promise<Resol continue; } if (c.kind === "post") { + // Never a post of an X trending library (lane x-trending): private, + // whatever the host and the visibility rule would allow. + if (isXTrendingChannel(await configOf(c.channel))) { + problems.push({ kind: "not-visible", citation: ref, report: report.id, message: X_TRENDING_NOT_CITABLE(c.channel) }); + refusedChannel.add(c.channel); + continue; + } if (!postsVisibleTo(host, await configOf(c.channel), settings)) { problems.push({ kind: "not-visible", citation: ref, report: report.id, message: `${carrier} may not carry posts of "${c.channel}" (the post visibility rule)` }); continue; diff --git a/common/publish/reportHost.ts b/common/publish/reportHost.ts @@ -24,6 +24,8 @@ // articles' corpus check (a channel directory exists). import { existsSync, statSync } from "node:fs"; +import { X_TRENDING_NOT_CITABLE } from "../lib/xTrending/config"; +import { isXTrendingLibrarySync } from "../lib/xTrending/library-server"; import path from "node:path"; import type { Paths } from "../lib/paths"; import { PROJECT_NAME, PROJECT_URL } from "../lib/project"; @@ -69,8 +71,18 @@ export type ReportHost = ReportStore & { }; // A site's pages. -export function siteReportHost(paths: Pick<Paths, "sitesDir" | "exportSitesIndexDir">, site: Site): ReportHost { +export function siteReportHost( + paths: Pick<Paths, "sitesDir" | "exportSitesIndexDir"> & Partial<Pick<Paths, "channelsDir">>, + site: Site, +): ReportHost { const citable = siteCitableChannelSlugs(site); + // An X trending library is never citable (lane x-trending): the site writer + // refuses one as a member, and a site.json written by hand is caught here. + const library = new Map<string, boolean>(); + const isLibrary = (slug: string) => { + if (!library.has(slug)) library.set(slug, isXTrendingLibrarySync(paths.channelsDir, slug)); + return library.get(slug) === true; + }; const cited = isCitedSite(site); return { ...siteReportStore(paths, site.siteId), @@ -81,7 +93,8 @@ export function siteReportHost(paths: Pick<Paths, "sitesDir" | "exportSitesIndex audience: isPrivateSite(site) ? "private" : "public", published: site.pages ?? [], listedBy: (id) => `the site lists report "${id}"`, - citableProblem: (slug) => (citable.has(slug) ? null : notInSiteMessage(slug)), + citableProblem: (slug) => + isLibrary(slug) ? X_TRENDING_NOT_CITABLE(slug) : citable.has(slug) ? null : notInSiteMessage(slug), // No corpus page to link a moment to: a cited site publishes none, and a // cited-only channel (`citedChannels`) is not in the site's corpus. corpusBase: (slug) => (cited || isCitedOnlyChannel(site, slug) ? null : ""), @@ -115,6 +128,7 @@ export async function articlesReportHost( ): Promise<ReportHost> { const audience = opts.audience ?? "private"; const isChannel = new Map<string, boolean>(); + const library = new Map<string, boolean>(); return { ...articleReportStore(paths), base: ARTICLES_REPORTS_BASE, @@ -124,6 +138,10 @@ export async function articlesReportHost( published: opts.published ?? (await publishedArticleIds(audience, paths)), listedBy: (id) => `reports/index.json lists article "${id}"`, citableProblem: (slug) => { + // The whole corpus is citable — but never an X trending library, which + // is private (lane x-trending). + if (!library.has(slug)) library.set(slug, isXTrendingLibrarySync(paths.channelsDir, slug)); + if (library.get(slug)) return X_TRENDING_NOT_CITABLE(slug); if (!isChannel.has(slug)) { let dir = false; try { diff --git a/common/publish/reportMedia.ts b/common/publish/reportMedia.ts @@ -59,6 +59,7 @@ import { } from "../lib/report/store"; import { siteReportHost, type ReportHost } from "./reportHost"; import { postsVisibleTo } from "../lib/postsVisibility"; +import { isXTrendingChannel, X_TRENDING_NOT_CITABLE } from "../lib/xTrending/config"; import { inspectChannelMedia } from "../lib/channelMedia"; import type { ChannelConfig } from "../lib/channelConfig"; import { readChannelConfig } from "../controller/channels"; @@ -321,6 +322,10 @@ export async function prepareReportMedia(opts: PrepareReportMediaOptions): Promi } const config = await configOf(slug); if (m.kind === "post") { + if (isXTrendingChannel(config)) { + fail(m, "not-visible", X_TRENDING_NOT_CITABLE(slug)); + continue; + } if (!postsVisibleTo(host, config, settings)) { fail(m, "not-visible", `this site may not carry posts of "${slug}" (the post visibility rule)`); continue; @@ -569,6 +574,10 @@ export async function missingEvidenceWindows( continue; } const config = await configOf(slug); + if (isXTrendingChannel(config)) { + unfetchable("not-in-site", X_TRENDING_NOT_CITABLE(slug)); + continue; + } const localRefusal = localMediaFetchRefusal(slug, config, id); if (localRefusal) { unfetchable("local-media", localRefusal); diff --git a/common/publish/xTrendingReportDoor.test.ts b/common/publish/xTrendingReportDoor.test.ts @@ -0,0 +1,186 @@ +// THE REPORT DOOR IS SHUT ON AN X TRENDING LIBRARY (lane x-trending, review 1 +// MUST 1). An article may cite any channel of the corpus, and a draft resolves +// an X URL to whichever channel holds the post — so, before this, a library's +// post could be composed into the homepage's public dir, even unasked. +// +// Pinned here over a temp corpus, with a marker in the library's post, and the +// post ALSO planted where an ordinary posts channel keeps its posts (so the +// refusals are tested, not only the fact that a library keeps its posts under +// trending/, where no ordinary reader looks): +// - both report hosts refuse a library as citable; +// - composing an article that cites a library post is refused, and nothing +// of the post is written; +// - no site may carry a library's posts by the visibility rule, private +// sites included; +// - a draft's X URL never resolves to a library; +// - a research run is never shown a library. +// +// Run with: node_modules/.bin/tsx --test publish/xTrendingReportDoor.test.ts + +import { after, test } from "node:test"; +import assert from "node:assert/strict"; +import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; + +const ROOT = mkdtempSync(path.join(tmpdir(), "x-trending-report-door-")); +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"), +}); +after(() => rmSync(ROOT, { recursive: true, force: true })); + +const { getPaths } = await import("../lib/paths"); +const { writePosts, readAllPosts } = await import("../lib/posts-server"); +const { setPublished, articleDir } = await import("../lib/report/registry"); +const { articlesReportHost, siteReportHost } = await import("./reportHost"); +const { composeHostReports, ComposeReportsError } = await import("./composeReports"); +const { postsVisibleTo } = await import("../lib/postsVisibility"); +const { diskPostChannelOf, diskPostOf } = await import("../lib/report/convert-server"); +const { editorChannelsOf } = await import("../controller/reportDraft"); +const { writeXTrendingPosts, readXTrendingPosts } = await import("../lib/xTrending/store"); +const { X_TRENDING_NOT_CITABLE } = await import("../lib/xTrending/config"); + +const paths = getPaths(); +const OUT = path.join(ROOT, "homepage-public"); +const LIB = "trending-lib"; +const ACCOUNT = "kettle-org-x"; +const LIB_ID = "1900000000000006001"; +const SHARED_ID = "1900000000000006002"; +const MARK = "trenddoormarkerq7x"; +const HANDLE = "trenddoorhandlez4k"; + +const writeJson = (file: string, value: unknown) => { + mkdirSync(path.dirname(file), { recursive: true }); + writeFileSync(file, JSON.stringify(value, null, 2)); +}; + +const post = (channelSlug: string, id: string, author: string, text: string) => ({ + id, + slug: `${channelSlug}/${id}`, + channelSlug, + author, + createdAt: "2026-11-16T12:00:00.000Z", + uploadDate: "20261116", + text, + url: `https://x.com/${author}/status/${id}`, + platform: "twitter" as const, + isReply: false, + isRepost: false, + links: [], +}); + +const LIBRARY_CONFIG = { handling: "transcribe", sourceKind: "social", platform: "twitter", name: "Trending", xTrending: {} }; +writeJson(paths.settingsFile, {}); +const libRoot = path.join(paths.channelsDir, LIB); +writeJson(path.join(libRoot, "config.json"), LIBRARY_CONFIG); +const libPosts = [post(LIB, LIB_ID, HANDLE, `a trending post ${MARK}`), post(LIB, SHARED_ID, "kettle_org", `shared ${MARK}`)]; +await writeXTrendingPosts(libRoot, libPosts); +// And where an ordinary posts channel keeps them (a hand copy; an older library). +await writePosts(libRoot, libPosts); +const accountRoot = path.join(paths.channelsDir, ACCOUNT); +writeJson(path.join(accountRoot, "config.json"), { + handling: "transcribe", sourceKind: "social", platform: "twitter", name: "Kettle Org (X)", url: "https://x.com/kettle_org", socialHandle: "kettle_org", +}); +await writePosts(accountRoot, [post(ACCOUNT, SHARED_ID, "kettle_org", "the account's own copy")]); + +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 out.push({ rel: path.relative(dir, p), text: readFileSync(p).toString("latin1") }); + } + }; + if (existsSync(dir)) walk(dir); + return out; +} + +test("a library keeps its posts under trending/: where a posts channel's readers look, it has none of its own making", async () => { + const fresh = path.join(paths.channelsDir, "fresh-lib"); + writeJson(path.join(fresh, "config.json"), LIBRARY_CONFIG); + await writeXTrendingPosts(fresh, [post("fresh-lib", "1900000000000006009", HANDLE, MARK)]); + assert.equal((await readXTrendingPosts(fresh)).length, 1); + assert.equal((await readAllPosts(fresh)).length, 0); + assert.equal(existsSync(path.join(fresh, "posts")), false); + assert.equal(existsSync(path.join(fresh, "posts-archive")), false); + assert.equal(existsSync(path.join(fresh, "trending", "posts")), true); + rmSync(fresh, { recursive: true, force: true }); +}); + +test("both report hosts refuse a library as citable", async () => { + const articles = await articlesReportHost(paths, { audience: "private" }); + assert.equal(articles.citableProblem(LIB), X_TRENDING_NOT_CITABLE(LIB)); + assert.equal(articles.citableProblem(ACCOUNT), null); + // A site whose site.json, written by hand, names the library. + const site = { + siteId: "priv", siteTitle: "priv", audience: "private", pages: [], + groups: [{ id: "default", name: "All", selectedByDefault: true }], defaultGroupId: "default", + channels: [{ slug: ACCOUNT, groupId: "default" }, { slug: LIB, groupId: "default" }], + }; + const host = siteReportHost(paths, site as never); + assert.equal(host.citableProblem(LIB), X_TRENDING_NOT_CITABLE(LIB)); + assert.equal(host.citableProblem(ACCOUNT), null); + assert.match(X_TRENDING_NOT_CITABLE(LIB), /is an X trending library: it is private/); +}); + +test("no site may carry a library's posts, a private one included, whatever social.x.visibility says", () => { + const priv = { audience: "private" as const }; + assert.equal(postsVisibleTo(priv, LIBRARY_CONFIG as never, {}), false); + assert.equal(postsVisibleTo(priv, LIBRARY_CONFIG as never, { social: { x: { visibility: "public" } } }), false); + // The marker alone decides: a library whose kind was edited by hand is still one. + assert.equal(postsVisibleTo(priv, { ...LIBRARY_CONFIG, sourceKind: "video" } as never, {}), false); + assert.equal(postsVisibleTo(priv, { sourceKind: "social", platform: "twitter" } as never, {}), true); +}); + +test("composing an article that cites a library post is refused, and nothing of the post is published", async () => { + writeJson(path.join(articleDir(paths, "art-lib"), "report.json"), { + format: "archilyzer-report", + version: 1, + id: "art-lib", + kind: "sweep", + title: "Article citing a library", + sections: [{ id: "s1", title: "What was said", body: "It was said: [p01](cite:p01)." }], + citations: { p01: { kind: "post", channel: LIB, id: LIB_ID, quote: "a trending post" } }, + }); + await setPublished("art-lib", true, {}, paths); + for (const audience of ["private", "public"] as const) { + const host = await articlesReportHost(paths, { audience, published: ["art-lib"] }); + await assert.rejects(composeHostReports({ paths, host, publicDir: OUT, settings: {}, log: () => {} }), (e: unknown) => { + assert.ok(e instanceof ComposeReportsError, String(e)); + assert.deepEqual( + e.problems.map((p) => [p.kind, p.citation, p.message]), + [["not-in-site", "art-lib#p01", X_TRENDING_NOT_CITABLE(LIB)]], + ); + return true; + }); + } + for (const dir of [OUT, paths.exportPublicDir]) { + for (const f of filesUnder(dir)) { + assert.ok(!f.text.includes(MARK) && !f.text.includes(HANDLE), `${f.rel} holds the library's post`); + } + } +}); + +test("a draft's X URL never resolves to a library, and a library's post is not read as a record", async () => { + const channelOf = diskPostChannelOf(paths.channelsDir); + // Only the library holds it: unresolved. + assert.equal(await channelOf({ platform: "x", id: LIB_ID, handle: HANDLE }), null); + // The library and an account channel hold it: the account's, never the library's. + assert.equal(await channelOf({ platform: "x", id: SHARED_ID, handle: "kettle_org" }), ACCOUNT); + assert.equal(await channelOf({ platform: "x", id: SHARED_ID, handle: "trending" }), ACCOUNT); + const postOf = diskPostOf(paths.channelsDir); + assert.equal(await postOf(LIB, LIB_ID), null); + assert.ok(await postOf(ACCOUNT, SHARED_ID)); +}); + +test("a research run is never shown a library among the editor's channels", async () => { + const channels = await editorChannelsOf(paths); + assert.deepEqual(channels.map((c) => c.slug), [ACCOUNT]); +}); diff --git a/editor/app/api/ops/read-x-trending/route.test.ts b/editor/app/api/ops/read-x-trending/route.test.ts @@ -25,7 +25,7 @@ const TREND = "https://x.com/i/trending/1900000000000000001"; async function channel(slug: string, config: Record<string, unknown>): Promise<string> { const dir = path.join(ROOT, "channels", slug); - await mkdir(path.join(dir, "posts"), { recursive: true }); + await mkdir(path.join(dir, "trending", "posts"), { recursive: true }); await writeFile(path.join(dir, "config.json"), JSON.stringify({ handling: "transcribe", name: slug, ...config })); return dir; } @@ -33,7 +33,7 @@ async function channel(slug: string, config: Record<string, unknown>): Promise<s const lib = await channel("trending", { sourceKind: "social", platform: "twitter", xTrending: {} }); await channel("account-x", { sourceKind: "social", platform: "twitter", postFetcher: "x-gallery-dl", socialHandle: "example", url: "https://x.com/example" }); await writeFile( - path.join(lib, "posts", "2026-11.jsonl"), + path.join(lib, "trending", "posts", "2026-11.jsonl"), ["1900000000000001001", "1900000000000001002"] .map((id, i) => JSON.stringify({ @@ -53,7 +53,7 @@ await writeFile( ) .join("\n") + "\n", ); -await writeFile(path.join(lib, "posts-archive"), "twitter 1900000000000001001\ntwitter 1900000000000001002\n"); +await writeFile(path.join(lib, "trending", "posts-archive"), "twitter 1900000000000001001\ntwitter 1900000000000001002\n"); await mkdir(path.join(lib, "trending", "reads", READ), { recursive: true }); await writeFile(path.join(lib, "trending", "reads", READ, "responses.jsonl"), JSON.stringify({ n: 1, op: "Op", status: 200, bytes: 9, url: "u", at: "x", body: { secret: "rawcapturemarker" } }) + "\n"); await writeFile( diff --git a/editor/e2e/x-trending.spec.ts b/editor/e2e/x-trending.spec.ts @@ -29,7 +29,8 @@ const rel = (p: string) => `${testPaths().transcriptsDir}/${p}`; type Config = { platform?: string; sourceKind?: string; url?: string; socialHandle?: string; postFetcher?: string; xTrending?: Record<string, number> }; const archiveLines = async (): Promise<number> => { - const file = rel(`channels/${SLUG}/posts-archive`); + // A library keeps its posts under trending/, not where a posts channel does. + const file = rel(`channels/${SLUG}/trending/posts-archive`); return (await pathExists(file)) ? (await readFile(resolvePath(file), "utf8")).split("\n").filter(Boolean).length : 0; }; @@ -165,4 +166,7 @@ test("an X trending library: the form, one read, the library by topic, the listi expect(((await stale.json()) as { error: string }).error).toMatch(/^X cookies were last refreshed 2 h ago \(limit 60 min\)/); expect((await readdir(readsDir)).length).toBe(1); expect(await archiveLines()).toBe(4); + // Where every other reader of a posts channel looks, the library has nothing. + expect(await pathExists(rel(`channels/${SLUG}/posts`))).toBe(false); + expect(await pathExists(rel(`channels/${SLUG}/posts-archive`))).toBe(false); }); diff --git a/mcp/src/xTrendingPrivacy.test.ts b/mcp/src/xTrendingPrivacy.test.ts @@ -41,7 +41,7 @@ const { getPaths } = await import("yt-dlp-transcript-common/lib/paths"); const { buildIndex } = await import("yt-dlp-transcript-common/controller/buildIndex"); const { main: composeSite } = await import("yt-dlp-transcript-common/bin/compose-site"); const { writePosts } = await import("yt-dlp-transcript-common/lib/posts-server"); -const { recordXTrendingRead, trendingReadDir } = await import("yt-dlp-transcript-common/lib/xTrending/store"); +const { recordXTrendingRead, writeXTrendingPosts, trendingReadDir } = await import("yt-dlp-transcript-common/lib/xTrending/store"); const { createCorpusTools } = await import("./callTool"); const paths = getPaths(); @@ -83,7 +83,11 @@ const libRoot = path.join(paths.channelsDir, LIB); writeJson(path.join(libRoot, "config.json"), { handling: "transcribe", sourceKind: "social", platform: "twitter", name: "Trending", xTrending: {}, }); -await writePosts(libRoot, [post(LIB, LIB_ID, MARKS[1], `kettles ${MARKS[0]}`)]); +const libPosts = [post(LIB, LIB_ID, MARKS[1], `kettles ${MARKS[0]}`)]; +// Where a library keeps them, AND where an ordinary posts channel would (a +// hand copy): neither may reach a build. +await writeXTrendingPosts(libRoot, libPosts); +await writePosts(libRoot, libPosts); await recordXTrendingRead(libRoot, { readId: READ, at: "2026-11-17T10:00:00.000Z", diff --git a/umtool/lib/report/xTrendingLibrary.test.mjs b/umtool/lib/report/xTrendingLibrary.test.mjs @@ -0,0 +1,43 @@ +// AN X TRENDING LIBRARY IS NOT OFFERED TO A VIDEO PROJECT (lane x-trending, +// review 1). umtool reads a posts channel's archive straight off the corpus +// (`channels/<slug>/posts/*.jsonl`: the post search, Add posts, the reels). A +// library keeps its posts one directory down, `channels/<lib>/trending/posts/` +// (common/lib/xTrending/store.ts xTrendingPostsRoot), so none of those readers +// finds a library or its posts until the Posts library page (slice 3) reads +// it on purpose. Pinned here over a temp corpus, laid out as the editor's +// store writes it; invented ids, handles and words. +// +// Run with: pnpm test:scripts +import assert from "node:assert/strict"; +import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import test from "node:test"; +import { postChannels, searchPostArchive } from "./postCards.mjs"; +import { readPostsArchive } from "./postReel.mjs"; + +const row = (slug, id, author, text) => ({ id, slug: `${slug}/${id}`, channelSlug: slug, author, createdAt: "2026-11-16T12:00:00.000Z", uploadDate: "20261116", text, url: `https://x.com/${author}/status/${id}`, platform: "twitter", isReply: false, isRepost: false, links: [] }); + +test("the post search, the channels offered and the reels' archive reader find nothing of a library", async () => { + const channels = await mkdtemp(path.join(tmpdir(), "umtool-x-trending-")); + try { + // An ordinary X account channel (the control) and a library. + await mkdir(path.join(channels, "kettle-org-x", "posts"), { recursive: true }); + await writeFile(path.join(channels, "kettle-org-x", "config.json"), JSON.stringify({ handling: "transcribe", sourceKind: "social", platform: "twitter", url: "https://x.com/kettle_org" })); + await writeFile(path.join(channels, "kettle-org-x", "posts", "2026-11.jsonl"), JSON.stringify(row("kettle-org-x", "1900000000000005001", "kettle_org", "an ordinary post about kettles")) + "\n"); + await mkdir(path.join(channels, "trending-lib", "trending", "posts"), { recursive: true }); + await writeFile(path.join(channels, "trending-lib", "config.json"), JSON.stringify({ handling: "transcribe", sourceKind: "social", platform: "twitter", xTrending: {} })); + await writeFile(path.join(channels, "trending-lib", "trending", "posts", "2026-11.jsonl"), JSON.stringify(row("trending-lib", "1900000000000006001", "trend_author", "kettles trendmarkerq7x")) + "\n"); + await writeFile(path.join(channels, "trending-lib", "trending", "posts-archive"), "twitter 1900000000000006001\n"); + + assert.deepEqual((await postChannels(channels, null)).map((c) => c.slug), ["kettle-org-x"]); + const control = await searchPostArchive(channels, "kettle-org-x", "kettles"); + assert.equal(control.total, 1); + assert.deepEqual(await searchPostArchive(channels, "trending-lib", "kettles"), { slug: "trending-lib", archive: false, hits: [], total: 0 }); + assert.deepEqual(await searchPostArchive(channels, "trending-lib", ""), { slug: "trending-lib", archive: false, hits: [], total: 0 }); + assert.equal((await readPostsArchive(channels, "kettle-org-x")).length, 1); + assert.deepEqual(await readPostsArchive(channels, "trending-lib"), []); + } finally { + await rm(channels, { recursive: true, force: true }); + } +});