/** Synthetic local CPU comparison; never calls upstreams or remote storage. */ import { getActivityHistory, getInitialActivityFeed, refreshScheduledActivity } from "../src/lib/activity/feed"; import { githubProvider } from "../src/lib/activity/providers/github"; import { blueskyProvider } from "../src/lib/activity/providers/bluesky"; import { runActivityCron } from "../src/lib/activity/scheduled"; import type { ActivityEvent, ActivityProvider, ProviderContext } from "../src/lib/activity/types"; const now = new Date("2026-10-05T13:00:00.000Z"); const did = "did:plc:jhvnnnd3adml7t6anu3ay7ip"; const cid = "bafyreid3l3mpwbadpafmoajnc2ukaaf42cmnti6shcomrrqnqq4ctap5xy"; const calendarDays = Number(process.env.PROFILE_CALENDAR_DAYS ?? 2000); const postCount = Number(process.env.PROFILE_POSTS ?? 300); const providerDays = Number(process.env.PROFILE_PROVIDER_CALENDAR_DAYS ?? calendarDays); const githubEvents = Number(process.env.PROFILE_GITHUB_EVENTS ?? 100); const runs = Number(process.env.PROFILE_RUNS ?? 100); const mode = process.env.PROFILE_MODE ?? "cron"; if (!["cron", "full-cron", "bounded-cron", "providers", "handoff", "head", "history"].includes(mode)) throw new Error("Invalid PROFILE_MODE"); if (![calendarDays, postCount, providerDays, githubEvents, runs].every(Number.isSafeInteger) || Math.min(calendarDays, postCount, providerDays, githubEvents) < 0 || githubEvents > 100 || runs < 2) { throw new Error("Fixture counts must be nonnegative integers, PROFILE_GITHUB_EVENTS at most 100, and PROFILE_RUNS at least 2"); } const events: ActivityEvent[] = []; for (let i = 0; i < calendarDays; i++) { const occurredAt = new Date(+now - (i + 1) * 86_400_000).toISOString(); events.push({ id: `github:contributions:${occurredAt.slice(0, 10)}`, source: "github", kind: "contributions", occurredAt, count: 20 }); } for (let i = 0; i < postCount; i++) { const occurredAt = new Date(+now - i * 2 * 86_400_000).toISOString(); const uri = `at://${did}/app.bsky.feed.post/fixture${i}` as const; const text = "Public synthetic post. ".repeat(8); events.push({ id: `bluesky:post:${uri}:${occurredAt}`, source: "bluesky", action: "post", occurredAt, uri, url: `https://bsky.app/profile/${did}/post/fixture${i}`, text, author: { handle: "kualta.dev" }, post: { uri, cid, indexedAt: occurredAt, author: { did, handle: "kualta.dev" }, record: { $type: "app.bsky.feed.post", createdAt: occurredAt, text }, embed: { $type: "app.bsky.embed.images#view", images: [{ alt: "Synthetic image", thumb: "https://cdn.bsky.app/fixture.jpg", fullsize: "https://cdn.bsky.app/fixture.jpg", aspectRatio: { width: 1, height: 1 } }] }, }, }); } events.sort((a, b) => Date.parse(b.occurredAt) - Date.parse(a.occurredAt)); const sources = { github: { fetchedAt: now.toISOString(), attemptedAt: now.toISOString() }, bluesky: { fetchedAt: now.toISOString(), attemptedAt: now.toISOString() } }; // Diagnostic upper bound on the saving from moving history to another store. // This deliberately omits retained history; it is not a deployable cache design. const cachedArchive = mode === "bounded-cron" ? events.slice(0, 40) : events; const values = new Map([ ["activity:state:v3", JSON.stringify({ version: 3, sources, coverage: {}, events: events.slice(0, 40) })], ["activity:archive:v3", JSON.stringify({ version: 3, events: cachedArchive })], ]); const bytes = Object.fromEntries([...values].map(([key, value]) => [key, Buffer.byteLength(value)])); const cache = { async get(key: string) { return values.get(key) ?? null; }, async put(key: string, value: string) { values.set(key, value); } }; const providers: ActivityProvider[] = [ { id: "github", async fetch() { return events.filter(event => event.source === "github"); } }, { id: "bluesky", async fetch() { return events.filter(event => event.source === "bluesky").slice(0, 100); } }, ]; // All raw response bytes are prepared outside the samples. The real providers // still parse JSON/HTML, validate schemas and hash synthetic GitHub identifiers. const days = Array.from({ length: providerDays }, (_, i) => ({ date: new Date(+now - (i + 1) * 86_400_000).toISOString().slice(0, 10), contributionCount: 20, })); const years = [...new Set(days.map(day => Number(day.date.slice(0, 4))))]; const calendars = new Map(years.map(year => [year, days.filter(day => day.date.startsWith(String(year))).map(day => `