Public: anyone can read this; the crew can change it.

Revert "Main's full check still runs 40+ minutes after #16613 landed" #16635

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

revert-16623 → main 0 commits

  • Merged. revert-16623 was merged into main as 277660c.

Review

Sign in to review this change.
99 files changed +215 −335
docs/features/maintenance-duties.md +1 −1
@@ -66,6 +66,6 @@ Tests: `test/duty-idle.test.ts`.
6666
6767 ## Adding a duty (#14355)
6868
69 A duty is one file in `src/maintain/duties/` that exports `duty` (a `Duty`, see `src/maintain/duty.ts`). `src/maintain/registry.ts` lists that directory on first use and builds the roster from it, so a pull that adds a duty adds that file and edits no shared list; `scripts/unreached.ts` counts every file there as reached. A file that does not export `duty` stops boot with an error naming it. `duty_idle.ts` is the one exception: it watches the others and is appended last.
69 A duty is one file in `src/maintain/duties/` that exports `duty` (a `Duty`, see `src/maintain/duty.ts`). `src/maintain/registry.ts` lists that directory when it loads and builds the roster from it, so a pull that adds a duty adds that file and edits no shared list; `scripts/unreached.ts` counts every file there as reached. A file that does not export `duty` stops boot with an error naming it. `duty_idle.ts` is the one exception: it watches the others and is appended last.
7070
7171 The roster is in file-name order, and that is the order the runner ticks the duties and `/maintenance` lists them (it used to be a hand-picked order). To place a duty, name its file for where it should sit. Tests: `test/duty-roster.test.ts`.
scripts/unused-exports-allow.json +2 −1
@@ -162,17 +162,18 @@
162162 "src/snapshot/drill_job.ts markerLeft",
163163 "src/spawn/births.ts provideHoldForTest",
164164 "src/spawn/births.ts provideMemoryForTest",
165 "src/spawn/door.ts useWatchProbeByDefault",
165166 "src/spawn/child-apps.ts childRuntime",
166167 "src/spawn/child_db.ts childDbReaders",
167168 "src/spawn/clients.ts monthsSettled",
168169 "src/spawn/clients.ts useChildFetch",
169170 "src/spawn/door.ts usePlacement",
170 "src/spawn/door.ts useProbe",
171171 "src/spawn/host.ts provideCellsForTest",
172172 "src/spawn/included_credit.ts worstCaseDailyUsd",
173173 "src/spawn/parent_credential.ts keepParentCredential",
174174 "src/spawn/pod.ts renderPod",
175175 "src/spawn/rate.ts resetAnonSpawns",
176 "src/spawn/reach.ts useReachByDefault",
176177 "src/spawn/usage.ts forgetSelfCpu",
177178 "src/story/records.ts isKnownRecord",
178179 "src/story/records.ts parseRecords",
src/actions/business_plan.ts +4 −2
@@ -24,8 +24,7 @@ import { transact } from "../kernel/db.ts";
2424 import type { User } from "../core/users.ts";
2525 import { err, ok, type Result } from "../kernel/result.ts";
2626 import { MAX_DIRECTION_CHARS, MAX_FRESH_CHARS } from "../spawn/plan.ts";
27 import { PLAN_MAX } from "./plan_words.ts";
28 import { openPlan, proposePlan, type PlanItem, type Planned, type Proposed } from "./plan.ts";
27 import { openPlan, PLAN_MAX, proposePlan, type PlanItem, type Planned, type Proposed } from "./plan.ts";
2928
3029 /** The description, in words: long enough for a business, short enough to read. */
3130 export const DESCRIPTION_MAX = 4_000;
@@ -239,6 +238,9 @@ export function spawnSeed(plan: BusinessPlan): { direction: string; fresh?: stri
239238 };
240239 }
241240
241 /** The largest body either door reads: a description, twelve parts and their edges, with room. */
242 export const ATLAS_BODY_MAX = 64 * 1024;
243
242244 /**
243245 * The issues an earlier confirm of this plan opened here, by number. The
244246 * stamp line is matched only where `businessItems` puts it, at the very end
src/actions/dependencies.ts +9
@@ -18,8 +18,17 @@ import { canRead, canWrite, type Repo } from "../core/repos.ts";
1818 import type { User } from "../core/users.ts";
1919 import { err, ok, type Result } from "../kernel/result.ts";
2020 import type { AccessError } from "./access.ts";
21 import { SELF_WAIT } from "./plan_words.ts";
2122 import { followLink } from "./pillars.ts";
2223
24 /** What a refused link says, in the words the API and the MCP share. */
25 export const dependencyWords: Record<string, string> = {
26 self: SELF_WAIT,
27 cycle: "that would make a loop",
28 cross_repo: "dependencies stay inside one repository",
29 not_an_issue: "only issues can depend on issues",
30 };
31
2332 function requirePlanner(
2433 app: App,
2534 actor: User | undefined,
src/actions/forge_view.ts +1 −2
@@ -15,9 +15,8 @@ import { appsOf } from "../web/studio/asks.ts";
1515 import { clientLines, IDLE_LINE } from "./client_line.ts";
1616 import { crewNow } from "./crew_now.ts";
1717 import { readHealth } from "./health.ts";
18 import { VIEW_TTL_MS } from "./forge_view_ttl.ts";
19
2018
19 export const VIEW_TTL_MS = 2000;
2120 /** Most apps listed; `counts.apps` stays the true number. */
2221 export const VIEW_APPS = 200;
2322
src/actions/forge_view_ttl.ts deleted −6
@@ -1,6 +0,0 @@
1 /**
2 * How long a reader's view of the forge is reused. A leaf: the stream that paces itself by it reads
3 * it without loading the view's whole graph (#16622).
4 */
5
6 export const VIEW_TTL_MS = 2000;
src/actions/plan.ts +2 −1
@@ -33,9 +33,10 @@ import { id as newId } from "../kernel/id.ts";
3333 import { err, ok, type Result } from "../kernel/result.ts";
3434 import { isMirror } from "../origins/write-through.ts";
3535 import { lookAlikes } from "./look_alike.ts";
36 import { PLAN_MAX, SELF_WAIT } from "./plan_words.ts";
36 import { SELF_WAIT } from "./plan_words.ts";
3737 import { followLink } from "./pillars.ts";
3838
39 export const PLAN_MAX = 12;
3940 /** One sentence, with room. */
4041 export const WHY_MAX = 300;
4142 const KEY = /^[A-Za-z][A-Za-z0-9_.-]{0,39}$/;
src/actions/plan_words.ts −14
@@ -10,17 +10,3 @@ export const SELF_WAIT = "an issue cannot wait for itself";
1010
1111 /** A re-plan that can no longer be taken back: the planner has been given it. */
1212 export const IN_HAND = "the planner has it in hand already";
13
14 /** What a refused link says, in the words the API and the MCP share. */
15 export const dependencyWords: Record<string, string> = {
16 self: SELF_WAIT,
17 cycle: "that would make a loop",
18 cross_repo: "dependencies stay inside one repository",
19 not_an_issue: "only issues can depend on issues",
20 };
21
22 /** The most issues one plan opens. */
23 export const PLAN_MAX = 12;
24
25 /** The largest body either door reads: a description, twelve parts and their edges, with room. */
26 export const ATLAS_BODY_MAX = 64 * 1024;
src/actions/search.ts +2 −1
@@ -38,12 +38,13 @@ import {
3838 } from "../core/search.ts";
3939 import type { Repo } from "../core/repos.ts";
4040 import type { User } from "../core/users.ts";
41 import { SEARCH_LIMIT_MAX } from "../core/page_ceilings.ts";
4241 import { searchDocs } from "../view/docs.ts";
4342 import { providerForOrigin } from "../origins/credential.ts";
4443
4544 /** Default page size for each list. */
4645 export const SEARCH_LIMIT = 20;
46 /** Hard ceiling on a caller-chosen limit. */
47 export const SEARCH_LIMIT_MAX = 100;
4748
4849 /**
4950 * The refusal an API or MCP caller gets for a `kind` or `limit` the search
src/checks/culprit.ts +2 −8
@@ -186,14 +186,8 @@ function unbisected(app: App, repo: Repo, red: Run, why: string): string {
186186 export async function afterVerify(app: App, repo: Repo, run: Run, ask: Ask): Promise<string[]> {
187187 const red = run.env === VERIFY_ENV ? run : getRun(app.db, bisectOrigin(run.reason) ?? "");
188188 if (red === undefined || red.state !== "failed") return [];
189 const named = red.checkDetail?.files ?? [];
190 const passAlone = red.checkDetail?.flakyUnderLoad ?? [];
191 const files = named.filter((f) => !passAlone.includes(f));
192 if (named.length === 0) return ["not bisected: the red names no failed test file"];
193 // A file that passed when re-run alone failed for the load it ran under, not for a landing
194 // (#16622).
195 if (files.length === 0)
196 return [`not bisected: ${named.join(", ")} pass alone, so load failed them and no landing did`];
189 const files = red.checkDetail?.files ?? [];
190 if (files.length === 0) return ["not bisected: the red names no failed test file"];
197191 if (run === red) {
198192 const before = finishedBefore(app, repo.id, red.id);
199193 const known = before?.state === "failed" ? (before.checkDetail?.files ?? []) : [];
src/checks/red_main.ts +5 −18
@@ -34,8 +34,6 @@ export interface RedMain {
3434 readonly branch: string;
3535 /** The check was stopped by its cell's limit or its budget, not by a test: no pull shares it. */
3636 readonly limit: boolean;
37 /** Every failing file passed when re-run alone: load tripped it, no landing broke it (#16622). */
38 readonly flaky: boolean;
3937 readonly since: string;
4038 }
4139
@@ -88,27 +86,17 @@ const lastMain = (from: string): string => `
8886
8987 /**
9088 * A summary of a cell stop (`apps/contain.ts`), a budget kill (`kernel/budgets.ts`), a check that
91 * stalled (`checks/stall.ts`), one the forge's stopping cut off, or one whose step ran past its
92 * time ("check took longer than 2400s", `checks/job_step.ts`): the machine's, not a pull's
93 * (#16622).
89 * stalled (`checks/stall.ts`) or one the forge's stopping cut off: the machine's, not a pull's.
9490 */
95 const LIMIT =
96 /^(?:check failed: )?(?:stopped: |budget:|check stalled:|the forge was stopped under this check|\S+ took longer than \d+s)/;
91 const LIMIT = /^(?:check failed: )?(?:stopped: |budget:|check stalled:|the forge was stopped under this check)/;
9792
9893 function toRed(row: Row): RedMain | undefined {
9994 if (row.state !== "failed") return undefined;
10095 let failing: string[] = [];
101 let flaky = false;
10296 try {
103 const detail = row.check_detail
104 ? (JSON.parse(row.check_detail) as { names?: unknown; files?: unknown; flakyUnderLoad?: unknown })
105 : {};
106 const strings = (v: unknown): string[] =>
107 Array.isArray(v) ? v.filter((n): n is string => typeof n === "string") : [];
108 failing = strings(detail.names);
109 const files = strings(detail.files);
110 const green = strings(detail.flakyUnderLoad);
111 flaky = files.length > 0 && files.every((f) => green.includes(f));
97 const detail = row.check_detail ? (JSON.parse(row.check_detail) as { names?: unknown }) : {};
98 if (Array.isArray(detail.names))
99 failing = detail.names.filter((n): n is string => typeof n === "string");
112100 } catch {
113101 failing = [];
114102 }
@@ -121,7 +109,6 @@ function toRed(row: Row): RedMain | undefined {
121109 summary: row.summary,
122110 branch: row.branch,
123111 limit: LIMIT.test(row.summary),
124 flaky,
125112 since: row.finished_at ?? row.created_at,
126113 };
127114 }
src/checks/revert_red.ts +2 −3
@@ -5,8 +5,7 @@
55 * for the pull it takes back and naming the failing test. It is only ever
66 * proposed — a person lands it. A red that spans more than one landing (or a
77 * push no pull carried) is the alarm's, not this module's, and a landing
8 * already reverted, open or shipped or closed, is never proposed twice. A red
9 * the machine caused (a limit, a stall, or files that pass alone) proposes none.
8 * already reverted, open or shipped or closed, is never proposed twice.
109 */
1110
1211 import type { App } from "../app.ts";
@@ -89,7 +88,7 @@ export async function proposeRevert(app: App, repoId: string): Promise<Pull | un
8988 working.add(repoId);
9089 try {
9190 const red = redMain(app.db, repoId);
92 if (red === undefined || red.limit || red.flaky || manifestError(red) !== undefined) return undefined;
91 if (red === undefined || red.limit || manifestError(red) !== undefined) return undefined;
9392 const green = greenBefore(app, repoId, red.branch, red.runId);
9493 if (green === undefined) return undefined;
9594 const landed = await soleLanding(app, red, green);
src/contract/openapi/routes/getApiV1Feed.ts +1 −1
@@ -1,5 +1,5 @@
11 import { type Route, limitTo } from "../shared.ts";
2 import { FEED_LIMIT_MAX } from "../../../core/page_ceilings.ts";
2 import { FEED_LIMIT_MAX } from "../../../feed/feed.ts";
33
44 export const route: Route = {
55 method: "get",
src/contract/openapi/routes/getApiV1Search.ts +1 −1
@@ -1,4 +1,4 @@
11 import { type Route, limitTo } from "../shared.ts";
2 import { SEARCH_LIMIT_MAX } from "../../../core/page_ceilings.ts";
2 import { SEARCH_LIMIT_MAX } from "../../../actions/search.ts";
33
44 export const route: Route = { method: "get", path: "/api/v1/search", summary: "Search guides, issues, pulls, repositories and code; `kind` narrows it", auth: false, role: "anonymous", query: { q: "string", kind: "string", limit: limitTo(SEARCH_LIMIT_MAX) }, refusals: { invalid_kind: "kind is not all, repos, issues or code (422)", invalid_limit: "limit is not a whole number from 1 to 100 (422)" }, reply: { repos: "array", issues: "array", code: "array", docs: "array of { title, path, snippet }, at most 5, guides matching; only for kind all", truncated: "object", moreCode: "boolean", codeSkipped: "boolean", note: "string, only when q is blank: what to send" } };
src/core/page_ceilings.ts deleted −12
@@ -1,12 +0,0 @@
1 /**
2 * The hard ceilings on a caller-chosen page size that the contract's route table names
3 * (`contract/openapi/routes/`). A leaf: it imports nothing, so a route file reads its ceiling
4 * without loading the module that enforces it, and no import cycle runs through the contract
5 * (#16622).
6 */
7
8 /** Hard ceiling on a caller-chosen search limit. */
9 export const SEARCH_LIMIT_MAX = 100;
10
11 /** Hard ceiling on a caller-chosen feed page. */
12 export const FEED_LIMIT_MAX = 50;
src/crew/breaker.ts +1 −1
@@ -7,7 +7,7 @@
77
88 import type { Database } from "bun:sqlite";
99 import type { Repo } from "../core/repos.ts";
10 import { CAP_NOTE } from "./cap_note.ts";
10 import { CAP_NOTE } from "./guard.ts";
1111 import { directorsAmong } from "./direct.ts";
1212 import { REPEAT_NOTE } from "./repeat_note.ts";
1313
src/crew/cap_note.ts deleted −8
@@ -1,8 +0,0 @@
1 /**
2 * What a capped issue is parked with. A leaf, so the breaker that lists it among the notes it
3 * waits on does not load the guard that writes it (#16622).
4 */
5
6 /** The note a capped issue is parked with: the map reads it as `parked`, the asks as a question. */
7 export const CAP_NOTE =
8 "Parked by the crew: this issue started its day's share of runs without landing, so nothing more starts here until a person says what to try.";
src/crew/dispatch.ts +1 −1
@@ -97,8 +97,8 @@ import { detectAgent } from "./agent_runner.ts";
9797 import { followDivergence, settleAll, settleOnPush } from "./converge.ts";
9898 import { breakerTripped } from "./breaker.ts";
9999 import { REPEAT_NOTE, repeatTripped } from "./repeat.ts";
100 import { CAP_NOTE } from "./cap_note.ts";
101100 import {
101 CAP_NOTE,
102102 capNoted,
103103 capReached,
104104 HANDOVER_NOTE,
src/crew/guard.ts +4 −1
@@ -25,7 +25,6 @@ import { listPulls } from "../core/pulls.ts";
2525 import type { Repo } from "../core/repos.ts";
2626 import { directorsAmong } from "./direct.ts";
2727 import { nothingNew, plannerNothingNew } from "./news.ts";
28 import { CAP_NOTE } from "./cap_note.ts";
2928
3029 /** Runs one issue may start in `CAP_WINDOW_MS` unless the setting says otherwise. */
3130 export const ISSUE_RUN_CAP = 6;
@@ -41,6 +40,10 @@ export function runCapOf(
4140 : (caps.issueRunCap ?? ISSUE_RUN_CAP);
4241 }
4342
43 /** The note a capped issue is parked with: the map reads it as `parked`, the asks as a question. */
44 export const CAP_NOTE =
45 "Parked by the crew: this issue started its day's share of runs without landing, so nothing more starts here until a person says what to try.";
46
4447 /** What a skipped follow-up records, and what its run says when one was already queued. */
4548 export const SKIP_SUMMARY = "skipped: nothing new to act on since the last run";
4649
src/feed/feed.ts +1 −1
@@ -7,7 +7,6 @@
77 */
88
99 import type { Database } from "bun:sqlite";
10 import { FEED_LIMIT_MAX } from "../core/page_ceilings.ts";
1110 import { chipsOf, type Chips } from "../core/feed_chips.ts";
1211 import { chipHides } from "./chips.ts";
1312 import { dismissedItems, mutedRepos } from "../core/interactions.ts";
@@ -26,6 +25,7 @@ import { settledOf } from "./settled.ts";
2625 import { repliesOf } from "./replies.ts";
2726
2827 export const FEED_LIMIT_DEFAULT = 20;
28 export const FEED_LIMIT_MAX = 50;
2929
3030 const CURSOR = /^(-?\d{1,6}(?:\.\d{1,6})?)\|([a-z]{2,12}:[A-Za-z0-9_.:-]{1,160})$/;
3131
src/feed/last_seen.ts +3 −2
@@ -11,10 +11,11 @@ import { chipsOf } from "../core/feed_chips.ts";
1111 import { dismissedItems, mutedRepos } from "../core/interactions.ts";
1212 import type { User } from "../core/users.ts";
1313 import { chipHides } from "./chips.ts";
14 import { NEW_COUNT_CAP } from "./new_count_cap.ts";
15
1614 import { viewerCandidates } from "./feed.ts";
1715
16 /** Counted up to here; more is "99+", so the read never walks a long absence. */
17 export const NEW_COUNT_CAP = 99;
18
1819 /**
1920 * How long a count stands when no event has been written: what no event sees (a grant, a watch).
2021 */
src/feed/new_count_cap.ts deleted −7
@@ -1,7 +0,0 @@
1 /**
2 * The count a "new" label stops at. A leaf: the label modules read it without loading the feed read
3 * (#16622).
4 */
5
6 /** Counted up to here; more is "99+", so the read never walks a long absence. */
7 export const NEW_COUNT_CAP = 99;
src/feed/newer_label.ts +1 −1
@@ -4,7 +4,7 @@
44 * function as plain JS for the page's poll.
55 */
66
7 import { NEW_COUNT_CAP } from "./new_count_cap.ts";
7 import { NEW_COUNT_CAP } from "./last_seen.ts";
88
99 export function newerLabel(n: number): string {
1010 if (!(n >= 1)) return "";
src/feed/timeline.ts +1 −2
@@ -25,8 +25,7 @@ import { dismissedItems, mutedRepos } from "../core/interactions.ts";
2525 import { getReposByIds } from "../core/repos.ts";
2626 import type { User } from "../core/users.ts";
2727 import { chipHides } from "./chips.ts";
28 import { FEED_LIMIT_MAX } from "../core/page_ceilings.ts";
29 import { decorate, FEED_LIMIT_DEFAULT } from "./feed.ts";
28 import { decorate, FEED_LIMIT_DEFAULT, FEED_LIMIT_MAX } from "./feed.ts";
3029 import { eventCandidates } from "./items.ts";
3130 import { showFilter, type Show } from "./mine.ts";
3231 import { ago, type FeedItem } from "./rank.ts";
src/fleet/verbs.ts +1 −2
@@ -21,8 +21,7 @@ import {
2121 setIssueLabels,
2222 setIssueState,
2323 } from "../actions/issues.ts";
24 import { linkIssue, unlinkIssue } from "../actions/dependencies.ts";
25 import { dependencyWords } from "../actions/plan_words.ts";
24 import { linkIssue, unlinkIssue, dependencyWords } from "../actions/dependencies.ts";
2625 import { updateRepoSettings } from "../actions/repos.ts";
2726 import { cancelRepoRun, requeueRepoRun } from "../actions/runs.ts";
2827 import { isCrew } from "../core/agents.ts";
src/http/api.ts +1 −2
@@ -97,8 +97,7 @@ import {
9797 } from "../actions/contribute.ts";
9898 import { watchMilestone } from "../actions/watches.ts";
9999 import { THOUGHT_MAX, keepThought } from "../actions/thought.ts";
100 import { SEARCH_LIMIT_MAX } from "../core/page_ceilings.ts";
101 import { search, searchRefusal, searchWithin, type SearchPhase } from "../actions/search.ts";
100 import { SEARCH_LIMIT_MAX, search, searchRefusal, searchWithin, type SearchPhase } from "../actions/search.ts";
102101 import { runRepos } from "./run_gate.ts";
103102 import {
104103 commitToBranch,
src/http/api/business_plan.ts +1 −1
@@ -5,6 +5,7 @@
55 */
66
77 import {
8 ATLAS_BODY_MAX,
89 businessItems,
910 checkPillar,
1011 confirmBusinessPlan,
@@ -12,7 +13,6 @@ import {
1213 spawnSeed,
1314 stampOf,
1415 } from "../../actions/business_plan.ts";
15 import { ATLAS_BODY_MAX } from "../../actions/plan_words.ts";
1616 import { loadRepo } from "../api.ts";
1717 import type { Handler } from "../context.ts";
1818 import { apiError, boundedBody, json, notFound, requireScope } from "../respond.ts";
src/http/api/issues.ts +1 −2
@@ -15,8 +15,7 @@ import { holds, weakEtag } from "../etag.ts";
1515 import { ISSUE_TEAMS_SAY, nameTeams } from "../../actions/issue_teams.ts";
1616 import { askEstimate, recordEstimate } from "../../actions/estimates.ts";
1717 import { estimatesOf } from "../../core/estimates.ts";
18 import { confirmIssue, linkIssue, unlinkIssue } from "../../actions/dependencies.ts";
19 import { dependencyWords } from "../../actions/plan_words.ts";
18 import { confirmIssue, dependencyWords, linkIssue, unlinkIssue } from "../../actions/dependencies.ts";
2019 import {
2120 addCommentThrough,
2221 closingFrom,
src/http/feed.ts +1 −1
@@ -32,8 +32,8 @@ import { feedDigest } from "../web/studio/since.ts";
3232 import { holds } from "../web/feeds.ts";
3333 import { share, RECIPIENTS_MAX } from "../feed/share.ts";
3434 import { canRead, getRepo } from "../core/repos.ts";
35 import { FEED_LIMIT_MAX } from "../core/page_ceilings.ts";
3635 import {
36 FEED_LIMIT_MAX,
3737 parseCursor,
3838 readFeed,
3939 } from "../feed/feed.ts";
src/http/mcp/tools/atlas.ts +1 −1
@@ -1,5 +1,5 @@
1 import { ATLAS_BODY_MAX } from "../../../actions/plan_words.ts";
21 import {
2 ATLAS_BODY_MAX,
33 businessItems,
44 checkPillar,
55 confirmBusinessPlan,
src/http/mcp/tools/feed.ts +1 −2
@@ -1,5 +1,4 @@
1 import { FEED_LIMIT_MAX } from "../../../core/page_ceilings.ts";
2 import { FEED_LIMIT_DEFAULT, parseCursor, readFeed } from "../../../feed/feed.ts";
1 import { FEED_LIMIT_DEFAULT, FEED_LIMIT_MAX, parseCursor, readFeed } from "../../../feed/feed.ts";
32 import { parseBefore, readTimeline } from "../../../feed/timeline.ts";
43 import { CURSOR_NOT_ISSUED } from "../../../actions/feed_words.ts";
54 import { appFilterOf, APP_UNKNOWN_LINE, onlyLine } from "../../../feed/app_filter.ts";
src/http/mcp/tools/plan.ts +1 −2
@@ -1,5 +1,4 @@
1 import { openPlan, parsePlan, proposePlan } from "../../../actions/plan.ts";
2 import { PLAN_MAX } from "../../../actions/plan_words.ts";
1 import { openPlan, parsePlan, PLAN_MAX, proposePlan } from "../../../actions/plan.ts";
32 import { good, bad, type Tool, APP_ARG, planRepo, isAnswer } from "../shared.ts";
43
54 export const tool: Tool = {
src/http/mcp/tools/system.ts +1 −1
@@ -93,7 +93,7 @@ export const tool: Tool = {
9393 const reader = telemetryReader(ctx.app, user);
9494 if (!reader) return badBlocked("forbidden", noTelemetryBlocked(ctx.app, user, "Reading this forge's maintenance workers takes the telemetry:read grant."));
9595 noteRead(ctx.app, user, reader, "system");
96 return good({ workers: weekRows(ctx.app.db, duties().map((d) => d.name)).map((w) => ({ ...w, says: resultWords(w) })) });
96 return good({ workers: weekRows(ctx.app.db, duties.map((d) => d.name)).map((w) => ({ ...w, says: resultWords(w) })) });
9797 }
9898 if (args["kind"] === "adopted") {
9999 if (!user.isAdmin) return bad("forbidden", "only an admin of this forge reads its child forges across a restart");
src/http/mcp/tools/wait_for.ts +1 −2
@@ -1,6 +1,5 @@
11 import { THREAD_SAYS } from "../../../actions/thread_words.ts";
2 import { linkIssue } from "../../../actions/dependencies.ts";
3 import { dependencyWords } from "../../../actions/plan_words.ts";
2 import { dependencyWords, linkIssue } from "../../../actions/dependencies.ts";
43 import { stopWaiting } from "../../../actions/gate.ts";
54 import { good, bad, type Tool, APP_ARG, planRepo, issueArg, isAnswer } from "../shared.ts";
65
src/http/view_stream.ts +1 −2
@@ -9,8 +9,7 @@
99 * A stream ends with its token (revoked, expired, its person suspended) and
1010 * is held at most `STREAMS_PER_TOKEN` at a time per credential.
1111 */
12 import { forgeViewText } from "../actions/forge_view.ts";
13 import { VIEW_TTL_MS } from "../actions/forge_view_ttl.ts";
12 import { forgeViewText, VIEW_TTL_MS } from "../actions/forge_view.ts";
1413 import { tokenLive } from "../core/tokens.ts";
1514 import { getUserById, isActive } from "../core/users.ts";
1615 import { heldOf } from "../perf/held.ts";
src/maintain/pause.ts +2 −2
@@ -116,7 +116,7 @@ function stateWords(name: string, s: Row | null, last: string | undefined, f: {
116116 * after a duty's newest `ok` (and after its last resume), the only ones `failing` can count.
117117 */
118118 export function dutyStates(db: Database, now = Date.now()): DutyState[] {
119 const names = JSON.stringify(registered().map((d) => d.name));
119 const names = JSON.stringify(registered.map((d) => d.name));
120120 const heads = db
121121 .query(
122122 `SELECT d.value AS name, s.paused, s.reason, s.by, s.since, s.from_run,
@@ -146,7 +146,7 @@ export function dutyStates(db: Database, now = Date.now()): DutyState[] {
146146 });
147147 }
148148
149 export const knownDuty = (name: string): boolean => registered().some((d) => d.name === name);
149 export const knownDuty = (name: string): boolean => registered.some((d) => d.name === name);
150150
151151 /** One switch for page, API and MCP: the same words. */
152152 export function switchDuty(db: Database, name: unknown, paused: unknown, by: string): { ok: true; says: string } | { ok: false; code: "invalid" | "not_found"; says: string } {
src/maintain/registry.ts +3 −14
@@ -33,18 +33,7 @@ export function loadDuties(from: URL = dir): Duty[] {
3333 });
3434 }
3535
36 /**
37 * The duties plus the one that watches them for silence. Built on the first call, not when this
38 * module loads: a duty file reaches the app's modules, which reach this registry, so loading the
39 * files here while one of them is still mid-load threw whichever way a caller entered the cycle
40 * (#16622). Every caller runs after the graph is loaded.
41 */
42 export function duties(): readonly Duty[] {
43 if (built === undefined) {
44 const others = loadDuties();
45 built = [...others, dutyIdle(others)];
46 }
47 return built;
48 }
36 const others: readonly Duty[] = loadDuties();
4937
50 let built: readonly Duty[] | undefined;
38 /** The duties plus the one that watches them for silence. */
39 export const duties: readonly Duty[] = [...others, dutyIdle(others)];
src/maintain/runner.ts +1 −1
@@ -32,7 +32,7 @@ export interface Maintain {
3232 }
3333
3434 export function startMaintain(app: App, options: { duties?: readonly Duty[]; everyMs?: number; timeoutMs?: number; keep?: number } = {}): Maintain {
35 const list = options.duties ?? registered();
35 const list = options.duties ?? registered;
3636 const seen = new Set<string>();
3737 for (const d of list) {
3838 if (!validName(d.name)) throw new Error(`maintenance duty name "${d.name}" is not lowercase words and dashes`);
src/maintain/schedule.ts +1 −1
@@ -55,7 +55,7 @@ export function scheduleOf(o: { lastStarted: number | undefined; intervalMs: num
5555 export function dutySchedules(db: Database, states: readonly { name: string; paused: boolean }[], now: number): Map<string, Schedule> {
5656 const results = lastResultAll(db);
5757 const paused = new Map(states.map((d) => [d.name, d.paused]));
58 return new Map(registered().map((d) => [d.name, scheduleOf({ lastStarted: results.get(d.name)?.started, intervalMs: d.intervalMs, paused: paused.get(d.name) === true, now, last: results.get(d.name) })]));
58 return new Map(registered.map((d) => [d.name, scheduleOf({ lastStarted: results.get(d.name)?.started, intervalMs: d.intervalMs, paused: paused.get(d.name) === true, now, last: results.get(d.name) })]));
5959 }
6060
6161 /**
src/spawn/clients.ts +7 −1
@@ -39,7 +39,6 @@ import { billTo, personReading } from "./person_activity.ts";
3939 import { archiveProposal, type ArchiveProposal } from "./archive_proposal.ts";
4040 import { appLinkLines, type AppLinkLine } from "./app_links.ts";
4141 import { madeFromOf, type MadeFrom } from "./template_record.ts";
42 import { servedWindow } from "./suite_defaults.ts";
4342 import { NO_KEY_HELD, NO_KEY_HOST_LINE } from "../crew/no_key.ts";
4443
4544 /** What a spawned forge says about itself to anyone: nothing more. */
@@ -576,6 +575,13 @@ export const memoryOf = (rows: readonly Pick<ClientRow, "size">[]): number =>
576575 /** `memoryOf` the list last read; undefined before any was. */
577576 export const servedMemoryMiB = (app: App): number | undefined => heldMemory.get(app);
578577 const building = new WeakMap<App, Promise<ClientRow[]>>();
578 /**
579 * The list a page serves is looked at again in the background when it is older than `ms`. At 0
580 * (the suite's setting) a read waits for a fresh one: a test changes a forge and reads the list at
581 * once.
582 */
583 export const servedWindow = { ms: 15_000 };
584
579585 /**
580586 * Read every row now, off the request: what `servedRows` answers from. One at a time; a caller
581587 * that comes while one is being made takes that one. `probe: false` asks no child anything.
src/spawn/door.ts +11 −9
@@ -12,7 +12,6 @@ import { contributeAnswer, wantsToContribute } from "./contribute_words.ts";
1212 import { nameShapeVerdict } from "./name_verdict.ts";
1313 import { linkRequestVisitor } from "../perf/visitor_link.ts";
1414 import { templateOfInput } from "../actions/template_timing.ts";
15 import { watchProbeDefault } from "./suite_defaults.ts";
1615 import { startWatch, probeOf, type Probe } from "./live.ts";
1716 import { firstProof, homeBudgetOf, proves, reachWords, settleChild, type ChildReach } from "./reach.ts";
1817 import {
@@ -93,6 +92,16 @@ export function probeFor(app: App, url: string, timeoutMs: number): Probe {
9392 return swapped ? swapped(url) : probeOf(url, timeoutMs);
9493 }
9594
95 let watchProbe: (url: string) => Probe = probeOf;
96 /**
97 * Tests: how a new child is asked whether it is live, for every forge, unless `useProbe` gave one.
98 * The suite's children answer nowhere, so each would keep its place among the births for the whole
99 * cap; `test/helpers/preload.ts` has them answer at once.
100 */
101 export function useWatchProbeByDefault(probe: ((url: string) => Probe) | undefined): void {
102 watchProbe = probe ?? probeOf;
103 }
104
96105 /** Tests swap how a new child is asked whether it is live. */
97106 export function useProbe(app: App, probe: (url: string) => Probe): void {
98107 probes.set(app, probe);
@@ -578,14 +587,7 @@ export async function spawnDoor(
578587 let watching = false;
579588 try {
580589 up = bootHostedChild(ctx.app, made.value.name);
581 const probeFor = probes.get(ctx.app) ?? watchProbeDefault.probe ?? probeOf;
582 watching = startWatch(ctx.app, {
583 name: made.value.name,
584 startedAt,
585 ...templateOfInput(raw["template"]),
586 probe: probeFor(made.value.url),
587 onSettled: place.release,
588 });
590 watching = startWatch(ctx.app, { name: made.value.name, startedAt, ...templateOfInput(raw["template"]), probe: (probes.get(ctx.app) ?? watchProbe)(made.value.url), onSettled: place.release });
589591 } finally {
590592 if (!watching) place.release();
591593 }
src/spawn/reach.ts +8 −2
@@ -30,7 +30,6 @@ import { uncleanInFirstMinutes } from "../kernel/boots.ts";
3030 import { lastStop, stoppedMark } from "./stopped.ts";
3131 import { readRecord } from "./cell_record.ts";
3232 import { during } from "../perf/jobs.ts";
33 import { reachDefault } from "./suite_defaults.ts";
3433
3534 export const APP_HEADER = "x-forge-app";
3635
@@ -103,7 +102,14 @@ export function useReach(app: App, o: Options): void {
103102 options.set(app, o);
104103 }
105104
106 const optionsOf = (app: App): Options => options.get(app) ?? reachDefault;
105 let fallback: Options = {};
106
107 /** What every app without its own `useReach` does; the test preload turns proving off. */
108 export function useReachByDefault(o: Options): void {
109 fallback = o;
110 }
111
112 const optionsOf = (app: App): Options => options.get(app) ?? fallback;
107113 /** The most a spawn holds its reply for the new forge to come up and answer. */
108114 export const homeBudgetOf = (app: App): number => optionsOf(app).homeWaitMs ?? HOME_WAIT_MS;
109115 const off = (app: App): boolean => optionsOf(app).fetch === undefined && optionsOf(app).off === true;
src/spawn/suite_defaults.ts deleted −23
@@ -1,23 +0,0 @@
1 /**
2 * What the test suite sets for every forge before any test file loads (`test/helpers/preload.ts`).
3 * Plain state with no imports of the spawn modules that read it: the preload touches only this
4 * file, so a test file that never reaches the spawn door does not pay to load it (#16622).
5 */
6
7 import type { Probe } from "./live.ts";
8
9 /** How long a served list of children stays fresh; see `servedWindow` in `clients.ts`. */
10 export const servedWindow = { ms: 15_000 };
11
12 /** What every app without its own `useReach` does; see `useReachByDefault` in `reach.ts`. */
13 export const reachDefault: {
14 off?: boolean;
15 fetch?: (url: string, init?: RequestInit) => Promise<Response>;
16 settleMs?: number;
17 homeWaitMs?: number;
18 pollMs?: number;
19 confirmMs?: number;
20 } = {};
21
22 /** How a new child is asked whether it is live, when set; see `door.ts`. */
23 export const watchProbeDefault: { probe?: (url: string) => Probe } = {};
src/tui/screens/atlas.ts +1 −1
@@ -7,8 +7,8 @@
77 * viewers live are one code path. Offered to whoever may plan here.
88 */
99
10 import { ATLAS_BODY_MAX } from "../../actions/plan_words.ts";
1110 import {
11 ATLAS_BODY_MAX,
1212 businessItems,
1313 checkPillar,
1414 confirmBusinessPlan,
src/tui/screens/dutybudgets.ts +3 −3
@@ -19,7 +19,7 @@ const mayAct = (session: Session): boolean => session.user?.isAdmin === true &&
1919 /** One duty a line, the chosen one marked; empty for anyone the gate refuses. */
2020 export function budgetLines(session: Session, chosen: number): string[] {
2121 if (!mayAct(session)) return [];
22 return duties().map((d, i) => {
22 return duties.map((d, i) => {
2323 const b = budgetOf(session.db, d);
2424 const u = usedToday(session.db, d.name, new Date());
2525 return `${i === chosen ? ">" : " "} ${d.name}: ${u.runs} of ${b.runsPerDay} runs, $${u.dollars.toFixed(2)} of $${b.dollarsPerDay.toFixed(2)} today (${d.budget.reason})`;
@@ -29,7 +29,7 @@ export function budgetLines(session: Session, chosen: number): string[] {
2929 /** Move the chosen duty's budget by `delta` (or back to its own with `reset`); what it says, or nothing for anyone the gate refuses. */
3030 export function moveBudget(session: Session, chosen: number, kind: BudgetKind, delta: number, reset = false): string {
3131 if (!mayAct(session)) return "";
32 const d = duties()[chosen];
32 const d = duties[chosen];
3333 if (d === undefined) return "";
3434 const actor = session.user!.id;
3535 if (reset) {
@@ -58,7 +58,7 @@ export function dutyBudgetScreen(session: Session, ctx: Ctx): Screen {
5858 key(e) {
5959 if (e.ctrl || e.alt) return true;
6060 if (e.key === "esc" || e.key === "q") ctx.pop();
61 else if (e.key === "j" || e.key === "down") chosen = Math.min(chosen + 1, duties().length - 1);
61 else if (e.key === "j" || e.key === "down") chosen = Math.min(chosen + 1, duties.length - 1);
6262 else if (e.key === "k" || e.key === "up") chosen = Math.max(chosen - 1, 0);
6363 else if (e.key === "+") note = moveBudget(session, chosen, "runs", 1);
6464 else if (e.key === "-") note = moveBudget(session, chosen, "runs", -1);
src/tui/screens/entries.ts +8 −16
@@ -47,28 +47,20 @@ export function entryFiles(dir: string = import.meta.dir): [string, string[]][]
4747 });
4848 }
4949
50 let entries: readonly PaletteEntry[] | undefined;
51
52 /**
53 * Every entry the files declare, by rank, then file name, then export name. Read on first use, not
54 * at load: the screen files import modules that may still be loading when this one is.
55 */
56 export function allEntries(): readonly PaletteEntry[] {
57 entries ??= entryFiles()
58 .flatMap(([f, names]) => {
59 const mod = require(join(import.meta.dir, f)) as Record<string, PaletteEntry>;
60 return [...names].sort().map((k) => mod[k]!);
61 })
62 .sort((a, b) => a.rank - b.rank);
63 return entries;
64 }
50 /** Every entry the files declare, by rank, then file name, then export name. */
51 export const ENTRIES: readonly PaletteEntry[] = entryFiles()
52 .flatMap(([f, names]) => {
53 const mod = require(join(import.meta.dir, f)) as Record<string, PaletteEntry>;
54 return [...names].sort().map((k) => mod[k]!);
55 })
56 .sort((a, b) => a.rank - b.rank);
6557
6658 /**
6759 * Put each entry the session is offered into `commands`, after the command it names or at the end.
6860 */
6961 export function addEntries(commands: Command[], session: Session, ctx: Ctx): void {
7062 const placed = new Map<string, number>();
71 for (const e of allEntries()) {
63 for (const e of ENTRIES) {
7264 if (!e.offered(session)) continue;
7365 const command: Command = { id: e.id, title: e.title, hint: e.hint, run: () => e.run(session, ctx) };
7466 const anchor = e.after?.find((id) => commands.some((c) => c.id === id));
src/tui/screens/issue.ts +5 −2
@@ -27,8 +27,11 @@ import {
2727 TAKEN_UP,
2828 } from "../../actions/issues.ts";
2929 import { sealedWords, sealRefusedWords } from "../../actions/seal_issue_words.ts";
30 import { linkIssue, unlinkIssue } from "../../actions/dependencies.ts";
31 import { dependencyWords } from "../../actions/plan_words.ts";
30 import {
31 dependencyWords,
32 linkIssue,
33 unlinkIssue,
34 } from "../../actions/dependencies.ts";
3235 import { THREAD_SAYS } from "../../actions/thread_words.ts";
3336 import { ISSUE_TEAMS_SAY, nameTeams } from "../../actions/issue_teams.ts";
3437 import { teamsOfIssue, TEAMS_MAX } from "../../core/issue_teams.ts";
src/tui/screens/maintenanceweek.ts +1 −1
@@ -21,7 +21,7 @@ const mayRead = (session: Session): boolean => telemetryReader(session.app, sess
2121 /** The screen's lines; empty for anyone the gate refuses. */
2222 export function weekLines(session: Session, now = new Date()): string[] {
2323 if (!mayRead(session)) return [];
24 const rows = weekRows(session.app.db, duties().map((d) => d.name), now);
24 const rows = weekRows(session.app.db, duties.map((d) => d.name), now);
2525 const width = Math.max(0, ...rows.map((r) => r.name.length));
2626 return [
2727 weekWords(rows),
src/web/pages/maintenance_budgets.ts +3 −3
@@ -16,10 +16,10 @@ import { btn, field as formControl } from "../ui.ts";
1616
1717 /** Every duty's budget row, in `names` order: two reads for all of them, not three a duty. */
1818 export function budgetRows(app: App, names: readonly string[], now = new Date()): Html[] {
19 const budgets = budgetsOf(app.db, duties());
19 const budgets = budgetsOf(app.db, duties);
2020 const used = usedTodayAll(app.db, now);
2121 return names.map((name) => {
22 const d = duties().find((x) => x.name === name);
22 const d = duties.find((x) => x.name === name);
2323 const b = budgets.get(name);
2424 return d === undefined || b === undefined ? html`` : budgetOfRow(d, b, used.get(name) ?? { runs: 0, dollars: 0 });
2525 });
@@ -44,7 +44,7 @@ export async function maintenanceBudget(ctx: Ctx): Promise<Response> {
4444 if (user === undefined || !user.isAdmin || user.kind === "agent") return flashTo(ctx, "/maintenance", { tone: "danger", message: "Only a forge admin who is a person sets a budget." });
4545 const form = await readForm(ctx, "admin");
4646 if (form instanceof Response) return form;
47 const duty = duties().find((d) => d.name === formField(form, "duty"));
47 const duty = duties.find((d) => d.name === formField(form, "duty"));
4848 if (duty === undefined) return flashTo(ctx, "/maintenance", { tone: "danger", message: "No such duty." });
4949 const picked: [("runs" | "dollars"), number | null][] = [];
5050 for (const kind of ["runs", "dollars"] as const) {
src/web/pages/system.ts +1 −1
@@ -825,7 +825,7 @@ export async function systemPage(ctx: Ctx, patterns: () => readonly string[]): P
825825 ${routeUseSection(timePhase(ctx.request, "routes", () => {
826826 return leastUsed(routeUsage(ctx.app.db, patterns(), new Date()));
827827 }))}
828 ${maintenanceSection(timePhase(ctx.request, "maintenance", () => weekRows(ctx.app.db, duties().map((d) => d.name))), timePhase(ctx.request, "starts", () => startStats(ctx.app.db, new Date(Date.now() - 7 * 86_400_000).toISOString())))}
828 ${maintenanceSection(timePhase(ctx.request, "maintenance", () => weekRows(ctx.app.db, duties.map((d) => d.name))), timePhase(ctx.request, "starts", () => startStats(ctx.app.db, new Date(Date.now() - 7 * 86_400_000).toISOString())))}
829829 ${footprintSection(lastFootprint() ?? lastProof(ctx.app.config.dataDir)?.footprint ?? null)}
830830 ${footingSection(standsOn)}
831831 ${restoreSection(timePhase(ctx.request, "restore", () => restoreLine(lastPass(ctx.app.db), lastDrill(ctx.app.db), Date.now())))}
src/web/pages/thread.ts +6 −2
@@ -17,8 +17,12 @@ import { ISSUE_TEAMS_SAY, nameTeams } from "../../actions/issue_teams.ts";
1717 import { teamsOfIssue, TEAMS_MAX } from "../../core/issue_teams.ts";
1818 import { listTeams } from "../../core/teams.ts";
1919 import { listCrew } from "../../actions/crew.ts";
20 import { confirmIssue, linkIssue, unlinkIssue } from "../../actions/dependencies.ts";
21 import { dependencyWords } from "../../actions/plan_words.ts";
20 import {
21 confirmIssue,
22 dependencyWords,
23 linkIssue,
24 unlinkIssue,
25 } from "../../actions/dependencies.ts";
2226 import { dependenciesOf } from "../../core/dependencies.ts";
2327 import { blockerByTitle, cyclePath, standingOf } from "../../core/dep_standing.ts";
2428 import { chain } from "./dep_chain.ts";
src/web/studio/held_posts.ts +1 −1
@@ -4,7 +4,7 @@
44 * is the same two functions as plain JS for the page.
55 */
66
7 import { NEW_COUNT_CAP } from "../../feed/new_count_cap.ts";
7 import { NEW_COUNT_CAP } from "../../feed/last_seen.ts";
88 import { newerLabelJs } from "../../feed/newer_label.ts";
99
1010 /** The ids in `fresh` not in `shown`, in `fresh`'s order, each once. */
test/account-purge.test.ts +1 −1
@@ -45,7 +45,7 @@ afterAll(() => rmSync(root, { recursive: true, force: true }));
4545 describe("the purge", () => {
4646 test("is a duty on the roster, hourly", async () => {
4747 const { duties } = await import("../src/maintain/registry.ts");
48 expect(duties().some((d) => d.name === "account-purge")).toBe(true);
48 expect(duties.some((d) => d.name === "account-purge")).toBe(true);
4949 expect(duty.intervalMs).toBe(3_600_000);
5050 });
5151
test/cloud-watch.test.ts +1 −1
@@ -77,7 +77,7 @@ describe("cloud watch", () => {
7777 });
7878
7979 test("the duty is on the roster", () => {
80 expect(duties().map((d) => d.name)).toContain("cloud-watch");
80 expect(duties.map((d) => d.name)).toContain("cloud-watch");
8181 });
8282
8383 test("the forge's own machine and volume are quiet, and the page says when it looked", async () => {
test/crew-guard-cap.test.ts +1 −1
@@ -17,8 +17,8 @@ import { getIssueById, type Issue } from "../src/core/issues.ts";
1717 import { getRepoById, type Repo } from "../src/core/repos.ts";
1818 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
1919 import { createUser, getUserByName, type User } from "../src/core/users.ts";
20 import { CAP_NOTE } from "../src/crew/cap_note.ts";
2120 import {
21 CAP_NOTE,
2222 CAP_WINDOW_MS,
2323 capNoted,
2424 capReached,
test/crew-guard.test.ts +1 −1
@@ -50,8 +50,8 @@ import { createUser, getUserByName, type User } from "../src/core/users.ts";
5050 import { driveRepo } from "../src/crew/autonomy.ts";
5151 import { breakerParked, breakerTripped } from "../src/crew/breaker.ts";
5252 import { queueAgentRun } from "../src/crew/dispatch.ts";
53 import { CAP_NOTE } from "../src/crew/cap_note.ts";
5453 import {
54 CAP_NOTE,
5555 guardCounts,
5656 ISSUE_RUN_CAP,
5757 SKIP_SUMMARY,
test/displays-list.test.ts +2 −2
@@ -21,7 +21,7 @@ import { serve, type Servers } from "../src/http/server.ts";
2121 import { createForgeApp } from "../src/tui/forge.ts";
2222 import { DISPLAYS_SENTENCE } from "../src/display/known.ts";
2323 import { entry as displaysEntry, displaysScreen } from "../src/tui/screens/displays.ts";
24 import { allEntries } from "../src/tui/screens/entries.ts";
24 import { ENTRIES } from "../src/tui/screens/entries.ts";
2525 import { headlessTerminal } from "../src/tui/term/terminal.ts";
2626 import { settleApp } from "./helpers/tui.ts";
2727 import { statements } from "./helpers/statements.ts";
@@ -198,7 +198,7 @@ describe("the displays list, page and terminal screen", () => {
198198 expect(mine).toContain("display.json is invalid");
199199 expect(mine).toContain("alice/hidden");
200200 expect(await screenText(bob)).not.toContain("alice/hidden");
201 expect(allEntries()).toContain(displaysEntry);
201 expect(ENTRIES).toContain(displaysEntry);
202202 });
203203
204204 test("a stranger is sent to sign in", async () => {
test/duty-idle.test.ts +1 −1
@@ -20,7 +20,7 @@ const run = (at: number) => watcher.run({ db: w.app.db, bus: w.app.bus, now: new
2020 const defects = () => w.titles().filter((t) => t === titleOf("quiet-one"));
2121
2222 test("registered, and a duty that never ran or ran recently files nothing", async () => {
23 expect(duties().map((d) => d.name)).toContain(NAME);
23 expect(duties.map((d) => d.name)).toContain(NAME);
2424 expect((await run(T0)).actions).toEqual([]);
2525 ran(T0);
2626 expect((await run(T0 + 20 * MIN)).actions).toEqual([]); // exactly twice: not over
test/duty-roster.test.ts +3 −3
@@ -10,9 +10,9 @@ import { validName } from "../src/maintain/duty.ts";
1010 test("every duty file is on the roster, once, and the idle watcher is last", () => {
1111 const files = readdirSync("src/maintain/duties").filter((f) => f.endsWith(".ts") && f !== "duty_idle.ts");
1212 expect(dutyFiles()).toEqual(files.sort());
13 expect(duties().length).toBe(files.length + 1);
14 expect(duties().at(-1)?.name).toBe(NAME);
15 const names = duties().map((d) => d.name);
13 expect(duties.length).toBe(files.length + 1);
14 expect(duties.at(-1)?.name).toBe(NAME);
15 const names = duties.map((d) => d.name);
1616 expect(new Set(names).size).toBe(names.length);
1717 for (const n of names) expect(validName(n)).toBe(true);
1818 });
test/efficiency-runner.test.ts +1 −1
@@ -38,7 +38,7 @@ function falling(now: number): void {
3838 }
3939
4040 test("run by the runner with the app, the duty finds the fall; the admin screen lists it", async () => {
41 expect(duties().map((d) => d.name)).toContain("efficiency-watcher");
41 expect(duties.map((d) => d.name)).toContain("efficiency-watcher");
4242 const now = Date.now();
4343 falling(now);
4444 const m = startMaintain(app, { duties: [duty], everyMs: 1e9 });
test/feed-new-count.test.ts +1 −2
@@ -4,8 +4,7 @@
44 */
55 import { afterAll, beforeAll, expect, test } from "bun:test";
66 import { lastVisit } from "../src/core/home_visit.ts";
7 import { NEW_COUNT_CAP } from "../src/feed/new_count_cap.ts";
8 import { newLine, newSince } from "../src/feed/last_seen.ts";
7 import { newLine, newSince, NEW_COUNT_CAP } from "../src/feed/last_seen.ts";
98 import { snappyFixture, type SnappyFixture } from "../bench/snappy.ts";
109
1110 let f: SnappyFixture;
test/helpers/preload.ts +5 −3
@@ -7,7 +7,8 @@ import "../../src/kernel/bun_guard.ts";
77 import { provideCpusForTest } from "../../src/core/capacity.ts";
88 import { provideMirrorOutboundForTest } from "../../src/origins/git-mirror.ts";
99 import { installCheapHash } from "./cheap-hash.ts";
10 import { reachDefault, servedWindow, watchProbeDefault } from "../../src/spawn/suite_defaults.ts";
10 import { useReachByDefault } from "../../src/spawn/reach.ts";
11 import { servedWindow } from "../../src/spawn/clients.ts";
1112 import "./roomy-disk.ts";
1213 import { provideEmptyImagesForTest } from "../../src/kernel/db.ts";
1314 import { emptyImagesIn } from "./empty-images.ts";
@@ -30,7 +31,7 @@ provideEmptyImagesForTest(emptyImagesIn(join(SCRATCH_ROOT, "empty-db")));
3031 process.env.FORGE_DEV = "1";
3132
3233 // A suite has no public network to prove a child through (`spawn/reach.ts`); a test of reach injects its own fetch.
33 reachDefault.off = true;
34 useReachByDefault({ off: true });
3435
3536 // The /forges list is served from memory in production; a test reads what it just changed (`spawn/clients.ts`).
3637 servedWindow.ms = 0;
@@ -56,4 +57,5 @@ const { provideMemoryForTest } = await import("../../src/spawn/births.ts");
5657 provideMemoryForTest(() => 64 * 1024 ** 3);
5758
5859 // A new child of the suite answers its first look, so its place among the births is given back.
59 watchProbeDefault.probe = () => async () => true;
60 const { useWatchProbeByDefault } = await import("../../src/spawn/door.ts");
61 useWatchProbeByDefault(() => async () => true);
test/maint-stale-branches.test.ts +1 −1
@@ -56,7 +56,7 @@ test("lists stale branches without an open pull, never the default or a pulled o
5656 });
5757
5858 test("the duty files one finding with a count, is registered, and deletes nothing", async () => {
59 expect(duties()).toContain(duty);
59 expect(duties).toContain(duty);
6060 const r = await duty.run({ db: app.db, bus: app.bus, now: NOW, app });
6161 expect(r.findings).toHaveLength(1);
6262 expect(r.findings[0]!.probe?.number).toBe(2);
test/maint-untested.test.ts +1 −1
@@ -57,5 +57,5 @@ test("an empty list files nothing", async () => {
5757 });
5858
5959 test("it is registered", () => {
60 expect(duties().map((d) => d.name)).toContain("untested-sources");
60 expect(duties.map((d) => d.name)).toContain("untested-sources");
6161 });
test/maintain-backup-age.test.ts +2 −2
@@ -36,7 +36,7 @@ const run = (hours: number) => duty.run(at(hours));
3636 const filed = () => w.titles().filter((t) => t === TITLE);
3737
3838 test("the duty is registered", () => {
39 expect(duties().map((d) => d.name)).toContain("backup-age");
39 expect(duties.map((d) => d.name)).toContain("backup-age");
4040 });
4141
4242 test("a backup under 36 hours old files nothing", async () => {
@@ -80,7 +80,7 @@ test("no backup directory set, or an empty one, is quiet", async () => {
8080 });
8181
8282 test("the maintenance board lists backup-age as a row", () => {
83 const rows = weekRows(w.app.db, duties().map((d) => d.name));
83 const rows = weekRows(w.app.db, duties.map((d) => d.name));
8484 expect(rows.map((r) => r.name)).toContain("backup-age");
8585 });
8686
test/maintain-dead-doc-paths.test.ts +1 −1
@@ -40,7 +40,7 @@ test("the duty makes one finding with a probe, and none when nothing is dead", a
4040 });
4141
4242 test("the duty is registered", () => {
43 expect(duties()).toContain(duty);
43 expect(duties).toContain(duty);
4444 });
4545
4646 test("one finding per doc, every dead path listed, and the terminal's run board counts them", async () => {
test/maintain-disk-free.test.ts +1 −1
@@ -116,5 +116,5 @@ test("dataSizes sums every top-level directory and the loose files, largest firs
116116 });
117117
118118 test("the duty is in the registry", () => {
119 expect(duties().map((d) => d.name)).toContain("disk-free");
119 expect(duties.map((d) => d.name)).toContain("disk-free");
120120 });
test/maintain-duty-states.test.ts +3 −3
@@ -30,8 +30,8 @@ const run = (duty: string, outcome: string) => {
3030 };
3131
3232 test("every duty's state, batched, is the state read one duty at a time", async () => {
33 expect(duties().length).toBeGreaterThan(7);
34 const [byPerson, byRunner, failingOn, erroredOnce, resumed, budgeted, okAfterErrors] = duties().map((d) => d.name);
33 expect(duties.length).toBeGreaterThan(7);
34 const [byPerson, byRunner, failingOn, erroredOnce, resumed, budgeted, okAfterErrors] = duties.map((d) => d.name);
3535 setPaused(app.db, byPerson!, true, "alice", new Date(t));
3636 for (const o of ["ok", "failed: one", "failed: two", "failed: three\nmore"]) run(byRunner!, o);
3737 pauseOnErrors(app.db, byRunner!, new Date(t));
@@ -46,7 +46,7 @@ test("every duty's state, batched, is the state read one duty at a time", async
4646
4747 const now = t + 3_600_000;
4848 const batched = dutyStates(app.db, now);
49 expect(batched).toEqual(duties().map((d) => dutyState(app.db, d.name, now)));
49 expect(batched).toEqual(duties.map((d) => dutyState(app.db, d.name, now)));
5050 const said = new Map(batched.map((s) => [s.name, s.detail]));
5151 expect(said.get(failingOn!)).toStartWith("on; failing since ");
5252 expect(said.get(budgeted!)).toStartWith("on; failing since ");
test/maintain-edge-kept.test.ts +1 −1
@@ -59,7 +59,7 @@ async function run(read: Get, url: string | undefined = "https://forge.example",
5959 const shareable = (edge: Record<string, string>): Get => async () => h({ "cache-control": "public, max-age=0, s-maxage=60", ...edge });
6060
6161 test("the duty is on the roster, hourly, and reads only the configured URL", async () => {
62 expect(duties().find((d) => d.name === "edge-kept")?.intervalMs).toBe(3_600_000);
62 expect(duties.find((d) => d.name === "edge-kept")?.intervalMs).toBe(3_600_000);
6363 const seen: string[] = [];
6464 const { once } = await run(async (u) => (seen.push(u), h({ "cache-control": "public, s-maxage=60", "cf-cache-status": "HIT" })));
6565 const r = await once();
test/maintain-failing.test.ts +1 −1
@@ -25,7 +25,7 @@ let app: App;
2525 let servers: Servers;
2626 let admin = "";
2727 let adminId = "";
28 const name = duties()[0]!.name;
28 const name = duties[0]!.name;
2929 beforeAll(async () => {
3030 root = mkdtempSync(join(tmpdir(), "forge-failing-"));
3131 app = createApp({ dataDir: root, port: 0 });
test/maintain-flaky-tests.test.ts +1 −1
@@ -39,5 +39,5 @@ test("files that flaked in the week are named with counts", async () => {
3939 });
4040
4141 test("it is registered", () => {
42 expect(duties().map((d) => d.name)).toContain("flaky-tests");
42 expect(duties.map((d) => d.name)).toContain("flaky-tests");
4343 });
test/maintain-merged-branches.test.ts +1 −1
@@ -70,7 +70,7 @@ test("never lists main, even when a pull merged from it", async () => {
7070 });
7171
7272 test("the duty posts one finding with a number, and is registered", async () => {
73 expect(duties()).toContain(duty);
73 expect(duties).toContain(duty);
7474 const r = await duty.run({ db: app.db, bus: app.bus, now: NOW, app });
7575 expect(r.findings).toHaveLength(1);
7676 expect(r.findings[0]!.probe?.number).toBe(1);
test/maintain-nothing.test.ts +1 −1
@@ -57,7 +57,7 @@ test("a run with a finding says so and is not 'nothing'", async () => {
5757
5858 test("the schedule read from the runs table says 'checked' for a clean row and 'found' for a finding", async () => {
5959 const { duties } = await import("../src/maintain/registry.ts");
60 const { clean, found } = { clean: duties()[0]!, found: duties()[1]! };
60 const { clean, found } = { clean: duties[0]!, found: duties[1]! };
6161 app.db.exec("DELETE FROM maintenance_run");
6262 const at = new Date(Date.now() - 3 * H).toISOString();
6363 const ins = app.db.query("INSERT INTO maintenance_run (duty, started, finished, findings, outcome) VALUES (?1, ?2, ?2, ?3, 'ok')");
test/maintain-pause.test.ts +1 −1
@@ -21,7 +21,7 @@ let app: App;
2121 let servers: Servers;
2222 let admin = "";
2323 let ro = "";
24 const name = duties()[0]!.name;
24 const name = duties[0]!.name;
2525
2626 beforeAll(async () => {
2727 root = mkdtempSync(join(tmpdir(), "forge-pause-"));
test/maintain-previews-duty.test.ts +1 −1
@@ -50,7 +50,7 @@ afterAll(async () => {
5050 });
5151
5252 test("the duty is registered, and with nothing old it finds nothing", async () => {
53 expect(duties().some((d) => d.name === "preview-dirs")).toBe(true);
53 expect(duties.some((d) => d.name === "preview-dirs")).toBe(true);
5454 expect(await duty.run(ctx())).toEqual({ findings: [], actions: [] });
5555 });
5656
test/maintain-red-apps.test.ts +1 −1
@@ -52,5 +52,5 @@ test("recovered: a green latest check files nothing, even after the old issue is
5252 });
5353
5454 test("the duty is in the registry", () => {
55 expect(duties().map((d) => d.name)).toContain("red-apps");
55 expect(duties.map((d) => d.name)).toContain("red-apps");
5656 });
test/maintain-slow-tests.test.ts +1 −1
@@ -62,7 +62,7 @@ test("a stored log without timings is said, not guessed", async () => {
6262 });
6363
6464 test("it is registered", () => {
65 expect(duties().map((d) => d.name)).toContain("slow-tests");
65 expect(duties.map((d) => d.name)).toContain("slow-tests");
6666 });
6767
6868 test("the slow-tests duty is one of the rows /maintenance lists, on, from the same registry", () => {
test/maintain-stale-issues.test.ts +1 −1
@@ -62,5 +62,5 @@ test("at most 20 names, the rest counted; a closed report lets the next night fi
6262 });
6363
6464 test("the duty is in the registry", () => {
65 expect(duties().map((d) => d.name)).toContain("stale-issues");
65 expect(duties.map((d) => d.name)).toContain("stale-issues");
6666 });
test/maintain-v1-proven.test.ts +1 −1
@@ -120,7 +120,7 @@ test("no public origin: nothing is called", async () => {
120120 });
121121
122122 test("the duty is registered, weekly", () => {
123 expect(duties().find((d) => d.name === "v1-proven")?.intervalMs).toBe(7 * 86_400_000);
123 expect(duties.find((d) => d.name === "v1-proven")?.intervalMs).toBe(7 * 86_400_000);
124124 });
125125
126126 test("a passing probe notes it once on its open defect and leaves it open; the defect is found by its body key, not its title", async () => {
test/maintain-wait-split.test.ts +1 −1
@@ -118,7 +118,7 @@ test("the run's bound sits under the runner's deadline", () => {
118118 });
119119
120120 test("the forge runs it", () => {
121 expect(duties().map((d) => d.name)).toContain("wait-split");
121 expect(duties.map((d) => d.name)).toContain("wait-split");
122122 });
123123
124124 test("in a cell the duty never asks its own public host: loopback alone, and the line says so (#14664)", async () => {
test/maintain.test.ts +32 −32
@@ -102,8 +102,8 @@ test("a duty that throws is recorded as failed and the next still runs", async (
102102
103103 test("the pulls duty is registered and a run with no quiet pull leaves an ok row with no findings", async () => {
104104 clear();
105 expect(duties().map((d) => d.name)).toContain("stale-pulls");
106 const m = startMaintain(app, { duties: duties().filter((d) => d.name === "stale-pulls"), everyMs: 1e9 });
105 expect(duties.map((d) => d.name)).toContain("stale-pulls");
106 const m = startMaintain(app, { duties: duties.filter((d) => d.name === "stale-pulls"), everyMs: 1e9 });
107107 m.stop();
108108 await m.tick(new Date("2026-11-11T12:00:00Z"));
109109 const [row] = latest(app.db, 1);
@@ -239,7 +239,7 @@ test("a stored budget replaces the declared one, and a blank takes it back; the
239239 expect(parseBudget("runs", "0")).toBeUndefined();
240240 expect(parseBudget("runs", "1e3")).toBeUndefined();
241241 expect(parseBudget("dollars", "0.5")).toBe(0.5);
242 for (const d of duties()) expect(d.budget.reason.length).toBeGreaterThan(10);
242 for (const d of duties) expect(d.budget.reason.length).toBeGreaterThan(10);
243243 });
244244
245245 test("POST /maintenance/budget moves a budget for an admin, refuses a bad number, and the page shows the reason", async () => {
@@ -249,42 +249,42 @@ test("POST /maintenance/budget moves a budget for an admin, refuses a bad number
249249 const cookie = `forge_session=${createSession(app.db, adminId).token}`;
250250 const post = (body: Record<string, string>) =>
251251 fetch(`${servers.url}/maintenance/budget`, { method: "POST", redirect: "manual", headers: { cookie, origin: servers.url, "content-type": "application/x-www-form-urlencoded" }, body: new URLSearchParams(body) });
252 const name = duties()[0]!.name;
252 const name = duties[0]!.name;
253253 expect((await post({ duty: name, runs: "7", dollars: "2.5" })).status).toBe(303);
254254 const { budgetOf } = await import("../src/maintain/budget.ts");
255 expect(budgetOf(app.db, duties()[0]!)).toEqual({ runsPerDay: 7, dollarsPerDay: 2.5 });
255 expect(budgetOf(app.db, duties[0]!)).toEqual({ runsPerDay: 7, dollarsPerDay: 2.5 });
256256 await post({ duty: name, runs: "0", dollars: "2.5" });
257 expect(budgetOf(app.db, duties()[0]!).runsPerDay).toBe(7);
257 expect(budgetOf(app.db, duties[0]!).runsPerDay).toBe(7);
258258 await post({ duty: name, runs: "", dollars: "" });
259 expect(budgetOf(app.db, duties()[0]!).runsPerDay).toBe(duties()[0]!.budget.runsPerDay);
259 expect(budgetOf(app.db, duties[0]!).runsPerDay).toBe(duties[0]!.budget.runsPerDay);
260260 const page = await (await fetch(`${servers.url}/maintenance`, { headers: { cookie } })).text();
261 expect(page).toContain(duties()[0]!.budget.reason);
261 expect(page).toContain(duties[0]!.budget.reason);
262262 });
263263
264264 test("only an admin moves a budget: a non-admin, a guest and a cross-origin post are refused and nothing changes", async () => {
265265 const { createSession } = await import("../src/core/sessions.ts");
266266 const { budgetOf } = await import("../src/maintain/budget.ts");
267267 const id = (n: string) => (app.db.query("SELECT id FROM user WHERE username = ?1").get(n) as { id: string }).id;
268 const own = { ...budgetOf(app.db, duties()[0]!) };
268 const own = { ...budgetOf(app.db, duties[0]!) };
269269 const post = (cookie: string, origin: string) =>
270270 fetch(`${servers.url}/maintenance/budget`, {
271271 method: "POST", redirect: "manual",
272272 headers: { ...(cookie ? { cookie } : {}), origin, "content-type": "application/x-www-form-urlencoded" },
273 body: new URLSearchParams({ duty: duties()[0]!.name, runs: "3", dollars: "3" }),
273 body: new URLSearchParams({ duty: duties[0]!.name, runs: "3", dollars: "3" }),
274274 });
275275 const bobCookie = `forge_session=${createSession(app.db, id("bob")).token}`;
276276 const aliceCookie = `forge_session=${createSession(app.db, id("alice")).token}`;
277277 await post(bobCookie, servers.url);
278 expect(budgetOf(app.db, duties()[0]!)).toEqual(own);
278 expect(budgetOf(app.db, duties[0]!)).toEqual(own);
279279 await post("", servers.url);
280 expect(budgetOf(app.db, duties()[0]!)).toEqual(own);
280 expect(budgetOf(app.db, duties[0]!)).toEqual(own);
281281 app.db.query("UPDATE user SET is_agent = 1, is_admin = 1 WHERE username = 'bob'").run();
282282 await post(bobCookie, servers.url);
283 expect(budgetOf(app.db, duties()[0]!)).toEqual(own);
283 expect(budgetOf(app.db, duties[0]!)).toEqual(own);
284284 app.db.query("UPDATE user SET is_agent = 0, is_admin = 0 WHERE username = 'bob'").run();
285285 const cross = await post(aliceCookie, "https://evil.example");
286286 expect(cross.status).toBeGreaterThanOrEqual(400);
287 expect(budgetOf(app.db, duties()[0]!)).toEqual(own);
287 expect(budgetOf(app.db, duties[0]!)).toEqual(own);
288288 });
289289
290290 test("a stored dollars budget is enforced, and a value equal to the declared one is not stored", async () => {
@@ -311,17 +311,17 @@ test("the budget screen moves a budget for an admin who is a person and shows no
311311 const id = (app.db.query("SELECT id FROM user WHERE username = 'alice'").get() as { id: string }).id;
312312 const as = (user: unknown) => ({ user, db: app.db }) as never;
313313 const adminS = as({ isAdmin: true, kind: "person", id, username: "alice" });
314 const before = budgetOf(app.db, duties()[0]!).runsPerDay;
315 expect(budgetLines(adminS, 0).some((l) => l.startsWith("> " + duties()[0]!.name))).toBe(true);
314 const before = budgetOf(app.db, duties[0]!).runsPerDay;
315 expect(budgetLines(adminS, 0).some((l) => l.startsWith("> " + duties[0]!.name))).toBe(true);
316316 moveBudget(adminS, 0, "runs", 1);
317 expect(budgetOf(app.db, duties()[0]!).runsPerDay).toBe(before + 1);
317 expect(budgetOf(app.db, duties[0]!).runsPerDay).toBe(before + 1);
318318 moveBudget(adminS, 0, "runs", 0, true);
319 expect(budgetOf(app.db, duties()[0]!).runsPerDay).toBe(duties()[0]!.budget.runsPerDay);
319 expect(budgetOf(app.db, duties[0]!).runsPerDay).toBe(duties[0]!.budget.runsPerDay);
320320 for (const who of [as({ isAdmin: false, kind: "person", id }), as({ isAdmin: true, kind: "agent", id }), as(undefined)]) {
321321 expect(budgetLines(who, 0)).toEqual([]);
322322 expect(moveBudget(who, 0, "runs", 1)).toBe("");
323323 }
324 expect(budgetOf(app.db, duties()[0]!).runsPerDay).toBe(duties()[0]!.budget.runsPerDay);
324 expect(budgetOf(app.db, duties[0]!).runsPerDay).toBe(duties[0]!.budget.runsPerDay);
325325 });
326326
327327 test("the budget screen's keys move the chosen duty's budget, and a refused session's keys do nothing", async () => {
@@ -331,7 +331,7 @@ test("the budget screen's keys move the chosen duty's budget, and a refused sess
331331 let popped = 0;
332332 const ctx = { invalidate: () => {}, pop: () => popped++, theme: {} } as never;
333333 const press = (screen: { key?: (e: never) => boolean }, key: string) => screen.key!({ key, ctrl: false, alt: false } as never);
334 const d = duties()[0]!;
334 const d = duties[0]!;
335335 const own = { ...budgetOf(app.db, d) };
336336 const screen = dutyBudgetScreen({ user: { isAdmin: true, kind: "person", id }, db: app.db } as never, ctx);
337337 press(screen, "+");
@@ -357,21 +357,21 @@ test("every duty's budget and today's use, read in two statements, are what the
357357 const { budgetOf, budgetsOf, setBudget, usedToday, usedTodayAll } = await import("../src/maintain/budget.ts");
358358 const now = new Date("2026-11-11T12:00:00Z");
359359 const ins = app.db.query("INSERT INTO maintenance_run (duty, started, finished, findings, actions, probes, outcome, dollars) VALUES (?1, ?2, ?2, '[]', '[]', '[]', ?3, ?4)");
360 ins.run(duties()[0]!.name, "2026-11-11T01:00:00.000Z", "ok", 0.25);
361 ins.run(duties()[0]!.name, "2026-11-11T02:00:00.000Z", "ok", 0.5);
362 ins.run(duties()[0]!.name, "2026-11-11T03:00:00.000Z", "budget: runs per day, 2 of 2 used", 0);
363 ins.run(duties()[1]!.name, "2026-11-10T23:00:00.000Z", "ok", 1);
364 setBudget(app.db, duties()[1]!, "runs", 9, "u");
365 app.db.query("INSERT INTO forge_setting (key, value, updated_by, updated_at) VALUES (?1, 'nonsense', 'u', '')").run(`maintain.${duties()[2]!.name}.dollars`);
366 const budgets = budgetsOf(app.db, duties());
360 ins.run(duties[0]!.name, "2026-11-11T01:00:00.000Z", "ok", 0.25);
361 ins.run(duties[0]!.name, "2026-11-11T02:00:00.000Z", "ok", 0.5);
362 ins.run(duties[0]!.name, "2026-11-11T03:00:00.000Z", "budget: runs per day, 2 of 2 used", 0);
363 ins.run(duties[1]!.name, "2026-11-10T23:00:00.000Z", "ok", 1);
364 setBudget(app.db, duties[1]!, "runs", 9, "u");
365 app.db.query("INSERT INTO forge_setting (key, value, updated_by, updated_at) VALUES (?1, 'nonsense', 'u', '')").run(`maintain.${duties[2]!.name}.dollars`);
366 const budgets = budgetsOf(app.db, duties);
367367 const used = usedTodayAll(app.db, now);
368 for (const d of duties()) {
368 for (const d of duties) {
369369 expect(budgets.get(d.name)).toEqual(budgetOf(app.db, d));
370370 expect(used.get(d.name) ?? { runs: 0, dollars: 0 }).toEqual(usedToday(app.db, d.name, now));
371371 }
372 expect(budgets.get(duties()[1]!.name)!.runsPerDay).toBe(9);
373 expect(used.get(duties()[0]!.name)).toEqual({ runs: 2, dollars: 0.75 });
374 setBudget(app.db, duties()[1]!, "runs", null, "u");
375 app.db.query("DELETE FROM forge_setting WHERE key = ?1").run(`maintain.${duties()[2]!.name}.dollars`);
372 expect(budgets.get(duties[1]!.name)!.runsPerDay).toBe(9);
373 expect(used.get(duties[0]!.name)).toEqual({ runs: 2, dollars: 0.75 });
374 setBudget(app.db, duties[1]!, "runs", null, "u");
375 app.db.query("DELETE FROM forge_setting WHERE key = ?1").run(`maintain.${duties[2]!.name}.dollars`);
376376 clear();
377377 });
test/maintenance-chapter-stall.test.ts +1 −1
@@ -81,5 +81,5 @@ test("a closed issue is not stalled", () => {
8181 });
8282
8383 test("the duty is in the registry", () => {
84 expect(duties().map((d) => d.name)).toContain("chapter-stall");
84 expect(duties.map((d) => d.name)).toContain("chapter-stall");
8585 });
test/maintenance-last-run.test.ts +3 −3
@@ -66,10 +66,10 @@ afterAll(async () => {
6666 * one standing alone.
6767 */
6868 function seed(): { a: string; b: string; c: string; ran: string } {
69 const [a, b, c] = duties();
69 const [a, b, c] = duties;
7070 setSystemTime(new Date(NOW));
7171 app.db.run("DELETE FROM maintenance_run");
72 for (const d of duties()) setPaused(app.db, d.name, false, "boss");
72 for (const d of duties) setPaused(app.db, d.name, false, "boss");
7373 const ins = app.db.query("INSERT INTO maintenance_run (duty, started, finished, outcome) VALUES (?1, ?2, ?2, 'ok')");
7474 ins.run(a!.name, new Date(NOW - a!.intervalMs / 2).toISOString());
7575 ins.run(b!.name, new Date(NOW - 4 * b!.intervalMs).toISOString());
@@ -98,7 +98,7 @@ test("the page shows ran/next, late in the attn tone, and says paused once", asy
9898 test("every registered duty has a schedule; a paused one's words are only when it ran", () => {
9999 seed();
100100 const all = dutySchedules(app.db, dutyStates(app.db), Date.now());
101 expect([...all.keys()]).toEqual(duties().map((d) => d.name));
101 expect([...all.keys()]).toEqual(duties.map((d) => d.name));
102102 expect(scheduleWords({ ran: "ran 2h ago", next: "next in 4h", late: true })).toBe("ran 2h ago; next in 4h");
103103 expect(scheduleWords({ ran: "ran 4d ago", next: "paused", late: false })).toBe("ran 4d ago");
104104 });
test/maintenance-page.test.ts +1 −1
@@ -38,7 +38,7 @@ beforeAll(async () => {
3838 // 200 stored rows, a third of them errored, spread over the registered duties.
3939 const ins = app.db.query("INSERT INTO maintenance_run (duty, started, finished, outcome) VALUES (?1, ?2, ?2, ?3)");
4040 app.db.transaction(() => {
41 for (let i = 0; i < 200; i++) ins.run(duties()[i % duties().length]!.name, new Date(Date.now() - (200 - i) * 60_000).toISOString(), i % 3 === 0 ? "failed: boom" : "ok");
41 for (let i = 0; i < 200; i++) ins.run(duties[i % duties.length]!.name, new Date(Date.now() - (200 - i) * 60_000).toISOString(), i % 3 === 0 ? "failed: boom" : "ok");
4242 })();
4343 });
4444 afterAll(async () => {
test/maintenance-pause-who.test.ts +1 −1
@@ -19,7 +19,7 @@ let root = "";
1919 let app: App;
2020 let servers: Servers;
2121 let admin = "";
22 const name = duties()[0]!.name;
22 const name = duties[0]!.name;
2323 const page = async (): Promise<string> => (await fetch(`${servers.url}/maintenance`, { headers: { authorization: `Bearer ${admin}` } })).text();
2424
2525 beforeAll(async () => {
test/maintenance-week-doors.test.ts +4 −4
@@ -26,7 +26,7 @@ let admin = "";
2626 let plain = "";
2727 let alice: User;
2828 let bob: User;
29 const first = duties()[0]!.name;
29 const first = duties[0]!.name;
3030
3131 const identity = (user?: User) => ({ sshUsername: user?.username ?? "git", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user });
3232
@@ -66,7 +66,7 @@ test("MCP maintenance answers a row per worker; a non-admin is forbidden; teleme
6666 const out = await call(admin);
6767 expect(out.result.isError).not.toBe(true);
6868 const { workers } = JSON.parse(out.result.content[0].text);
69 expect(workers.map((w: any) => w.name)).toEqual(duties().map((d) => d.name));
69 expect(workers.map((w: any) => w.name)).toEqual(duties.map((d) => d.name));
7070 expect(workers[0]).toMatchObject({ name: first, found: 2, acted: 1, result: "ok", says: "ok in 0 ms" });
7171 expect(workers[0].last).not.toBeNull();
7272 expect(workers[1]).toMatchObject({ found: 0, acted: 0, last: null });
@@ -85,8 +85,8 @@ test("MCP maintenance answers a row per worker; a non-admin is forbidden; teleme
8585
8686 test("the terminal screen says the sentence and lists every worker, for the same gate; others get nothing", () => {
8787 const lines = weekLines(new Session(app, identity(alice)));
88 expect(lines[0]).toBe(`1 of ${String(duties().length)} workers found something this week`);
89 expect(lines.length).toBe(duties().length + 2);
88 expect(lines[0]).toBe(`1 of ${String(duties.length)} workers found something this week`);
89 expect(lines.length).toBe(duties.length + 2);
9090 expect(lines[2]).toContain("found 2 · acted 1");
9191 expect(lines[2]).toContain("ok in 0 ms");
9292 expect(lines[3]).toContain("not yet run");
test/memory-watch.test.ts −3
@@ -69,9 +69,6 @@ test("the minute lines name the owner and the figures", () => {
6969 const r = { rss: 5 * 1024 * MIB, heap: 1024 * MIB, commit: 512 * MIB, peakCommit: 700 * MIB, dbCeiling: 1536 * MIB };
7070 expect(memoryLine(r, 3_600_000)).toBe("memory main: rss 5120 MiB, heap 1024 MiB, process mimalloc committed 512 MiB (peak 700 MiB), database caches up to 1536 MiB, up 60 min");
7171 expect(workerMemoryLine("engine", r)).toBe("memory worker engine: heap 1024 MiB, process rss 5120 MiB");
72 // A VM reports no heap until it has collected once; a process that loaded little has not
73 // (#16622).
74 Bun.gc(true);
7572 expect(readNow().heap).toBeGreaterThan(0);
7673 });
7774
test/palette-entries.test.ts +6 −6
@@ -1,6 +1,6 @@
11 import { expect, test } from "bun:test";
22 import type { Command } from "../src/tui/app/palette.ts";
3 import { addEntries, allEntries, entryFiles, type PaletteEntry } from "../src/tui/screens/entries.ts";
3 import { addEntries, ENTRIES, entryFiles, type PaletteEntry } from "../src/tui/screens/entries.ts";
44 import { mkdtempSync, writeFileSync, rmSync } from "node:fs";
55 import { tmpdir } from "node:os";
66 import { join } from "node:path";
@@ -10,12 +10,12 @@ const stub = (id: string, after?: string[], rank = 0): PaletteEntry => ({
1010 id, rank, title: id, hint: "", ...(after ? { after } : {}), offered: () => true, run: () => undefined,
1111 });
1212 const place = (commands: Command[], entries: PaletteEntry[]): string[] => {
13 const saved = [...allEntries()];
14 (allEntries() as PaletteEntry[]).splice(0, allEntries().length, ...entries);
13 const saved = [...ENTRIES];
14 (ENTRIES as PaletteEntry[]).splice(0, ENTRIES.length, ...entries);
1515 try {
1616 addEntries(commands, {} as never, {} as never);
1717 } finally {
18 (allEntries() as PaletteEntry[]).splice(0, allEntries().length, ...saved);
18 (ENTRIES as PaletteEntry[]).splice(0, ENTRIES.length, ...saved);
1919 }
2020 return commands.map((c) => c.id);
2121 };
@@ -40,7 +40,7 @@ test("an entry the session is not offered is left out", () => {
4040 // The roster is built from the directory, not listed: these are known to be in it, including the
4141 // entries a file exports under another name than `entry`, in the order the palette has always had.
4242 test("the palette roster holds the known entries in their pinned order", () => {
43 const ids = allEntries().map((e) => e.id);
43 const ids = ENTRIES.map((e) => e.id);
4444 expect(ids.length).toBeGreaterThan(100);
4545 const known = ["bills", "payments", "sentinel", "boards", "drift", "model-grant", "model-ceiling", "claim-start", "claim-link", "recovery-link", "new-issue-anywhere"];
4646 expect(ids.filter((id) => known.includes(id))).toEqual(known.filter((id) => ids.includes(id)));
@@ -55,7 +55,7 @@ test("entries sort by rank, then by file name", () => {
5555 });
5656
5757 test("no two entries share an id", () => {
58 const ids = allEntries().map((e) => e.id);
58 const ids = ENTRIES.map((e) => e.id);
5959 expect(new Set(ids).size).toBe(ids.length);
6060 });
6161
test/red-main-line.test.ts +1 −1
@@ -4,7 +4,7 @@ import { mainLineFor, redMainLine, redOnMain } from "../src/checks/red_main_line
44
55 const red = (over: Partial<RedMain> = {}): RedMain => ({
66 repoId: "r", repo: "a/forge", runId: "x", commitOid: "abcdef0123456789", failing: ["sizes hold"],
7 summary: "check failed: 1 failed", branch: "main", limit: false, flaky: false, since: "2026-11-16T00:00:00Z", ...over,
7 summary: "check failed: 1 failed", branch: "main", limit: false, since: "2026-11-16T00:00:00Z", ...over,
88 });
99 const failed = (names: string[]) => ({ state: "failed" as const, checkDetail: { passed: 1, failed: names.length, names } });
1010
test/revert-red.test.ts +2 −18
@@ -42,12 +42,7 @@ describe("a red main after one landing proposes its revert", () => {
4242 return getPull(app.db, repo.id, opened.value.number)!;
4343 };
4444
45 const mainCheck = async (
46 state: "ok" | "failed",
47 names: string[] = [],
48 summary?: string,
49 detail: object = {},
50 ): Promise<void> => {
45 const mainCheck = async (state: "ok" | "failed", names: string[] = [], summary?: string): Promise<void> => {
5146 const oid = await resolveOid(repoDir(app.reposRoot, repo.ownerName, repo.name), "refs/heads/main");
5247 const run = createRun(app.db, { repoId: repo.id, kind: "check", env: "main", commitOid: oid ?? "" });
5348 app.db
@@ -56,7 +51,7 @@ describe("a red main after one landing proposes its revert", () => {
5651 run.id,
5752 state,
5853 summary ?? (state === "ok" ? "check passed in 1s" : "check failed: 1 test failed"),
59 state === "ok" ? "" : JSON.stringify({ names, ...detail }),
54 state === "ok" ? "" : JSON.stringify({ names }),
6055 new Date().toISOString(),
6156 );
6257 };
@@ -124,7 +119,6 @@ describe("a red main after one landing proposes its revert", () => {
124119 "stopped: out of memory",
125120 "the forge was stopped under this check 3 times; not trying again",
126121 "check stalled: started and wrote nothing, offered to no runner, twice; not trying again",
127 "check took longer than 2400s",
128122 ]) {
129123 await mainCheck("ok");
130124 await land(`b${reverts().length}${summary.length}`, `${summary}\n`);
@@ -134,16 +128,6 @@ describe("a red main after one landing proposes its revert", () => {
134128 expect(reverts()).toHaveLength(0);
135129 });
136130
137 test("a red whose every failing file passes alone opens none (#16622)", async () => {
138 await mainCheck("ok");
139 await land("loaded", "load\n");
140 await mainCheck("failed", ["t"], undefined, { files: ["test/a.test.ts"], flakyUnderLoad: ["test/a.test.ts"] });
141 expect(await proposeRevert(app, repo.id)).toBeUndefined();
142 // one file red alone besides: that one is a test's failure, and the landing is proposed
143 await mainCheck("failed", ["t"], undefined, { files: ["test/a.test.ts", "test/b.test.ts"], flakyUnderLoad: ["test/a.test.ts"] });
144 expect(await proposeRevert(app, repo.id)).toBeDefined();
145 });
146
147131 test("a green main opens none", async () => {
148132 await mainCheck("ok");
149133 await land("one", "beta\n");
test/spawn-in-process-visible.test.ts +1 −2
@@ -22,8 +22,7 @@ import {
2222 import { during, jobWatchOf } from "../src/perf/jobs.ts";
2323 import { liveOf } from "../src/perf/live.ts";
2424 import { stallLine } from "../src/perf/loop.ts";
25 import { clientRows } from "../src/spawn/clients.ts";
26 import { servedWindow } from "../src/spawn/suite_defaults.ts";
25 import { clientRows, servedWindow } from "../src/spawn/clients.ts";
2726 import { closeHostedChildren, openChildren, provideCellsForTest } from "../src/spawn/host.ts";
2827 import { hostedPlacement } from "../src/spawn/placement.ts";
2928 import {
test/spawn-move-cell-sizes.test.ts +1 −2
@@ -14,8 +14,7 @@ import {
1414 } from "bun:test";
1515 import { writeFileSync } from "node:fs";
1616 import { join } from "node:path";
17 import { clientRows } from "../src/spawn/clients.ts";
18 import { servedWindow } from "../src/spawn/suite_defaults.ts";
17 import { servedWindow, clientRows } from "../src/spawn/clients.ts";
1918 import { provideCellsForTest, sleepIdleChildren } from "../src/spawn/host.ts";
2019 import { moveDisk } from "../src/spawn/move_check.ts";
2120 import {
test/spawn-move-cell.test.ts +1 −2
@@ -20,8 +20,7 @@ import {
2020 import { Database } from "bun:sqlite";
2121 import { readFileSync, rmSync, writeFileSync } from "node:fs";
2222 import { join } from "node:path";
23 import { clientRows } from "../src/spawn/clients.ts";
24 import { servedWindow } from "../src/spawn/suite_defaults.ts";
23 import { servedWindow, clientRows } from "../src/spawn/clients.ts";
2524 import { provideCellsForTest, sleepIdleChildren } from "../src/spawn/host.ts";
2625 import { moveDisk } from "../src/spawn/move_check.ts";
2726 import {
test/spawn-sealed-host.test.ts +1 −2
@@ -30,8 +30,7 @@ import {
3030 stopCellChildren,
3131 type CellChild,
3232 } from "../src/spawn/cell.ts";
33 import { clientRows } from "../src/spawn/clients.ts";
34 import { servedWindow } from "../src/spawn/suite_defaults.ts";
33 import { clientRows, servedWindow } from "../src/spawn/clients.ts";
3534 import {
3635 bootHostedChild,
3736 closeHostedChildren,
test/tui-drift.test.ts +2 −2
@@ -10,7 +10,7 @@ import { createApp, type App } from "../src/app.ts";
1010 import { createUser, type User } from "../src/core/users.ts";
1111 import type { Repo } from "../src/core/repos.ts";
1212 import { createForgeApp } from "../src/tui/forge.ts";
13 import { allEntries } from "../src/tui/screens/entries.ts";
13 import { ENTRIES } from "../src/tui/screens/entries.ts";
1414 import { askUpdate, driftRows, driftScreen, entry } from "../src/tui/screens/drift.ts";
1515 import { headlessTerminal } from "../src/tui/term/terminal.ts";
1616 import { quietLogs } from "./helpers/globals.ts";
@@ -49,7 +49,7 @@ afterAll(async () => {
4949 });
5050
5151 test("the entry is in the palette list and offered to a person admin alone", () => {
52 expect(allEntries()).toContain(entry);
52 expect(ENTRIES).toContain(entry);
5353 const a = open(alice);
5454 const b = open(bob);
5555 expect(entry.offered(a.session)).toBe(true);
test/tui-issue-waits.test.ts +1 −2
@@ -8,8 +8,7 @@ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
88 import { mkdtemp, rm } from "node:fs/promises";
99 import { tmpdir } from "node:os";
1010 import { join } from "node:path";
11 import { linkIssue } from "../src/actions/dependencies.ts";
12 import { dependencyWords } from "../src/actions/plan_words.ts";
11 import { dependencyWords, linkIssue } from "../src/actions/dependencies.ts";
1312 import { THREAD_SAYS } from "../src/actions/thread_words.ts";
1413 import { openIssue } from "../src/actions/issues.ts";
1514 import { openPull } from "../src/actions/pulls.ts";
test/tui-maintenance-pause-who.test.ts +1 −1
@@ -29,7 +29,7 @@ afterAll(async () => {
2929 });
3030
3131 test("a paused duty reads 'paused by <handle> 3 h ago' in the terminal", async () => {
32 setPaused(app.db, duties()[0]!.name, true, "boss", new Date(Date.now() - 3 * 3_600_000 - 1000));
32 setPaused(app.db, duties[0]!.name, true, "boss", new Date(Date.now() - 3 * 3_600_000 - 1000));
3333 const terminal = headlessTerminal(160, 40);
3434 const { app: tui, session } = createForgeApp(app, { sshUsername: "boss", remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user: admin }, { terminal, exitHooks: false });
3535 tui.start();
test/verify-after-landing.test.ts −17
@@ -252,23 +252,6 @@ describe("a red verification names its culprit", () => {
252252 expect(listPulls(app.db, repo.id, { state: "all" }).filter((p) => p.revertsPullId !== null)).toHaveLength(1);
253253 });
254254
255 test("a red whose every file passes alone is the load's: no bisection, no revert (#16622)", async () => {
256 await verification("ok");
257 await land("loaded");
258 const red = await verification("failed");
259 app.db
260 .query("UPDATE run SET check_detail = ?2 WHERE id = ?1")
261 .run(red.id, JSON.stringify({ passed: 0, failed: 1, names: ["thing > works"], files: [FILE], flakyUnderLoad: [FILE] }));
262 const asked: string[] = [];
263 const lines = await afterVerify(app, repo, getRun(app.db, red.id)!, async (_r, _e, oid) => {
264 asked.push(oid);
265 return undefined;
266 });
267 expect(lines[0]).toContain("pass alone");
268 expect(asked).toEqual([]);
269 expect(listPulls(app.db, repo.id, { state: "all" }).filter((p) => p.revertsPullId !== null)).toHaveLength(0);
270 });
271
272255 test("a push no pull carried is named in one issue", async () => {
273256 await verification("ok");
274257 await commitToBranch(app, alice, repo, { branch: "main", message: "direct", files: [{ path: "b.txt", content: "b\n" }] });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs