Public: anyone can read this; the crew can change it.
Budget tests run only after merge: a pull's fast check should run them #14331
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/14318-budget-tests-run-only-after-merge-a-pull → main 1 commit fork
3 files
changed +50
−2
src/checks/tiers.ts +23 −1
| @@ -54,6 +54,26 @@ export const RULE_TESTS: readonly string[] = [ | ||
| 54 | 54 | "test/client-size.test.ts", |
| 55 | 55 | ]; |
| 56 | 56 | |
| 57 | /** | |
| 58 | * The page budgets every page spends from (#14318): SQL statements per page, | |
| 59 | * first-page bytes, the /docs index size. Shared code moves them all — the | |
| 60 | * layout, the stylesheet, the router, any page — yet neither coverage nor | |
| 61 | * imports tie such a diff to them reliably, and on 2026-11-17 three pulls | |
| 62 | * passed their check and turned main red on one of these. | |
| 63 | */ | |
| 64 | export const PAGE_BUDGET_TESTS: readonly string[] = [ | |
| 65 | "test/pages-budget.test.ts", | |
| 66 | "test/client-size.test.ts", | |
| 67 | "test/docs-link.test.ts", | |
| 68 | ]; | |
| 69 | ||
| 70 | /** Whether a changed file is shared page code, which moves every {@link PAGE_BUDGET_TESTS}. */ | |
| 71 | export const movesPageBudgets = (file: string): boolean => | |
| 72 | file === "src/web/layout.ts" || | |
| 73 | file === "src/http/server.ts" || | |
| 74 | file.startsWith("src/web/style/") || | |
| 75 | file.startsWith("src/web/pages/"); | |
| 76 | ||
| 57 | 77 | /** What a test the times table does not name is assumed to take. */ |
| 58 | 78 | const UNKNOWN_SECONDS = 5; |
| 59 | 79 | |
| @@ -142,7 +162,7 @@ export interface FastPlan { | ||
| 142 | 162 | * The fast tier for a diff: a changed test; a test importing a changed file |
| 143 | 163 | * directly or through up to two hops of source; a test whose name matches a |
| 144 | 164 | * changed source path; every repo-wide rule test and every tree scan |
| 145 | * (`scans.ts`); whatever the pull | |
| 165 | * (`scans.ts`); the page budgets when shared page code changed; whatever the pull | |
| 146 | 166 | * learned; and every test known to take under a second. A test with no recorded time is not known |
| 147 | 167 | * to be quick, so it runs only when something above picks it. |
| 148 | 168 | */ |
| @@ -207,6 +227,8 @@ export function fastSet(input: FastInput): FastPlan { | ||
| 207 | 227 | for (const test of RULE_TESTS) take(test, "repo-wide rule"); |
| 208 | 228 | for (const [test, why] of input.scans ?? []) take(test, `tree scan: ${why}`); |
| 209 | 229 | } |
| 230 | const shared = diffed.find(movesPageBudgets); | |
| 231 | if (shared !== undefined) for (const test of PAGE_BUDGET_TESTS) take(test, `page budget: ${shared} changed`); | |
| 210 | 232 | // What a guess looks for. A test the map has measured already answered |
| 211 | 233 | // for every change the map can see, by what it executes; it is guessed |
| 212 | 234 | // only against the changes the map cannot see, so one unreached file |
test/check-tiers.test.ts +18
| @@ -25,6 +25,7 @@ import { | ||
| 25 | 25 | fastSet, |
| 26 | 26 | importsOf, |
| 27 | 27 | landVerdict, |
| 28 | PAGE_BUDGET_TESTS, | |
| 28 | 29 | tierLine, |
| 29 | 30 | } from "../src/checks/tiers.ts"; |
| 30 | 31 | import { |
| @@ -297,6 +298,23 @@ describe("the fast set, by measured coverage", () => { | ||
| 297 | 298 | expect(logic.files).toEqual(base.tests); |
| 298 | 299 | }); |
| 299 | 300 | |
| 301 | test("shared page code runs the page budgets, though no coverage reaches them (#14318)", () => { | |
| 302 | const withBudgets = { ...base, tests: [...base.tests, ...PAGE_BUDGET_TESTS] }; | |
| 303 | for (const file of [ | |
| 304 | "src/web/layout.ts", | |
| 305 | "src/web/style/content.ts", | |
| 306 | "src/http/server.ts", | |
| 307 | "src/web/pages/docs_link.ts", | |
| 308 | ]) { | |
| 309 | const plan = fastSet({ ...withBudgets, changed: [file] }); | |
| 310 | for (const budget of PAGE_BUDGET_TESTS) expect(plan.files).toContain(budget); | |
| 311 | expect(plan.why.get("test/pages-budget.test.ts")).toBe(`page budget: ${file} changed`); | |
| 312 | } | |
| 313 | const elsewhere = fastSet({ ...withBudgets, changed: ["src/snapshot/store.ts"] }); | |
| 314 | expect(elsewhere.files).not.toContain("test/pages-budget.test.ts"); | |
| 315 | expect(elsewhere.files).not.toContain("test/docs-link.test.ts"); | |
| 316 | }); | |
| 317 | ||
| 300 | 318 | test("lcov: only src files with a line hit count as executed", () => { |
| 301 | 319 | const lcov = "SF:src/a.ts\nDA:1,0\nend_of_record\nSF:src/b.ts\nDA:1,3\nend_of_record\nSF:test/x.test.ts\nDA:1,1\nend_of_record\n"; |
| 302 | 320 | expect(executedFiles(lcov)).toEqual(["src/b.ts"]); |
test/rule-tests-always.test.ts +9 −1
| @@ -12,7 +12,7 @@ import { tmpdir } from "node:os"; | ||
| 12 | 12 | import { join } from "node:path"; |
| 13 | 13 | import { gateFiles } from "../scripts/gate.ts"; |
| 14 | 14 | import { rawBudgets } from "../scripts/flake.ts"; |
| 15 | import { fastSet, RULE_TESTS } from "../src/checks/tiers.ts"; | |
| 15 | import { fastSet, PAGE_BUDGET_TESTS, RULE_TESTS } from "../src/checks/tiers.ts"; | |
| 16 | 16 | import { summariseCheckFailure } from "../src/checks/summary.ts"; |
| 17 | 17 | |
| 18 | 18 | const breaker = [ |
| @@ -45,6 +45,14 @@ describe("the repo-wide rule tests in the fast tier", () => { | ||
| 45 | 45 | for (const rule of RULE_TESTS) expect(gate).toContain(rule); |
| 46 | 46 | }); |
| 47 | 47 | |
| 48 | test("every page budget is a gate file, and shared page code runs them all (#14318)", () => { | |
| 49 | for (const budget of PAGE_BUDGET_TESTS) expect(gate).toContain(budget); | |
| 50 | for (const shared of ["src/web/layout.ts", "src/web/style/base.ts", "src/http/server.ts", "src/web/pages/repo.ts"]) { | |
| 51 | const fast = plan([shared]); | |
| 52 | for (const budget of PAGE_BUDGET_TESTS) expect(fast.files).toContain(budget); | |
| 53 | } | |
| 54 | }); | |
| 55 | ||
| 48 | 56 | test("a pull adding only test/x.test.ts runs every rule test", () => { |
| 49 | 57 | const fast = plan(["test/x.test.ts"]); |
| 50 | 58 | for (const rule of RULE_TESTS) { |
new above
offline