// 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//posts/*.jsonl`: the post search, Add posts, the reels). A // library keeps its posts one directory down, `channels//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"; import { findPostRow } from "./postsCli.mjs"; import { statusResolver } from "./postContext.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"); // Lane x-trending-2: the library's post is kept, captured and watched — // a judgement, a capture record, a shot, a media file, the store, a watch. const lib = path.join(channels, "trending-lib", "trending"); await mkdir(path.join(lib, "posts-media", "1900000000000006001"), { recursive: true }); await mkdir(path.join(lib, "media-store", "ab"), { recursive: true }); await writeFile(path.join(lib, "posts-media", "1900000000000006001", "shot.png"), "shot trendshotmarkert6b"); await writeFile(path.join(lib, "posts-media", "1900000000000006001", "1900000000000006001_1.jpg"), "picture trendmediamarkerk8d"); await writeFile(path.join(lib, "posts-media", "1900000000000006001", "capture.json"), JSON.stringify({ version: 1, id: "1900000000000006001", state: "captured", mediaState: "ok", media: [] })); await writeFile(path.join(lib, "media-store", "ab", `${"ab".repeat(32)}.jpg`), "picture trendmediamarkerk8d"); await writeFile(path.join(lib, "media-index.json"), JSON.stringify({ version: 1, blobs: {}, oversize: {} })); await writeFile(path.join(lib, "judgements.json"), JSON.stringify({ version: 1, posts: { "1900000000000006001": { state: "keep", note: "kept trendnotemarkerh3v", by: "operator", at: "2026-11-18T10:00:00.000Z" } }, threads: {} })); await writeFile(path.join(lib, "watch.json"), JSON.stringify({ version: 1, topics: {} })); 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"), []); // Nothing any of them answered carries the kept post, its note or its media. const answered = JSON.stringify([ await postChannels(channels, null), await searchPostArchive(channels, "trending-lib", "kettles"), await searchPostArchive(channels, "trending-lib", "trendnotemarkerh3v"), await readPostsArchive(channels, "trending-lib"), ]); for (const leak of ["trendnotemarkerh3v", "trendmediamarkerk8d", "trendshotmarkert6b", "posts-media", "media-store", "judgements", "1900000000000006001"]) { assert.ok(!answered.includes(leak), `a reader answered with ${leak}`); } } finally { await rm(channels, { recursive: true, force: true }); } }); // Review 2 N8b: BY NAME, not only by layout. A marker-carrying library whose // posts sit where an ordinary posts channel keeps them (a hand copy, a library // from before the move) is still not offered: each reader asks the marker. test("a library with posts in the ordinary place is refused by its marker: not offered, not searched, not read into a reel", async () => { const channels = await mkdtemp(path.join(tmpdir(), "umtool-x-trending-legacy-")); try { 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, "old-lib", "posts"), { recursive: true }); // The marker alone makes it a library, whatever its kind says. await writeFile(path.join(channels, "old-lib", "config.json"), JSON.stringify({ handling: "transcribe", sourceKind: "video", platform: "twitter", xTrending: {} })); await writeFile(path.join(channels, "old-lib", "posts", "2026-11.jsonl"), JSON.stringify(row("old-lib", "1900000000000006001", "trend_author", "kettles trendmarkerq7x")) + "\n"); assert.deepEqual((await postChannels(channels, null)).map((c) => c.slug), ["kettle-org-x"]); assert.deepEqual(await searchPostArchive(channels, "old-lib", "kettles"), { slug: "old-lib", archive: false, hits: [], total: 0 }); assert.deepEqual(await readPostsArchive(channels, "old-lib"), []); assert.equal((await searchPostArchive(channels, "kettle-org-x", "kettles")).total, 1); assert.equal((await readPostsArchive(channels, "kettle-org-x")).length, 1); // `posts add` and a link's resolver find nothing in it either. assert.deepEqual(await findPostRow(channels, "old-lib", "1900000000000006001"), { row: null, shard: null, shards: 0 }); assert.equal((await findPostRow(channels, "kettle-org-x", "1900000000000005001")).row?.author, "kettle_org"); const resolve = statusResolver(channels); assert.equal(await resolve({ handle: "trend_author", id: "1900000000000006001" }), null); assert.ok(await resolve({ handle: "kettle_org", id: "1900000000000005001" })); } finally { await rm(channels, { recursive: true, force: true }); } }); // Lane posts-library (slice 3): the Posts library page reads a library ON // PURPOSE, through the editor, and serves its captured media from one route. // It is still no way into a project, a report, an article, the post archive or // a site: nothing of it imports a writer of those, and the media route is the // one reader of the corpus that REQUIRES the marker. import { readdir, readFile as readSource } from "node:fs/promises"; import { fileURLToPath } from "node:url"; import { resolveLibraryMedia } from "../library/media.mjs"; const UMTOOL = fileURLToPath(new URL("../../", import.meta.url)); async function sourcesUnder(rel) { const out = []; const walk = async (dir) => { for (const e of await readdir(dir, { withFileTypes: true }).catch(() => [])) { const p = path.join(dir, e.name); if (e.isDirectory()) await walk(p); else if (/\.(ts|tsx|mjs)$/.test(e.name) && !e.name.includes(".test.")) out.push({ rel: path.relative(UMTOOL, p), text: await readSource(p, "utf8") }); } }; await walk(path.join(UMTOOL, rel)); return out; } test("posts-library: nothing of the page, its routes or its CLI imports a way into a project, a report, an article, the post archive or a site", async () => { const files = (await Promise.all(["lib/library", "app/tools/library", "app/api/library", "components/tools/library"].map(sourcesUnder))).flat(); assert.ok(files.length >= 14, `the Posts library's sources were read (${files.length})`); const WAYS_OUT = [ "addPostFromArchive", "postsCli", "postCards", "postReel", "postContext", "timelineCli", "timelineApi", "report/chain", "report/manifest", "lib/projects", "@/lib/articles/sites", "publish", "report-draft", "build-deploy", "capture-posts", "create-channel", "writeManifest", ]; for (const f of files) { const imports = [...f.text.matchAll(/from\s+"([^"]+)"|import\("([^"]+)"\)/g)].map((m) => m[1] ?? m[2]); for (const spec of imports) { for (const way of WAYS_OUT) assert.ok(!spec.includes(way), `${f.rel} imports ${spec}`); } // The editor is asked for the listing and the presses, and nothing else. LANE x-trending-publish ADDS // THREE, and they are the only ways out of a library there are: organising its topics (inside the // library), PUBLISHING A TOPIC (the editor's publish-trending: the operator's, in two steps, into an // ordinary channel on no site) and archiving an ACCOUNT (the editor's x-search-lead: `-x` on no // site, nothing of the library in it). Still no way into a project, a report, an article, the post // archive or a site: a site carries the PUBLISHED channel, by the operator's separate act in the editor. const EDITOR_ROUTES = [ "/api/ops/trending", "/api/ops/judge-trending", "/api/ops/watch-trending", "/api/ops/purge-trending", "/api/ops/organise-trending", "/api/ops/publish-trending", "/api/ops/x-search-lead", ]; for (const m of f.text.matchAll(/["'`](\/api\/ops\/[a-z-]+)/g)) { assert.ok(EDITOR_ROUTES.includes(m[1]), `${f.rel} asks the editor for ${m[1]}`); } // The lead action is asked for "archive" only, and a site is never named to the editor from here. if (f.text.includes("/api/ops/x-search-lead")) assert.ok(/action: "archive"/.test(f.text) && !/action: "(never|restore)"/.test(f.text), `${f.rel} asks the lead action for more than archive`); assert.ok(!/siteMemberships|site-config|\/api\/ops\/sites|create-site/.test(f.text), `${f.rel} names a site to the editor`); // No request of X or of any outside host is built here. assert.ok(!/fetch\(\s*["'`]https?:\/\//.test(f.text), `${f.rel} fetches an outside address`); // The corpus is never written from here. if (!f.rel.endsWith("seen.mjs")) assert.ok(!/\b(writeFile|rename|rm|unlink|mkdir|appendFile|copyFile|symlink|link)\(/.test(f.text), `${f.rel} writes a file`); } // Mark seen writes umtool's own state, under the reports root's .umtool/, and nowhere in the corpus. const seen = files.find((f) => f.rel.endsWith("seen.mjs")); assert.match(seen.text, /reportsRoot, "\.umtool", "posts-library\.json"/); assert.ok(!/channels|trending\//.test(seen.text.replace(/^\/\/.*$/gm, ""))); }); test("posts-library: the media route's resolver serves a marked library's captured picture, and refuses the same file of a channel that is no library", async () => { const channels = await mkdtemp(path.join(tmpdir(), "umtool-x-trending-media-")); try { for (const [slug, config] of [["trending-lib", { handling: "transcribe", sourceKind: "social", platform: "twitter", xTrending: {} }], ["kettle-org-x", { handling: "transcribe", sourceKind: "social", platform: "twitter", url: "https://x.com/kettle_org" }]]) { await mkdir(path.join(channels, slug, "trending", "posts-media", "1900000000000006001"), { recursive: true }); await mkdir(path.join(channels, slug, "posts-media", "1900000000000006001"), { recursive: true }); await writeFile(path.join(channels, slug, "config.json"), JSON.stringify(config)); await writeFile(path.join(channels, slug, "trending", "posts-media", "1900000000000006001", "shot.png"), "shot trendshotmarkert6b"); await writeFile(path.join(channels, slug, "trending", "posts-media", "1900000000000006001", "capture.json"), "{}"); await writeFile(path.join(channels, slug, "posts-media", "1900000000000006001", "shot.png"), "an ordinary capture"); } const ask = (lib, name = "shot.png") => resolveLibraryMedia({ channelsDir: channels, lib, id: "1900000000000006001", name }); assert.equal((await ask("trending-lib")).ok, true); assert.deepEqual(await ask("kettle-org-x"), { ok: false, status: 404 }); assert.equal((await ask("trending-lib", "capture.json")).ok, false); // It reaches only trending/posts-media: an ordinary channel's own captures are not its to serve. assert.match((await ask("trending-lib")).abs, /trending[\\/]posts-media[\\/]1900000000000006001[\\/]shot\.png$/); // And the readers a video project uses still find nothing of the library. assert.deepEqual((await postChannels(channels, null)).map((c) => c.slug), []); assert.deepEqual(await readPostsArchive(channels, "trending-lib"), []); } finally { await rm(channels, { recursive: true, force: true }); } });