Archilyzer · Source

archilyzer

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

commit a8a04cb29e622fd5d8bcea3abe4bc7c17abb5b30
parent 116ee814d5d5ca5cd876d6a030773f59255415b3
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Mon,  9 Nov 2026 14:41:14 -0500

channels: account activity -- posts per day and the long silences, each linked to the posts on either side

A posts channel's page (not a Wayback pages channel, not an X search) gets
an activity panel from its stored posts: a compact per-UTC-day bar strip
over the archive's range, its long silences shaded and listed newest first
-- a gap of at least 3x the account's median gap AND 48 h -- each with links
to the post before and the post after, and an open-ended silence since the
last post when the last fetch is that far past it. Only the account's own
posts count when any carry its handle (a with-replies timeline archives
other accounts' posts too). common/lib/accountActivity.ts, pure.

Real data, read-only: ObviousRises-x shows 4 Nov 10:54 -> 8 Nov 19:00 UTC
(4 d 8 h, median gap 13 min); ObviousRises-x-replies 5 Nov 00:36 -> 8 Nov
19:00.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Acommon/lib/accountActivity.test.ts | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Acommon/lib/accountActivity.ts | 182+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aeditor/app/channels/[slug]/components/AccountActivityPanel.tsx | 160+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Meditor/app/channels/[slug]/page.tsx | 14++++++++++++++
Aeditor/e2e/account-activity.spec.ts | 127+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 598 insertions(+), 0 deletions(-)

diff --git a/common/lib/accountActivity.test.ts b/common/lib/accountActivity.test.ts @@ -0,0 +1,115 @@ +// Account activity (lane x-console): posts per day over the archive's range, +// and long silences — ≥ 3× the median gap AND ≥ 48 h — each with the post +// before and after. +// +// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/accountActivity.test.ts + +import test from "node:test"; +import assert from "node:assert/strict"; +import { accountActivity, median, medianText, spanHours } from "./accountActivity"; + +const post = (id: string, createdAt: string, author = "acct", text = `post ${id}`) => ({ + id, + createdAt, + url: `https://x.com/${author}/status/${id}`, + text, + author, +}); + +// A busy account (a post every 15 min on 3–4 Nov), three days of nothing, +// then busy again on 8 Nov — the shape of Mr Obvious's 5–8 Nov 2026 gap. +function busyWithGap() { + const out = []; + let n = 0; + for (const day of ["2026-11-03", "2026-11-04"]) { + for (let m = 0; m < 8 * 60; m += 15) { + const h = String(10 + Math.floor(m / 60)).padStart(2, "0"); + const mm = String(m % 60).padStart(2, "0"); + out.push(post(String(++n), `${day}T${h}:${mm}:00.000Z`)); + } + } + for (let m = 0; m < 4 * 60; m += 15) { + const h = String(19 + Math.floor(m / 60)).padStart(2, "0"); + out.push(post(String(++n), `2026-11-08T${h}:${String(m % 60).padStart(2, "0")}:00.000Z`)); + } + return out; +} + +test("a busy account's three-day gap is one silence, with the posts on either side; nights are not", () => { + const a = accountActivity(busyWithGap())!; + assert.equal(a.medianGapMinutes, 15); + // 3 × 15 min is far below 48 h: the 48 h floor decides. + assert.equal(a.thresholdHours, 48); + assert.equal(a.silences.length, 1); + const s = a.silences[0]; + assert.equal(s.before.createdAt, "2026-11-04T17:45:00.000Z"); + assert.equal(s.after.createdAt, "2026-11-08T19:00:00.000Z"); + assert.equal(s.before.url, `https://x.com/acct/status/${s.before.id}`); + assert.equal(spanHours(s.hours), "4 d 1 h"); + // The overnight gap 3 → 4 Nov (≈ 16 h) is not a silence. + // Days: 3 Nov .. 8 Nov, empty days included. + assert.deepEqual( + a.days.map((d) => [d.day, d.count]), + [["2026-11-03", 32], ["2026-11-04", 32], ["2026-11-05", 0], ["2026-11-06", 0], ["2026-11-07", 0], ["2026-11-08", 16]], + ); + assert.equal(a.maxPerDay, 32); +}); + +test("a sparse account: 3× its median gap decides, so its usual week is not a silence", () => { + // Every 4 days, then a 20-day gap, then every 4 days again. + const days = ["2026-01-01", "2026-01-05", "2026-01-09", "2026-01-13", "2026-02-02", "2026-02-06", "2026-02-10"]; + const a = accountActivity(days.map((d, i) => post(String(i), `${d}T12:00:00.000Z`)))!; + assert.equal(a.medianGapMinutes, 4 * 24 * 60); + assert.equal(a.thresholdHours, 12 * 24); + assert.equal(a.silences.length, 1); + assert.equal(a.silences[0].before.createdAt, "2026-01-13T12:00:00.000Z"); + assert.equal(a.silences[0].ratio, 5); +}); + +test("silences are newest first; a trailing silence runs to the last fetch", () => { + const posts = [ + post("1", "2026-10-01T00:00:00Z"), + post("2", "2026-10-01T00:10:00Z"), + post("3", "2026-10-05T00:00:00Z"), + post("4", "2026-10-05T00:10:00Z"), + post("5", "2026-10-05T00:20:00Z"), + post("6", "2026-10-10T00:00:00Z"), + post("7", "2026-10-10T00:10:00Z"), + ]; + const a = accountActivity(posts, { asOf: "2026-10-14T00:10:00.000Z" })!; + assert.deepEqual(a.silences.map((s) => [s.before.id, s.after.id]), [["5", "6"], ["2", "3"]]); + assert.equal(a.trailing?.since.id, "7"); + assert.equal(spanHours(a.trailing!.hours), "4 d"); + assert.equal(accountActivity(posts, { asOf: "2026-10-11T00:00:00.000Z" })!.trailing, null); +}); + +test("only the account's own posts count when any carry its handle; none, and every post counts", () => { + const posts = [ + post("1", "2026-10-01T00:00:00Z", "Acct"), + post("2", "2026-10-02T00:00:00Z", "someone_else"), + post("3", "2026-10-03T00:00:00Z", "acct"), + ]; + const own = accountActivity(posts, { author: "@acct" })!; + assert.equal(own.posts, 2); + assert.equal(own.author, "acct"); + const all = accountActivity(posts, { author: "nobody" })!; + assert.equal(all.posts, 3); + assert.equal(all.author, null); +}); + +test("fewer than two datable posts: nothing to measure", () => { + assert.equal(accountActivity([]), null); + assert.equal(accountActivity([post("1", "2026-10-01T00:00:00Z"), post("2", "not a date")]), null); +}); + +test("the words", () => { + assert.equal(median([3, 1, 2]), 2); + assert.equal(median([4, 1, 2, 3]), 2.5); + assert.equal(spanHours(0.5), "30 min"); + assert.equal(spanHours(47.6), "48 h"); + assert.equal(spanHours(48), "2 d"); + assert.equal(spanHours(4 * 24 + 8.2), "4 d 8 h"); + assert.equal(spanHours(2 * 24 + 23.8), "3 d"); + assert.equal(medianText(13), "13 min"); + assert.equal(medianText(150), "2.5 h"); +}); diff --git a/common/lib/accountActivity.ts b/common/lib/accountActivity.ts @@ -0,0 +1,182 @@ +// AN ACCOUNT'S ACTIVITY, FROM ITS ARCHIVED POSTS (lane x-console): posts per +// UTC day over the archive's range, and its LONG SILENCES — the gaps between +// two consecutive archived posts that are long for THIS account. +// +// A silence is a gap of at least SILENCE_MEDIAN_FACTOR (3) times the +// account's median gap between consecutive posts AND at least +// SILENCE_MIN_HOURS (48 h). Either rule alone is wrong: a prolific account's +// median is minutes, so "3× the median" alone marks every night's sleep; a +// once-a-week account's normal week would pass "48 h" alone. Together, a busy +// account's silence is anything over two days, and a sparse one's is three of +// its usual gaps. Mr Obvious's 5–8 Nov 2026 gap (the real-data case) is the +// first kind: a median of minutes, and three days of nothing. +// +// IT IS A SILENCE IN THE ARCHIVE, not necessarily on the account: a fetch that +// did not reach a stretch (an older walk not yet run below it, a capped run) +// shows the same hole. The panel says "no archived post", not "the account was +// silent". +// +// Pure and client-safe: the channel page reads the posts (lib/posts-server.ts) +// and hands this the four fields it needs. + +export const SILENCE_MEDIAN_FACTOR = 3; +export const SILENCE_MIN_HOURS = 48; + +export type ActivityPost = { + id: string; + createdAt: string; + url: string; + text?: string; + // The post's author's handle. + author?: string; +}; + +export type ActivityEnd = { + id: string; + createdAt: string; + url: string; + // The post's first line, short (a tooltip). + snippet: string; +}; + +export type ActivitySilence = { + before: ActivityEnd; + after: ActivityEnd; + hours: number; + // The gap over the median gap. + ratio: number; +}; + +export type ActivityDay = { day: string; count: number }; + +export type AccountActivity = { + posts: number; + // The account counted, when only its own posts were (a with-replies + // timeline also archives the posts it answers, by others). + author: string | null; + firstAt: string; + lastAt: string; + // Every UTC day from the first post's to the last's, empty days included. + days: ActivityDay[]; + maxPerDay: number; + medianGapMinutes: number; + // max(SILENCE_MIN_HOURS, SILENCE_MEDIAN_FACTOR × the median gap), hours. + thresholdHours: number; + // Newest first. + silences: ActivitySilence[]; + // No archived post since the last one for at least the threshold, as of + // `asOf` (the last fetch): open-ended, so it has no post after it. + trailing: { since: ActivityEnd; hours: number; asOf: string } | null; +}; + +const HOUR = 3_600_000; +const DAY = 24 * HOUR; + +function snippet(text: string | undefined): string { + const first = (text ?? "").split("\n").find((l) => l.trim()) ?? ""; + const t = first.trim(); + return t.length > 90 ? `${t.slice(0, 89)}…` : t; +} + +function end(p: ActivityPost): ActivityEnd { + return { id: p.id, createdAt: p.createdAt, url: p.url, snippet: snippet(p.text) }; +} + +export function median(values: readonly number[]): number { + if (values.length === 0) return 0; + const s = [...values].sort((a, b) => a - b); + const mid = Math.floor(s.length / 2); + return s.length % 2 ? s[mid] : (s[mid - 1] + s[mid]) / 2; +} + +function utcDay(ms: number): string { + return new Date(ms).toISOString().slice(0, 10); +} + +// null when there are fewer than two datable posts (no gap to measure). +// +// `author` (the channel's handle) counts only the account's own posts when +// any carry it — a with-replies timeline archives the posts it answers too, +// and another account's post is not this one's activity. No post by it (an X +// search channel's many accounts, a forum thread): every post counts. +export function accountActivity( + input: readonly ActivityPost[], + opts: { asOf?: string; minHours?: number; factor?: number; author?: string } = {}, +): AccountActivity | null { + const minHours = opts.minHours ?? SILENCE_MIN_HOURS; + const factor = opts.factor ?? SILENCE_MEDIAN_FACTOR; + const who = opts.author?.replace(/^@/, "").toLowerCase(); + const own = who ? input.filter((p) => p.author?.replace(/^@/, "").toLowerCase() === who) : []; + const author = own.length > 0 ? opts.author!.replace(/^@/, "") : null; + const posts = (own.length > 0 ? own : input) + .map((p) => ({ p, t: Date.parse(p.createdAt) })) + .filter((x) => Number.isFinite(x.t)) + .sort((a, b) => a.t - b.t || a.p.id.localeCompare(b.p.id)); + if (posts.length < 2) return null; + const gaps: number[] = []; + for (let i = 1; i < posts.length; i++) gaps.push(posts[i].t - posts[i - 1].t); + const med = median(gaps); + const thresholdMs = Math.max(minHours * HOUR, factor * med); + const silences: ActivitySilence[] = []; + for (let i = 1; i < posts.length; i++) { + const gap = gaps[i - 1]; + if (gap < thresholdMs) continue; + silences.push({ + before: end(posts[i - 1].p), + after: end(posts[i].p), + hours: gap / HOUR, + ratio: med > 0 ? gap / med : Infinity, + }); + } + silences.reverse(); + // Days, first to last, zeros included. + const counts = new Map<string, number>(); + for (const { t } of posts) { + const d = utcDay(t); + counts.set(d, (counts.get(d) ?? 0) + 1); + } + const first = posts[0].t; + const last = posts[posts.length - 1].t; + const days: ActivityDay[] = []; + let maxPerDay = 0; + for (let t = Date.parse(`${utcDay(first)}T00:00:00Z`); t <= last; t += DAY) { + const day = utcDay(t); + const count = counts.get(day) ?? 0; + if (count > maxPerDay) maxPerDay = count; + days.push({ day, count }); + } + let trailing: AccountActivity["trailing"] = null; + const asOf = opts.asOf ? Date.parse(opts.asOf) : NaN; + if (Number.isFinite(asOf) && asOf - last >= thresholdMs) { + trailing = { since: end(posts[posts.length - 1].p), hours: (asOf - last) / HOUR, asOf: opts.asOf! }; + } + return { + posts: posts.length, + author, + firstAt: posts[0].p.createdAt, + lastAt: posts[posts.length - 1].p.createdAt, + days, + maxPerDay, + medianGapMinutes: med / 60_000, + thresholdHours: thresholdMs / HOUR, + silences, + trailing, + }; +} + +// "2 d 19 h", "52 h" → "2 d 4 h", "50 min". +export function spanHours(hours: number): string { + if (hours < 1) return `${Math.round(hours * 60)} min`; + if (hours < 48) return `${Math.round(hours)} h`; + const d = Math.floor(hours / 24); + const h = Math.round(hours - d * 24); + return h === 24 ? `${d + 1} d` : h > 0 ? `${d} d ${h} h` : `${d} d`; +} + +// "22 min", "3.5 h", "2 d". +export function medianText(minutes: number): string { + if (minutes < 90) return `${Math.max(0, Math.round(minutes))} min`; + const h = minutes / 60; + if (h < 48) return `${Math.round(h * 10) / 10} h`; + return spanHours(h); +} diff --git a/editor/app/channels/[slug]/components/AccountActivityPanel.tsx b/editor/app/channels/[slug]/components/AccountActivityPanel.tsx @@ -0,0 +1,160 @@ +// ACCOUNT ACTIVITY (lane x-console): a posts channel's archived posts per UTC +// day over the archive's range, as a compact bar strip, with its long +// silences shaded — a gap of at least 3× the account's median gap AND 48 h +// (common/lib/accountActivity.ts says why both) — and each silence linked to +// the post before it and the post after. Read from the stored posts; a server +// component, no client code. + +import { + medianText, + spanHours, + type AccountActivity, + type ActivityEnd, +} from "yt-dlp-transcript-common/lib/accountActivity"; + +const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + +// "4 Nov 10:54" (UTC); the year when it is not the strip's last. +function at(iso: string, lastYear: string): string { + const d = new Date(iso); + const y = String(d.getUTCFullYear()); + const hm = iso.slice(11, 16); + return `${d.getUTCDate()} ${MONTHS[d.getUTCMonth()]}${y === lastYear ? "" : ` ${y}`} ${hm}`; +} + +function dayText(day: string): string { + return `${Number(day.slice(8, 10))} ${MONTHS[Number(day.slice(5, 7)) - 1]} ${day.slice(0, 4)}`; +} + +const SHOWN_SILENCES = 12; +const H = 40; + +function PostLink({ end, label }: { end: ActivityEnd; label: string }) { + return ( + <a + href={end.url} + target="_blank" + rel="noreferrer" + title={end.snippet || undefined} + className="underline underline-offset-2 hover:text-foreground" + > + {label} + </a> + ); +} + +export function AccountActivityPanel({ activity }: { activity: AccountActivity }) { + const { days, maxPerDay, silences } = activity; + const n = days.length; + const index = new Map(days.map((d, i) => [d.day, i])); + const lastYear = activity.lastAt.slice(0, 4); + const barW = n <= 120 ? 0.8 : 1; + // Month starts, at most ~12 labels. + const starts = days.flatMap((d, i) => (d.day.endsWith("-01") || i === 0 ? [i] : [])); + const step = Math.max(1, Math.ceil(starts.length / 12)); + // A label too near the right edge would run off it. + const ticks = starts.filter((i, k) => k % step === 0 && (i === 0 || i / n < 0.92)); + const silenceDays = (s: { before: ActivityEnd; after: ActivityEnd }) => { + const a = index.get(s.before.createdAt.slice(0, 10)) ?? 0; + const b = index.get(s.after.createdAt.slice(0, 10)) ?? n - 1; + return { x: a, w: Math.max(1, b - a + 1) }; + }; + return ( + <section aria-label="account activity" className="rounded-lg border border-border bg-card p-4 flex flex-col gap-3"> + <div className="flex items-baseline gap-x-3 gap-y-1 flex-wrap"> + <h2 className="text-sm font-medium">{activity.author ? "Account activity" : "Activity"}</h2> + <p aria-label="account activity summary" className="text-xs text-muted-foreground"> + {activity.posts.toLocaleString("en-US")} posts{activity.author ? ` by @${activity.author}` : ""} ·{" "} + {dayText(days[0].day)} – {dayText(days[n - 1].day)} · median gap {medianText(activity.medianGapMinutes)} · + busiest day {maxPerDay} · UTC + </p> + </div> + <div className="flex flex-col gap-1"> + <svg + role="img" + aria-label="posts per day" + viewBox={`0 0 ${n} ${H}`} + preserveAspectRatio="none" + className="w-full h-14 block" + > + {silences.map((s) => { + const { x, w } = silenceDays(s); + return ( + <rect key={`s-${s.before.id}`} x={x} y={0} width={w} height={H} className="fill-warning-soft" data-silence=""> + <title>{`No archived post for ${spanHours(s.hours)}`}</title> + </rect> + ); + })} + <rect x={0} y={H - 0.5} width={n} height={0.5} className="fill-border" /> + {days.map((d, i) => + d.count > 0 ? ( + <rect + key={d.day} + x={i + (1 - barW) / 2} + y={H - Math.max(1.5, (d.count / maxPerDay) * (H - 2))} + width={barW} + height={Math.max(1.5, (d.count / maxPerDay) * (H - 2))} + className="fill-info" + > + <title>{`${d.day}: ${d.count} post${d.count === 1 ? "" : "s"}`}</title> + </rect> + ) : null, + )} + </svg> + <div className="relative h-4 text-[11px] text-muted-foreground" aria-hidden="true"> + {ticks.map((i) => ( + <span + key={days[i].day} + className="absolute whitespace-nowrap" + style={{ left: `${(i / n) * 100}%` }} + > + {i === 0 ? dayText(days[i].day).replace(/ \d{4}$/, "") : MONTHS[Number(days[i].day.slice(5, 7)) - 1]} + </span> + ))} + </div> + </div> + <div className="flex flex-col gap-1"> + <h3 className="text-xs font-medium"> + Long silences ({silences.length}){" "} + <span className="font-normal text-muted-foreground"> + — no archived post for ≥ {spanHours(activity.thresholdHours)} (≥ 48 h and ≥ 3× the median gap) + </span> + </h3> + {silences.length === 0 && !activity.trailing ? ( + <p className="text-xs text-muted-foreground">None in the archive&apos;s range.</p> + ) : ( + <ul aria-label="long silences" className="flex flex-col gap-0.5 text-xs"> + {activity.trailing && ( + <li aria-label={`silence since ${activity.trailing.since.createdAt.slice(0, 10)}`} className="flex gap-2 flex-wrap"> + <span className="tabular-nums"> + since {at(activity.trailing.since.createdAt, lastYear)} + </span> + <span className="text-muted-foreground"> + {spanHours(activity.trailing.hours)} by the last fetch + </span> + <PostLink end={activity.trailing.since} label="last post" /> + </li> + )} + {silences.slice(0, SHOWN_SILENCES).map((s) => ( + <li + key={s.before.id} + aria-label={`silence ${s.before.createdAt.slice(0, 10)} to ${s.after.createdAt.slice(0, 10)}`} + className="flex gap-2 flex-wrap" + > + <span className="tabular-nums"> + {at(s.before.createdAt, lastYear)} → {at(s.after.createdAt, lastYear)} + </span> + <span className="text-muted-foreground">{spanHours(s.hours)}</span> + <PostLink end={s.before} label="post before" /> + <PostLink end={s.after} label="post after" /> + </li> + ))} + {silences.length > SHOWN_SILENCES && ( + <li className="text-muted-foreground">and {silences.length - SHOWN_SILENCES} older</li> + )} + </ul> + )} + </div> + </section> + ); +} diff --git a/editor/app/channels/[slug]/page.tsx b/editor/app/channels/[slug]/page.tsx @@ -33,6 +33,8 @@ import { meanPagePauseSeconds, } from "yt-dlp-transcript-common/lib/forumWalk"; import { SocialChannelPanel } from "./components/SocialChannelPanel"; +import { AccountActivityPanel } from "./components/AccountActivityPanel"; +import { accountActivity } from "yt-dlp-transcript-common/lib/accountActivity"; import { WaybackPagesPanel } from "./components/WaybackPagesPanel"; import { WaybackLivePanel } from "./components/WaybackLivePanel"; import { waybackLiveState } from "./waybackLiveState"; @@ -243,6 +245,17 @@ export default async function ChannelDetailPage({ // when the full-history walk is part-way, Resume backfill — never a forum // thread's (its own two walks) or an X search's (one walk). const timeline = !forumThread && !xSearch ? timelineWalks(fetchState) : null; + // ACCOUNT ACTIVITY (lane x-console): posts per day and the long silences, + // from the stored posts — every posts channel but a Wayback pages one + // (its records are captures) and an X search (its posts are many + // accounts' answers to a query, not one account's activity). + const activity = + !isWaybackPagesChannel(config) && !xSearch && postCount >= 2 + ? accountActivity(await readAllPosts(channelRoot), { + ...(fetchState?.lastFetchedAt ? { asOf: fetchState.lastFetchedAt } : {}), + ...(config.socialHandle ? { author: config.socialHandle } : {}), + }) + : null; return ( <div className="flex flex-col gap-6"> <RunningJobsList jobs={socialRunningJobs} hideChannelSlug /> @@ -320,6 +333,7 @@ export default async function ChannelDetailPage({ }} /> )} + {activity && <AccountActivityPanel activity={activity} />} {leads && leads.ok && <XSearchLeadsPanel slug={slug} leads={leads} />} {/* THE SAME DANGER ZONE A VIDEO CHANNEL HAS, which a social channel used to lack entirely: this branch returns before the stage list, diff --git a/editor/e2e/account-activity.spec.ts b/editor/e2e/account-activity.spec.ts @@ -0,0 +1,127 @@ +// ACCOUNT ACTIVITY on a posts channel's page (lane x-console): posts per day +// over the archive's range, and the long silences — ≥ 3× the account's median +// gap AND ≥ 48 h — each linked to the post before and the post after. +// +// The shape is Mr Obvious's 5–8 Nov 2026 gap (verified read-only against the +// real corpus by an offline script): a busy account, a post every 15 minutes +// on 3–4 Nov, nothing for four days, busy again on 8 Nov. The posts are +// written straight to the channel's shard (no fetch, nothing reaches X), plus +// posts by another account the with-replies timeline archived, which do not +// count. + +import { mkdir, writeFile } from "node:fs/promises"; +import path from "node:path"; +import { test, expect, type Page } from "@playwright/test"; +import { resetData, resolvePath, testPaths, writeSettings } from "./helpers"; + +const SLUG = "x-obvious"; +const HANDLE = "obvious_user"; + +type P = { id: string; createdAt: string; author: string }; + +function posts(): P[] { + const out: P[] = []; + let n = 1000; + for (const day of ["2026-11-03", "2026-11-04"]) { + for (let m = 0; m < 8 * 60; m += 15) { + const h = String(10 + Math.floor(m / 60)).padStart(2, "0"); + out.push({ id: String(++n), createdAt: `${day}T${h}:${String(m % 60).padStart(2, "0")}:00.000Z`, author: HANDLE }); + } + } + // Another account's post inside the gap (a reply's parent): not this + // account's activity. + out.push({ id: "9000", createdAt: "2026-11-06T12:00:00.000Z", author: "someone_else" }); + for (let m = 0; m < 4 * 60; m += 15) { + const h = String(19 + Math.floor(m / 60)).padStart(2, "0"); + out.push({ id: String(++n), createdAt: `2026-11-08T${h}:${String(m % 60).padStart(2, "0")}:00.000Z`, author: HANDLE }); + } + return out; +} + +async function writeChannel(): Promise<P[]> { + const dir = resolvePath(`${testPaths().transcriptsDir}/channels/${SLUG}`); + await mkdir(path.join(dir, "posts"), { recursive: true }); + await writeFile( + path.join(dir, "config.json"), + JSON.stringify({ + name: "Obvious (X)", + handling: "transcribe", + sourceKind: "social", + postFetcher: "x-gallery-dl", + platform: "twitter", + socialHandle: HANDLE, + url: `https://x.com/${HANDLE}`, + }), + ); + const all = posts(); + const lines = all.map((p) => + JSON.stringify({ + id: p.id, + slug: `${SLUG}/${p.id}`, + channelSlug: SLUG, + author: p.author, + createdAt: p.createdAt, + text: `post ${p.id}`, + url: `https://x.com/${p.author}/status/${p.id}`, + platform: "twitter", + isReply: false, + isRepost: false, + links: [], + }), + ); + await writeFile(path.join(dir, "posts", "2026-11.jsonl"), lines.join("\n") + "\n"); + await writeFile(path.join(dir, "posts-archive"), all.map((p) => `twitter ${p.id}\n`).join("")); + await writeFile( + path.join(dir, "posts-state.json"), + JSON.stringify({ lastFetchedAt: "2026-11-09T00:00:00.000Z", lastFetchedCount: 16 }), + ); + return all; +} + +const SHOTS = process.env.E2E_UI_OPS_SHOTS ?? ""; +async function shot(page: Page, name: string) { + if (!SHOTS) return; + await mkdir(SHOTS, { recursive: true }); + await page.screenshot({ path: path.join(SHOTS, `${name}.png`), fullPage: false }); +} + +test("a posts channel's activity: posts per day, the four-day silence marked and linked to the posts on either side", async ({ + page, +}) => { + await resetData("empty"); + await writeSettings({ minFreeDiskGB: 0 }); + const all = await writeChannel(); + const own = all.filter((p) => p.author === HANDLE); + const before = own.filter((p) => p.createdAt.startsWith("2026-11-04")).at(-1)!; + const after = own.find((p) => p.createdAt.startsWith("2026-11-08"))!; + + await page.setViewportSize({ width: 1366, height: 768 }); + await page.goto(`/channels/${SLUG}`); + const panel = page.getByRole("region", { name: "account activity" }); + await expect(panel.getByRole("heading", { name: "Account activity" })).toBeVisible(); + // Only the account's own posts count; the range is 3 – 8 Nov. + await expect(panel.getByLabel("account activity summary")).toContainText( + "80 posts by @obvious_user · 3 Nov 2026 – 8 Nov 2026 · median gap 15 min · busiest day 32", + ); + // The strip: one bar per day with a post (4 days carry none), one silence shaded. + const strip = panel.getByRole("img", { name: "posts per day" }); + await expect(strip.locator("rect.fill-info")).toHaveCount(3); + await expect(strip.locator("rect[data-silence]")).toHaveCount(1); + + const silences = panel.getByRole("list", { name: "long silences" }); + await expect(silences.getByRole("listitem")).toHaveCount(1); + const gap = silences.getByLabel("silence 2026-11-04 to 2026-11-08"); + await expect(gap).toContainText("4 Nov 17:45 → 8 Nov 19:00"); + await expect(gap).toContainText("4 d 1 h"); + await expect(gap.getByRole("link", { name: "post before" })).toHaveAttribute( + "href", + `https://x.com/${HANDLE}/status/${before.id}`, + ); + await expect(gap.getByRole("link", { name: "post after" })).toHaveAttribute( + "href", + `https://x.com/${HANDLE}/status/${after.id}`, + ); + await expect(panel).toContainText("no archived post for ≥ 2 d (≥ 48 h and ≥ 3× the median gap)"); + await panel.scrollIntoViewIfNeeded(); + await shot(page, "account-activity"); +});