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
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/16331-fewer-merge-conflicts-split-the-files-ev → main 0 commits fork 5 threads · 5 unresolved
40 files
changed +326
−109
- CLAUDE.md
- docs/design/size-budget.json
- docs/design/size-budget/board.json
- docs/design/size-budget/changelog.json
- docs/design/size-budget/claim.json
- docs/design/size-budget/explore.json
- docs/design/size-budget/feed.json
- docs/design/size-budget/fleet.json
- docs/design/size-budget/forges-new.json
- docs/design/size-budget/home.json
- docs/design/size-budget/maintenance.json
- docs/design/size-budget/map.json
- docs/design/size-budget/owner-name-next.json
- docs/design/size-budget/owner-name-pulls-number.json
- docs/design/size-budget/owner-name-space-json.json
- docs/design/size-budget/owner-name-space.json
- docs/design/size-budget/owner-name.json
- docs/design/size-budget/pricing.json
- docs/design/size-budget/system.json
- docs/design/size-budget/talk.json
- docs/design/size-budget/templates.json
- scripts/client-size.ts
- scripts/test_honesty.ts
- src/measure/client_size.ts
- test/budgets/pages/api-v1-asks.json
- test/budgets/pages/api-v1-maintenance-duties.json
- test/budgets/pages/board.json
- test/budgets/pages/flow.json
- test/budgets/pages/maintenance.json
- test/budgets/pages/next.json
- test/budgets/pages/owner-name-issues-number.json
- test/budgets/pages/owner-name-next.json
- test/budgets/pages/owner-name-pulls-number.json
- test/budgets/pages/settings-capacity.json
- test/budgets/pages/settings-crew.json
- test/budgets/pages/talk.json
- test/client-size.test.ts
- test/helpers/page_budgets.ts
- test/page-budget-files.test.ts
- test/pages-budget.test.ts
CLAUDE.md +1 −1
| @@ -270,7 +270,7 @@ Read this before touching `src/web/`. Principles live in `docs/DESIGN.md`; these | ||
| 270 | 270 | |
| 271 | 271 | 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). |
| 272 | 272 | 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. | |
| 274 | 274 | |
| 275 | 275 | ## Recipes |
| 276 | 276 |
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
docs/design/size-budget/changelog.json added +5
docs/design/size-budget/claim.json added +5
docs/design/size-budget/explore.json added +5
docs/design/size-budget/feed.json added +5
docs/design/size-budget/fleet.json added +5
docs/design/size-budget/forges-new.json added +5
docs/design/size-budget/home.json added +5
docs/design/size-budget/maintenance.json added +5
docs/design/size-budget/map.json added +5
docs/design/size-budget/owner-name-next.json added +5
docs/design/size-budget/owner-name-pulls-number.json added +5
docs/design/size-budget/owner-name-space-json.json added +5
docs/design/size-budget/owner-name-space.json added +5
docs/design/size-budget/owner-name.json added +5
docs/design/size-budget/pricing.json added +5
docs/design/size-budget/system.json added +5
docs/design/size-budget/talk.json added +5
docs/design/size-budget/templates.json added +5
scripts/client-size.ts +8 −5
| @@ -1,14 +1,14 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * 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): | |
| 4 | 4 | * bun scripts/client-size.ts https://forge.example [cookie] |
| 5 | 5 | * The cookie ("name=value") signs the walk in; signed-out pages are walked without it. |
| 6 | 6 | * Each page is fetched twice; counted inline code that differs between the two is a |
| 7 | 7 | * finding (#12040). Prints the ceilings `FORGE_SIZE_WRITE=1` would write from this walk. |
| 8 | 8 | * Exits 1 naming each page and the bytes over. |
| 9 | 9 | */ |
| 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"; | |
| 12 | 12 | import { PAGE_BUDGETS, pagePath } from "../src/perf/page_budget.ts"; |
| 13 | 13 | |
| 14 | 14 | const [base, cookie] = process.argv.slice(2); |
| @@ -16,7 +16,7 @@ if (base === undefined || !/^https?:\/\//.test(base)) { | ||
| 16 | 16 | console.error("usage: bun scripts/client-size.ts <https://forge> [cookie]"); |
| 17 | 17 | process.exit(2); |
| 18 | 18 | } |
| 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))); | |
| 20 | 20 | const get = (path: string, signedIn: boolean): Promise<Response> => |
| 21 | 21 | fetch(new URL(path, base), { headers: { "accept-encoding": "identity", ...(signedIn && cookie ? { cookie } : {}) } }); |
| 22 | 22 | |
| @@ -36,6 +36,9 @@ for (const b of PAGE_BUDGETS) { | ||
| 36 | 36 | console.log(`${b.pattern}\tjs ${size.js}\tcss ${size.css}`); |
| 37 | 37 | findings.push(...sizeFindings(`${b.pattern} (${b.page})`, size, ceilings[b.pattern])); |
| 38 | 38 | } |
| 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)}`); | |
| 40 | 43 | for (const f of findings) console.error(f); |
| 41 | 44 | process.exit(findings.length === 0 ? 0 : 1); |
scripts/test_honesty.ts +1 −1
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | * when it is busy; `scripts/flake.ts` finds such a flake only after it |
| 6 | 6 | * happened. This counts, per file under `test/`, three kinds of reliance on |
| 7 | 7 | * 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/`): | |
| 9 | 9 | * |
| 10 | 10 | * wait `Bun.sleep(<number>)`, `Bun.sleepSync(<number>)` and |
| 11 | 11 | * `setTimeout(<name>, <number>)`: a delay chosen by hand. |
src/measure/client_size.ts +42 −2
| @@ -5,12 +5,15 @@ | ||
| 5 | 5 | * served at those URLs, compressed with gzip level default) plus every |
| 6 | 6 | * inline `<script>` and `<style>` body. Data blocks (`type=application/json`, |
| 7 | 7 | * 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 | |
| 9 | 10 | * `FORGE_SIZE_WRITE=1 bun test test/client-size.test.ts` as the measured |
| 10 | 11 | * bytes plus headroom (#12040, `ceilingFor`), so one landed byte does not red |
| 11 | 12 | * main; a pull that grows a page past its ceiling raises it in the same push |
| 12 | 13 | * and says why. |
| 13 | 14 | */ |
| 15 | import { mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | |
| 16 | import { join } from "node:path"; | |
| 14 | 17 | |
| 15 | 18 | export interface ClientSize { |
| 16 | 19 | readonly js: number; |
| @@ -125,10 +128,47 @@ export async function clientSize(html: string, fetchText: (path: string) => Prom | ||
| 125 | 128 | */ |
| 126 | 129 | export function sizeFindings(page: string, size: ClientSize, ceiling: ClientSize | undefined): string[] { |
| 127 | 130 | 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}\``]; | |
| 129 | 132 | const out: string[] = []; |
| 130 | 133 | for (const kind of ["js", "css"] as const) |
| 131 | 134 | if (size[kind] > ceiling[kind]) |
| 132 | 135 | 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`); |
| 133 | 136 | return out; |
| 134 | 137 | } |
| 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
test/budgets/pages/api-v1-maintenance-duties.json added +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
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
test/budgets/pages/owner-name-issues-number.json added +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
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 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * 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 | |
| 4 | 4 | * page-load budget. FORGE_SIZE_WRITE=1 rewrites the file with today's numbers |
| 5 | 5 | * plus headroom (2 %, up to the next 256 B: `ceilingFor`, #12040); raising one |
| 6 | 6 | * needs a note in the pull. Each page is rendered twice and its counted inline |
| @@ -9,7 +9,7 @@ | ||
| 9 | 9 | * (#13805). |
| 10 | 10 | */ |
| 11 | 11 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 12 | import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | |
| 12 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 13 | 13 | import { tmpdir } from "node:os"; |
| 14 | 14 | import { join } from "node:path"; |
| 15 | 15 | import { openPull } from "../src/actions/pulls.ts"; |
| @@ -19,7 +19,7 @@ import { createOrg } from "../src/core/orgs.ts"; | ||
| 19 | 19 | import { getRepo } from "../src/core/repos.ts"; |
| 20 | 20 | import { createUser } from "../src/core/users.ts"; |
| 21 | 21 | 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"; | |
| 23 | 23 | import { RULE_TESTS } from "../src/checks/tiers.ts"; |
| 24 | 24 | import { PAGE_BUDGETS, pagePath } from "../src/perf/page_budget.ts"; |
| 25 | 25 | import { mintClaim } from "../src/spawn/claim.ts"; |
| @@ -29,7 +29,6 @@ import { proveAll } from "./helpers/verified.ts"; | ||
| 29 | 29 | |
| 30 | 30 | quietLogs(); |
| 31 | 31 | |
| 32 | const FILE = "docs/design/size-budget.json"; | |
| 33 | 32 | let root = ""; |
| 34 | 33 | let app: App; |
| 35 | 34 | let servers: Servers; |
| @@ -112,17 +111,17 @@ test("no first page's client JavaScript or CSS passes its ceiling, and each page | ||
| 112 | 111 | const { sizes, drift } = await measure(); |
| 113 | 112 | expect(drift).toEqual([]); |
| 114 | 113 | if (process.env["FORGE_SIZE_WRITE"] === "1") { |
| 115 | writeFileSync(FILE, `${JSON.stringify(ceilingsFor(sizes), null, 2)}\n`); | |
| 114 | writeCeilings(ceilingsFor(sizes)); | |
| 116 | 115 | return; |
| 117 | 116 | } |
| 118 | const ceilings = JSON.parse(readFileSync(FILE, "utf8")) as Ceilings; | |
| 117 | const ceilings = readCeilings(); | |
| 119 | 118 | const findings = PAGE_BUDGETS.flatMap((b) => sizeFindings(`${b.pattern} (${b.page})`, sizes[b.pattern]!, ceilings[b.pattern])); |
| 120 | 119 | console.log(`client bytes, gzip:\n${PAGE_BUDGETS.map((b) => `${b.pattern}\tjs ${sizes[b.pattern]!.js}\tcss ${sizes[b.pattern]!.css}`).join("\n")}`); |
| 121 | 120 | expect(findings).toEqual([]); |
| 122 | 121 | }, 60_000); |
| 123 | 122 | |
| 124 | 123 | test("the ceiling file names exactly the budgeted pages", () => { |
| 125 | const ceilings = JSON.parse(readFileSync(FILE, "utf8")) as Ceilings; | |
| 124 | const ceilings = readCeilings(); | |
| 126 | 125 | expect(Object.keys(ceilings).sort()).toEqual(PAGE_BUDGETS.map((b) => b.pattern).sort()); |
| 127 | 126 | }); |
| 128 | 127 | |
| @@ -180,3 +179,18 @@ test("the size test runs in every pull's check; it measures that pull on its own | ||
| 180 | 179 | // this only makes each pull's own overshoot visible before it lands. |
| 181 | 180 | expect(RULE_TESTS).toContain("test/client-size.test.ts"); |
| 182 | 181 | }); |
| 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 |
||
| 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"; | ||
| 49 | 49 | import { promote } from "./helpers/members.ts"; |
| 50 | 50 | import { proveAll } from "./helpers/verified.ts"; |
| 51 | 51 | import { pageWork, type PageWork } from "./helpers/work.ts"; |
| 52 | import { heavierPages } from "./helpers/page_budgets.ts"; | |
| 52 | 53 | |
| 53 | 54 | quietLogs(); |
| 54 | 55 | |
| 55 | 56 | /** Statements and git processes one warm page may cost unless listed below. */ |
| 56 | 57 | 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(); | |
| 72 | 63 | |
| 73 | 64 | /** Patterns with no fixture today: lower this as fixtures are added, never raise it silently. */ |
| 74 | 65 | 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) |
new above
offline
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 indocs/design/size-budget/". Also fix "writes every ceiling", which should say it writes one file per page.