Public: anyone can read this; the crew can change it.
Size ceilings are re-measured on the merged tree at landing, so two pulls that together pass a ceiling cannot both land #14030
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/14026-size-ceilings-are-re-measured-on-the-mer → main 1 commit fork
3 files
changed +114
−1
CLAUDE.md +1 −1
| @@ -246,7 +246,7 @@ Read this before touching `src/web/`. Principles live in `docs/DESIGN.md`; these | ||
| 246 | 246 | |
| 247 | 247 | 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). |
| 248 | 248 | 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. |
| 249 | 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. | |
| 249 | 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. | |
| 250 | 250 | |
| 251 | 251 | ## Recipes |
| 252 | 252 |
forge.json +1
| @@ -20,6 +20,7 @@ | ||
| 20 | 20 | "check": { |
| 21 | 21 | "fast": "bun scripts/gate.ts && mkdir -p .forge-cache && GOMEMLIMIT=2GiB ./node_modules/typescript/bin/tsc --noEmit --incremental --tsBuildInfoFile .forge-cache/tsc.tsbuildinfo && bun scripts/test-shards.ts --timeout 60000 --tier fast --diff $FORGE_CHECK_BASE..HEAD --learned \"$FORGE_CHECK_LEARNED\"", |
| 22 | 22 | "run": "bun scripts/gate.ts && mkdir -p .forge-cache && GOMEMLIMIT=2GiB ./node_modules/typescript/bin/tsc --noEmit --incremental --tsBuildInfoFile .forge-cache/tsc.tsbuildinfo", |
| 23 | "full": "bun scripts/gate.ts && mkdir -p .forge-cache && GOMEMLIMIT=2GiB ./node_modules/typescript/bin/tsc --noEmit --incremental --tsBuildInfoFile .forge-cache/tsc.tsbuildinfo && bun test test/client-size.test.ts", | |
| 23 | 24 | "verify": "bun scripts/gate.ts && bun scripts/test-shards.ts --timeout 60000 --gate --impact --keep-going --nice", |
| 24 | 25 | "timeout": 7200, |
| 25 | 26 | "limits": { |
test/gate-size-ceiling-merged.test.ts added +112
| @@ -0,0 +1,112 @@ | ||
| 1 | /** | |
| 2 | * Two pulls that each fit under a shared size ceiling and together pass it (#14026, item 3 of | |
| 3 | * #13805): the gate on land measures the merge of the pull with main as it is now, so the second | |
| 4 | * is held and its verdict names the ceiling. The ceiling here is a stand-in for the shared | |
| 5 | * stylesheet's: 10 bytes in `shared/`, measured by hand below. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { readFileSync } from "node:fs"; | |
| 10 | import { tmpdir } from "node:os"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { mergePull, openPull } from "../src/actions/pulls.ts"; | |
| 14 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 15 | import { parseCheck } from "../src/apps/manifest.ts"; | |
| 16 | import { gateCandidate } from "../src/checks/landing.ts"; | |
| 17 | import { mergeForCheck } from "../src/checks/merged.ts"; | |
| 18 | import { startChecks, type ChecksHandle } from "../src/checks/service.ts"; | |
| 19 | import { getPull } from "../src/core/pulls.ts"; | |
| 20 | import { getRepo, type Repo } from "../src/core/repos.ts"; | |
| 21 | import { createUser, type User } from "../src/core/users.ts"; | |
| 22 | import { resolveOid } from "../src/git/merge.ts"; | |
| 23 | import { repoDir } from "../src/git/repos.ts"; | |
| 24 | ||
| 25 | let dataDir: string; | |
| 26 | let app: App; | |
| 27 | let checks: ChecksHandle; | |
| 28 | let alice: User; | |
| 29 | const cells = process.env["FORGE_CELLS"]; | |
| 30 | ||
| 31 | // Prints what `bun test` prints for a red test, so the verdict reads it as the real one does. | |
| 32 | const FULL = | |
| 33 | "n=$(cat shared/* | wc -c); echo test/client-size.test.ts:; " + | |
| 34 | "if [ $n -gt 10 ]; then echo \"(fail) no first page's client JavaScript or CSS passes its ceiling: shared is $n B, over its ceiling of 10 B\"; exit 1; fi"; | |
| 35 | ||
| 36 | beforeAll(async () => { | |
| 37 | process.env["FORGE_CELLS"] = "off"; | |
| 38 | dataDir = await mkdtemp(join(tmpdir(), "forge-size-merged-")); | |
| 39 | app = createApp({ dataDir, port: 0 }); | |
| 40 | checks = startChecks(app, { forgeUrl: "http://127.0.0.1:1", concurrency: 2 }); | |
| 41 | const a = await createUser(app.db, { | |
| 42 | origin: "seed", trusted: true, username: "alice", email: "[email protected]", | |
| 43 | password: "a-good-passphrase", adminIfFirst: true, | |
| 44 | }); | |
| 45 | if (!a.ok) throw new Error(a.error); | |
| 46 | alice = a.value; | |
| 47 | }); | |
| 48 | ||
| 49 | afterAll(async () => { | |
| 50 | await checks.stop({ drain: false }); | |
| 51 | app.close(); | |
| 52 | if (cells === undefined) delete process.env["FORGE_CELLS"]; | |
| 53 | else process.env["FORGE_CELLS"] = cells; | |
| 54 | await rm(dataDir, { recursive: true, force: true }); | |
| 55 | }); | |
| 56 | ||
| 57 | async function branch(repo: Repo, name: string, file: string, bytes: number) { | |
| 58 | const made = await commitToBranch(app, alice, repo, { | |
| 59 | branch: name, message: `Grow ${file}`, files: [{ path: `shared/${file}`, content: "x".repeat(bytes) }], | |
| 60 | }); | |
| 61 | if (!made.ok) throw new Error(JSON.stringify(made.error)); | |
| 62 | const opened = await openPull(app, alice, repo, { title: name, baseBranch: "main", headBranch: name }); | |
| 63 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 64 | return getPull(app.db, repo.id, opened.value.number)!; | |
| 65 | } | |
| 66 | ||
| 67 | /** The gate as the merge queue asks it: on the pull merged into main's tip now. */ | |
| 68 | async function gateOnMerge(repo: Repo, pull: NonNullable<ReturnType<typeof getPull>>) { | |
| 69 | const dir = repoDir(app.reposRoot, repo.ownerName, repo.name); | |
| 70 | const tip = await resolveOid(dir, "refs/heads/main"); | |
| 71 | const merged = await mergeForCheck(dir, "main", tip!, pull.headOid); | |
| 72 | if (!merged.ok) throw new Error(merged.error); | |
| 73 | return gateCandidate(app, repo, pull, dir, merged.commit); | |
| 74 | } | |
| 75 | ||
| 76 | test("two pulls that each fit and together pass the ceiling: the second is held, naming the ceiling", async () => { | |
| 77 | const made = await createRepo(app, alice, { name: "styles", visibility: "public" }); | |
| 78 | if (!made.ok) throw new Error(String(made.error)); | |
| 79 | const repo = made.value; | |
| 80 | const seeded = await commitToBranch(app, alice, repo, { | |
| 81 | message: "Start", | |
| 82 | files: [ | |
| 83 | { path: "forge.json", content: JSON.stringify({ check: { run: "true", fast: "true", full: FULL } }) }, | |
| 84 | { path: "shared/base.css", content: "xxxx" }, // 4 B | |
| 85 | ], | |
| 86 | }); | |
| 87 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 88 | // By hand: 4 B on main + 4 B each = 8 B alone, under 10; together 4 + 4 + 4 = 12 B, over. | |
| 89 | const first = await branch(repo, "first", "a.css", 4); | |
| 90 | const second = await branch(repo, "second", "b.css", 4); | |
| 91 | ||
| 92 | expect(await gateOnMerge(repo, first)).toEqual({ lands: true }); | |
| 93 | expect(await gateOnMerge(repo, second)).toEqual({ lands: true }); // fits on its own base: both are green | |
| 94 | ||
| 95 | const landed = await mergePull(app, alice, getRepo(app.db, "alice", "styles")!, getPull(app.db, repo.id, first.number)!, "merge"); | |
| 96 | if (!landed.ok) throw new Error(JSON.stringify(landed.error)); | |
| 97 | ||
| 98 | const held = await gateOnMerge(repo, getPull(app.db, repo.id, second.number)!); | |
| 99 | expect(held.lands).toBe(false); | |
| 100 | if (held.lands || !("reopen" in held)) throw new Error("the second pull was not judged red"); | |
| 101 | expect(held.comment).toContain("The full gate on land was red"); | |
| 102 | expect(held.comment).toContain("ceiling"); | |
| 103 | }, 60_000); | |
| 104 | ||
| 105 | test("this repository's own full tier measures the first-page ceilings on the merged tree", () => { | |
| 106 | const forgeJson = readFileSync(join(import.meta.dir, "..", "forge.json"), "utf8"); | |
| 107 | const declared = parseCheck(forgeJson, undefined); | |
| 108 | if (!declared.ok || declared.value === undefined) throw new Error("forge.json declares no check"); | |
| 109 | expect(declared.value.full).toContain("bun test test/client-size.test.ts"); | |
| 110 | // The tier on land still judges everything `run` does. | |
| 111 | expect(declared.value.full.startsWith(declared.value.run)).toBe(true); | |
| 112 | }); |
new above
offline