Public: anyone can read this; the crew can change it.
A closing forge forgets its repositories in every process-wide map keyed by repository #17594
Merged 16h 24m ago, live in production
fix/app-close-resets → main 0 commits
22 files
changed +139
−14
- src/actions/detach.ts
- src/actions/upstream_follow.ts
- src/app.ts
- src/apps/egress.ts
- src/checks/queue.ts
- src/checks/revert_red.ts
- src/core/recombine.ts
- src/crew/dispatch.ts
- src/crew/finishing.ts
- src/crew/governed.ts
- src/crew/green_sweep.ts
- src/crew/hot_files.ts
- src/crew/hot_history.ts
- src/crew/repeat_checks.ts
- src/crew/waits.ts
- src/display/config.ts
- src/flows/probe.ts
- src/flows/start.ts
- src/kernel/repo_keyed.ts
- src/origins/mirror-pulls.ts
- test/flow-clog-page.test.ts
- test/repo-keyed.test.ts
src/actions/detach.ts +2
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | * asking again finishes the job. |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 12 | 13 | import type { App } from "../app.ts"; |
| 13 | 14 | import { forkFollowMode } from "../core/fork_follow.ts"; |
| 14 | 15 | import { clearForkParent, forkParentFor, type Repo } from "../core/repos.ts"; |
| @@ -37,6 +38,7 @@ export interface DetachJob { | ||
| 37 | 38 | * forks in this forge, and empties on restart. |
| 38 | 39 | */ |
| 39 | 40 | const jobs = new Map<string, DetachJob>(); |
| 41 | REPO_KEYED.add(jobs); | |
| 40 | 42 | |
| 41 | 43 | /** The detach under way on this repository, or the last that failed. */ |
| 42 | 44 | export function detachJob(repoId: string): DetachJob | undefined { |
src/actions/upstream_follow.ts +2
| @@ -18,6 +18,7 @@ | ||
| 18 | 18 | * repository at a time, whoever asks. |
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 21 | 22 | import type { Database } from "bun:sqlite"; |
| 22 | 23 | import type { App } from "../app.ts"; |
| 23 | 24 | import { |
| @@ -167,6 +168,7 @@ export function mayCarryCredential(upstreamUrl: string, webUrl: string, loopback | ||
| 167 | 168 | * a time each. |
| 168 | 169 | */ |
| 169 | 170 | const checking = new Map<string, Set<string>>(); |
| 171 | REPO_KEYED.add(checking); | |
| 170 | 172 | |
| 171 | 173 | /** Take the claim on one check; `undefined` when it is already running, else the release. */ |
| 172 | 174 | export function claimCheck(repoId: string, sourceId = ""): (() => void) | undefined { |
src/app.ts +8
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * side-effect-contained, so tests boot real forges by the dozen. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { forgetRepositories } from "./kernel/repo_keyed.ts"; | |
| 7 | 8 | import { reviewAfterPush } from "./actions/quarantine.ts"; |
| 8 | 9 | import { onPushLarge } from "./blob/large.ts"; |
| 9 | 10 | import { settleEstimates } from "./actions/estimates_settle.ts"; |
| @@ -377,6 +378,13 @@ export function createApp(config: ForgeConfig): App { | ||
| 377 | 378 | closing, |
| 378 | 379 | close: () => { |
| 379 | 380 | closing.abort(); |
| 381 | // Its repositories leave the process-wide maps keyed by repository (`kernel/repo_keyed.ts`): | |
| 382 | // another forge in this process, or the next test file, never reads them. | |
| 383 | try { | |
| 384 | forgetRepositories(db.query<{ id: string }, []>("SELECT id FROM repo").all().map((r) => r.id)); | |
| 385 | } catch { | |
| 386 | // A database already closed holds nothing to read; nothing is kept for it either. | |
| 387 | } | |
| 380 | 388 | // The pooled `cat-file` readers for this forge's repos are processes, |
| 381 | 389 | // and processes outlive a closed database unless somebody says |
| 382 | 390 | // otherwise. One data dir is one forge, so closing the forge is where |
src/apps/egress.ts +2
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | * second host the first answer did not cover. |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 20 | 21 | import { storedText } from "../kernel/blocked.ts"; |
| 21 | 22 | import { lookup } from "node:dns/promises"; |
| 22 | 23 | import { isIP } from "node:net"; |
| @@ -237,6 +238,7 @@ const meters = new Map<string, { bytesIn: number; npmIn: number; holders: number | ||
| 237 | 238 | * `NPM_REPOS_MAX` repositories the quietest is dropped first. |
| 238 | 239 | */ |
| 239 | 240 | const npmByRepo = new Map<string, Moved>(); |
| 241 | REPO_KEYED.add(npmByRepo); | |
| 240 | 242 | const NPM_REPOS_MAX = 256; |
| 241 | 243 | |
| 242 | 244 | function ring(): Moved { |
src/checks/queue.ts +2
| @@ -63,6 +63,7 @@ | ||
| 63 | 63 | * the flow panel on /boards. |
| 64 | 64 | */ |
| 65 | 65 | |
| 66 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 66 | 67 | import type { Pull } from "../core/pulls.ts"; |
| 67 | 68 | import { runGit } from "../git/env.ts"; |
| 68 | 69 | import { mergeable, resolveOid, treeOf } from "../git/merge.ts"; |
| @@ -373,6 +374,7 @@ interface Flight { | ||
| 373 | 374 | const log = createLog("queue"); |
| 374 | 375 | |
| 375 | 376 | const lines = new Map<string, Line>(); |
| 377 | REPO_KEYED.add(lines); | |
| 376 | 378 | |
| 377 | 379 | /** Gates in flight beyond each line's first, every line together. */ |
| 378 | 380 | let extra = 0; |
src/checks/revert_red.ts +2
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | * shipped or closed, is never proposed twice. |
| 11 | 11 | */ |
| 12 | 12 | |
| 13 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 13 | 14 | import type { App } from "../app.ts"; |
| 14 | 15 | import { LANE_LINE, openLaneRevert } from "./revert_lane.ts"; |
| 15 | 16 | import { addComment, getIssueById } from "../core/issues.ts"; |
| @@ -25,6 +26,7 @@ import { sameFailure } from "./verify.ts"; | ||
| 25 | 26 | |
| 26 | 27 | /** The reds being answered now: a check finishing twice at once proposes once. */ |
| 27 | 28 | const working = new Set<string>(); |
| 29 | REPO_KEYED.add(working); | |
| 28 | 30 | |
| 29 | 31 | /** The id of the last passed default-branch check before run `below`, with its commit. */ |
| 30 | 32 | function greenBefore(app: App, repoId: string, branch: string, below: string): string | undefined { |
src/core/recombine.ts +3
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * a push that moves the default branch (`http/server.ts`). |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 9 | 10 | import type { Database } from "bun:sqlite"; |
| 10 | 11 | import { combine, readFailure, setFailure } from "../git/combined.ts"; |
| 11 | 12 | import { repoDir } from "../git/repos.ts"; |
| @@ -23,7 +24,9 @@ export interface RecombineForge { | ||
| 23 | 24 | } |
| 24 | 25 | |
| 25 | 26 | const running = new Map<string, { again: boolean; done: Promise<number> }>(); |
| 27 | REPO_KEYED.add(running); | |
| 26 | 28 | const started = new Map<string, number>(); |
| 29 | REPO_KEYED.add(started); | |
| 27 | 30 | |
| 28 | 31 | /** How many runs have been started for the repository: what a test counts. */ |
| 29 | 32 | export function runsStarted(repoId: string): number { |
src/crew/dispatch.ts +2
| @@ -8,6 +8,7 @@ | ||
| 8 | 8 | * a run. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 11 | 12 | import { provideCrewWork, registerCrew, forgetCrew } from "./registry.ts"; |
| 12 | 13 | import { agentFor, lastHumanWord, taskOf } from "./task.ts"; |
| 13 | 14 | import { CHECK_FAILED_LIMIT, INTERRUPTED_OUT } from "./give_up.ts"; |
| @@ -1318,6 +1319,7 @@ export function decideStrandedAtBoot(app: App): void { | ||
| 1318 | 1319 | * pull's next push or a person's ask checks it again. |
| 1319 | 1320 | */ |
| 1320 | 1321 | const waitingOnMain = new Map<string, Map<string, { env: string; commitOid: string }>>(); |
| 1322 | REPO_KEYED.add(waitingOnMain); | |
| 1321 | 1323 | |
| 1322 | 1324 | /** |
| 1323 | 1325 | * Whether a failed check is main's red or the lane's, shared: if so, the pull is noted as waiting. |
src/crew/finishing.ts +2
| @@ -40,6 +40,7 @@ | ||
| 40 | 40 | * pulls to this pass (`approvedOnHead`). |
| 41 | 41 | */ |
| 42 | 42 | |
| 43 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 43 | 44 | import type { Database } from "bun:sqlite"; |
| 44 | 45 | import type { App } from "../app.ts"; |
| 45 | 46 | import { addComment, assignIssue } from "../actions/issues.ts"; |
| @@ -374,6 +375,7 @@ threadHeld.add("finishing said", said.size); | ||
| 374 | 375 | |
| 375 | 376 | /** What each repository's pass last said it read, so its entry is said when that changes. */ |
| 376 | 377 | const entered = new Map<string, string>(); |
| 378 | REPO_KEYED.add(entered); | |
| 377 | 379 | |
| 378 | 380 | function enter(repo: Repo, what: string): void { |
| 379 | 381 | if (entered.get(repo.id) === what) return; |
src/crew/governed.ts +2
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * the governor holds the crew below the operator's slots. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 9 | 10 | import type { App } from "../app.ts"; |
| 10 | 11 | import { canSeeOwnerFacts, type Repo } from "../core/repos.ts"; |
| 11 | 12 | import type { User } from "../core/users.ts"; |
| @@ -50,6 +51,7 @@ export function governorLine(g: GovernorSeen): string { | ||
| 50 | 51 | |
| 51 | 52 | /** The governed number each repository was last seen at; unseen means the operator's slots. */ |
| 52 | 53 | const seen = new Map<string, number>(); |
| 54 | REPO_KEYED.add(seen); | |
| 53 | 55 | |
| 54 | 56 | /** |
| 55 | 57 | * Says a change of the governed number, once: the event is appended only |
src/crew/green_sweep.ts +2
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | /** The sweep that lands green pulls that have not landed, and the merge queue's line it prunes. */ |
| 2 | 2 | |
| 3 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 3 | 4 | import type { App } from "../app.ts"; |
| 4 | 5 | import { dropFromLine, enqueue, type Queued, waitingPulls } from "../checks/queue.ts"; |
| 5 | 6 | import { getHold } from "../core/holds.ts"; |
| @@ -67,6 +68,7 @@ export function pruneLine(app: App, repo: Repo): number { | ||
| 67 | 68 | |
| 68 | 69 | /** The sweep each repository has in flight, by repository id. */ |
| 69 | 70 | const sweeping = new Map<string, Promise<number>>(); |
| 71 | REPO_KEYED.add(sweeping); | |
| 70 | 72 | |
| 71 | 73 | /** |
| 72 | 74 | * Starts the green sweep beside the tick, never in front of it: a landing |
src/crew/hot_files.ts +4
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | * the feed shows while they stand. |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 19 | 20 | import type { App } from "../app.ts"; |
| 20 | 21 | import { getIssuesByIds, type Issue } from "../core/issues.ts"; |
| 21 | 22 | import { joinMany, pullDir } from "../core/pulls.ts"; |
| @@ -83,6 +84,7 @@ export interface HotFile { | ||
| 83 | 84 | |
| 84 | 85 | /** Per repository, per open pull: the head and base it was read at, and the files. */ |
| 85 | 86 | const touched = new Map<string, Map<string, { at: string; number: number; files: readonly string[] }>>(); |
| 87 | REPO_KEYED.add(touched); | |
| 86 | 88 | |
| 87 | 89 | const OID = /^[0-9a-f]{40,64}$/; |
| 88 | 90 | |
| @@ -236,6 +238,7 @@ export interface HotHold { | ||
| 236 | 238 | |
| 237 | 239 | /** The pulls too wide to count as the picker last saw them, per repository, held builds or not. */ |
| 238 | 240 | const standingWideBy = new Map<string, { at: string; wide: readonly WidePull[] }>(); |
| 241 | REPO_KEYED.add(standingWideBy); | |
| 239 | 242 | |
| 240 | 243 | /** The pulls too wide to count in `repoId` as the picker last saw them, if any. */ |
| 241 | 244 | export function standingWide(repoId: string): { at: string; wide: readonly WidePull[] } | undefined { |
| @@ -244,6 +247,7 @@ export function standingWide(repoId: string): { at: string; wide: readonly WideP | ||
| 244 | 247 | |
| 245 | 248 | /** What the picker last held on hot files, per repository, and when. */ |
| 246 | 249 | const standing = new Map<string, { at: string; holds: readonly HotHold[]; wide: readonly WidePull[] }>(); |
| 250 | REPO_KEYED.add(standing); | |
| 247 | 251 | |
| 248 | 252 | /** Remember the builds the picker holds on hot files in `repoId` now; none clears it. */ |
| 249 | 253 | export function holdHot( |
src/crew/hot_history.ts +2
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * and nothing is said until a sample at least `MIN_AGE_MS` old exists. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 9 | 10 | import type { Database } from "bun:sqlite"; |
| 10 | 11 | import { getRepoById } from "../core/repos.ts"; |
| 11 | 12 | import { byRise, hotTrend, hotTrendSays, TREND_NAMED, type Warming } from "../flow/hot_trend.ts"; |
| @@ -19,6 +20,7 @@ const KEEP_MS = HOUR_MS + HOUR_MS / 2; | ||
| 19 | 20 | const EVERY_MS = 5 * 60_000; |
| 20 | 21 | |
| 21 | 22 | const samples = new Map<string, { at: number; counts: ReadonlyMap<string, number> }[]>(); |
| 23 | REPO_KEYED.add(samples); | |
| 22 | 24 | |
| 23 | 25 | /** Keep `counts` for `repoId` as read at `at` (epoch ms), and drop samples too old to matter. */ |
| 24 | 26 | export function sampleHeat(repoId: string, counts: ReadonlyMap<string, number>, at: number): void { |
src/crew/repeat_checks.ts +2
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * issues a sweep, and a sweep at most every {@link EVERY_MS} per repository. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 9 | 10 | import type { App } from "../app.ts"; |
| 10 | 11 | import { createIssue } from "../core/issues.ts"; |
| 11 | 12 | import type { Repo } from "../core/repos.ts"; |
| @@ -15,6 +16,7 @@ export const EVERY_MS = 6 * 3_600_000; | ||
| 15 | 16 | export const PER_SWEEP = 2; |
| 16 | 17 | |
| 17 | 18 | const swept = new Map<string, number>(); |
| 19 | REPO_KEYED.add(swept); | |
| 18 | 20 | |
| 19 | 21 | export interface RepeatMoves { |
| 20 | 22 | readonly proposed: number[]; |
src/crew/waits.ts +3
| @@ -7,6 +7,8 @@ | ||
| 7 | 7 | * re-check (#3316). |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 11 | ||
| 10 | 12 | /** Why a pull did not join the merge queue on this sweep, or that it did. */ |
| 11 | 13 | export type Wait = |
| 12 | 14 | | "queued" |
| @@ -45,6 +47,7 @@ export function waitWords(waits: Waits): string | undefined { | ||
| 45 | 47 | |
| 46 | 48 | /** The last finished sweep's tally, by repository id: the sweep runs beside the tick. */ |
| 47 | 49 | const last = new Map<string, Waits>(); |
| 50 | REPO_KEYED.add(last); | |
| 48 | 51 | |
| 49 | 52 | export function noteWaits(repoId: string, waits: Waits): void { |
| 50 | 53 | last.set(repoId, waits); |
src/display/config.ts +2
| @@ -23,6 +23,7 @@ | ||
| 23 | 23 | * than a guess. |
| 24 | 24 | */ |
| 25 | 25 | |
| 26 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 26 | 27 | import type { App } from "../app.ts"; |
| 27 | 28 | import type { Repo } from "../core/repos.ts"; |
| 28 | 29 | import { exactRefOid } from "../git/branches.ts"; |
| @@ -191,6 +192,7 @@ export async function readDisplay(app: App, repo: Repo): Promise<Result<DisplayC | ||
| 191 | 192 | const KNOWN_TTL_MS = 15_000; |
| 192 | 193 | const KNOWN_MAX = 2000; |
| 193 | 194 | const known = new Map<string, { has: boolean; at: number }>(); |
| 195 | REPO_KEYED.add(known); | |
| 194 | 196 | |
| 195 | 197 | function remember(repo: Repo, has: boolean): void { |
| 196 | 198 | known.delete(repo.id); |
src/flows/probe.ts +2
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * Admin only, never an agent, one at a time per repository, a few a minute. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 9 | 10 | import { checkSource, checkUpstream } from "../actions/upstream_follow.ts"; |
| 10 | 11 | import type { App } from "../app.ts"; |
| 11 | 12 | import { getFollow } from "../core/upstream_follow.ts"; |
| @@ -37,6 +38,7 @@ export const LANES = 4; | ||
| 37 | 38 | export const DEADLINE_MS = 30_000; |
| 38 | 39 | |
| 39 | 40 | const running = new Set<string>(); |
| 41 | REPO_KEYED.add(running); | |
| 40 | 42 | const defaultLimiter = new RateLimiter({ perMinute: 4, adminPerMinute: 4, enabled: true }); |
| 41 | 43 | |
| 42 | 44 | export async function probeLinks( |
src/flows/start.ts +2
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * time, and one identity gets a few runs a minute. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 7 | 8 | import type { App } from "../app.ts"; |
| 8 | 9 | import { RateLimiter } from "../core/ratelimit.ts"; |
| 9 | 10 | import { canAdmin, type Repo } from "../core/repos.ts"; |
| @@ -14,6 +15,7 @@ import { runRadar } from "./run.ts"; | ||
| 14 | 15 | export type Started = { ok: true; read: number } | { ok: false; why: string }; |
| 15 | 16 | |
| 16 | 17 | const running = new Set<string>(); |
| 18 | REPO_KEYED.add(running); | |
| 17 | 19 | const RUNS_PER_MINUTE = 4; |
| 18 | 20 | const defaultLimiter = new RateLimiter({ perMinute: RUNS_PER_MINUTE, adminPerMinute: RUNS_PER_MINUTE, enabled: true }); |
| 19 | 21 |
src/kernel/repo_keyed.ts added +19
| @@ -0,0 +1,19 @@ | ||
| 1 | /** | |
| 2 | * Module-level maps and sets keyed by a repository id, which a forge forgets when it closes. Such a | |
| 3 | * map is process-wide (`test/module-state.test.ts` holds the older ones on its baseline), so it | |
| 4 | * outlived the forge whose repositories it described: a second forge in the same process, an | |
| 5 | * in-process restart, or the next test file under `bun test --no-isolate` read the first one's | |
| 6 | * entries (a flow page named another forge's hot file, 2026-12-02). A module adds its map to this | |
| 7 | * set at module level, once, as it loads, never from inside a function; `app.close()` deletes its | |
| 8 | * own repositories from each. | |
| 9 | */ | |
| 10 | ||
| 11 | /** | |
| 12 | * The maps to forget a closing forge's repositories in; filled as modules load, never by a request. | |
| 13 | */ | |
| 14 | export const REPO_KEYED = new Set<{ delete(repoId: string): unknown }>(); | |
| 15 | ||
| 16 | /** Forget `repoIds` in every registered map: what a closing forge does for its own repositories. */ | |
| 17 | export function forgetRepositories(repoIds: readonly string[]): void { | |
| 18 | for (const map of REPO_KEYED) for (const id of repoIds) map.delete(id); | |
| 19 | } |
src/origins/mirror-pulls.ts +2
| @@ -16,6 +16,7 @@ | ||
| 16 | 16 | * per repository, so the two never make two copies of one pull. |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | import { REPO_KEYED } from "../kernel/repo_keyed.ts"; | |
| 19 | 20 | import type { App } from "../app.ts"; |
| 20 | 21 | import { openPull } from "../actions/pulls.ts"; |
| 21 | 22 | import { getMirrorTarget, type MirrorTarget } from "../core/migrate_mirror.ts"; |
| @@ -76,6 +77,7 @@ export interface MirrorPullsReport { | ||
| 76 | 77 | } |
| 77 | 78 | |
| 78 | 79 | const running = new Map<string, Promise<MirrorPullsReport>>(); |
| 80 | REPO_KEYED.add(running); | |
| 79 | 81 | |
| 80 | 82 | /** |
| 81 | 83 | * Bring `repo`'s mirror's open pulls in. A second caller while one runs |
test/flow-clog-page.test.ts +1 −14
| @@ -5,7 +5,7 @@ import { tmpdir } from "node:os"; | ||
| 5 | 5 | import { join } from "node:path"; |
| 6 | 6 | import { createRepo } from "../src/actions/repos.ts"; |
| 7 | 7 | import { createApp, type App } from "../src/app.ts"; |
| 8 | import { adoptTouched, learnedPulls, rememberPullFiles } from "../src/crew/hot_files.ts"; | |
| 8 | import { rememberPullFiles } from "../src/crew/hot_files.ts"; | |
| 9 | 9 | import { createUser } from "../src/core/users.ts"; |
| 10 | 10 | import { serve, type Servers } from "../src/http/server.ts"; |
| 11 | 11 | import { id } from "../src/kernel/id.ts"; |
| @@ -44,19 +44,7 @@ const red = (num: number, names: string[]) => { | ||
| 44 | 44 | .run(id(), repoId, issue.id, JSON.stringify({ names })); |
| 45 | 45 | }; |
| 46 | 46 | |
| 47 | /** | |
| 48 | * The pulls each repository's open pulls touch are one map per process (`crew/hot_files.ts`), and | |
| 49 | * the clog sentence names the hottest file of all of them. Under `bun test --no-isolate` a file | |
| 50 | * before this one in the worker left its own there (hot-files-relieves: "8 open pulls touch | |
| 51 | * src/tui/forge.ts"), and this page named that file, not src/a.ts (red on three pulls, 2026-12-02). | |
| 52 | * This file starts from none, and leaves none. | |
| 53 | */ | |
| 54 | const forgetLearned = (): void => { | |
| 55 | for (const repo of new Set(learnedPulls().map((p) => p.repoId))) adoptTouched(repo, undefined); | |
| 56 | }; | |
| 57 | ||
| 58 | 47 | beforeAll(async () => { |
| 59 | forgetLearned(); | |
| 60 | 48 | dataDir = await mkdtemp(join(tmpdir(), "forge-clogpage-")); |
| 61 | 49 | app = createApp({ dataDir, port: 0 }); |
| 62 | 50 | servers = await serve(app); |
| @@ -73,7 +61,6 @@ beforeAll(async () => { | ||
| 73 | 61 | }, 60_000); |
| 74 | 62 | |
| 75 | 63 | afterAll(async () => { |
| 76 | forgetLearned(); | |
| 77 | 64 | rememberPullFiles(repoId, []); |
| 78 | 65 | servers.stop(); |
| 79 | 66 | app.close(); |
test/repo-keyed.test.ts added +71
| @@ -0,0 +1,71 @@ | ||
| 1 | /** | |
| 2 | * A closing forge forgets its repositories in the process-wide maps keyed by repository | |
| 3 | * (`kernel/repo_keyed.ts`), and only its own: another forge in the process keeps its entries. And a | |
| 4 | * module-level map keyed by a repository id is registered, so the next one cannot leak either | |
| 5 | * (a flow page named another forge's hot file under `bun test --no-isolate`, 2026-12-02). | |
| 6 | * | |
| 7 | * @tree-scan: reads every file under src/. | |
| 8 | */ | |
| 9 | import { afterAll, expect, test } from "bun:test"; | |
| 10 | import { readFileSync } from "node:fs"; | |
| 11 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 12 | import { tmpdir } from "node:os"; | |
| 13 | import { join } from "node:path"; | |
| 14 | import { Glob } from "bun"; | |
| 15 | import { createRepo } from "../src/actions/repos.ts"; | |
| 16 | import { createApp, type App } from "../src/app.ts"; | |
| 17 | import { learnedPulls, rememberPullFiles } from "../src/crew/hot_files.ts"; | |
| 18 | import { createUser } from "../src/core/users.ts"; | |
| 19 | ||
| 20 | const dirs: string[] = []; | |
| 21 | afterAll(async () => { | |
| 22 | for (const d of dirs) await rm(d, { recursive: true, force: true }); | |
| 23 | }); | |
| 24 | ||
| 25 | async function forgeWithRepo(): Promise<{ app: App; repoId: string }> { | |
| 26 | const dir = await mkdtemp(join(tmpdir(), "repo-keyed-")); | |
| 27 | dirs.push(dir); | |
| 28 | const app = createApp({ dataDir: dir, port: 0 }); | |
| 29 | const u = await createUser(app.db, { | |
| 30 | origin: "seed", | |
| 31 | trusted: true, | |
| 32 | username: "ada", | |
| 33 | email: "[email protected]", | |
| 34 | password: "a-good-passphrase", | |
| 35 | adminIfFirst: true, | |
| 36 | }); | |
| 37 | if (!u.ok) throw new Error(u.error); | |
| 38 | const r = await createRepo(app, u.value, { name: "lib", visibility: "public" }); | |
| 39 | if (!r.ok) throw new Error(String(r.error)); | |
| 40 | return { app, repoId: r.value.id }; | |
| 41 | } | |
| 42 | ||
| 43 | test("closing a forge forgets its repositories' learned pulls, and keeps another forge's", async () => { | |
| 44 | const a = await forgeWithRepo(); | |
| 45 | const b = await forgeWithRepo(); | |
| 46 | rememberPullFiles(a.repoId, [{ number: 1, files: ["src/a.ts"] }]); | |
| 47 | rememberPullFiles(b.repoId, [{ number: 2, files: ["src/b.ts"] }]); | |
| 48 | const held = () => new Set(learnedPulls().map((p) => p.repoId)); | |
| 49 | expect(held().has(a.repoId)).toBe(true); | |
| 50 | a.app.close(); | |
| 51 | expect(held().has(a.repoId)).toBe(false); | |
| 52 | expect(held().has(b.repoId)).toBe(true); | |
| 53 | b.app.close(); | |
| 54 | expect(held().has(b.repoId)).toBe(false); | |
| 55 | }); | |
| 56 | ||
| 57 | test("every module-level map or set a module keys by repository id is registered to be forgotten", () => { | |
| 58 | const DECL = /^(?:export )?(?:const|let) ([A-Za-z_$][\w$]*)(?:: [^=\n]+)? = new (?:Bounded)?(?:Map|Set)\b/gm; | |
| 59 | const unregistered: string[] = []; | |
| 60 | for (const file of new Glob("src/**/*.ts").scanSync(".")) { | |
| 61 | const text = readFileSync(file, "utf8"); | |
| 62 | for (const m of text.matchAll(DECL)) { | |
| 63 | const name = m[1]!; | |
| 64 | const byRepo = new RegExp( | |
| 65 | `\\b${name}\\.(set|get|delete|has|add)\\(\\s*(repo\\.id|repoId|r\\.repoId|repo_id|run\\.repoId|x\\.repoId|record\\.repoId)\\b`, | |
| 66 | ); | |
| 67 | if (byRepo.test(text) && !text.includes(`REPO_KEYED.add(${name});`)) unregistered.push(`${file}:${name}`); | |
| 68 | } | |
| 69 | } | |
| 70 | expect(unregistered).toEqual([]); | |
| 71 | }); |
new above
offline