Archilyzer · Source

archilyzer

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

commit 9f5a2912e712065b54f570be6aea1b52911ceee9
parent be101061b60b285cd13d0178ee8d4edc60e2ea98
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 18 Nov 2026 23:08:23 -0500

x-trending: review 3 S7/S8 -- the opening tab is the one named Top; after the page changed, only the trend's own timelines are read

S7: the tab a sighting with no tab belongs to is the source's tab named Top,
wherever the page's answer lists it, else its first tab.

S8: the parser's filter is by operation only (every listing answer not in
X_TRENDING_IGNORED_OPS is the page's), so after a press took the page
elsewhere another page's timeline was read as the topic's. With
pageTabsOnly -- set by the controller when a tab of the read (or, on a
reparse, of its record) was not read because the page changed -- only the
timelines the trend answer names as its tabs are read; the other answers
stay counted in the capture, unread.

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

Diffstat:
Mcommon/controller/readXTrending.test.ts | 27+++++++++++++++++++++++++++
Mcommon/controller/readXTrending.ts | 8+++++++-
Mcommon/lib/xTrending/store.test.ts | 45+++++++++++++++++++++++++++++++++++++++++++++
Mcommon/lib/xTrending/store.ts | 9++++++---
Mcommon/social/xTrendingParse.test.ts | 31+++++++++++++++++++++++++++++++
Mcommon/social/xTrendingParse.ts | 23++++++++++++++++++++++-
Mcommon/social/xTrendingRead.ts | 7++++++-
7 files changed, 144 insertions(+), 6 deletions(-)

diff --git a/common/controller/readXTrending.test.ts b/common/controller/readXTrending.test.ts @@ -929,3 +929,30 @@ test("S2: a deadline during Latest keeps Top's result — \"Top read; Latest sto assert.equal(result.posts.onPage, 5); // An ending of "read" is what the watch counts no strike for (xTrendingWatch.ts noteXTrendingWatchRead). }); + +// Review 3 S8: after the press took the page elsewhere, the answers the +// other page sent (its own timelines) are kept in the capture and never +// ingested as this topic's — on the read and on a reparse alike. +test("review 3 S8: after the page changed, an answer for any other timeline is kept in the capture and not ingested", async () => { + const away = fixtureTwoTabResponses(); + away.tabs.Latest.navigatesTo = "https://x.com/explore"; + const STRAY = "1900000000000003991"; + const strayUrl = `https://x.com/i/api/graphql/q/${FIXTURE_TIMELINE_OP}?variables=${encodeURIComponent(JSON.stringify({ timelineId: "fixture-timeline-elsewhere", count: 20 }))}`; + away.tabs.Latest.load = [{ url: strayUrl, status: 200, body: fixtureTimelineBody([{ id: STRAY, handle: "elsewhere", text: "A post of the page the press went to." }]) }]; + const paths = corpus("s8-elsewhere"); + const { result } = await run(paths, away, { tabs: ["top", "latest"], topic: "Kettle Festival" }); + assert.equal(result.outcome, "read"); + assert.match(result.sentence, / Top read; Latest not read: the page changed\.$/); + assert.deepEqual(result.posts, { onPage: 4, added: 4 }, "Top's four, not the other page's post"); + assert.ok(!(await readXTrendingPosts(root(paths))).some((p) => p.id === STRAY)); + // It is in the capture all the same. + const capture = readFileSync(path.join(root(paths), "trending", "reads", READ_1, "responses.jsonl"), "utf8"); + assert.ok(capture.includes(STRAY)); + // A reparse of the same read reads the record's tabs and does the same. + const planned = await planReadXTrending(paths, { slug: "trending", reparse: READ_1 }); + assert.ok(planned.ok && planned.plan.mode === "reparse"); + const reparsed = await reparseXTrendingRead({ plan: planned.plan as never }); + assert.equal(reparsed.ok, true); + assert.equal(reparsed.posts.onPage, 4); + assert.ok(!(await readXTrendingPosts(root(paths))).some((p) => p.id === STRAY)); +}); diff --git a/common/controller/readXTrending.ts b/common/controller/readXTrending.ts @@ -80,6 +80,7 @@ import { parseTrendingCapture, readCaptureLines } from "../social/xTrendingParse import { openXTrendingPage, readXTrendingPage, + TRENDING_PAGE_CHANGED, TRENDING_TAB_ASKS, type TrendingPageRead, type TrendingPageSession, @@ -426,7 +427,12 @@ async function ingestCapture(o: { }): Promise<Ingested> { const file = path.join(trendingReadDir(o.channelRoot, o.readId), TRENDING_RESPONSES_FILENAME); const lines = await readCaptureLines(file).catch(() => []); - const whole = parseTrendingCapture(lines, o.slug); + // THE PAGE CHANGED (a press took it elsewhere): only the trend answer's own + // timelines are the page's (review 3 S8) — whatever the other page sent + // stays in the capture, unread. Said by the reader's tabs, or by the + // record's on a reparse. + const pageChanged = [...(o.pageTabs ?? []), ...(o.recordedTabs ?? [])].some((t) => t.why === TRENDING_PAGE_CHANGED); + const whole = parseTrendingCapture(lines, o.slug, pageChanged ? { pageTabsOnly: true } : {}); // A TAB THE READ SAYS WAS NOT READ gives the library nothing (review 2 // S1): answers for its timeline that came in before the read stopped — a // press that took the page elsewhere — stay in the capture, unread. A post diff --git a/common/lib/xTrending/store.test.ts b/common/lib/xTrending/store.test.ts @@ -907,3 +907,48 @@ test("R-d: gone from the PAGE needs every tab that showed the post to drop it IN const fifth = await read(5, ["622"], [], { top: true, latest: true }); assert.deepEqual([fifth.gone, fifth.goneFromTab], [[], [{ id: "622", tab: "Latest" }]]); }); + +test("review 3 S7: the opening tab is the one named Top, wherever the page's answer lists it; else the first", async () => { + const dir = root("s7-opening"); + const at = (h: number) => `2026-11-17T${String(h).padStart(2, "0")}:00:00.000Z`; + await writeXTrendingPosts(dir, ["621", "622"].map((p) => post(p, "a", `post ${p}`))); + // A read from before tabs: its sightings name none (the page opened on Top). + await recordXTrendingRead(dir, { readId: READ_A, at: at(9), ref: REF, topic: "T", postIds: ["621", "622"], added: 2 }); + // The page's answer lists Latest FIRST. Top stopped at its cap; Latest read to its end; neither shows 621. + const latestFirst = { ...PAGE, tabs: [PAGE.tabs[1], PAGE.tabs[0]] }; + const r = await recordXTrendingRead(dir, { + readId: READ_B, + at: at(10), + ref: REF, + topic: "T", + page: latestFirst, + postIds: ["622"], + added: 0, + tabReads: [ + { tab: "Top", timelineId: "tl-top", postIds: ["622"] }, + { tab: "Latest", timelineId: "tl-latest", postIds: [], complete: true }, + ], + }); + assert.deepEqual(r.gone, [], "Latest is not the opening tab because it is listed first"); + const members = await readXTrendingMembership(dir); + assert.equal(members["621"].goneTabs, undefined); + // A page whose tabs name no Top: its first tab opens. + const dir2 = root("s7-first"); + await writeXTrendingPosts(dir2, ["631", "632"].map((p) => post(p, "a", `post ${p}`))); + await recordXTrendingRead(dir2, { readId: READ_A, at: at(9), ref: REF, topic: "T", postIds: ["631", "632"], added: 2 }); + const other = { ...PAGE, tabs: [{ label: "For you", timelineId: "tl-a" }, { label: "Newest", timelineId: "tl-b" }] }; + const r2 = await recordXTrendingRead(dir2, { + readId: READ_B, + at: at(10), + ref: REF, + topic: "T", + page: other, + postIds: ["632"], + added: 0, + tabReads: [ + { tab: "For you", timelineId: "tl-a", postIds: ["632"], complete: true }, + { tab: "Newest", timelineId: "tl-b", postIds: [] }, + ], + }); + assert.deepEqual(r2.gone, ["631"]); +}); diff --git a/common/lib/xTrending/store.ts b/common/lib/xTrending/store.ts @@ -773,9 +773,12 @@ export async function recordXTrendingRead(channelRoot: string, input: RecordRead } await writeJsonAtomic(topicsPath(channelRoot), { version: 1, topics } satisfies TopicsFile, { mkdir: true }); // THE TAB THE PAGE OPENS ON (the reader reads it first, as "Top"): the - // source's first known tab, else a tab of that name. A sighting that - // names no tab was this tab's (review 2 M2). - const openingTab = source.tabs?.[0]?.label ?? tabReads.find((t) => t.tab?.trim().toLowerCase() === "top")?.tab; + // source's tab NAMED Top, wherever the page's answer lists it (review 3 + // S7), else its first known tab, else a tab of that name in this read. A + // sighting that names no tab was this tab's (review 2 M2). + const isTop = (label: string | undefined) => label?.trim().toLowerCase() === "top"; + const openingTab = + source.tabs?.find((t) => isTop(t.label))?.label ?? source.tabs?.[0]?.label ?? tabReads.find((t) => isTop(t.tab))?.tab; return { id: found.id, title: found.title, created, ...(renamed ? { renamed } : {}), tabReads, tabLabels, openingTab }; }); const counts = await withJsonFileLock(membershipPath(channelRoot), async () => { diff --git a/common/social/xTrendingParse.test.ts b/common/social/xTrendingParse.test.ts @@ -358,3 +358,34 @@ test("the real shape: two tabs in one capture show no end, and each post is the const crossed = [real.realFirstPage(real.INVENTED_FIRST), real.realContinuation([], { ...latest, asked: real.realBottomCursor(1) })]; assert.equal(parseTrendingCapture(linesOf(crossed), "lib").pageEnd, false); }); + +// Review 3 S8: THE PARSER'S OP FILTER. Every answer of an operation not in +// X_TRENDING_IGNORED_OPS that lists posts is the page's — so after a press +// took the page elsewhere, another page's timeline would be read as this +// topic's. `pageTabsOnly` (the controller sets it when a tab was abandoned, +// "the page changed") ingests only the timelines the trend answer names as +// its own tabs; the other answers stay counted in the capture, unread. +test("review 3 S8: after the page changed, only the trend answer's own timelines are ingested; the others stay in the capture", async () => { + const real = await import("./__fixtures__/xTrendingRealShape"); + const stray: typeof real.INVENTED_SECOND = [{ id: "1900000000000003901", handle: "elsewhere", text: "A post of another page." }]; + const responses = [ + real.realPageAnswer(), + real.realFirstPage(real.INVENTED_FIRST), + // Another trend's timeline, and a home-like answer naming no timeline. + real.realFirstPage(stray, { timelineId: "VGltZWxpbmU6Zml4dHVyZS1lbHNld2hlcmU=" }), + { ...real.realFirstPage([{ id: "1900000000000003902", handle: "home", text: "A home post." }]), url: "https://x.com/i/api/graphql/abc/HomeLatestTimeline?variables=%7B%22count%22%3A20%7D" }, + ]; + const all = parseTrendingCapture(linesOf(responses), "lib"); + assert.ok(all.posts.some((p) => p.id === "1900000000000003901"), "without the option every listing answer is read (the filter is by operation only)"); + const own = parseTrendingCapture(linesOf(responses), "lib", { pageTabsOnly: true }); + const ids = own.posts.map((p) => p.id); + assert.ok(!ids.includes("1900000000000003901") && !ids.includes("1900000000000003902"), ids.join(",")); + assert.ok(ids.includes(real.INVENTED_FIRST[0].id)); + assert.deepEqual(own.timelines.map((t) => t.timelineId), [real.INVENTED_TOP_TIMELINE]); + // The capture still says what it holds: every answer counted. + assert.equal(own.responses, all.responses); + assert.deepEqual(own.operations.map((o) => [o.op, o.responses]), all.operations.map((o) => [o.op, o.responses])); + // With no trend answer to name the tabs, nothing is the page's own: nothing is ingested. + const none = parseTrendingCapture(linesOf(responses.slice(1)), "lib", { pageTabsOnly: true }); + assert.equal(none.posts.length, 0); +}); diff --git a/common/social/xTrendingParse.ts b/common/social/xTrendingParse.ts @@ -416,10 +416,29 @@ export type ParsedTrendingCapture = { }; // The capture, parsed. `channelSlug` is the library's (a Post names its channel). +// +// WHICH ANSWERS ARE THE PAGE'S: every answer of an operation that is not in +// X_TRENDING_IGNORED_OPS and lists posts. `pageTabsOnly` (review 3 S8; the +// controller sets it when a tab of the read was abandoned because the page +// changed) narrows that to the timelines the trend answer names as its own +// tabs: an answer for any other timeline, or naming none, came from wherever +// the page went, and is counted in the capture (operations, responses, +// bytes) but not read. With no trend answer in the capture, no timeline is +// the page's own and nothing is read. export function parseTrendingCapture( lines: ReadonlyArray<TrendingCaptureLine>, channelSlug: string, + opts: { pageTabsOnly?: boolean } = {}, ): ParsedTrendingCapture { + const own = opts.pageTabsOnly + ? new Set( + (lines + .filter((l) => !X_TRENDING_IGNORED_OPS.includes(l.op) && l.body !== undefined && l.status >= 200 && l.status < 300) + .map((l) => trendPageOf(l.body)) + .find((pg) => pg !== undefined)?.tabs ?? [] + ).map((t) => t.timelineId), + ) + : null; const raws: XTweetRaw[] = []; const media: Record<string, TrendingMediaSummary> = {}; const ops = new Map<string, TrendingOperation>(); @@ -452,9 +471,11 @@ export function parseTrendingCapture( if (Array.isArray(errors) && errors.length > 0) failed = true; // The page itself: the first answer that carries it. page ??= trendPageOf(line.body); + const asked = requestVariablesOf(line.url); + // Not one of the page's own timelines, after the page changed: kept, unread. + if (own && !(asked.timelineId !== undefined && own.has(asked.timelineId))) continue; const found = collectTimelineTweets(line.body); op.tweets += found.length; - const asked = requestVariablesOf(line.url); let fresh = 0; let freshOfTimeline = 0; const key = asked.timelineId ?? ""; diff --git a/common/social/xTrendingRead.ts b/common/social/xTrendingRead.ts @@ -101,6 +101,11 @@ export const READ_DEADLINE_MS = readDeadlineMs({ scrolls: 20 }, 1); // the page opens on, then the other. export type TrendingTabAsk = "top" | "latest"; export const TRENDING_TAB_ASKS: readonly TrendingTabAsk[] = ["top", "latest"]; +// WHY A TAB WAS NOT READ when the press took the page off the trending page +// (review 2 S1). Said in read.json; the controller reads it to ingest only the +// page's own timelines from such a read (review 3 S8). +export const TRENDING_PAGE_CHANGED = "the page changed"; + export const TRENDING_TAB_LABEL: Readonly<Record<TrendingTabAsk, string>> = { top: "Top", latest: "Latest" }; // One tab of a read: what was asked, the page's own label and timeline for it @@ -562,7 +567,7 @@ export async function readXTrendingPage(o: { if (pressed) { const href = await bounded("reading its address", page.evaluate("location.href"), t.call, signal).catch(() => null); if (!sameTrendingPage(href, o.url)) { - second.why = "the page changed"; + second.why = TRENDING_PAGE_CHANGED; abandoned = true; pressed = false; log(`After pressing "${label}" the page is no longer the trending page${typeof href === "string" ? ` (${safePath(href)})` : ""}: the read stops here.`);