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

The gate every push is judged by runs 23 of the repository's 113 test files #410

Closed opened this
Closed without merging

mason/forge:mason/261-the-gate-every-push-is-judged-by-runs-23 → main 8 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
5 files changed +200 −10
README.md +13 −3
@@ -364,9 +364,19 @@ bun run check # exactly what the forge runs against every push
364364 ```
365365
366366 `bun run check` is the gate: the same command `forge.json` declares, so what
367 it says here is what the deploy will say. It type-checks once, then runs the
368 test files named in `check.run` as parallel `bun test` shards
369 (`scripts/test-shards.ts`): one per CPU the process may use, at most eight,
367 it says here is what the deploy will say. It type-checks once, then runs
368 every `test/*.test.ts` except the few listed in `EXCLUDED` in
369 `scripts/gate.ts`. `check.run` names no test file, so a new one is in the gate
370 the moment it exists. Each exclusion is a known-red file with a one-line
371 reason and the open issue that owns it, and `test/check-list.test.ts` turns
372 the check red if a file is neither in the gate nor excluded, or if an
373 exclusion has no reason, no issue number, or no file behind it. **To put a
374 file back**, the pull that fixes its issue deletes that file's row from
375 `EXCLUDED`. A file that goes red and is not yours to fix gets a row of its
376 own, with a new issue, in the pull that found it.
377
378 The files run as parallel `bun test` shards
379 (`scripts/test-shards.ts`; name files after the flags to run just those): one per CPU the process may use, at most eight,
370380 and `FORGE_CHECK_SHARDS=2` turns that down on a small or busy host. Each
371381 shard's output is written whole as it finishes; the log ends with every
372382 failing test from every shard, or on green with one line — how many tests,
forge.json +1 −1
@@ -6,7 +6,7 @@
66 "ready": 90
77 },
88 "check": {
9 "run": "bun x tsc --noEmit && bun scripts/test-shards.ts --timeout 60000 test/crew.test.ts test/crew-wrapup.test.ts test/crew-limits.test.ts test/crew-sandbox.test.ts test/steer.test.ts test/landing.test.ts test/decide.test.ts test/ledger.test.ts test/checks.test.ts test/dependencies.test.ts test/autonomy.test.ts test/studio.test.ts test/studio-words.test.ts test/forks.test.ts test/fork-flow.test.ts test/cross-repo-pull.test.ts test/pulls.test.ts test/apps.test.ts test/apps-adversarial.test.ts test/apps-busy.test.ts test/web.test.ts test/git-trust.test.ts test/helpers.test.ts test/shards.test.ts test/migrate.test.ts test/vitals.test.ts test/asks.test.ts test/feed.test.ts test/feed-page.test.ts test/offline.test.ts test/share.test.ts test/cloud.test.ts test/run-secrets.test.ts test/forge-cloudflare.test.ts test/usage.test.ts test/standing.test.ts test/board-windows.test.ts",
9 "run": "bun x tsc --noEmit && bun scripts/test-shards.ts --timeout 60000",
1010 "timeout": 1800
1111 }
1212 }
scripts/gate.ts added +86
@@ -0,0 +1,86 @@
1 /**
2 * The files the gate runs: every `test/*.test.ts`, minus a short list that
3 * says out loud why each one is out.
4 *
5 * The gate used to name its files by hand in `forge.json`, so a new test
6 * file joined the suite and the gate ignored it — silently, forever (#261).
7 * The default is inverted here: a file in `test/` is in the gate the moment
8 * it exists, and leaving one out costs an entry in `EXCLUDED` with a reason
9 * and the open issue that will put it back. `test/check-list.test.ts` makes
10 * that mechanical — an exclusion with no reason, no issue, or no file on
11 * disk is red.
12 *
13 * `scripts/test-shards.ts` runs this list when it is named no files.
14 */
15
16 import { readdirSync } from "node:fs";
17
18 /** One test file the gate does not run, and the reason a reader can check. */
19 export type Exclusion = {
20 /** Path from the repository root, e.g. `test/looks.test.ts`. */
21 readonly file: string;
22 /** One line: why it is out, ending in the issue that puts it back. */
23 readonly reason: string;
24 };
25
26 /**
27 * Known red, each owned by an open issue: red on its own, measured on
28 * `main` at `bc947db` (#261). When that issue ships, its pull
29 * deletes the row here, and the file is back in the gate. Slow is not a
30 * reason while the suite fits the check's timeout.
31 */
32 export const EXCLUDED: readonly Exclusion[] = [
33 {
34 file: "test/web-apps.test.ts",
35 reason:
36 "9 red: asserts dashboard and repo headings the studio redesign moved (#290)",
37 },
38 {
39 file: "test/web-code.test.ts",
40 reason: "4 red: asserts the pre-studio search page and repo rows (#291)",
41 },
42 {
43 file: "test/web-origins.test.ts",
44 reason: "1 red: asserts the dashboard's old 'On your machine' card (#291)",
45 },
46 {
47 file: "test/ssh-site.test.ts",
48 reason: "1 red: asserts the dashboard's old Terminal card (#291)",
49 },
50 {
51 file: "test/looks.test.ts",
52 reason: "1 red: asserts the studio look ask's pre-redesign markup (#291)",
53 },
54 {
55 file: "test/surfaces-adversarial.test.ts",
56 reason: "2 red: /apps and the dashboard cards query per row again (#292)",
57 },
58 {
59 file: "test/agents.test.ts",
60 reason: "1 red: fifty concurrent pushes lose auth on the hook socket (#293)",
61 },
62 {
63 file: "test/highlight.test.ts",
64 reason:
65 "1 red: a 10,000-character line scans in 25ms against a 10ms bound (#294)",
66 },
67 {
68 file: "test/prompts.test.ts",
69 reason:
70 "4 red: the Instagram token's age follows the real date, not the test's clock (#408)",
71 },
72 ];
73
74 /** Every `test/*.test.ts`, sorted, whether or not the gate runs it. */
75 export function allTestFiles(): string[] {
76 return readdirSync(new URL("../test", import.meta.url))
77 .filter((name) => name.endsWith(".test.ts"))
78 .map((name) => `test/${name}`)
79 .sort();
80 }
81
82 /** The files the gate runs: everything, minus `EXCLUDED`. */
83 export function gateFiles(): string[] {
84 const out = new Set(EXCLUDED.map((one) => one.file));
85 return allTestFiles().filter((file) => !out.has(file));
86 }
scripts/test-shards.ts +11 −6
@@ -1,11 +1,14 @@
11 /**
22 * `bun test`, over the named files, in parallel shards.
33 *
4 * bun scripts/test-shards.ts [bun test flags…] test/a.test.ts test/b.test.ts …
4 * bun scripts/test-shards.ts [bun test flags…] [test/a.test.ts …]
55 *
6 * The files come from the command line, so `forge.json`'s `check.run`
7 * stays the one place that names them. Each shard is its own `bun test`
8 * over a disjoint slice (`scripts/shards.ts` decides the slices); a
6 * Named no files, it runs the gate's list (`scripts/gate.ts`): every
7 * `test/*.test.ts` minus the reasoned exclusions. That is what
8 * `forge.json`'s `check.run` does, so the gate names no test file and a new
9 * one is in it the moment it exists. Naming files runs just those.
10 *
11 * Each shard is its own `bun test` over a disjoint slice (`scripts/shards.ts` decides the slices); a
912 * shard's output is written through whole when it finishes, so the log
1013 * reads one shard at a time, and the tail names every failing test from
1114 * every shard. Exits non-zero if any shard does.
@@ -13,16 +16,18 @@
1316
1417 import { availableParallelism } from "node:os";
1518 import { statSync } from "node:fs";
19 import { gateFiles } from "./gate.ts";
1620 import { shardCount, splitFiles, tally, type ShardResult } from "./shards.ts";
1721
1822 const TEST_FILE = /\.test\.[cm]?[jt]sx?$/;
1923
2024 const args = process.argv.slice(2);
21 const files = args.filter((arg) => TEST_FILE.test(arg));
25 const named = args.filter((arg) => TEST_FILE.test(arg));
2226 const flags = args.filter((arg) => !TEST_FILE.test(arg));
27 const files = named.length > 0 ? named : gateFiles();
2328
2429 if (files.length === 0) {
25 console.error("test-shards: name the test files to run");
30 console.error("test-shards: no test files to run");
2631 process.exit(2);
2732 }
2833 // A file that is not there would be a filter matching nothing to `bun
test/check-list.test.ts added +89
@@ -0,0 +1,89 @@
1 /**
2 * The gate covers the suite, and can only stop covering it out loud.
3 *
4 * For a long while `forge.json`'s check named its test files by hand: 23 of
5 * 115, so a file that joined the suite was never run before a push and rotted
6 * unseen — found red on `main` after the fact (#238, #253, then #261). The
7 * list is gone; `scripts/gate.ts` starts from every `test/*.test.ts` and
8 * subtracts an explicit `EXCLUDED`, and `scripts/test-shards.ts` runs that
9 * when it is named no files. These tests keep that true: a file left out
10 * needs a reason and an issue, an exclusion for a file that no longer exists
11 * is a stale claim, and a check command that names test files is the old
12 * hand-list coming back.
13 */
14
15 import { describe, expect, test } from "bun:test";
16 import { existsSync } from "node:fs";
17 import { allTestFiles, EXCLUDED, gateFiles } from "../scripts/gate.ts";
18
19 const manifest = (await Bun.file(
20 new URL("../forge.json", import.meta.url),
21 ).json()) as { check?: { run?: string; timeout?: number } };
22
23 const command = manifest.check?.run ?? "";
24
25 describe("the gate in forge.json", () => {
26 test("runs the gate's list through scripts/test-shards.ts, and names no test file itself", () => {
27 expect(command).toContain("scripts/test-shards.ts");
28 // A hand-written list is the hole this closes: any `.test.ts` in the
29 // command means files are being chosen one at a time again — and
30 // test-shards runs only the named files when it is given any.
31 expect(command).not.toContain(".test.");
32 // Types first, then the suite — the gate a crew member runs locally with
33 // `bun run check` is this exact string (`scripts/check.ts`).
34 expect(command).toContain("tsc --noEmit");
35 });
36
37 test("declares a timeout the whole suite fits in", () => {
38 expect(manifest.check?.timeout ?? 0).toBeGreaterThanOrEqual(1800);
39 });
40 });
41
42 describe("every test file is in the gate, or excluded for a stated reason", () => {
43 test("no file is in neither", () => {
44 const covered = new Set([
45 ...gateFiles(),
46 ...EXCLUDED.map((one) => one.file),
47 ]);
48 const orphans = allTestFiles().filter((file) => !covered.has(file));
49 expect(orphans).toEqual([]);
50 });
51
52 test("the gate is every test file minus exactly the exclusions", () => {
53 const gate = gateFiles();
54 expect(gate.length).toBe(allTestFiles().length - EXCLUDED.length);
55 for (const one of EXCLUDED) expect(gate).not.toContain(one.file);
56 // This file is how the list stays honest; it is never the one left out.
57 expect(gate).toContain("test/check-list.test.ts");
58 });
59
60 test("each exclusion names a test file that exists", () => {
61 const known = new Set(allTestFiles());
62 for (const one of EXCLUDED) {
63 // A file that was deleted or renamed leaves an exclusion that quietly
64 // covers nothing; the entry has to go when the file does.
65 expect(`${one.file} ${known.has(one.file) ? "exists" : "is gone"}`).toBe(
66 `${one.file} exists`,
67 );
68 expect(existsSync(new URL(`../${one.file}`, import.meta.url))).toBe(true);
69 }
70 });
71
72 test("each exclusion carries a one-line reason and the issue that ends it", () => {
73 for (const one of EXCLUDED) {
74 const reason = one.reason.trim();
75 expect(`${one.file}: ${reason.length > 20}`).toBe(`${one.file}: true`);
76 expect(reason).not.toContain("\n");
77 // Not a note — a ticket. Something outside the gate is work someone
78 // owns, and the number is how a reader finds out whether it is done.
79 expect(`${one.file}: ${/\(#\d+\)$/.test(reason)}`).toBe(
80 `${one.file}: true`,
81 );
82 }
83 });
84
85 test("no file is excluded twice", () => {
86 const files = EXCLUDED.map((one) => one.file);
87 expect([...new Set(files)].length).toBe(files.length);
88 });
89 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs