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

Fewer merge conflicts: split the files every pull touches, and show collisions in the queue #17029

Merged opened this in answer to

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

Merged

mason/forge:mason/16331-fewer-merge-conflicts-split-the-files-ev → main 0 commits fork 5 threads · 5 unresolved

  • Merged. mason/16331-fewer-merge-conflicts-split-the-files-ev was merged into main as 692d75f.

Review

Sign in to review this change.
40 files changed +326 −109
CLAUDE.md +1 −1
@@ -270,7 +270,7 @@ Read this before touching `src/web/`. Principles live in `docs/DESIGN.md`; these
270270
271271 1. **A spec per component.** Each design-system component has one spec asserting the same list at 390x844 and 1280x800: operable by keyboard alone, a name and role on every control, visible focus, tap targets of 44 px or more, no horizontal page scroll, nothing closed covering the page, right in `dir="rtl"`, contrast in light and dark. A component without its spec fails the check (#12016 owns the helper).
272272 2. **A lint over `src/web/`.** `bun scripts/design-lint.ts` before you push: off-token colours, spacing and z-index, and a full-viewport `position: fixed` box outside the overlay host are refused, each with the rule and the fix in one line. Build a control from its component, never by hand.
273 3. **A byte ceiling per page.** `docs/design/size-budget.json` holds each first page's client JS and CSS in gzip bytes (linked assets plus inline script and style, counted by `src/measure/client_size.ts`). `test/client-size.test.ts` renders each page twice and refuses counted inline code that differs between renders (a per-request value goes in a data block or an attribute), then names the page, the bytes over and the command that raises the ceiling. `FORGE_SIZE_WRITE=1 bun test test/client-size.test.ts` writes every ceiling as the measure plus 2 %, rounded up to the next 256 B; a pull that grows a page past its ceiling runs it in the same push and says why. The full tier on land (`check.full` in forge.json) runs the same test on the pull merged into main as it is then, so two pulls that each fit and together pass a ceiling cannot both land: the second is held, its verdict naming the ceiling, and it raises the ceiling or trims in its own pull (#14026). Headroom stays 2 % plus the 256 B rounding: the gate, not slack, now stops the race, so a ceiling is a hard line each landing is measured against, not a pool thirty landings an hour share.
273 3. **A byte ceiling per page.** One file per page in `docs/design/size-budget/` holds each first page's client JS and CSS in gzip bytes (linked assets plus inline script and style, counted by `src/measure/client_size.ts`). `test/client-size.test.ts` renders each page twice and refuses counted inline code that differs between renders (a per-request value goes in a data block or an attribute), then names the page, the bytes over and the command that raises the ceiling. `FORGE_SIZE_WRITE=1 bun test test/client-size.test.ts` writes one file per page, each ceiling the measure plus 2 %, rounded up to the next 256 B; a pull that grows a page past its ceiling runs it in the same push and says why. The full tier on land (`check.full` in forge.json) runs the same test on the pull merged into main as it is then, so two pulls that each fit and together pass a ceiling cannot both land: the second is held, its verdict naming the ceiling, and it raises the ceiling or trims in its own pull (#14026). Headroom stays 2 % plus the 256 B rounding: the gate, not slack, now stops the race, so a ceiling is a hard line each landing is measured against, not a pool thirty landings an hour share.
outdated

The text docs/design/size-budget/ (one file per page) is the literal output of a search-and-replace and reads badly. Write it as "one file per page in docs/design/size-budget/". Also fix "writes every ceiling", which should say it writes one file per page.

274274
275275 ## Recipes
276276
docs/design/size-budget.json deleted −78
@@ -1,78 +0,0 @@
1 {
2 "/": {
3 "js": 24576,
4 "css": 51712
5 },
6 "/explore": {
7 "js": 24320,
8 "css": 51712
9 },
10 "/map": {
11 "js": 31744,
12 "css": 53248
13 },
14 "/:owner/:name": {
15 "js": 41216,
16 "css": 51712
17 },
18 "/changelog": {
19 "js": 29696,
20 "css": 51712
21 },
22 "/:owner/:name/next": {
23 "js": 26112,
24 "css": 51968
25 },
26 "/:owner/:name/space": {
27 "js": 33024,
28 "css": 52736
29 },
30 "/:owner/:name/space.json": {
31 "js": 0,
32 "css": 0
33 },
34 "/maintenance": {
35 "js": 24320,
36 "css": 51712
37 },
38 "/pricing": {
39 "js": 24320,
40 "css": 51712
41 },
42 "/forges/new": {
43 "js": 24320,
44 "css": 51712
45 },
46 "/claim": {
47 "js": 27136,
48 "css": 51712
49 },
50 "/templates": {
51 "js": 24320,
52 "css": 51712
53 },
54 "/system": {
55 "js": 26112,
56 "css": 51712
57 },
58 "/feed": {
59 "js": 39168,
60 "css": 51712
61 },
62 "/board": {
63 "js": 29184,
64 "css": 51712
65 },
66 "/fleet": {
67 "js": 24320,
68 "css": 51712
69 },
70 "/talk": {
71 "js": 42496,
72 "css": 58112
73 },
74 "/:owner/:name/pulls/:number": {
75 "js": 34560,
76 "css": 51712
77 }
78 }
docs/design/size-budget/board.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/board",
3 "js": 29184,
4 "css": 51712
5 }
docs/design/size-budget/changelog.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/changelog",
3 "js": 29696,
4 "css": 51712
5 }
docs/design/size-budget/claim.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/claim",
3 "js": 27136,
4 "css": 51712
5 }
docs/design/size-budget/explore.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/explore",
3 "js": 24320,
4 "css": 51712
5 }
docs/design/size-budget/feed.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/feed",
3 "js": 39168,
4 "css": 51712
5 }
docs/design/size-budget/fleet.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/fleet",
3 "js": 24320,
4 "css": 51712
5 }
docs/design/size-budget/forges-new.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/forges/new",
3 "js": 24320,
4 "css": 51712
5 }
docs/design/size-budget/home.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/",
3 "js": 24576,
4 "css": 51712
5 }
docs/design/size-budget/maintenance.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/maintenance",
3 "js": 24320,
4 "css": 51712
5 }
docs/design/size-budget/map.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/map",
3 "js": 31744,
4 "css": 53248
5 }
docs/design/size-budget/owner-name-next.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/:owner/:name/next",
3 "js": 26112,
4 "css": 51968
5 }
docs/design/size-budget/owner-name-pulls-number.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/:owner/:name/pulls/:number",
3 "js": 34560,
4 "css": 51712
5 }
docs/design/size-budget/owner-name-space-json.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/:owner/:name/space.json",
3 "js": 0,
4 "css": 0
5 }
docs/design/size-budget/owner-name-space.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/:owner/:name/space",
3 "js": 33024,
4 "css": 52736
5 }
docs/design/size-budget/owner-name.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/:owner/:name",
3 "js": 41216,
4 "css": 51712
5 }
docs/design/size-budget/pricing.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/pricing",
3 "js": 24320,
4 "css": 51712
5 }
docs/design/size-budget/system.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/system",
3 "js": 26112,
4 "css": 51712
5 }
docs/design/size-budget/talk.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/talk",
3 "js": 42496,
4 "css": 58112
5 }
docs/design/size-budget/templates.json added +5
@@ -0,0 +1,5 @@
1 {
2 "page": "/templates",
3 "js": 24320,
4 "css": 51712
5 }
scripts/client-size.ts +8 −5
@@ -1,14 +1,14 @@
11 /**
22 * Reads the client bytes (gzip JS and CSS) of each first page of a running forge and
3 * judges them against docs/design/size-budget.json (#12018):
3 * judges them against docs/design/size-budget/ (#12018):
44 * bun scripts/client-size.ts https://forge.example [cookie]
55 * The cookie ("name=value") signs the walk in; signed-out pages are walked without it.
66 * Each page is fetched twice; counted inline code that differs between the two is a
77 * finding (#12040). Prints the ceilings `FORGE_SIZE_WRITE=1` would write from this walk.
88 * Exits 1 naming each page and the bytes over.
99 */
10 import { readFileSync } from "node:fs";
11 import { ceilingsFor, clientSize, inlineDrift, sizeFindings, type Ceilings } from "../src/measure/client_size.ts";
10 import { fileURLToPath } from "node:url";
11 import { ceilingsFor, clientSize, inlineDrift, readCeilings, sizeFindings, writeCeilings, type Ceilings } from "../src/measure/client_size.ts";
1212 import { PAGE_BUDGETS, pagePath } from "../src/perf/page_budget.ts";
1313
1414 const [base, cookie] = process.argv.slice(2);
@@ -16,7 +16,7 @@ if (base === undefined || !/^https?:\/\//.test(base)) {
1616 console.error("usage: bun scripts/client-size.ts <https://forge> [cookie]");
1717 process.exit(2);
1818 }
outdated

new URL(...).pathname keeps percent-encoding, so a checkout path with a space fails. Use fileURLToPath.

19 const ceilings = JSON.parse(readFileSync(new URL("../docs/design/size-budget.json", import.meta.url), "utf8")) as Ceilings;
19 const ceilings = readCeilings(fileURLToPath(new URL("../docs/design/size-budget", import.meta.url)));
2020 const get = (path: string, signedIn: boolean): Promise<Response> =>
2121 fetch(new URL(path, base), { headers: { "accept-encoding": "identity", ...(signedIn && cookie ? { cookie } : {}) } });
2222
@@ -36,6 +36,9 @@ for (const b of PAGE_BUDGETS) {
3636 console.log(`${b.pattern}\tjs ${size.js}\tcss ${size.css}`);
3737 findings.push(...sizeFindings(`${b.pattern} (${b.page})`, size, ceilings[b.pattern]));
3838 }
39 console.log(`ceilings with headroom from this walk:\n${JSON.stringify(ceilingsFor(sizes), null, 2)}`);
39 if (process.env["FORGE_SIZE_WRITE"] === "1") {
40 writeCeilings(ceilingsFor(sizes));
41 console.log("ceilings written to docs/design/size-budget/, one file per page");
42 } else console.log(`ceilings with headroom from this walk:\n${JSON.stringify(ceilingsFor(sizes), null, 2)}`);
4043 for (const f of findings) console.error(f);
4144 process.exit(findings.length === 0 ? 0 : 1);
scripts/test_honesty.ts +1 −1
@@ -5,7 +5,7 @@
55 * when it is busy; `scripts/flake.ts` finds such a flake only after it
66 * happened. This counts, per file under `test/`, three kinds of reliance on
77 * the clock or on module surgery, and holds each count to a committed
8 * allowance (`ALLOWANCE_FILE`, the pattern of `docs/design/size-budget.json`):
8 * allowance (`ALLOWANCE_FILE`, the pattern of the per-page files in `docs/design/size-budget/`):
outdated

The same mangled replacement: docs/design/size-budget/ (one file per page) inside a parenthesis. Say "the pattern of the per-page files in docs/design/size-budget/".

99 *
1010 * wait `Bun.sleep(<number>)`, `Bun.sleepSync(<number>)` and
1111 * `setTimeout(<name>, <number>)`: a delay chosen by hand.
src/measure/client_size.ts +42 −2
@@ -5,12 +5,15 @@
55 * served at those URLs, compressed with gzip level default) plus every
66 * inline `<script>` and `<style>` body. Data blocks (`type=application/json`,
77 * speculation rules) are not code and are left out.
8 * The ceilings live in docs/design/size-budget.json, written by
8 * The ceilings live one file per page in docs/design/size-budget/ (#16331: two pulls on two
9 * pages never touch one file), written by
910 * `FORGE_SIZE_WRITE=1 bun test test/client-size.test.ts` as the measured
1011 * bytes plus headroom (#12040, `ceilingFor`), so one landed byte does not red
1112 * main; a pull that grows a page past its ceiling raises it in the same push
1213 * and says why.
1314 */
15 import { mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
16 import { join } from "node:path";
1417
1518 export interface ClientSize {
1619 readonly js: number;
@@ -125,10 +128,47 @@ export async function clientSize(html: string, fetchText: (path: string) => Prom
125128 */
126129 export function sizeFindings(page: string, size: ClientSize, ceiling: ClientSize | undefined): string[] {
127130 if (ceiling === undefined)
128 return [`${page}: no ceiling in docs/design/size-budget.json (js ${size.js} B, css ${size.css} B gzip); write one with \`${SIZE_WRITE_COMMAND}\``];
131 return [`${page}: no ceiling in docs/design/size-budget/ (js ${size.js} B, css ${size.css} B gzip); write one with \`${SIZE_WRITE_COMMAND}\``];
129132 const out: string[] = [];
130133 for (const kind of ["js", "css"] as const)
131134 if (size[kind] > ceiling[kind])
132135 out.push(`${page}: ${kind} ${size[kind]} B gzip, ${size[kind] - ceiling[kind]} B over its ceiling of ${ceiling[kind]} B; raise it in this pull with \`${SIZE_WRITE_COMMAND}\` and say why`);
133136 return out;
134137 }
138
139 /** The folder of ceilings, one small file per page. */
140 export const CEILING_DIR = "docs/design/size-budget";
141
142 /**
143 * A page pattern's file name: `/` is `home`, `/:owner/:name/space.json` is `owner-name-space-json`.
144 */
145 export function ceilingFile(pattern: string): string {
146 const slug = pattern.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
147 return `${slug === "" ? "home" : slug}.json`;
148 }
149
150 /** Every page's ceilings, read from the folder; each file is `{ page, js, css }`. */
151 export function readCeilings(dir: string = CEILING_DIR): Ceilings {
152 const out: Ceilings = {};
153 for (const name of readdirSync(dir).filter((n) => n.endsWith(".json")).sort()) {
154 const one = JSON.parse(readFileSync(join(dir, name), "utf8")) as { page: string; js: number; css: number };
155 if (typeof one.page !== "string" || typeof one.js !== "number" || typeof one.css !== "number") {
156 throw new Error(`${name}: a ceiling file is { page: string, js: number, css: number }`);
157 }
158 if (one.page in out) throw new Error(`${name}: page ${one.page} already has a ceiling file`);
159 out[one.page] = { js: one.js, css: one.css };
160 }
161 return out;
162 }
163
164 /** Writes one file per page and removes the files of pages no longer budgeted. */
165 export function writeCeilings(ceilings: Ceilings, dir: string = CEILING_DIR): void {
166 mkdirSync(dir, { recursive: true });
167 const keep = new Set<string>();
168 for (const [page, c] of Object.entries(ceilings)) {
169 const name = ceilingFile(page);
170 keep.add(name);
171 writeFileSync(join(dir, name), `${JSON.stringify({ page, js: c.js, css: c.css }, null, 2)}\n`);
172 }
173 for (const name of readdirSync(dir)) if (name.endsWith(".json") && !keep.has(name)) rmSync(join(dir, name));
174 }
test/budgets/pages/api-v1-asks.json added +5
@@ -0,0 +1,5 @@
1 {
2 "pattern": "/api/v1/asks",
3 "statements": 61,
4 "why": "+1: the stopped apps someone asked for, one read of the viewer's archived repositories (#12277)"
5 }
test/budgets/pages/api-v1-maintenance-duties.json added +5
@@ -0,0 +1,5 @@
1 {
2 "pattern": "/api/v1/maintenance/duties",
3 "statements": 81,
4 "why": "the same duties as JSON; slow-tests (#13966), stale-branches (#14141), edge-kept (#14682), deepsec-sweep (#15026), daily-proof (#15625) account-purge (#15620) and v1-probe (#15652) each add 3"
5 }
test/budgets/pages/board.json added +5
@@ -0,0 +1,5 @@
1 {
2 "pattern": "/board",
3 "statements": 72,
4 "why": "+1: the forge-copy read for the tell box (#12037); +1: the vitals read the database's growth (#12025); +6: the money line (#510) — one settings read, then the month's and the 30 days' meter, storage and ledger reads; constant in the number of apps"
5 }
test/budgets/pages/flow.json added +5
@@ -0,0 +1,5 @@
1 {
2 "pattern": "/flow",
3 "statements": 61,
4 "why": "+1 over the default: the estimates the slots were last changed on, one read of both settings' changes, so each line says how its estimate held up (Bridge v1)"
5 }
test/budgets/pages/maintenance.json added +5
@@ -0,0 +1,5 @@
1 {
2 "pattern": "/maintenance",
3 "statements": 99,
4 "why": "+3: account-purge (#15620); +3: daily-proof (#15625); +3: deepsec-sweep (#15026); +3: edge-kept (#14682), one more duty reading its own state; +1: every duty's last run in one query (#14674); +1: quieted findings (#14557); +1: the findings fold (#14577); +5: slow-tests (#13966); +3: untested-sources (#14125) and the dismissal query (#13967); +4: flaky-tests (#13937), red apps (#13938), chapter stall (#14057), dead-doc-paths (#13977); +3: stale-branches (#14141); +3: v1-probe (#15652) — each reads its own state and runs"
5 }
test/budgets/pages/next.json added +5
@@ -0,0 +1,5 @@
1 {
2 "pattern": "/next",
3 "statements": 90,
4 "why": "a new page: measured 90 warm over the fixture's repositories, one ranking per administered repository, at most GROUPS_MAX = 5 (#15870)"
5 }
test/budgets/pages/owner-name-issues-number.json added +5
@@ -0,0 +1,5 @@
1 {
2 "pattern": "/:owner/:name/issues/:number",
3 "statements": 71,
4 "why": "+1: whether the repository is archived, so its pages say noindex (#14305)"
5 }
test/budgets/pages/owner-name-next.json added +5
@@ -0,0 +1,5 @@
1 {
2 "pattern": "/:owner/:name/next",
3 "statements": 63,
4 "why": "-3 (#15913): the waiting offers and outsider reports ride the page's own writer check, the open-pull ceiling and count are one statement; -6 (#15940): the page's repository read once per request, the palette lists skip counts, the runs tab reuses the app read; +2: the waiting offers and the decision check beside the reports (#15887); +1: the size limits of held issues, one read of both (#15845); +2: the waiting outsider reports, the decider check and the list (#15840); +1: whether the repository is archived (#14305); +1: the wallet row, one read of the monthly cap (#13529); +1: the growth line, one read for the week, the open counts and the planner pause (#12290, #12867)"
5 }
test/budgets/pages/owner-name-pulls-number.json added +5
@@ -0,0 +1,5 @@
1 {
2 "pattern": "/:owner/:name/pulls/:number",
3 "statements": 115,
4 "why": "+1: what a green pull waits for (#15812), and the head's check is read once for it, the next actor and the step (#15913); +1: whether the reports door is closed, one primary-key read per request, never from memory (#15053); +1: whether the repository is archived (#14305); +1: the desk hold on the pull, one read of the notes that link it (#12536); +1: whether a repository is the forge's own copy, one read of the source setting for the tell box (#12037); +1: the paused sentence, one read of a queued paused run on the pull (#12010); +1: the header Talk count (#10327); +1: the landing line (#10860); +1: whether a reviewer is seated, read only when Require review is off and the pull would otherwise wait on one; the page loads no crew besides (#11666)"
5 }
test/budgets/pages/settings-capacity.json added +5
@@ -0,0 +1,5 @@
1 {
2 "pattern": "/settings/capacity",
3 "statements": 70,
4 "why": "the capacity page reads the machine, the app roster and the meters once each; constant in the number of apps"
5 }
test/budgets/pages/settings-crew.json added +5
@@ -0,0 +1,5 @@
1 {
2 "pattern": "/settings/crew",
3 "statements": 69,
4 "why": "+1 over main's 68: the Planner card reads the last pass, the week and the outcomes in one statement (#16231); the crew's top (#16230): 11 over the 57 the page cost before it, each section one bounded read or a few (now: the visible repositories, their apps and open counts, the live runs; accounts: the credentials in one read, the week's ledger, the standings' three; failed-early: one); the week's card is read once for the panel and the member records"
5 }
test/budgets/pages/talk.json added +5
@@ -0,0 +1,5 @@
1 {
2 "pattern": "/talk",
3 "statements": 62,
4 "why": "+1 on a conversation with no message yet, as the fixture's is: the person's unsent files (a picture shared from a phone, #16311) ride the read of the sent ones, so a conversation with messages pays nothing more; +1: the conversation's own plan, pinned at the top, one primary-key read (#16575)"
5 }
test/client-size.test.ts +21 −7
@@ -1,6 +1,6 @@
11 /**
22 * Each first page's client JavaScript and CSS, gzip bytes, stay under the
3 * ceiling in docs/design/size-budget.json (#12018). Same pages as the
3 * ceiling in docs/design/size-budget/ (#12018). Same pages as the
44 * page-load budget. FORGE_SIZE_WRITE=1 rewrites the file with today's numbers
55 * plus headroom (2 %, up to the next 256 B: `ceilingFor`, #12040); raising one
66 * needs a note in the pull. Each page is rendered twice and its counted inline
@@ -9,7 +9,7 @@
99 * (#13805).
1010 */
1111 import { afterAll, beforeAll, expect, test } from "bun:test";
12 import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
12 import { mkdtempSync, rmSync } from "node:fs";
1313 import { tmpdir } from "node:os";
1414 import { join } from "node:path";
1515 import { openPull } from "../src/actions/pulls.ts";
@@ -19,7 +19,7 @@ import { createOrg } from "../src/core/orgs.ts";
1919 import { getRepo } from "../src/core/repos.ts";
2020 import { createUser } from "../src/core/users.ts";
2121 import { serve, type Servers } from "../src/http/server.ts";
22 import { ceilingFor, ceilingsFor, clientSize, inlineDrift, sizeFindings, SIZE_WRITE_COMMAND, type Ceilings } from "../src/measure/client_size.ts";
22 import { ceilingFile, ceilingFor, ceilingsFor, clientSize, inlineDrift, readCeilings, sizeFindings, SIZE_WRITE_COMMAND, writeCeilings, type Ceilings } from "../src/measure/client_size.ts";
2323 import { RULE_TESTS } from "../src/checks/tiers.ts";
2424 import { PAGE_BUDGETS, pagePath } from "../src/perf/page_budget.ts";
2525 import { mintClaim } from "../src/spawn/claim.ts";
@@ -29,7 +29,6 @@ import { proveAll } from "./helpers/verified.ts";
2929
3030 quietLogs();
3131
32 const FILE = "docs/design/size-budget.json";
3332 let root = "";
3433 let app: App;
3534 let servers: Servers;
@@ -112,17 +111,17 @@ test("no first page's client JavaScript or CSS passes its ceiling, and each page
112111 const { sizes, drift } = await measure();
113112 expect(drift).toEqual([]);
114113 if (process.env["FORGE_SIZE_WRITE"] === "1") {
115 writeFileSync(FILE, `${JSON.stringify(ceilingsFor(sizes), null, 2)}\n`);
114 writeCeilings(ceilingsFor(sizes));
116115 return;
117116 }
118 const ceilings = JSON.parse(readFileSync(FILE, "utf8")) as Ceilings;
117 const ceilings = readCeilings();
119118 const findings = PAGE_BUDGETS.flatMap((b) => sizeFindings(`${b.pattern} (${b.page})`, sizes[b.pattern]!, ceilings[b.pattern]));
120119 console.log(`client bytes, gzip:\n${PAGE_BUDGETS.map((b) => `${b.pattern}\tjs ${sizes[b.pattern]!.js}\tcss ${sizes[b.pattern]!.css}`).join("\n")}`);
121120 expect(findings).toEqual([]);
122121 }, 60_000);
123122
124123 test("the ceiling file names exactly the budgeted pages", () => {
125 const ceilings = JSON.parse(readFileSync(FILE, "utf8")) as Ceilings;
124 const ceilings = readCeilings();
126125 expect(Object.keys(ceilings).sort()).toEqual(PAGE_BUDGETS.map((b) => b.pattern).sort());
127126 });
128127
@@ -180,3 +179,18 @@ test("the size test runs in every pull's check; it measures that pull on its own
180179 // this only makes each pull's own overshoot visible before it lands.
181180 expect(RULE_TESTS).toContain("test/client-size.test.ts");
182181 });
182
183 test("ceilings are one file per page and read back whole", () => {
184 const dir = mkdtempSync(join(tmpdir(), "forge-ceilings-"));
185 try {
186 const sizes: Ceilings = { "/": { js: 1, css: 2 }, "/:owner/:name/space.json": { js: 0, css: 0 } };
187 writeCeilings(sizes, dir);
188 expect(readCeilings(dir)).toEqual(sizes);
189 expect(ceilingFile("/")).toBe("home.json");
190 expect(ceilingFile("/:owner/:name/space.json")).toBe("owner-name-space-json.json");
191 writeCeilings({ "/": { js: 3, css: 4 } }, dir);
192 expect(readCeilings(dir)).toEqual({ "/": { js: 3, css: 4 } });
193 } finally {
194 rmSync(dir, { recursive: true, force: true });
195 }
196 });
test/helpers/page_budgets.ts added +27
@@ -0,0 +1,27 @@
1 /**
2 * The pages that cost more than the default, one file each in test/budgets/pages/
3 * (#16331): `{ pattern, statements?, git?, why? }`. A pull that moves one page's
4 * work edits that page's file, so two pulls on two pages never touch the same lines.
5 */
6 import { readdirSync, readFileSync } from "node:fs";
7 import { join } from "node:path";
8
9 const DIR = join(import.meta.dir, "..", "budgets", "pages");
10
11 export function heavierPages(dir: string = DIR): Record<string, { statements?: number; git?: number }> {
12 const out: Record<string, { statements?: number; git?: number }> = {};
13 for (const name of readdirSync(dir).filter((n) => n.endsWith(".json")).sort()) {

No test covers this reader. A duplicate pattern across two files silently overwrites the first, and a file with no statements or git is accepted. Add a test that reads a temporary directory and one that checks every committed file has a string pattern, a numeric statements or git, and a unique pattern. Do the same for readCeilings.

14 const { pattern, statements, git } = JSON.parse(readFileSync(join(dir, name), "utf8")) as {
15 pattern: string;
16 statements?: number;
17 git?: number;
18 };
19 if (typeof pattern !== "string") throw new Error(`${name}: "pattern" must be a string`);
20 if (typeof statements !== "number" && typeof git !== "number") {
21 throw new Error(`${name}: a page file needs a numeric "statements" or "git"`);
22 }
23 if (pattern in out) throw new Error(`${name}: pattern ${pattern} is already in another file`);
24 out[pattern] = { ...(statements === undefined ? {} : { statements }), ...(git === undefined ? {} : { git }) };
25 }
26 return out;
27 }
test/page-budget-files.test.ts added +65
@@ -0,0 +1,65 @@
1 /**
2 * The per-page budget files (#16331) are read by `heavierPages` and `readCeilings`.
3 * Both refuse a malformed or duplicated file instead of dropping it, and every
4 * committed file passes.
5 */
6 import { expect, test } from "bun:test";
7 import { mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { CEILING_DIR, readCeilings } from "../src/measure/client_size.ts";
11 import { heavierPages } from "./helpers/page_budgets.ts";
12
13 function withDir(files: Record<string, unknown>, run: (dir: string) => void): void {
14 const dir = mkdtempSync(join(tmpdir(), "budget-files-"));
15 try {
16 for (const [name, body] of Object.entries(files)) writeFileSync(join(dir, name), JSON.stringify(body));
17 run(dir);
18 } finally {
19 rmSync(dir, { recursive: true, force: true });
20 }
21 }
22
23 const jsonIn = (dir: string): Record<string, any>[] =>
24 readdirSync(dir).filter((n) => n.endsWith(".json")).map((n) => JSON.parse(readFileSync(join(dir, n), "utf8")));
25
26 test("heavierPages reads statements and git per pattern, and keys only what a file sets", () => {
27 withDir({ "a.json": { pattern: "/a", statements: 5 }, "b.json": { pattern: "/b", git: 2, why: "x" } }, (dir) => {
28 expect(heavierPages(dir)).toEqual({ "/a": { statements: 5 }, "/b": { git: 2 } });
29 });
30 });
31
32 test("heavierPages refuses a file with neither statements nor git, a missing pattern, and a shared pattern", () => {
33 withDir({ "a.json": { pattern: "/a" } }, (dir) => expect(() => heavierPages(dir)).toThrow("statements"));
34 withDir({ "a.json": { statements: 3 } }, (dir) => expect(() => heavierPages(dir)).toThrow("pattern"));
35 withDir({ "a.json": { pattern: "/a", statements: 3 }, "b.json": { pattern: "/a", statements: 4 } }, (dir) =>
36 expect(() => heavierPages(dir)).toThrow("already in another file"));
37 });
38
39 test("every file under test/budgets/pages/ has a string pattern, a numeric statements or git, and a pattern of its own", () => {
40 const dir = join(import.meta.dir, "budgets", "pages");
41 const files = jsonIn(dir);
42 expect(files.length).toBeGreaterThan(0);
43 for (const f of files) {
44 expect(typeof f.pattern).toBe("string");
45 expect(typeof f.statements === "number" || typeof f.git === "number").toBe(true);
46 }
47 expect(new Set(files.map((f) => f.pattern)).size).toBe(files.length);
48 });
49
50 test("readCeilings refuses a malformed ceiling file and a page with two files", () => {
51 withDir({ "a.json": { page: "/a", js: 1 } }, (dir) => expect(() => readCeilings(dir)).toThrow("ceiling file"));
52 withDir({ "a.json": { page: "/a", js: 1, css: 2 }, "b.json": { page: "/a", js: 3, css: 4 } }, (dir) =>
53 expect(() => readCeilings(dir)).toThrow("already has a ceiling file"));
54 withDir({ "a.json": { page: "/a", js: 1, css: 2 } }, (dir) => expect(readCeilings(dir)).toEqual({ "/a": { js: 1, css: 2 } }));
55 });
56
57 test("every committed ceiling file has a string page and numeric js and css, one file per page", () => {
58 const files = jsonIn(CEILING_DIR);
59 for (const f of files) {
60 expect(typeof f.page).toBe("string");
61 expect(typeof f.js).toBe("number");
62 expect(typeof f.css).toBe("number");
63 }
64 expect(new Set(files.map((f) => f.page)).size).toBe(files.length);
65 });
test/pages-budget.test.ts +6 −15
@@ -49,26 +49,17 @@ import { quietLogs } from "./helpers/globals.ts";
4949 import { promote } from "./helpers/members.ts";
5050 import { proveAll } from "./helpers/verified.ts";
5151 import { pageWork, type PageWork } from "./helpers/work.ts";
52 import { heavierPages } from "./helpers/page_budgets.ts";
5253
5354 quietLogs();
5455
5556 /** Statements and git processes one warm page may cost unless listed below. */
5657 const DEFAULT = { statements: 60, git: 8 };
57 /** Pages that cost more today, with the most they may: lower these, never raise them. */
58 const HEAVIER: Record<string, { statements?: number; git?: number }> = {
59 "/settings/crew": { statements: 69 }, // +1 over main's 68: the Planner card reads the last pass, the week and the outcomes in one statement (#16231); the crew's top (#16230): 11 over the 57 the page cost before it, each section one bounded read or a few (now: the visible repositories, their apps and open counts, the live runs; accounts: the credentials in one read, the week's ledger, the standings' three; failed-early: one); the week's card is read once for the panel and the member records
60 "/:owner/:name/issues/:number": { statements: 71 }, // +1: whether the repository is archived, so its pages say noindex (#14305)
61 "/next": { statements: 90 }, // a new page: measured 90 warm over the fixture's repositories, one ranking per administered repository, at most GROUPS_MAX = 5 (#15870)
62 "/:owner/:name/next": { statements: 63 }, // -3 (#15913): the waiting offers and outsider reports ride the page's own writer check, the open-pull ceiling and count are one statement; -6 (#15940): the page's repository read once per request, the palette lists skip counts, the runs tab reuses the app read; +2: the waiting offers and the decision check beside the reports (#15887); +1: the size limits of held issues, one read of both (#15845); +2: the waiting outsider reports, the decider check and the list (#15840); +1: whether the repository is archived (#14305); +1: the wallet row, one read of the monthly cap (#13529); +1: the growth line, one read for the week, the open counts and the planner pause (#12290, #12867)
63 "/:owner/:name/pulls/:number": { statements: 115 }, // +1: what a green pull waits for (#15812), and the head's check is read once for it, the next actor and the step (#15913); +1: whether the reports door is closed, one primary-key read per request, never from memory (#15053); +1: whether the repository is archived (#14305); +1: the desk hold on the pull, one read of the notes that link it (#12536); +1: whether a repository is the forge's own copy, one read of the source setting for the tell box (#12037); +1: the paused sentence, one read of a queued paused run on the pull (#12010); +1: the header Talk count (#10327); +1: the landing line (#10860); +1: whether a reviewer is seated, read only when Require review is off and the pull would otherwise wait on one; the page loads no crew besides (#11666)
64 "/flow": { statements: 61 }, // +1 over the default: the estimates the slots were last changed on, one read of both settings' changes, so each line says how its estimate held up (Bridge v1)
65 "/talk": { statements: 62 }, // +1 on a conversation with no message yet, as the fixture's is: the person's unsent files (a picture shared from a phone, #16311) ride the read of the sent ones, so a conversation with messages pays nothing more; +1: the conversation's own plan, pinned at the top, one primary-key read (#16575)
66 "/api/v1/asks": { statements: 61 }, // +1: the stopped apps someone asked for, one read of the viewer's archived repositories (#12277)
67 "/board": { statements: 72 }, // +1: the forge-copy read for the tell box (#12037); +1: the vitals read the database's growth (#12025); +6: the money line (#510) — one settings read, then the month's and the 30 days' meter, storage and ledger reads; constant in the number of apps
68 "/settings/capacity": { statements: 70 },
69 "/maintenance": { statements: 99 }, // +3: account-purge (#15620); +3: daily-proof (#15625); +3: deepsec-sweep (#15026); +3: edge-kept (#14682), one more duty reading its own state; +1: every duty's last run in one query (#14674); +1: quieted findings (#14557); +1: the findings fold (#14577); +5: slow-tests (#13966); +3: untested-sources (#14125) and the dismissal query (#13967); +4: flaky-tests (#13937), red apps (#13938), chapter stall (#14057), dead-doc-paths (#13977); +3: stale-branches (#14141); +3: v1-probe (#15652) — each reads its own state and runs
70 "/api/v1/maintenance/duties": { statements: 81 }, // the same duties as JSON; slow-tests (#13966), stale-branches (#14141), edge-kept (#14682), deepsec-sweep (#15026), daily-proof (#15625) account-purge (#15620) and v1-probe (#15652) each add 3
71 };
58 /**
59 * Pages that cost more today, with the most they may (one file each in test/budgets/pages/): lower
60 * these, never raise them.
61 */
62 const HEAVIER = heavierPages();
7263
7364 /** Patterns with no fixture today: lower this as fixtures are added, never raise it silently. */
7465 const MAX_UNFIXTURED = 168; // +4: /games/:box, /games/:box/:service, its stream and /games/jar/:id/:name, a game box the fixture does not make (#games, 2026-11-30) // +1: /api/v1/runner/jobs/:id/seed, a seed of a runner job, readable only with a claimed job's token, which the fixture holds none of (#16881) // +1: /api/v1/repos/:owner/:name/app/errors/:group, an error group the fixture app has not received (#6003) // +1: /:owner/:name/large/:oid, a redirect to a presigned URL with no large blob in the fixture (#4490) // +1: /:owner/:name/bets/:id/walk/:walk, a journey walk of a closed bet scope the fixture has not run (#8715) // +2: /status/:token and /api/v1/status/:token, an outsider status link the fixture has not been handed (#15768); // +1: /tell/share/:id, a receipt of a share the fixture has not sent; +1: /docs/features/:file, a static reference note with no fixture (#12069); +1: /:owner/:name/pulls/:number/check.txt, plain text with no page to fixture (#12165) // +1: /:owner/:name/data/:file, a CSV download with no app data in the fixture (#12684) // +1: /api/v1/repos/:owner/:name/drop/:file, a private file with no drop in the fixture (#645) // +1: /:owner/:name/stl/:ref/*path, an .stl download with no model file in the fixture (#15856) // +1: /api/v1/devices/:id/print/:job, a printer job the fixture has not sent (#16656) // +1: /:owner/:name/settings/app/flags/:flag, a flag the fixture app does not declare (#1830) // +1: /api/v1/repos/:owner/:name/changes/:room, a change stream of an app that declares sync, which the fixture does not (#10839)

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs