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

A rule red that is main's no longer stops a pull's behaviour files, so main's red cannot pass a check that never ran them #17188

opened this

Merged 37h 33m ago, live in production

fix/rule-red-main-runs-behaviour → main 0 commits

  • Merged. fix/rule-red-main-runs-behaviour was merged into main as 6a277c5.

Review

Sign in to review this change.
2 files changed +61 −13
scripts/test-shards.ts +37 −13
@@ -593,7 +593,7 @@ const banner = record
593593 console.log(banner);
594594 process.stderr.write(banner + "\n");
595595 if (ruleFiles.length > 0)
596 console.log(`test-shards: ${ruleFiles.length} rule and scan files first, in ${ruleSlices.length} shard${ruleSlices.length === 1 ? "" : "s"}; their red ends the run`);
596 console.log(`test-shards: ${ruleFiles.length} rule and scan files first, in ${ruleSlices.length} shard${ruleSlices.length === 1 ? "" : "s"}; their red ends the run, unless it is main's`);
597597
598598 const children = new Set<Bun.Subprocess>();
599599 for (const signal of ["SIGINT", "SIGTERM"] as const)
@@ -1082,14 +1082,22 @@ const busy: Busy[] = [];
10821082 // Never more side by side than the count: capped slices outnumber it.
10831083 const width = (n: number): number => (serialFiles ? 1 : Math.max(1, Math.min(count.value, n)));
10841084 const ruleResults = await pool(width(ruleSlices.length), 0, ruleSlices.length, busy);
1085 /** What each file did on main, once asked (`mainsRed`): the rule stage's answers are not asked again. */
1086 const askedOfMain = new Map<string, OnBase>();
10851087 const ruleRed = ruleResults.some((result) => result.code !== 0);
1086 if (ruleRed)
1088 // A rule red that is main's own does not stop the run: main's red would otherwise clear a check
1089 // whose behaviour files never ran (2026-12-01: #17137 passed with 3033 of them unrun, and merged
1090 // a red). So main is asked about the rule red first; only the pull's own rule red ends the run.
1091 const ruleStop = ruleRed && !(await mainsRed(ruleResults, "rule"));
1092 if (ruleStop)
10871093 console.log(
10881094 `test-shards: a rule or scan test is red, so the ${behaviourFiles.length} behaviour files were not run; fix it and push again`,
10891095 );
1096 else if (ruleRed)
1097 console.log(`test-shards: the rule and scan red is main's, so the ${behaviourFiles.length} behaviour files run`);
10901098 const results = [
10911099 ...ruleResults,
1092 ...(ruleRed ? [] : await pool(width(slices.length - ruleSlices.length), ruleSlices.length, slices.length, busy)),
1100 ...(ruleStop ? [] : await pool(width(slices.length - ruleSlices.length), ruleSlices.length, slices.length, busy)),
10931101 // Budget files, one at a time, once the rest are done and green.
10941102 ...(await pool(1, slices.length, slices.length)),
10951103 ];
@@ -1268,6 +1276,29 @@ function redTests(results: readonly Timed[]): Map<string, string[]> | undefined
12681276 return red;
12691277 }
12701278
1279 /**
1280 * Whether every red of `results` is main's (#10304), asked of main for a fast tier on a pull's
1281 * range: `stage` "rule" asks about the rule and scan red before the behaviour files run, "all"
1282 * about the whole run's red at the end. Says each file's verdict.
1283 */
1284 async function mainsRed(results: readonly Timed[], stage: "rule" | "all"): Promise<boolean> {
1285 if (tier !== "fast" || range === undefined || only !== undefined) return false;
1286 const red = redTests(results);
1287 const asked = askBase({ red, changed });
1288 if (red === undefined || asked === undefined) return false;
1289 const fresh = asked.filter((file) => !askedOfMain.has(file));
1290 if (fresh.length > 0) {
1291 console.log(`\ntest-shards: asking main at ${range[0]} about ${fresh.join(", ")}${stage === "rule" ? " (the rule and scan red)" : ""}`);
1292 for (const [file, did] of await runOnBase(fresh, range[0]!)) askedOfMain.set(file, did);
1293 }
1294 const verdict = baseVerdict(red, askedOfMain, range[0]!);
1295 // The cleared line (the last, when cleared) is the run's verdict, said once at the end: the rule
1296 // stage's would read as a green check (`clearedIn`) before the behaviour files have run.
1297 const said = stage === "rule" && verdict.cleared ? verdict.lines.slice(0, -1) : verdict.lines;
1298 for (const line of said) console.log(`test-shards: ${line}`);
1299 return verdict.cleared;
1300 }
1301
12711302 /**
12721303 * Each file run alone on the tree of `base`, in a worktree on the shard
12731304 * disk that shares this checkout's node_modules; removed however it ends.
@@ -1329,14 +1360,7 @@ async function runOnBase(asked: readonly string[], base: string): Promise<Map<st
13291360 // A fast tier red only on tests main's own tree fails too is main's red,
13301361 // not this pull's (#10304): said, and not counted against it.
13311362 let code = finalCode({ code: ending.code, auditDisagreed: auditDisagreement, clearedByBase: false });
1332 if (code !== 0 && tier === "fast" && range !== undefined && only === undefined) {
1333 const red = redTests(results);
1334 const asked = askBase({ red, changed });
1335 if (red !== undefined && asked !== undefined) {
1336 console.log(`\ntest-shards: asking main at ${range[0]} about ${asked.join(", ")}`);
1337 const verdict = baseVerdict(red, await runOnBase(asked, range[0]!), range[0]!);
1338 for (const line of verdict.lines) console.log(`test-shards: ${line}`);
1339 code = finalCode({ code, auditDisagreed: auditDisagreement, clearedByBase: verdict.cleared });
1340 }
1341 }
1363 // Never cleared when the behaviour files were skipped: main's red cannot stand for a run that did not happen.
1364 if (code !== 0 && !ruleStop)
1365 code = finalCode({ code, auditDisagreed: auditDisagreement, clearedByBase: await mainsRed(results, "all") });
13421366 process.exit(code);
test/red-on-main.test.ts +24
@@ -183,4 +183,28 @@ describe("the fast tier asks main", () => {
183183 expect(got.out).not.toContain("green: every red test is red on main");
184184 expect(got.code).not.toBe(0);
185185 }, 60_000);
186
187 test("main's red in a rule test does not stop the pull's behaviour files, and their own red keeps the check red", async () => {
188 // RED is a rule test, run first; test/two.test.ts is a behaviour test the pull breaks. Once,
189 // main's rule red stopped the run before it and then cleared the check (#17137 merged a red).
190 const two = `import { expect, test } from "bun:test";\nimport { two } from "../src/two.ts";\ntest("two", () => { expect(two).toBe(2); });\n`;
191 const got = await check(fail, { "src/two.ts": "export const two = 3;\n" }, { "src/two.ts": "export const two = 2;\n", "test/two.test.ts": two });
192 expect(got.out).toContain("rule and scan files first");
193 expect(got.out).toContain(`${RED} is red on main at HEAD~1 too, the same tests: not counted against this pull`);
194 expect(got.out).toMatch(/the rule and scan red is main's, so the \d+ behaviour files run/);
195 expect(got.out).not.toContain("behaviour files were not run");
196 expect(got.out).toContain("test/two.test.ts is green on main at HEAD~1");
197 expect(got.out).not.toContain("green: every red test is red on main");
198 expect(clearedIn(got.out.split("\n"))).toBeUndefined();
199 expect(got.code).not.toBe(0);
200 }, 60_000);
201
202 test("main's red in a rule test, with the pull's behaviour files green, passes once they have run", async () => {
203 const two = `import { expect, test } from "bun:test";\nimport { two } from "../src/two.ts";\ntest("two", () => { expect(two).toBeGreaterThan(1); });\n`;
204 const got = await check(fail, { "src/two.ts": "export const two = 3;\n" }, { "src/two.ts": "export const two = 2;\n", "test/two.test.ts": two });
205 expect(got.out).toMatch(/the rule and scan red is main's, so the \d+ behaviour files run/);
206 expect(got.out).toMatch(/\(exit 0, [\d.]+s\): test\/two\.test\.ts/);
207 expect(clearedIn(got.out.split("\n"))).toBe(`red on main at HEAD~1, not this pull's: ${RED}`);
208 expect(got.code).toBe(0);
209 }, 60_000);
186210 });

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

Keyboard shortcuts

Docs