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

Merged opened this in answer to

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

Merged

mason/forge:mason/14318-budget-tests-run-only-after-merge-a-pull → main 1 commit fork

  • Merged. mason/14318-budget-tests-run-only-after-merge-a-pull was merged into main as 7c29c34.

Review

Sign in to review this change.
3 files changed +50 −2
src/checks/tiers.ts +23 −1
@@ -54,6 +54,26 @@ export const RULE_TESTS: readonly string[] = [
5454 "test/client-size.test.ts",
5555 ];
5656
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
5777 /** What a test the times table does not name is assumed to take. */
5878 const UNKNOWN_SECONDS = 5;
5979
@@ -142,7 +162,7 @@ export interface FastPlan {
142162 * The fast tier for a diff: a changed test; a test importing a changed file
143163 * directly or through up to two hops of source; a test whose name matches a
144164 * 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
146166 * learned; and every test known to take under a second. A test with no recorded time is not known
147167 * to be quick, so it runs only when something above picks it.
148168 */
@@ -207,6 +227,8 @@ export function fastSet(input: FastInput): FastPlan {
207227 for (const test of RULE_TESTS) take(test, "repo-wide rule");
208228 for (const [test, why] of input.scans ?? []) take(test, `tree scan: ${why}`);
209229 }
230 const shared = diffed.find(movesPageBudgets);
231 if (shared !== undefined) for (const test of PAGE_BUDGET_TESTS) take(test, `page budget: ${shared} changed`);
210232 // What a guess looks for. A test the map has measured already answered
211233 // for every change the map can see, by what it executes; it is guessed
212234 // only against the changes the map cannot see, so one unreached file
test/check-tiers.test.ts +18
@@ -25,6 +25,7 @@ import {
2525 fastSet,
2626 importsOf,
2727 landVerdict,
28 PAGE_BUDGET_TESTS,
2829 tierLine,
2930 } from "../src/checks/tiers.ts";
3031 import {
@@ -297,6 +298,23 @@ describe("the fast set, by measured coverage", () => {
297298 expect(logic.files).toEqual(base.tests);
298299 });
299300
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
300318 test("lcov: only src files with a line hit count as executed", () => {
301319 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";
302320 expect(executedFiles(lcov)).toEqual(["src/b.ts"]);
test/rule-tests-always.test.ts +9 −1
@@ -12,7 +12,7 @@ import { tmpdir } from "node:os";
1212 import { join } from "node:path";
1313 import { gateFiles } from "../scripts/gate.ts";
1414 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";
1616 import { summariseCheckFailure } from "../src/checks/summary.ts";
1717
1818 const breaker = [
@@ -45,6 +45,14 @@ describe("the repo-wide rule tests in the fast tier", () => {
4545 for (const rule of RULE_TESTS) expect(gate).toContain(rule);
4646 });
4747
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
4856 test("a pull adding only test/x.test.ts runs every rule test", () => {
4957 const fast = plan(["test/x.test.ts"]);
5058 for (const rule of RULE_TESTS) {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs