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

The gate list finds tests by itself: every test/*.test.ts minus a short EXCLUDED list #2053

Parked opened this in answer to
Closed without merging

torque/forge:torque/2037-the-gate-list-finds-tests-by-itself-ever → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
14 files changed +214 −503
.forgejo/workflows/flake-hunt.yml +2 −2
@@ -3,7 +3,7 @@ name: flake-hunt
33 # run, on a loaded box (scripts/flake-hunt.ts). A file red in some runs and
44 # green in others is flaky: the hunt files an issue on the forge carrying
55 # the failure text, the seed and this run; the quarantine job then moves
6 # every file an open `Flaky: …` issue names from GATE to EXCLUDED and
6 # every file an open `Flaky: …` issue names into EXCLUDED and
77 # proposes that as a pull. Nobody hand-edits the list.
88 #
99 # Flakiness is judged per file across runs, so the gate splits into slices
@@ -83,4 +83,4 @@ jobs:
8383 push -q "${FORGE_URL}/${FORGE_REPO}.git" "HEAD:refs/heads/$branch"
8484 curl -fsS -X POST "$FORGE_API/repos/$FORGE_REPO/pulls" \
8585 -H "Authorization: Bearer $FORGE_TOKEN" -H "Content-Type: application/json" \
86 --data "$(BRANCH="$branch" bun -e 'const b = process.env.BRANCH; console.log(JSON.stringify({title: `Quarantine flaky tests (${b})`, head: b, base: "main", body: "Moved by `bun scripts/flake-hunt.ts quarantine`, not by hand: each file leaves GATE under the open `Flaky:` issue that carries its failure, seed and run."}))')"
86 --data "$(BRANCH="$branch" bun -e 'const b = process.env.BRANCH; console.log(JSON.stringify({title: `Quarantine flaky tests (${b})`, head: b, base: "main", body: "Moved by `bun scripts/flake-hunt.ts quarantine`, not by hand: each file leaves the gate under the open `Flaky:` issue that carries its failure, seed and run."}))')"
CLAUDE.md +6 −5
@@ -85,11 +85,12 @@ bun run src/main.ts # boots on :3000, data in ./data
8585 (the gate list), `test/check-list.test.ts`, `test/hollow.test.ts`. Never
8686 `bun scripts/test-shards.ts --gate` inside a run: the check on your push is
8787 that same gate, and running both doubles the load on a small machine.
88 It runs the files in `GATE` (`scripts/gate.ts`), not the whole suite; every
89 other test file is in `EXCLUDED` with its reason and owning issue. Add a new
90 test file to `GATE`, or the check goes red.
91 - **A flaky test is a red that teaches nothing.** A file joins `GATE` only
92 with ten green random-order runs under load in the pull
88 It runs every `test/*.test.ts` except the few in `EXCLUDED`
89 (`scripts/gate.ts`), each with its reason and owning issue. A new test file
90 is in the gate by existing: edit no list for it.
91 - **A flaky test is a red that teaches nothing.** An excluded file rejoins the
92 gate (its `EXCLUDED` entry deleted) only with ten green random-order runs
93 under load in the pull
9394 (`bun scripts/flake-hunt.ts admit test/x.test.ts`); the nightly hunt files
9495 a `Flaky:` issue and `flake-hunt.ts quarantine` moves the file to
9596 `EXCLUDED`, so never hand-edit that move. Never add `retry` — fix the
README.md +12 −9
@@ -737,15 +737,17 @@ bun run check:record # the same, and rewrites scripts/test-times.json
737737
738738 `bun run check` is the gate: the same command `forge.json` declares, so what
739739 it says here is what the deploy will say. It type-checks once, then runs the
740 test files `scripts/gate.ts` lists in `GATE` as parallel `bun test` shards
740 test files `scripts/gate.ts` admits — every `test/*.test.ts` not in its
741 `EXCLUDED` — as parallel `bun test` shards
741742 (`scripts/test-shards.ts`): one per CPU the process may use, at most eight,
742743 and `FORGE_CHECK_SHARDS=2` turns that down on a small or busy host. Each
743744 shard's output is written whole as it finishes; the log ends with every
744745 failing test from every shard, or on green with one line — how many tests,
745746 across how many files, in how long, then the slowest and fastest shard.
746747
747 The check's first step is the gate-list audit (`bun scripts/gate.ts`), so a
748 test file listed in neither `GATE` nor `EXCLUDED` fails in under a second,
748 The check's first step is the gate-list audit (`bun scripts/gate.ts`), so an
749 `EXCLUDED` entry for a file that is gone, or one with no reason or issue,
750 fails in under a second,
749751 before install-heavy work. `tsc` then runs `--incremental` with a 2 GB heap,
750752 its build info in `.forge-cache/` (made first with `mkdir -p`: tsc will not
751753 create the directory, and a checkout with no restored cache failed on it,
@@ -808,11 +810,12 @@ in that test. Two things it will not do:
808810 and names the tool (`test/helpers/tools.ts`). Install OpenSSH and they run
809811 again — the skip is conditional on the binary, never on anything else.
810812
811 Every `test/*.test.ts` is either in `GATE` or in `EXCLUDED` with a one-line
812 reason and the issue that owns admitting it; `test/check-list.test.ts` goes
813 red on a file in neither, in both, or named without existing, so a new test
814 file never sits outside the gate silently. A file joins the gate by moving
815 from `EXCLUDED` to `GATE` in a pull whose check is green and whose description
813 Every `test/*.test.ts` is in the gate unless `EXCLUDED` names it with a
814 one-line reason and the issue that owns admitting it, so a new test file is
815 gated the moment it exists and no pull edits a shared list for it (#2037);
816 `test/check-list.test.ts` goes red on an exclusion named twice, without a
817 reason or issue, or for a file that does not exist. An excluded file rejoins
818 the gate by deleting its `EXCLUDED` entry in a pull whose check is green and whose description
816819 carries ten green runs in random order under load:
817820 `bun scripts/flake-hunt.ts admit test/x.test.ts` runs the file ten times, each
818821 its own `bun test --randomize` with a fresh seed beside busy loops, prints the
@@ -828,7 +831,7 @@ dependence, a leaked server, a timeout set near the real duration, a tight
828831 wall-clock bound); then
829832 `bun scripts/flake-hunt.ts quarantine` moves every file an open `Flaky:`
830833 issue the hunt itself filed (its author is the token's user and the forge
831 has not marked it untrusted) names from `GATE` to `EXCLUDED` under that issue and proposes the move
834 has not marked it untrusted) into `EXCLUDED` under that issue and proposes the move
832835 as a pull. Nobody hand-edits the list. A file red in every run is broken,
833836 not flaky, and the check already says so. The fix is the test's shape, never
834837 a retry: `test/flake.test.ts` fails on `--retry`, `--rerun-each`, a bunfig
scripts/flake-hunt.ts +7 −4
@@ -10,8 +10,8 @@
1010 * seed and the run (FORGE_API, FORGE_REPO, FORGE_TOKEN; FORGE_RUN_URL
1111 * names the run). Exits 1 when it found one.
1212 * bun scripts/flake-hunt.ts quarantine
13 * Moves every file an open `Flaky: test/….test.ts` issue the hunt filed
14 * (author is the token's user, not untrusted) names from GATE to
13 * Puts every file an open `Flaky: test/….test.ts` issue the hunt filed
14 * (author is the token's user, not untrusted) names into
1515 * EXCLUDED under that issue, in scripts/gate.ts. The issue is
1616 * the record; this is the only hand that edits the list for a flake.
1717 * bun scripts/flake-hunt.ts admit test/x.test.ts [--runs 10]
@@ -35,7 +35,7 @@ import {
3535 shuffled,
3636 type FileRun,
3737 } from "./flake.ts";
38 import { GATE } from "./gate.ts";
38 import { gateFiles, presentTests } from "./gate.ts";
3939 import { parseShardSpec, sliceFiles } from "./shards.ts";
4040
4141 const GATE_FILE = new URL("./gate.ts", import.meta.url).pathname;
@@ -175,7 +175,7 @@ async function hunt(): Promise<number> {
175175 const runs = runsOf(HUNT_RUNS);
176176 const spec = parseShardSpec(valueOf("--shard"));
177177 if (!spec.ok) fail(spec.error);
178 let files = [...GATE];
178 let files = gateFiles();
179179 if (!("none" in spec)) {
180180 const sliced = sliceFiles(files, spec.index, spec.total);
181181 if (!sliced.ok) fail(sliced.error);
@@ -235,7 +235,10 @@ async function hunt(): Promise<number> {
235235 async function quarantineAll(): Promise<number> {
236236 let source = readFileSync(GATE_FILE, "utf8");
237237 const moved: string[] = [];
238 const present = new Set(presentTests());
238239 for (const [file, issue] of await openFlakyIssues()) {
240 // An exclusion for a file that is gone would turn the gate's audit red.
241 if (!present.has(file)) continue;
239242 const next = quarantine(source, file, issue);
240243 if (next === source) continue;
241244 source = next;
scripts/flake.ts +14 −18
@@ -4,8 +4,8 @@
44 * A test file that is red in one run and green in another, over the same
55 * code, is flaky. `scripts/flake-hunt.ts` runs each gate file several times
66 * in random order and hands every run here; this module names the flaky
7 * files, writes the issue that carries the evidence, and moves a file from
8 * `GATE` to `EXCLUDED` in `scripts/gate.ts` — so nobody hand-edits the list.
7 * files, writes the issue that carries the evidence, and adds a file to
8 * `EXCLUDED` in `scripts/gate.ts` — so nobody hand-edits a quarantine.
99 *
1010 * The unit is the file, judged by `bun test`'s exit code: that is what the
1111 * gate judges, what quarantine moves, and the only verdict a crash between
@@ -173,7 +173,7 @@ export function issueFor(
173173 "",
174174 ...ROOT_CAUSES.map((cause) => `- [ ] ${cause.name} — ${cause.fix}`),
175175 "",
176 `To rejoin the gate: fix it, run \`bun scripts/flake-hunt.ts admit ${flake.file}\`, and put its ${ADMISSION_RUNS}-run record in the pull that moves the file back to \`GATE\`.`,
176 `To rejoin the gate: fix it, run \`bun scripts/flake-hunt.ts admit ${flake.file}\`, and put its ${ADMISSION_RUNS}-run record in the pull that deletes its \`EXCLUDED\` entry.`,
177177 ].join("\n"),
178178 };
179179 }
@@ -190,8 +190,8 @@ export function flakyFile(title: string): string | undefined {
190190 /**
191191 * The file an issue from the forge's list quarantines, or undefined. Only
192192 * an issue the hunt filed counts: its author is the hunt's own user and the
193 * forge has not marked it `untrusted`. Anyone else's `Flaky:` title moves
194 * nothing out of GATE.
193 * forge has not marked it `untrusted`. Anyone else's `Flaky:` title takes
194 * nothing out of the gate.
195195 */
196196 export function huntedFile(
197197 issue: { title?: unknown; authorId?: unknown; untrusted?: unknown },
@@ -213,25 +213,21 @@ const entryFor = (file: string, reason: string, issue: number): string =>
213213 "",
214214 ].join("\n");
215215
216 /** `scripts/gate.ts` with `file` moved from GATE to EXCLUDED under `issue`. */
216 /**
217 * `scripts/gate.ts` with `file` excluded under `issue`: one entry at the end
218 * of `EXCLUDED`. Unchanged when the file is excluded already.
219 */
217220 export function quarantine(
218221 source: string,
219222 file: string,
220223 issue: number,
221224 reason = "flaky: red in one hunt run and green in another",
222225 ): string {
223 const gateStart = source.indexOf("export const GATE");
224 const gateEnd = source.indexOf("\n];", gateStart);
225 const line = ` ${JSON.stringify(file)},\n`;
226 const at = source.indexOf(line, gateStart);
227 if (gateStart === -1 || at === -1 || at > gateEnd) return source;
228 const without = source.slice(0, at) + source.slice(at + line.length);
229 const end = without.indexOf("\n];", without.indexOf("export const EXCLUDED"));
230 return (
231 without.slice(0, end + 1) +
232 entryFor(file, reason, issue) +
233 without.slice(end + 1)
234 );
226 const start = source.indexOf("export const EXCLUDED");
227 const end = source.indexOf("\n];", start);
228 if (start === -1 || end === -1) return source;
229 if (source.slice(start, end).includes(`file: ${JSON.stringify(file)}`)) return source;
230 return source.slice(0, end + 1) + entryFor(file, reason, issue) + source.slice(end + 1);
235231 }
236232
237233 /** A retry anywhere in what the gate runs: the lines that carry one. */
scripts/gate.ts +26 −359
@@ -1,14 +1,16 @@
11 /**
2 * Which test files the gate runs, and why every other one does not.
2 * Which test files the gate runs, and why the few others do not.
33 *
4 * `GATE` is the list `bun scripts/test-shards.ts --gate` runs, so
5 * `forge.json`'s `check.run` names no test file itself. `EXCLUDED` is every
6 * other `test/*.test.ts`, each with the reason it is out and the issue that
7 * owns bringing it in. `test/check-list.test.ts` goes red when a file is in
8 * neither list, in both, or named here without existing — so a new test file
9 * cannot sit outside the gate silently.
4 * The gate is every `test/*.test.ts` minus `EXCLUDED` (`gateFiles`): the
5 * list `bun scripts/test-shards.ts --gate` runs, so `forge.json`'s
6 * `check.run` names no test file itself, and a new test file is gated the
7 * moment it exists — no shared list to edit, nothing to conflict on (#2037).
8 * `EXCLUDED` is the quarantine: each file with the reason it is out and the
9 * issue that owns bringing it back. `test/check-list.test.ts` goes red when
10 * an exclusion names a file that does not exist, twice, or without a reason
11 * or an issue.
1012 *
11 * A file joins the gate by moving from `EXCLUDED` to `GATE` in a pull whose
13 * A file rejoins the gate by deleting its `EXCLUDED` entry in a pull whose
1214 * check is green and whose description carries ten green runs in random
1315 * order under load (`bun scripts/flake-hunt.ts admit <file>`). A flaky file
1416 * leaves it only through `bun scripts/flake-hunt.ts quarantine`, under the
@@ -26,338 +28,6 @@ export type Exclusion = {
2628 issue: number;
2729 };
2830
29 export const GATE: readonly string[] = [
30 "test/domain-drill.test.ts",
31 "test/conflicts.test.ts",
32 "test/lands-once.test.ts",
33 "test/conflicts-tui.test.ts",
34 "test/accounts-retire.test.ts",
35 "test/client-home.test.ts",
36 "test/cloud-use.test.ts",
37 "test/accounts.test.ts",
38 "test/asks-mute.test.ts",
39 "test/feed-chips.test.ts",
40 "test/agents.test.ts",
41 "test/app-domains.test.ts",
42 "test/app.test.ts",
43 "test/apps-idle.test.ts",
44 "test/body-limits.test.ts",
45 "test/boards-query.test.ts",
46 "test/boards-page.test.ts",
47 "test/boards-store.test.ts",
48 "test/boards-sampler.test.ts",
49 "test/turnstile.test.ts",
50 "test/variants-deck.test.ts",
51 "test/variants-surfaces.test.ts",
52 "test/thoughts.test.ts",
53 "test/triage.test.ts",
54 "test/passkeys.test.ts",
55 "test/passkey-recovery.test.ts",
56 "test/signup-passkey.test.ts",
57 "test/webauthn.test.ts",
58 "test/chaos.test.ts",
59 "test/flow-stage.test.ts",
60 "test/resilience.test.ts",
61 "test/flow-card.test.ts",
62 "test/cluster-jobs.test.ts",
63 "test/checks-placement.test.ts",
64 "test/checks-job-vanish.test.ts",
65 "test/fuzz-found.test.ts",
66 "test/fuzz-parsers.test.ts",
67 "test/attach-look.test.ts",
68 "test/protection.test.ts",
69 "test/tui-limbs.test.ts",
70 "test/tui-onyou.test.ts",
71 "test/tui-deploys.test.ts",
72 "test/tui-access.test.ts",
73 "test/tui-decider.test.ts",
74 "test/claim-link.test.ts",
75 "test/og-card.test.ts",
76 "test/og-route.test.ts",
77 "test/og-png.test.ts",
78 "test/router.test.ts",
79 "test/health.test.ts",
80 "test/client-address.test.ts",
81 "test/client-list.test.ts",
82 "test/family-heartbeat.test.ts",
83 "test/contents-api.test.ts",
84 "test/crew-agents-only.test.ts",
85 "test/crew-brief-audience.test.ts",
86 "test/run-log-audience.test.ts",
87 "test/crew.test.ts",
88 "test/crew-already-done.test.ts",
89 "test/crew-check-failed.test.ts",
90 "test/crew-continues.test.ts",
91 "test/crew-declines.test.ts",
92 "test/crew-network.test.ts",
93 "test/crew-pause.test.ts",
94 "test/crew-review.test.ts",
95 "test/crew-review-budget.test.ts",
96 "test/commit-identity.test.ts",
97 "test/enterable-apps.test.ts",
98 "test/event-order.test.ts",
99 "test/refresh-meta.test.ts",
100 "test/unfurl.test.ts",
101 "test/restore-card.test.ts",
102 "test/recovery-doc.test.ts",
103 "test/release-checkout.test.ts",
104 "test/release-preflight.test.ts",
105 "test/release-rollback.test.ts",
106 "test/release-swap.test.ts",
107 "test/threats-doc.test.ts",
108 "test/returns.test.ts",
109 "test/review-route.test.ts",
110 "test/review-lines.test.ts",
111 "test/review-gate.test.ts",
112 "test/review-from-check.test.ts",
113 "test/review-from-green.test.ts",
114 "test/themes.test.ts",
115 "test/waves.test.ts",
116 "test/cut-wave.test.ts",
117 "test/crew-wrapup.test.ts",
118 "test/crew-limits.test.ts",
119 "test/crew-parks.test.ts",
120 "test/crew-red-main.test.ts",
121 "test/crew-sandbox.test.ts",
122 "test/crew-remotes.test.ts",
123 "test/crew-brief-gate.test.ts",
124 "test/passport.test.ts",
125 "test/passport-edge.test.ts",
126 "test/crew-direction.test.ts",
127 "test/crew-direction-autonomy.test.ts",
128 "test/crew-guard.test.ts",
129 "test/review-waits.test.ts",
130 "test/scale.test.ts",
131 "test/sealed-private-work.test.ts",
132 "test/settings.test.ts",
133 "test/signin-throttle.test.ts",
134 "test/signins.test.ts",
135 "test/sole-owner-suspend.test.ts",
136 "test/standing-every-process.test.ts",
137 "test/steer.test.ts",
138 "test/sealed-git.test.ts",
139 "test/sealed-issues.test.ts",
140 "test/sealed-release.test.ts",
141 "test/sealed-preview.test.ts",
142 "test/session-settle.test.ts",
143 "test/landing.test.ts",
144 "test/decide.test.ts",
145 "test/ledger.test.ts",
146 "test/capacity.test.ts",
147 "test/access-log.test.ts",
148 "test/flow-pipeline.test.ts",
149 "test/flow-throughput.test.ts",
150 "test/limits.test.ts",
151 "test/guard-new-accounts.test.ts",
152 "test/checks.test.ts",
153 "test/dependencies.test.ts",
154 "test/map-closing.test.ts",
155 "test/parked-close.test.ts",
156 "test/autonomy.test.ts",
157 "test/autonomy_sweep.test.ts",
158 "test/studio.test.ts",
159 "test/studio-words.test.ts",
160 "test/converge-settled.test.ts",
161 "test/following.test.ts",
162 "test/forks.test.ts",
163 "test/front.test.ts",
164 "test/fork-counts.test.ts",
165 "test/fork-flow.test.ts",
166 "test/approve-here.test.ts",
167 "test/fork-pull-approval.test.ts",
168 "test/cross-repo-pull.test.ts",
169 "test/pull-mergeable.test.ts",
170 "test/pull-variants.test.ts",
171 "test/pull-checks-line.test.ts",
172 "test/pulls.test.ts",
173 "test/api-reader-marks.test.ts",
174 "test/app-members.test.ts",
175 "test/apps.test.ts",
176 "test/apps-crew.test.ts",
177 "test/apps-identity.test.ts",
178 "test/apps-new.test.ts",
179 "test/apps-slow-test.test.ts",
180 "test/apps-tests-clause.test.ts",
181 "test/apps-adversarial.test.ts",
182 "test/apps-busy.test.ts",
183 "test/apps-token.test.ts",
184 "test/contain.test.ts",
185 "test/contract.test.ts",
186 "test/subscription-budget.test.ts",
187 "test/surfaces-adversarial.test.ts",
188 "test/orgs.test.ts",
189 "test/suspended-hidden.test.ts",
190 "test/verify-email.test.ts",
191 "test/web.test.ts",
192 "test/git-trust.test.ts",
193 "test/helpers.test.ts",
194 "test/shards.test.ts",
195 "test/snapshot-drill.test.ts",
196 "test/drill-verdict.test.ts",
197 "test/drill-board-line.test.ts",
198 "test/snapshot-drill-page.test.ts",
199 "test/snapshot-store.test.ts",
200 "test/snapshot-mirror.test.ts",
201 "test/snapshot-mirror-page.test.ts",
202 "test/migrate.test.ts",
203 "test/schema-additive.test.ts",
204 "test/schema-migrations.test.ts",
205 "test/domains.test.ts",
206 "test/vitals.test.ts",
207 "test/vitals-degraded.test.ts",
208 "test/red-main.test.ts",
209 "test/sentinel.test.ts",
210 "test/tui-sentinel.test.ts",
211 "test/version.test.ts",
212 "test/watches.test.ts",
213 "test/guard.test.ts",
214 "test/asked.test.ts",
215 "test/thought-stream.test.ts",
216 "test/asks.test.ts",
217 "test/review-wait.test.ts",
218 "test/asks-bulk.test.ts",
219 "test/asks-waiting-for.test.ts",
220 "test/asks-one-list.test.ts",
221 "test/hand-decider.test.ts",
222 "test/decisions-by-doors.test.ts",
223 "test/standing-rule.test.ts",
224 "test/asks-expiry.test.ts",
225 "test/asks-rank.test.ts",
226 "test/plan-pillars.test.ts",
227 "test/plan-route.test.ts",
228 "test/planner-declined.test.ts",
229 "test/feed.test.ts",
230 "test/feed-choose.test.ts",
231 "test/feed-page.test.ts",
232 "test/card-shell.test.ts",
233 "test/offline.test.ts",
234 "test/share.test.ts",
235 "test/cloud.test.ts",
236 "test/run-secrets.test.ts",
237 "test/reserved-names.test.ts",
238 "test/forge-cloudflare.test.ts",
239 "test/forge-cloudflare-celld.test.ts",
240 "test/branch_tell.test.ts",
241 "test/tell_from.test.ts",
242 "test/usage.test.ts",
243 "test/tokens.test.ts",
244 "test/credentials.test.ts",
245 "test/standing.test.ts",
246 "test/board.test.ts",
247 "test/decider-day.test.ts",
248 "test/spawn-plan.test.ts",
249 "test/spawn-anon.test.ts",
250 "test/spawn-host.test.ts",
251 "test/spawn.test.ts",
252 "test/spawn-api.test.ts",
253 "test/spawn-child-apps.test.ts",
254 "test/spawn-child-runs-apps.test.ts",
255 "test/spawn-first-boot.test.ts",
256 "test/spawn-fresh-forks.test.ts",
257 "test/spawn-keys.test.ts",
258 "test/web-apps.test.ts",
259 "test/web-ui.test.ts",
260 "test/fleet-ops.test.ts",
261 "test/meter.test.ts",
262 "test/told-by.test.ts",
263 "test/highlight.test.ts",
264 "test/diff-edge-cases.test.ts",
265 "test/diff.test.ts",
266 "test/edge-auth.test.ts",
267 "test/own-session.test.ts",
268 "test/edit-words.test.ts",
269 "test/edits-security.test.ts",
270 "test/edits.test.ts",
271 "test/event-audience.test.ts",
272 "test/everyday.test.ts",
273 "test/explore.test.ts",
274 "test/feeds.test.ts",
275 "test/first-login.test.ts",
276 "test/fleet-graph.test.ts",
277 "test/git-local.test.ts",
278 "test/git-ssh.test.ts",
279 "test/git.test.ts",
280 "test/hardening.test.ts",
281 "test/here-manifest.test.ts",
282 "test/image-gif.test.ts",
283 "test/image-graphics.test.ts",
284 "test/image-jpeg.test.ts",
285 "test/image-png.test.ts",
286 "test/issues.test.ts",
287 "test/kernel.test.ts",
288 "test/keys.test.ts",
289 "test/limb_order.test.ts",
290 "test/limbs.test.ts",
291 "test/live-pages.test.ts",
292 "test/live.test.ts",
293 "test/looks.test.ts",
294 "test/mail-caps.test.ts",
295 "test/make-it-yours.test.ts",
296 "test/map.test.ts",
297 "test/pillars.test.ts",
298 "test/carried.test.ts",
299 "test/carried-deploy.test.ts",
300 "test/milestones.test.ts",
301 "test/mcp.test.ts",
302 "test/name-marks.test.ts",
303 "test/new-forge.test.ts",
304 "test/notify.test.ts",
305 "test/onboarding.test.ts",
306 "test/org-owners.test.ts",
307 "test/origins-oauth.test.ts",
308 "test/origins-operator.test.ts",
309 "test/origins-reconnect.test.ts",
310 "test/origins-security-auth.test.ts",
311 "test/origins-security-provider.test.ts",
312 "test/origins-security-push.test.ts",
313 "test/origins-sync.test.ts",
314 "test/origins.test.ts",
315 "test/overlap.test.ts",
316 "test/outsiders-switch.test.ts",
317 "test/check-budget.test.ts",
318 "test/check-proven.test.ts",
319 "test/check-list.test.ts",
320 "test/check-land-main.test.ts",
321 "test/check-tiers.test.ts",
322 "test/pull-check-again.test.ts",
323 "test/holds.test.ts",
324 "test/hollow.test.ts",
325 "test/flags.test.ts",
326 "test/home-feed.test.ts",
327 "test/home-walk.test.ts",
328 "test/oauth-discovery.test.ts",
329 "test/oauth-flow.test.ts",
330 "test/oidc.test.ts",
331 "test/data-home.test.ts",
332 "test/tree.test.ts",
333 "test/reports.test.ts",
334 "test/report-discovery.test.ts",
335 "test/apps-report.test.ts",
336 "test/apps-toolbar.test.ts",
337 "test/private-app.test.ts",
338 "test/actions.test.ts",
339 "test/app-env.test.ts",
340 "test/apps-ssh.test.ts",
341 "test/pacing.test.ts",
342 "test/openapi.test.ts",
343 "test/palette.test.ts",
344 "test/qr.test.ts",
345 "test/branches.test.ts",
346 "test/cli-sync.test.ts",
347 "test/code.test.ts",
348 "test/counts.test.ts",
349 "test/crew-loop.test.ts",
350 "test/crew-totals.test.ts",
351 "test/flake.test.ts",
352 "test/crew-locks.test.ts",
353 "test/ssh-site.test.ts",
354 "test/web-code.test.ts",
355 "test/web-origins.test.ts",
356 "test/roll.test.ts",
357 "test/rehearsal.test.ts",
358 "test/tui-tell.test.ts",
359 ];
360
36131 export const EXCLUDED: readonly Exclusion[] = [
36232 { file: "test/crew-sandbox-real.test.ts", reason: "landed unlisted and red locally; the builder admits it", issue: 1238 },
36333 { file: "test/api-errors.test.ts", reason: "not yet admitted", issue: 261 },
@@ -470,38 +140,26 @@ export const EXCLUDED: readonly Exclusion[] = [
470140 ];
471141
472142 /**
473 * Everything wrong with a gate list, against the test files that exist:
474 * one line per problem, none when every file is accounted for exactly once.
143 * Everything wrong with the quarantine, against the test files that exist:
144 * one line per problem, none when every exclusion is sound.
475145 */
476146 export function auditGate(
477147 present: readonly string[],
478 gate: readonly string[],
479148 excluded: readonly Exclusion[],
480149 ): string[] {
481150 const problems: string[] = [];
482151 const exists = new Set(present);
483 const gated = new Set<string>();
484 for (const file of gate) {
485 if (gated.has(file)) problems.push(`${file} is in GATE twice`);
486 gated.add(file);
487 if (!exists.has(file))
488 problems.push(`${file} is in GATE but does not exist`);
489 }
490152 const out = new Set<string>();
491153 for (const { file, reason, issue } of excluded) {
492154 if (out.has(file)) problems.push(`${file} is in EXCLUDED twice`);
493155 out.add(file);
494156 if (!exists.has(file))
495157 problems.push(`${file} is in EXCLUDED but does not exist`);
496 if (gated.has(file)) problems.push(`${file} is in both GATE and EXCLUDED`);
497158 if (typeof reason !== "string" || reason.trim() === "")
498159 problems.push(`${file} is excluded with no reason`);
499160 if (!Number.isInteger(issue) || issue <= 0)
500161 problems.push(`${file} is excluded with no issue number`);
501162 }
502 for (const file of present)
503 if (!gated.has(file) && !out.has(file))
504 problems.push(`${file} is in neither GATE nor EXCLUDED`);
505163 return problems;
506164 }
507165
@@ -517,24 +175,33 @@ export function presentTests(root = "."): string[] {
517175 }
518176 }
519177
178 /** What the gate runs: every present test file not excluded, in name order. */
179 export function gateFiles(
180 present: readonly string[] = presentTests(),
181 excluded: readonly Exclusion[] = EXCLUDED,
182 ): string[] {
183 const out = new Set(excluded.map((e) => e.file));
184 return present.filter((file) => !out.has(file));
185 }
186
520187 /**
521 * What the check prints when the list is wrong: every problem, then one
522 * last line naming the files to list. Empty when the list is right.
188 * What the check prints when the quarantine is wrong: every problem, then
189 * one last line naming the files to fix. Empty when it is right.
523190 */
524191 export function gateRefusal(present: readonly string[]): string[] {
525 const problems = auditGate(present, GATE, EXCLUDED);
192 const problems = auditGate(present, EXCLUDED);
526193 if (problems.length === 0) return [];
527194 const named = [
528195 ...new Set(problems.map((p) => p.match(/^(test\/\S+\.test\.ts) /)?.[1])),
529196 ].filter((f): f is string => f !== undefined);
530197 return [
531198 ...problems,
532 `${named.join(", ")}: list it in GATE or EXCLUDED in scripts/gate.ts`,
199 `${named.join(", ")}: fix its EXCLUDED entry in scripts/gate.ts`,
533200 ];
534201 }
535202
536203 // `bun scripts/gate.ts`: the audit alone, first in `forge.json`'s check, so
537 // an unlisted file fails in under a second — not after install and tsc.
204 // a stale exclusion fails in under a second — not after install and tsc.
538205 if (import.meta.main) {
539206 const refusal = gateRefusal(presentTests());
540207 for (const line of refusal) console.error(`gate: ${line}`);
scripts/test-shards.ts +6 −4
@@ -8,7 +8,8 @@
88 * bun scripts/test-shards.ts --record [bun test flags…] test/a.test.ts …
99 * bun scripts/test-shards.ts [bun test flags…] -- a b … (test/a.test.ts …)
1010 *
11 * `--gate` runs the files `scripts/gate.ts` admits, which is how
11 * `--gate` runs the files `scripts/gate.ts` admits (every test file not
12 * excluded), which is how
1213 * `forge.json`'s `check.run` names them; files on the command line are for
1314 * running a slice by hand. `--shard N/M` (or `FORGE_CHECK_SHARD_INDEX` +
1415 * `FORGE_CHECK_SHARD_TOTAL`) keeps only the Nth contiguous slice of that
@@ -56,7 +57,7 @@ import {
5657 weigher,
5758 type ShardResult,
5859 } from "./shards.ts";
59 import { GATE, gateRefusal, presentTests } from "./gate.ts";
60 import { gateFiles, gateRefusal, presentTests } from "./gate.ts";
6061 import { GATE_FILE, executedFiles, formatImpact, gateListAdds, handedImpact, mergeImpact, parseImpact } from "../src/checks/impact.ts";
6162 import { fastSet, importsOf, duration } from "../src/checks/tiers.ts";
6263 import { CHECK_CACHE } from "../src/checks/cache.ts";
@@ -219,8 +220,8 @@ if (!split.ok) {
219220 process.exit(2);
220221 }
221222 const flags = split.flags;
222 // A test file in neither GATE nor EXCLUDED costs a whole gate run to find
223 // out; say so before anything spawns. Explicit files alone are not audited.
223 // A stale exclusion costs a whole gate run to find out; say so before
224 // anything spawns. Explicit files alone are not audited.
224225 if (gate || tier === "fast") {
225226 const refusal = gateRefusal(presentTests());
226227 if (refusal.length > 0) {
@@ -228,6 +229,7 @@ if (gate || tier === "fast") {
228229 process.exit(2);
229230 }
230231 }
232 const GATE = gateFiles();
231233 let files = [...(gate || tier === "fast" ? GATE : []), ...split.files];
232234 if (tier === "fast") {
233235 const diff = Bun.spawnSync(
src/checks/impact.ts +11 −11
@@ -91,15 +91,16 @@ export function formatImpact(map: ReadonlyMap<string, readonly string[]>): strin
9191 export const GATE_FILE = "scripts/gate.ts";
9292
9393 /**
94 * The test files a `git diff -U0 scripts/gate.ts` adds to GATE or EXCLUDED
95 * (a move counts as an add). `undefined` when any changed line is anything
96 * but a list entry — that is logic, and the map cannot bound it. Removed
97 * entries select nothing and are not logic.
94 * The test files a `git diff -U0 scripts/gate.ts` brings into the gate: the
95 * entries it takes out of EXCLUDED and does not put back (a move within the
96 * list admits nothing). `undefined` when any changed line is anything but an
97 * exclusion — that is logic, and the map cannot bound it. Added entries
98 * take a file out of the gate, which selects nothing and is not logic.
9899 */
99100 export function gateListAdds(diff: string): string[] | undefined {
100 const entry = /^"(test\/[A-Za-z0-9_.-]+\.test\.[cm]?[jt]sx?)",?(?:\s*\/\/.*)?$/;
101101 const exclusion = /^\{?\s*file:\s*"(test\/[A-Za-z0-9_.-]+\.test\.[cm]?[jt]sx?)",?/;
102102 const data = /^(\{|\},?|reason:\s*.*|issue:\s*\d+,?)$/;
103 const removed = new Set<string>();
103104 const added = new Set<string>();
104105 let inHunk = false;
105106 for (const line of diff.split("\n")) {
@@ -109,18 +110,17 @@ export function gateListAdds(diff: string): string[] | undefined {
109110 const sign = line[0];
110111 if (sign !== "+" && sign !== "-") continue;
111112 const text = line.slice(1).trim();
112 const match = entry.exec(text) ?? exclusion.exec(text);
113 if (match) {
114 if (sign === "+") added.add(match[1]!);
115 } else if (text !== "" && !data.test(text) && !/^\{\s*file:.*\},?$/.test(text)) return undefined;
113 const match = exclusion.exec(text);
114 if (match) (sign === "-" ? removed : added).add(match[1]!);
115 else if (text !== "" && !data.test(text)) return undefined;
116116 }
117 return [...added];
117 return [...removed].filter((file) => !added.has(file));
118118 }
119119
120120 /**
121121 * What the map cannot bound: manifests, scripts, the kernel. `gateAdds` is
122122 * the result of `gateListAdds` for this pull; with it, a change to
123 * scripts/gate.ts alone is bounded by the tests it lists.
123 * scripts/gate.ts alone is bounded by the tests it admits.
124124 */
125125 export function needsFull(
126126 changed: readonly string[],
src/checks/tiers.ts +2 −2
@@ -73,7 +73,7 @@ export interface FastInput {
7373 readonly tests: readonly string[];
7474 /** A file's relative imports; `[]` for one that cannot be read. */
7575 readonly imports: (file: string) => readonly string[];
76 /** The tests a diff of scripts/gate.ts adds (`gateListAdds`); `undefined` when it is logic or unread. */
76 /** The tests a diff of scripts/gate.ts admits (`gateListAdds`); `undefined` when it is logic or unread. */
7777 readonly gateAdds?: readonly string[];
7878 /** Seconds each test took last time (`scripts/test-times.json`). */
7979 readonly times: ReadonlyMap<string, number>;
@@ -118,7 +118,7 @@ export function fastSet(input: FastInput): FastPlan {
118118 for (const test of input.tests) why.set(test, `full: ${unbounded} changed`);
119119 return finish(`full tier, ${unbounded} changed`);
120120 }
121 // A gate.ts that only lists tests is those tests, nothing more.
121 // A gate.ts that only edits EXCLUDED is the tests it admits, nothing more.
122122 const diffed =
123123 input.gateAdds === undefined
124124 ? input.changed
test/check-list.test.ts +43 −39
@@ -1,13 +1,13 @@
11 /**
2 * Every test file is accounted for (`scripts/gate.ts`): in the gate, or
3 * excluded by name with a reason and the issue that owns admitting it. A
4 * new test file that is in neither list turns the check red, so it cannot
5 * sit outside the gate silently.
2 * The gate is every test file minus a short quarantine (`scripts/gate.ts`,
3 * #2037): a new test file is gated by existing, with no list to edit, and
4 * every exclusion names a file that exists, a reason, and the issue that
5 * owns admitting it.
66 */
77
88 import { describe, expect, test } from "bun:test";
99 import { readdirSync } from "node:fs";
10 import { auditGate, EXCLUDED, GATE } from "../scripts/gate.ts";
10 import { auditGate, EXCLUDED, gateFiles, gateRefusal } from "../scripts/gate.ts";
1111
1212 const root = new URL("..", import.meta.url).pathname;
1313 const present = readdirSync(`${root}test`)
@@ -16,12 +16,19 @@ const present = readdirSync(`${root}test`)
1616 .sort();
1717
1818 describe("the gate's list", () => {
19 test("every test/*.test.ts is in exactly one list, and every entry exists", () => {
20 expect(auditGate(present, GATE, EXCLUDED)).toEqual([]);
19 test("every exclusion is sound against the files that exist", () => {
20 expect(auditGate(present, EXCLUDED)).toEqual([]);
21 expect(gateRefusal(present)).toEqual([]);
22 });
23
24 test("the gate is every present test file not excluded", () => {
25 const out = new Set(EXCLUDED.map((e) => e.file));
26 expect(gateFiles()).toEqual(present.filter((f) => !out.has(f)));
27 expect(gateFiles().length + EXCLUDED.length).toBe(present.length);
2128 });
2229
2330 test("this guard is itself in the gate", () => {
24 expect(GATE).toContain("test/check-list.test.ts");
31 expect(gateFiles()).toContain("test/check-list.test.ts");
2532 });
2633
2734 test("forge.json's check names no test file and runs the gate's list", async () => {
@@ -34,55 +41,52 @@ describe("the gate's list", () => {
3441 });
3542 });
3643
37 describe("auditGate", () => {
38 const files = ["test/a.test.ts", "test/b.test.ts"];
44 describe("gateFiles", () => {
45 const files = ["test/a.test.ts", "test/b.test.ts", "test/c.test.ts"];
3946
40 test("a file in neither list is named", () => {
41 expect(auditGate(files, ["test/a.test.ts"], [])).toEqual([
42 "test/b.test.ts is in neither GATE nor EXCLUDED",
47 test("a new file is in the gate with no list naming it", () => {
48 expect(gateFiles([...files, "test/x.test.ts"], [])).toEqual([
49 ...files,
50 "test/x.test.ts",
4351 ]);
4452 });
4553
46 test("a file in both lists is named", () => {
54 test("an excluded file is not", () => {
4755 expect(
48 auditGate(files, files, [
49 { file: "test/b.test.ts", reason: "slow", issue: 1 },
50 ]),
51 ).toEqual(["test/b.test.ts is in both GATE and EXCLUDED"]);
56 gateFiles(files, [{ file: "test/b.test.ts", reason: "slow", issue: 1 }]),
57 ).toEqual(["test/a.test.ts", "test/c.test.ts"]);
58 });
59 });
60
61 describe("auditGate", () => {
62 const files = ["test/a.test.ts", "test/b.test.ts"];
63
64 test("a file in no list is no problem", () => {
65 expect(auditGate(files, [])).toEqual([]);
5266 });
5367
5468 test("an exclusion with no reason or no issue is named", () => {
5569 expect(
56 auditGate(
57 files,
58 [],
59 [
60 { file: "test/a.test.ts", reason: " ", issue: 7 },
61 { file: "test/b.test.ts", reason: "slow", issue: 0 },
62 ],
63 ),
70 auditGate(files, [
71 { file: "test/a.test.ts", reason: " ", issue: 7 },
72 { file: "test/b.test.ts", reason: "slow", issue: 0 },
73 ]),
6474 ).toEqual([
6575 "test/a.test.ts is excluded with no reason",
6676 "test/b.test.ts is excluded with no issue number",
6777 ]);
6878 });
6979
70 test("an entry naming a file that does not exist is named", () => {
80 test("an exclusion naming a file that does not exist is named", () => {
7181 expect(
72 auditGate(
73 files,
74 [...files, "test/gone.test.ts"],
75 [{ file: "test/old.test.ts", reason: "slow", issue: 3 }],
76 ),
77 ).toEqual([
78 "test/gone.test.ts is in GATE but does not exist",
79 "test/old.test.ts is in EXCLUDED but does not exist",
80 ]);
82 auditGate(files, [{ file: "test/old.test.ts", reason: "slow", issue: 3 }]),
83 ).toEqual(["test/old.test.ts is in EXCLUDED but does not exist"]);
8184 });
8285
83 test("a file named twice in one list is named", () => {
84 expect(auditGate(files, [...files, "test/a.test.ts"], [])).toEqual([
85 "test/a.test.ts is in GATE twice",
86 test("a file excluded twice is named", () => {
87 const entry = { file: "test/a.test.ts", reason: "slow", issue: 3 };
88 expect(auditGate(files, [entry, entry])).toEqual([
89 "test/a.test.ts is in EXCLUDED twice",
8690 ]);
8791 });
8892 });
test/check-tiers.test.ts +22 −13
@@ -198,16 +198,22 @@ describe("the fast set, by measured coverage", () => {
198198 expect(fastSet({ ...base, changed: ["scripts/test-times.json"] }).files).toEqual([]);
199199 });
200200
201 test("a gate.ts diff that only lists tests selects those tests; logic runs full", () => {
201 test("a gate.ts diff that only edits EXCLUDED selects the tests it admits; logic runs full", () => {
202202 const listed = [
203 "@@ -10,0 +11,2 @@",
204 '+ "test/new.test.ts",',
205 '+ { file: "test/other.test.ts", reason: "slow", issue: 5 },',
206 "@@ -20 +22,0 @@",
207 '- "test/old.test.ts",',
203 "@@ -10,2 +10,0 @@",
204 '- { file: "test/new.test.ts", reason: "slow", issue: 5 },',
205 "- {",
206 '- file: "test/other.test.ts",',
207 '- reason: "flaky",',
208 "- issue: 6,",
209 "- },",
210 "@@ -20,0 +18,2 @@",
211 '+ { file: "test/old.test.ts", reason: "flaky", issue: 7 },',
212 '+ { file: "test/other.test.ts", reason: "moved", issue: 6 },',
208213 ].join("\n");
209214 const adds = gateListAdds(listed);
210 expect(adds).toEqual(["test/new.test.ts", "test/other.test.ts"]);
215 // Quarantining old selects nothing; other only moved, so it stays out.
216 expect(adds).toEqual(["test/new.test.ts"]);
211217 const plan = fastSet({ ...base, changed: ["scripts/gate.ts"], gateAdds: adds! });
212218 expect(plan.line).not.toContain("full tier");
213219 expect(plan.files).not.toContain("test/web-phone.test.ts");
@@ -219,12 +225,15 @@ describe("the fast set, by measured coverage", () => {
219225 gateAdds: adds!,
220226 });
221227 expect(more.why.get("test/new.test.ts")).toBe("changed");
222 expect(gateListAdds('@@ -1 +1 @@\n+ "test/a.test.ts",\n+export const X = 1;')).toBeUndefined();
223 expect(gateListAdds('@@ -1 +1 @@\n- if (x) return;')).toBeUndefined();
224 const hunk = "@@ -1,0 +2,2 @@\n";
225 expect(gateListAdds(`${hunk}+ "test/a.test.ts",\n+++i;`)).toBeUndefined();
226 expect(gateListAdds(`${hunk}+ "test/a.test.ts",\n---n;`)).toBeUndefined();
227 expect(gateListAdds(`--- a/scripts/gate.ts\n+++ b/scripts/gate.ts\n${hunk}+ "test/a.test.ts",`)).toEqual(["test/a.test.ts"]);
228 const hunk = "@@ -1,2 +1,0 @@\n";
229 const entry = '- { file: "test/a.test.ts", reason: "slow", issue: 1 },';
230 expect(gateListAdds(`${hunk}${entry}\n+export const X = 1;`)).toBeUndefined();
231 expect(gateListAdds("@@ -1 +1 @@\n- if (x) return;")).toBeUndefined();
232 // A bare name is no list entry now: there is no GATE to put it in.
233 expect(gateListAdds('@@ -1 +1 @@\n+ "test/a.test.ts",')).toBeUndefined();
234 expect(gateListAdds(`${hunk}${entry}\n+++i;`)).toBeUndefined();
235 expect(gateListAdds(`${hunk}${entry}\n---n;`)).toBeUndefined();
236 expect(gateListAdds(`--- a/scripts/gate.ts\n+++ b/scripts/gate.ts\n${hunk}${entry}`)).toEqual(["test/a.test.ts"]);
228237 const logic = fastSet({ ...base, changed: ["scripts/gate.ts"] });
229238 expect(logic.files).toEqual(base.tests);
230239 });
test/flake.test.ts +13 −11
@@ -9,7 +9,7 @@ import { mkdtemp, mkdir, rm, writeFile } from "node:fs/promises";
99 import { readdirSync, readFileSync } from "node:fs";
1010 import { tmpdir } from "node:os";
1111 import { join } from "node:path";
12 import { auditGate, GATE, type Exclusion } from "../scripts/gate.ts";
12 import { auditGate, gateFiles, type Exclusion } from "../scripts/gate.ts";
1313 import {
1414 admissionRecord,
1515 admitted,
@@ -164,30 +164,32 @@ describe("the issue", () => {
164164
165165 describe("quarantine", () => {
166166 const source = read("scripts/gate.ts");
167 const file = GATE[0]!;
167 const file = gateFiles()[0]!;
168168
169 test("moves the file from GATE to EXCLUDED under the issue", async () => {
169 test("takes the file out of the gate into EXCLUDED under the issue", async () => {
170170 const moved = quarantine(source, file, 4242);
171171 expect(moved).not.toBe(source);
172172 const dir = await scratch();
173173 await writeFile(join(dir, "gate.ts"), moved);
174174 const mod = (await import(join(dir, "gate.ts"))) as {
175 GATE: readonly string[];
176175 EXCLUDED: readonly Exclusion[];
176 gateFiles: (present?: readonly string[]) => string[];
177177 };
178178 const present = readdirSync(`${root}test`)
179179 .filter((name) => name.endsWith(".test.ts"))
180 .map((name) => `test/${name}`);
181 expect(auditGate(present, mod.GATE, mod.EXCLUDED)).toEqual([]);
182 expect(mod.GATE).not.toContain(file);
183 expect(mod.GATE).toHaveLength(GATE.length - 1);
180 .map((name) => `test/${name}`)
181 .sort();
182 expect(auditGate(present, mod.EXCLUDED)).toEqual([]);
183 const gate = mod.gateFiles(present);
184 expect(gate).not.toContain(file);
185 expect(gate).toHaveLength(gateFiles().length - 1);
184186 expect(mod.EXCLUDED.at(-1)).toMatchObject({ file, issue: 4242 });
185187 });
186188
187 test("a file not in GATE is left alone", async () => {
189 test("a file excluded already is left alone", async () => {
188190 const { EXCLUDED } = await import("../scripts/gate.ts");
189191 expect(quarantine(source, EXCLUDED[0]!.file, 1)).toBe(source);
190 expect(quarantine(source, "test/nope.test.ts", 1)).toBe(source);
192 expect(quarantine("no list here", file, 1)).toBe("no list here");
191193 });
192194 });
193195
@@ -268,7 +270,7 @@ describe("no retry in the gate", () => {
268270 (name) => `.forgejo/workflows/${name}`,
269271 ),
270272 // This file holds the detector's own examples.
271 ...GATE.filter((file) => file !== "test/flake.test.ts"),
273 ...gateFiles().filter((file) => file !== "test/flake.test.ts"),
272274 ];
273275 expect(named.flatMap((path) => retries(path, read(path)))).toEqual([]);
274276 });
test/hollow.test.ts +2 −2
@@ -6,7 +6,7 @@
66 */
77
88 import { describe, expect, test } from "bun:test";
9 import { GATE } from "../scripts/gate.ts";
9 import { gateFiles } from "../scripts/gate.ts";
1010 import { audit, hollow, readSources } from "../scripts/hollow.ts";
1111
1212 const root = new URL("..", import.meta.url).pathname;
@@ -55,7 +55,7 @@ describe("the repository", () => {
5555 );
5656
5757 test("this guard is itself in the gate", () => {
58 expect(GATE).toContain("test/hollow.test.ts");
58 expect(gateFiles()).toContain("test/hollow.test.ts");
5959 });
6060
6161 test(
test/shards.test.ts +48 −24
@@ -25,7 +25,7 @@ import {
2525 type ShardResult,
2626 } from "../scripts/shards.ts";
2727 import { parseCheck } from "../src/apps/manifest.ts";
28 import { EXCLUDED, GATE } from "../scripts/gate.ts";
28 import { EXCLUDED, gateFiles, presentTests } from "../scripts/gate.ts";
2929 import { CHECK_CACHE } from "../src/checks/cache.ts";
3030
3131 const files = Array.from({ length: 23 }, (_, i) => `test/f${i}.test.ts`);
@@ -328,7 +328,7 @@ describe("splitArgs", () => {
328328 expect(split.ok).toBe(true);
329329 if (!split.ok) return;
330330 const files = [
331 ...(split.flags.includes("--gate") ? GATE : []),
331 ...(split.flags.includes("--gate") ? gateFiles() : []),
332332 ...split.files,
333333 ];
334334 expect(files.length).toBeGreaterThan(0);
@@ -439,11 +439,27 @@ test("says two things, a pause apart", async () => {
439439
440440 describe("the gate audit before any shard", () => {
441441 const script = new URL("../scripts/test-shards.ts", import.meta.url).pathname;
442 const listed = [...GATE, ...EXCLUDED.map((e) => e.file)];
443 const run = async (extra: string[], args: string[]) => {
442 const listed = presentTests();
443 const git = (dir: string, ...args: string[]) =>
444 Bun.spawnSync(["git", "-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", ...args], {
445 cwd: dir,
446 stdout: "ignore",
447 stderr: "ignore",
448 }).exitCode;
449 const run = async (extra: string[], args: string[], drop: string[] = [], commit = false) => {
444450 const dir = mkdtempSync(join(tmpdir(), "forge-audit-"));
445451 mkdirSync(join(dir, "test"));
446 for (const file of [...listed, ...extra]) writeFileSync(join(dir, file), "");
452 for (const file of listed) if (!drop.includes(file)) writeFileSync(join(dir, file), "");
453 if (commit) {
454 expect(git(dir, "init", "-q")).toBe(0);
455 expect(git(dir, "add", "-A")).toBe(0);
456 expect(git(dir, "commit", "-qm", "base")).toBe(0);
457 }
458 for (const file of extra) writeFileSync(join(dir, file), "");
459 if (commit) {
460 expect(git(dir, "add", "-A")).toBe(0);
461 expect(git(dir, "commit", "-qm", "add a test")).toBe(0);
462 }
447463 const started = performance.now();
448464 const child = Bun.spawn(["bun", script, ...args], {
449465 cwd: dir,
@@ -460,36 +476,43 @@ describe("the gate audit before any shard", () => {
460476 return { code, out, err, ms: performance.now() - started };
461477 };
462478
463 test("an unlisted test file is refused by name, last line, nothing spawned", async () => {
479 test("a stale exclusion is refused by name, last line, nothing spawned", async () => {
480 const gone = EXCLUDED[0]!.file;
464481 for (const args of [["--gate"], ["--tier", "fast", "--diff", "a..b"]]) {
465 const got = await run(["test/zz-new.test.ts"], args);
482 const got = await run([], args, [gone]);
466483 expect(got.code).toBe(2);
467484 const last = got.err.trim().split("\n").pop()!;
468 expect(last).toContain("test/zz-new.test.ts");
469 expect(last).toContain("list it in GATE or EXCLUDED in scripts/gate.ts");
485 expect(last).toBe(`test-shards: ${gone}: fix its EXCLUDED entry in scripts/gate.ts`);
470486 expect(got.out + got.err).not.toContain("start ");
471487 expect(got.out).not.toContain("── shard");
472488 expect(got.ms).toBeLessThan(1000);
473489 }
474490 });
475491
476 test("a listed set proceeds, and explicit files are not audited", async () => {
477 const last = String(GATE.length);
478 const got = await run([], ["--gate", "--shard", `${last}/${last}`]);
479 expect(got.err).not.toContain("list it in GATE");
480 expect(got.out).toContain(`matrix slice ${last}/${last}`);
481 const explicit = await run(["test/zz-new.test.ts"], ["test/zz-new.test.ts"]);
482 expect(explicit.err).not.toContain("list it in GATE");
492 test("a new file is in the gate with no list naming it, and explicit files are not audited", async () => {
493 const last = String(gateFiles().length + 1);
494 const got = await run(["test/zz-new.test.ts"], ["--gate", "--shard", `${last}/${last}`]);
495 expect(got.err).not.toContain("EXCLUDED");
496 expect(got.out).toContain(`matrix slice ${last}/${last} (1 of ${last} files)`);
497 const explicit = await run(["test/zz-new.test.ts"], ["test/zz-new.test.ts"], [listed[0]!]);
498 expect(explicit.err).not.toContain("EXCLUDED");
499 }, 30_000);
500
501 test("a pull that only adds test/x.test.ts is gated on it (#2037)", async () => {
502 const got = await run(["test/zz-new.test.ts"], ["--tier", "fast", "--diff", "HEAD~1..HEAD"], [], true);
503 expect(got.err).not.toContain("EXCLUDED");
504 expect(got.out).toContain("for 1 changed");
505 expect(got.out).toContain(" test/zz-new.test.ts: changed\n");
483506 }, 30_000);
484507 });
485508
486509 describe("the gate audit alone, first in the check", () => {
487510 const script = new URL("../scripts/gate.ts", import.meta.url).pathname;
488 const listed = [...GATE, ...EXCLUDED.map((e) => e.file)];
489 const run = async (extra: string[]) => {
511 const listed = presentTests();
512 const run = async (extra: string[], drop: string[] = []) => {
490513 const dir = mkdtempSync(join(tmpdir(), "forge-gate-"));
491514 mkdirSync(join(dir, "test"));
492 for (const file of [...listed, ...extra]) writeFileSync(join(dir, file), "");
515 for (const file of [...listed, ...extra]) if (!drop.includes(file)) writeFileSync(join(dir, file), "");
493516 const child = Bun.spawn(["bun", script], { cwd: dir, stdin: "ignore", stdout: "pipe", stderr: "pipe" });
494517 const err = await new Response(child.stderr).text();
495518 const code = await child.exited;
@@ -497,13 +520,14 @@ describe("the gate audit alone, first in the check", () => {
497520 return { code, err };
498521 };
499522
500 test("an unlisted file fails it by name; a listed set passes", async () => {
501 const red = await run(["test/zz-new.test.ts"]);
523 test("a stale exclusion fails it by name; a new unlisted file passes", async () => {
524 const gone = EXCLUDED[0]!.file;
525 const red = await run([], [gone]);
502526 expect(red.code).toBe(2);
503 expect(red.err.trim().split("\n").pop()).toContain(
504 "test/zz-new.test.ts: list it in GATE or EXCLUDED in scripts/gate.ts",
527 expect(red.err.trim().split("\n").pop()).toBe(
528 `gate: ${gone}: fix its EXCLUDED entry in scripts/gate.ts`,
505529 );
506 const green = await run([]);
530 const green = await run(["test/zz-new.test.ts"]);
507531 expect(green.code).toBe(0);
508532 expect(green.err).toBe("");
509533 }, 30_000);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs