Archilyzer · Source

archilyzer

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

commit 5aedbbf9c579b329b598776423e1f6cc1ada237d
parent 1675f1124a0430b3217b8dd014d49aa0568127b0
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Tue, 17 Nov 2026 22:51:54 -0500

x-trending review 2 (N8): the refusals behind the host are tested; umtool refuses a library by its marker

N8a: xTrendingReportDoor.test.ts reaches composeReports' and reportMedia's own
refusals (prepare and the window plan) through a host stub that lets the library
through. Seen red with the three guards switched off, then restored.
N8b: the marker predicate lives in common/lib/xTrending/marker.mjs (config.ts
re-exports it), and umtool's readers of a posts archive ask it by name: the post
search, the channels offered, the reels' archive reader, `posts add`'s row finder
and the status resolver. A marker-carrying library whose posts sit in the ordinary
posts/ directory is not offered, searched or read. The test was seen red first.

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

Diffstat:
Mcommon/lib/xTrending/config.ts | 14+++++---------
Acommon/lib/xTrending/marker.d.mts | 3+++
Acommon/lib/xTrending/marker.mjs | 17+++++++++++++++++
Mcommon/package.json | 1+
Mcommon/publish/xTrendingReportDoor.test.ts | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/lib/report/postCards.mjs | 4++++
Mumtool/lib/report/postContext.mjs | 4+++-
Mumtool/lib/report/postReel.mjs | 3+++
Mumtool/lib/report/postsCli.mjs | 3+++
Mumtool/lib/report/xTrendingLibrary.test.mjs | 33+++++++++++++++++++++++++++++++++
Aumtool/lib/report/xTrendingMarker.mjs | 26++++++++++++++++++++++++++
11 files changed, 152 insertions(+), 10 deletions(-)

diff --git a/common/lib/xTrending/config.ts b/common/lib/xTrending/config.ts @@ -11,8 +11,8 @@ // corpus.json, llms.txt or MCP corpus tool carries its posts. The library's // own listing reads its files (store.ts), never the index. // -// Client-safe and a LEAF (no imports): lib/channelConfig.ts composes the -// coercion below, and the channel form imports the URL helper. +// Client-safe, and a leaf but for ./marker.mjs (itself one): lib/channelConfig.ts +// composes the coercion below, and the channel form imports the URL helper. export type XTrendingConfig = { // How many times a read moves to the bottom of the loaded page (each brings @@ -59,13 +59,9 @@ export function coerceXTrendingConfig(v: unknown): XTrendingConfig | undefined { } // 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); -} +// DECIDES (review 1) — ./marker.mjs holds the predicate, plain JavaScript so +// umtool's .mjs readers of the corpus ask the very same question. +export { isXTrendingChannel } from "./marker.mjs"; export const X_TRENDING_NOT_CITABLE = (slug: string) => `"${slug}" is an X trending library: it is private, and a report cannot cite its posts. ` + diff --git a/common/lib/xTrending/marker.d.mts b/common/lib/xTrending/marker.d.mts @@ -0,0 +1,3 @@ +// Types for ./marker.mjs (lane x-trending): the library marker's predicate. + +export function isXTrendingChannel(config: { xTrending?: unknown } | null | undefined): boolean; diff --git a/common/lib/xTrending/marker.mjs b/common/lib/xTrending/marker.mjs @@ -0,0 +1,17 @@ +// THE X TRENDING LIBRARY MARKER, as plain JavaScript (lane x-trending, review +// 2): the one predicate "is this channel config a library's?", importable by +// umtool's .mjs readers of the corpus as well as by common's TypeScript +// (lib/xTrending/config.ts re-exports it). A LEAF: no imports. +// +// THE MARKER ALONE DECIDES: `xTrending` is an object. Not the kind, not the +// platform — a config edit that changed either must not switch a library's +// privacy off while its posts stay. + +/** + * @param {{ xTrending?: unknown } | null | undefined} config + * @returns {boolean} + */ +export function isXTrendingChannel(config) { + const m = config?.xTrending; + return Boolean(m) && typeof m === "object" && !Array.isArray(m); +} diff --git a/common/package.json b/common/package.json @@ -40,6 +40,7 @@ "./lib/clips/segments.mjs": "./lib/clips/segments.mjs", "./lib/clips/suggest.mjs": "./lib/clips/suggest.mjs", "./lib/atomicFile.mjs": "./lib/atomicFile.mjs", + "./lib/xTrending/marker.mjs": "./lib/xTrending/marker.mjs", "./lib/cueWiden.mjs": "./lib/cueWiden.mjs", "./lib/detectPlatform.mjs": "./lib/detectPlatform.mjs", "./lib/platformSeek.mjs": "./lib/platformSeek.mjs", diff --git a/common/publish/xTrendingReportDoor.test.ts b/common/publish/xTrendingReportDoor.test.ts @@ -184,3 +184,57 @@ test("a research run is never shown a library among the editor's channels", asyn const channels = await editorChannelsOf(paths); assert.deepEqual(channels.map((c) => c.slug), [ACCOUNT]); }); + +// --- review 2 N8a: the refusals BEHIND the host's --------------------------- +// +// A host that lets the library through (a stub: the real hosts refuse it +// first) reaches the second line in composeReports and the two in +// reportMedia. Each must refuse by the library's own sentence. + +const { prepareReportMedia, missingEvidenceWindows } = await import("./reportMedia"); + +async function lenientHost(published: string[]) { + const host = await articlesReportHost(paths, { audience: "private", published }); + return { ...host, citableProblem: () => null }; +} + +test("N8a: behind a host that lets it through, compose still refuses a library's post by name", async () => { + const host = await lenientHost(["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-visible", "art-lib#p01", X_TRENDING_NOT_CITABLE(LIB)]], + ); + return true; + }); + for (const f of filesUnder(OUT)) assert.ok(!f.text.includes(MARK) && !f.text.includes(HANDLE), `${f.rel} holds the library's post`); +}); + +test("N8a: behind such a host, preparing media refuses a library's post, and no window of a library is planned", async () => { + const host = await lenientHost(["art-lib"]); + const index = await prepareReportMedia({ paths, host, settings: {} }); + assert.deepEqual( + index.problems.map((p) => [p.kind, p.moment, p.message]), + [["not-visible", `${LIB}/${LIB_ID}`, X_TRENDING_NOT_CITABLE(LIB)]], + ); + assert.deepEqual(Object.keys(index.moments), []); + + // A span cited on a library (a config edited by hand could carry videos). + writeJson(path.join(articleDir(paths, "art-lib-span"), "report.json"), { + format: "archilyzer-report", + version: 1, + id: "art-lib-span", + kind: "sweep", + title: "Article citing a span of a library", + sections: [{ id: "s1", title: "What was said", body: "It was said: [c01](cite:c01)." }], + citations: { c01: { kind: "video", channel: LIB, id: "vid00000001", start: 10, end: 20, quote: "said on a recording" } }, + }); + await setPublished("art-lib-span", true, {}, paths); + const windows = await missingEvidenceWindows(paths, await lenientHost(["art-lib-span"]), { settings: {} as never }); + assert.deepEqual(windows.missing, []); + assert.deepEqual( + windows.unfetchable.map((w) => [w.slug, w.id, w.why, w.message]), + [[LIB, "vid00000001", "not-in-site", X_TRENDING_NOT_CITABLE(LIB)]], + ); +}); diff --git a/umtool/lib/report/postCards.mjs b/umtool/lib/report/postCards.mjs @@ -13,6 +13,7 @@ // The cure is a crop (`shotMaxHeight` on the post) or another post. // // Plain ESM. +import { isTrendingLibrary } from "./xTrendingMarker.mjs"; import { readFile, readdir, stat } from "node:fs/promises"; import path from "node:path"; @@ -64,6 +65,8 @@ const dateOf = (row) => */ export async function searchPostArchive(channelsDir, slug, q, { limit = POST_SEARCH_MAX, manifest = null } = {}) { if (!SLUG_RE.test(slug)) throw new Error(`not a channel slug: ${slug}`); + // An X trending library is private: it has no archive to search here. + if (await isTrendingLibrary(channelsDir, slug)) return { slug, archive: false, hits: [], total: 0 }; const dir = path.join(/* turbopackIgnore: true */ channelsDir, slug, "posts"); const names = (await readdir(dir).catch(() => null))?.filter((n) => /^\d{4}-\d{2}\.jsonl$/.test(n)).sort().reverse() ?? null; if (names === null) return { slug, archive: false, hits: [], total: 0 }; @@ -128,6 +131,7 @@ export async function postChannels(channelsDir, manifest, cited = []) { const have = []; for (const d of dirs) { if (!d.isDirectory() || !SLUG_RE.test(d.name)) continue; + if (await isTrendingLibrary(channelsDir, d.name)) continue; if (await stat(path.join(/* turbopackIgnore: true */ channelsDir, d.name, "posts")).then((s) => s.isDirectory(), () => false)) have.push(d.name); } const used = new Set( diff --git a/umtool/lib/report/postContext.mjs b/umtool/lib/report/postContext.mjs @@ -31,6 +31,7 @@ // archive holds it (read lazily, only for a link), else the capture's. The // same pass snapshots the row's `threadId` as the entry's `conversation` // (post-conversation.mjs reads a conversation by it). +import { isTrendingLibrary } from "./xTrendingMarker.mjs"; import { readFile, readdir, stat } from "node:fs/promises"; import path from "node:path"; import { joinSplitLinks } from "umtool-report-to-video/post-narration"; @@ -163,7 +164,8 @@ export function statusResolver(channelsDir) { if (slugs === null) { const names = await readdir(channelsDir).catch(() => []); slugs = []; - for (const n of names) if (POST_KEY_RE.test(n) && (await stat(path.join(channelsDir, n, "posts")).catch(() => null))?.isDirectory()) slugs.push(n); + // Never an X trending library: a link must not resolve to a private one. + for (const n of names) if (POST_KEY_RE.test(n) && !(await isTrendingLibrary(channelsDir, n)) && (await stat(path.join(channelsDir, n, "posts")).catch(() => null))?.isDirectory()) slugs.push(n); } const h = str(handle).toLowerCase(); const order = [...slugs.filter((s) => h && s.toLowerCase().startsWith(h)), ...slugs.filter((s) => !(h && s.toLowerCase().startsWith(h)))]; diff --git a/umtool/lib/report/postReel.mjs b/umtool/lib/report/postReel.mjs @@ -33,6 +33,7 @@ // checks. // // Plain ESM: the CLI runs it under bare node. +import { isTrendingLibrary } from "./xTrendingMarker.mjs"; import { execFile } from "node:child_process"; import { copyFile, mkdir, readFile, readdir, realpath, stat } from "node:fs/promises"; import path from "node:path"; @@ -71,6 +72,8 @@ const timeOf = (row) => { * wins), each with `channelSlug` set to `slug`. A channel with no archive is []. */ export async function readPostsArchive(channelsDir, slug) { + // An X trending library is private: a reel is never made from one. + if (await isTrendingLibrary(channelsDir, slug)) return []; const dir = path.join(channelsDir, slug, "posts"); const names = (await readdir(dir).catch(() => [])).filter((n) => /^\d{4}-\d{2}\.jsonl$/.test(n)).sort(); const byId = new Map(); diff --git a/umtool/lib/report/postsCli.mjs b/umtool/lib/report/postsCli.mjs @@ -28,6 +28,7 @@ // replaced (its attachTo kept unless --attach says otherwise). // // Plain ESM: the CLI runs under bare node. +import { isTrendingLibrary } from "./xTrendingMarker.mjs"; import { readFileSync } from "node:fs"; import { copyFile, mkdir, readFile, readdir, realpath, stat } from "node:fs/promises"; import path from "node:path"; @@ -222,6 +223,8 @@ export function snowflakeMonth(id) { * line with the id wins (a re-fetch appends). */ export async function findPostRow(channelsDir, slug, postId) { + // An X trending library is private: `posts add` finds no post in one. + if (await isTrendingLibrary(channelsDir, slug)) return { row: null, shard: null, shards: 0 }; const dir = path.join(channelsDir, slug, "posts"); const names = (await readdir(dir).catch(() => [])).filter((n) => /^\d{4}-\d{2}\.jsonl$/.test(n)).sort().reverse(); const first = snowflakeMonth(postId); diff --git a/umtool/lib/report/xTrendingLibrary.test.mjs b/umtool/lib/report/xTrendingLibrary.test.mjs @@ -15,6 +15,8 @@ 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: [] }); @@ -41,3 +43,34 @@ test("the post search, the channels offered and the reels' archive reader find n 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 }); + } +}); + diff --git a/umtool/lib/report/xTrendingMarker.mjs b/umtool/lib/report/xTrendingMarker.mjs @@ -0,0 +1,26 @@ +// IS THIS CHANNEL AN X TRENDING LIBRARY? (lane x-trending, review 2 N8b.) The +// readers of a posts channel's archive in umtool -- the post search, the +// channels offered, Add posts and the reels, the status resolver -- ask it of +// every channel they enumerate or are handed, so a library is refused BY NAME +// (its marker, common/lib/xTrending/marker.mjs isXTrendingChannel), not only +// because its posts are kept one directory down. A library reaches a video +// project through the Posts library page alone, once that exists. +import { readFile } from "node:fs/promises"; +import path from "node:path"; +import { isXTrendingChannel } from "yt-dlp-transcript-common/lib/xTrending/marker.mjs"; + +/** + * True when `channels/<slug>/config.json` carries the library marker. A + * channel with no readable config is not a library. + * @param {string} channelsDir + * @param {string} slug + */ +export async function isTrendingLibrary(channelsDir, slug) { + const text = await readFile(path.join(/* turbopackIgnore: true */ channelsDir, slug, "config.json"), "utf8").catch(() => null); + if (text === null) return false; + try { + return isXTrendingChannel(JSON.parse(text)); + } catch { + return false; + } +}