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

Preflight always runs the slow-listed tests that scan the tree #17267

opened this

Merged 43h 19m ago, live in production

sold/preflight-slow → main 0 commits

  • Merged. sold/preflight-slow was merged into main as db30116.

Review

Sign in to review this change.
2 files changed +28 −5
scripts/preflight.ts +18 −4
@@ -14,7 +14,9 @@
1414 * the changed files, and says the check will run everything.
1515 *
1616 * The tests run in `--jobs` bun processes at once (default half the cores), longest first by the
17 * check's own times, as the check's shards do. SLOW files run only when the change names them.
17 * check's own times, as the check's shards do. SLOW files run only when the change names them,
18 * except those that read the whole tree (`scansIn`): a rule test like job-slices reds a pull that
19 * never names it (#17227), and each is a few seconds.
1820 * A test file that fails is run again alone (a pass there is load, not the change), then, if it
1921 * still fails, on the base in a scratch worktree (a fail there is the base's, not the change's).
2022 * Only a failure that is neither is the branch's own. Nothing is pushed or written outside the
@@ -175,9 +177,21 @@ function testsFor(base: string): { files: string[]; full: string | null } {
175177 .filter((s) => s.length >= 3 && [...listed].filter((f) => f.includes(s)).length <= STEM_MOST);
176178 reached = [...listed].filter((f) => changed.includes(f) || stems.some((s) => f.includes(s)));
177179 }
178 const slow = new Set(SLOW.map((s) => s.file));
179 const files = [...new Set([...always, ...reached])].filter((f) => listed.has(f) && (!slow.has(f) || reached.includes(f)));
180 return { files, full };
180 return { files: chosen({ listed, always, reached, slow: new Set(SLOW.map((s) => s.file)), scans }), full };
181 }
182
183 /**
184 * The files to run: the always-run and the reached, those the check gates; a SLOW file only when
185 * the change reaches it or it reads the whole tree (a scan reds pulls that never name it).
186 */
187 export function chosen(o: {
188 listed: ReadonlySet<string>;
189 always: readonly string[];
190 reached: readonly string[];
191 slow: ReadonlySet<string>;
192 scans: { has(file: string): boolean };
193 }): string[] {
194 return [...new Set([...o.always, ...o.reached])].filter((f) => o.listed.has(f) && (!o.slow.has(f) || o.reached.includes(f) || o.scans.has(f)));
181195 }
182196
183197 /** The check's own test times, seconds a file; none when they cannot be read (every file weighs a second). */
test/preflight.test.ts +10 −1
@@ -1,6 +1,6 @@
11 /** `scripts/preflight.ts`: which files failed in bun's output, and the tests dealt longest first onto the least loaded job. */
22 import { expect, test } from "bun:test";
3 import { deal, failedFiles } from "../scripts/preflight.ts";
3 import { chosen, deal, failedFiles } from "../scripts/preflight.ts";
44
55 test("the failing files are the ones bun printed a (fail) under", () => {
66 const out = ["test/a.test.ts:", "(pass) one [1ms]", "test/b.test.ts:", "(pass) two", "(fail) three [2ms]", "test/c.test.ts:", "(fail) four", "(fail) five"].join("\n");
@@ -15,3 +15,12 @@ test("files are dealt longest first onto the least loaded job; unknown files wei
1515 expect(deal(["test/a.test.ts"], 8, {})).toEqual([["test/a.test.ts"]]);
1616 expect(deal([], 4, {})).toEqual([]);
1717 });
18
19 test("a SLOW file runs when the change reaches it or it reads the whole tree, never otherwise", () => {
20 const listed = new Set(["test/job-slices.test.ts", "test/bundle.test.ts", "test/fast.test.ts", "test/reached-slow.test.ts"]);
21 const slow = new Set(["test/job-slices.test.ts", "test/bundle.test.ts", "test/reached-slow.test.ts"]);
22 const scans = new Set(["test/job-slices.test.ts"]);
23 const always = ["test/job-slices.test.ts", "test/bundle.test.ts", "test/fast.test.ts", "test/gone.test.ts"];
24 const reached = ["test/reached-slow.test.ts"];
25 expect(chosen({ listed, always, reached, slow, scans }).sort()).toEqual(["test/fast.test.ts", "test/job-slices.test.ts", "test/reached-slow.test.ts"]);
26 });

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

Keyboard shortcuts

Docs