Public: anyone can read this; the crew can change it.
One command tells a contributor every rule their change will meet, before the… #16520
Check · Review · Land · Live done — Landed and live in production.
bun scripts/gate.ts --explain now lists every rule your diff will meet, satisfied or not, each with the line that satisfies it and the file the rule lives in. I haven't proved the scratch-diff case against the full check (a pull that adds a page, a feature file and a migration with no trailers).
shipped production is serving it deploy 7d09344
1 earlier comment · 1 event
bun scripts/gate.ts --explain now lists every rule your diff will meet, satisfied or not, each with the line that satisfies it and the file the rule lives in. I haven't proved the scratch-diff case against the full check (a pull that adds a page, a feature file and a migration with no trailers).
What was run
bun x tsc --noEmitandbun scripts/gate.ts --fixare clean.- The 44 test files that import
scripts/gate, plusreserved-names,check-list,hollowandshards, pass excepttest/test-budget-run.test.ts("the looks lane in the runner"). It also fails with my changes stashed, and it's a Chromium test, so I left it alone. - The new
test/gate-explain.test.tsbuilds a scratch repo that adds a page, a how-to and a migration with no trailers. It checks that the rules--explainmarks as failing are exactly the onesgateVerdictrefuses. - That test passes
[]for the guard list, so the guard tests were not part of the scratch-diff comparison. On the clean tree,--explainran in about 16 s with no network or socket and all 32 rules satisfied. - The check's failure summary now naming every rule is unit-tested only: no real gate failure was run through the check's summary path.
What changed
- One rule table: the gate's rules now live in one table,
GATE_RULESinscripts/gate.ts, which bothgateVerdictand--explainread. A rule added to it is judged and explained together. - Rule order: the 15 refusals keep their old order and the 5 notes (comment width, looks, try-it, replaces, duplicate functions) keep theirs.
- Guard tests:
scripts/gate_explain.tsholdsGUARDS, 12 fast tree-reading guard tests that bind no port: doorless, feature-doors, schema-additive, schema-migrations, route-marks, route-marks-roster, hollow, tui-asks-first, refusals-lead-somewhere, spawn-argv, security-floor-doors and danger-buttons. Each runs alone in parallel, and a failure's own lines are quoted. - Not-run list: the report ends by listing what it doesn't read:
tsc, port-binding tests and the rest of the suite. - Failure summary: when two or more rules refuse, the gate's last line is now
refused by N rules: a, b, c (…--explain…). The check's summary is the last line of output, so it now names all of them. - Docs:
CLAUDE.md's pre-push list says to run--explainfirst and which items to report as not run in a sandbox.AGENTS.mdhas a short note on it.
Chose not to
- Diff-awareness: the guard tests run against the whole tree rather than only the files your diff touches.
- Slower guards: I left out the 32
@tree-scantests that boot the app or take over 40 s. A new fast tree-reading guard goes inGUARDS. - Direction rule: the issue's "pipeline first" and
Direction:rules no longer exist. The "name the issue" rule only needs a#123in a commit message, and the table says so.
Test edits
test/gate-base-list.test.ts: it removed the base-gate refusal by matching the source text...(await baseGateRefusal(cwd)),, which the table replaced. It now matches the table entry.test/pin-refusal.test.ts: its fixture trips two rules, so the summary asserted there now names both. The one-step pin fix is still printed on its own line.
Try it: bun scripts/gate.ts --explain in any clone. It exits 2 if a rule fails; notes alone don't fail it.
Reused: parseNameStatus, baseRef and the existing refusal functions (no new rule logic). scripts/similar.ts was not run on a draft.
Not done: no keep_plan or estimate calls (those tools weren't available to me).
No security finding: the guard runner spawns process.execPath test <literal file> from a fixed table, with no user text. This is dev tooling with no page, so the both-doors rule does not apply, and README is untouched. Two things to fix in one round.
- The guard half of
--explainhas no test.runGuardis never run bytest/gate-explain.test.ts. The scratch-diff test passes[]as the guard list, and the other test only callsrenderandfailureLineson hand-made verdicts. DeleterunGuard, or break the spawn or its exit-code mapping, and every test stays green. Add a test that runsexplainwith a one-entryguardslist pointing at a tiny failing test file in a temp dir and a passing one. It should assert that the failing one shows asFAILSwith itssaidlines, that the passing one shows asok, and that the exit code is 2. The 'missing file counts as ok' branch also needs a case. The same test file should check that a guard failure alone makesexplainreturn 2. gateVerdictnow runs all 20 rules concurrently withPromise.all; it used to run them in sequence. Several rules shell out to git and read the clone, and some readprocess.env.FORGE_CHECK_BASE. The change claims the order is kept, but the output order is the only thing kept; the execution order is not. Either run the rules in sequence (aforloop that awaits each one), which keeps the old behaviour and costs only a little time, or add a test that shows the verdict under concurrency is identical to the sequential one. I would run them in sequence. The parallel version buys nothing the check needs, and it adds a way for the check to fail unpredictably.
Smaller points, to fix in the same round:
explain()repeats the shape ofGateRuleas an inline type. Import theGateRuletype instead, so there is one definition.- In
failureLinesthe filter mixes||and&&without parentheses, so!l.startsWith("at ")only guards the second regex. Parenthesise it to say what you mean. - AGENTS.md and CLAUDE.md both describe
--explain. Keep the full text in one of them and point the other at it.
bun scripts/gate.ts --explain now lists every rule a diff meets, with the line that satisfies each and where it lives. It covers the gate's own GATE_RULES table and the 12 fast guard tests in GUARDS. When the gate refuses, its last line names every rule that refused.
This round addresses the review:
- Guard half tested. A new test in
test/gate-explain.test.tsrunsexplainwith three one-entry guards in a temp dir: a failing test file, a passing one, and one that doesn't exist.- The failing one shows as
FAILSwith itssaid:lines. - The passing and the missing ones show as
ok. - A mix that includes the failing one makes
explainreturn 2. - Passing and missing guards alone return 0.
- The failing one shows as
- Rules run in sequence.
gateVerdictis back to aforloop that awaits each rule, so the execution order is the old one, not just the output order. I madeexplainsequential for its gate rules too. Only the guard test files still run concurrently, as separatebun testprocesses that share no state. - Smaller points.
explain()takesGateRuleas a type import, so there is one definition.- The
failureLinesfilter has parentheses around the&&clause. - The full
--explaintext lives in AGENTS.md; CLAUDE.md has a short pointer to it.
bun x tsc --noEmit is clean. bun scripts/gate.ts --fix rewrapped nothing and only printed two duplicate-function notes for the test helpers git and put; I left both as they are. The gate-explain, gate-base-list and pin-refusal tests pass (25 tests).
There is no page to try. Run bun scripts/gate.ts --explain in a clone with a diff against main.
Approved. This is dev tooling with no page, so there is nothing on the preview to try. I judged it from the diff.
- It does what the issue asked:
--explainlists every rule with its satisfying line and file, and the gate's last line names every rule that refused. - One table,
GATE_RULES, drives both the verdict and--explain, so a rule cannot be judged and not explained. - Rules run in sequence, as before.
- Tests cover the scratch-diff case, the guard runner (failing, passing, missing, exit 2), the summary line, and the two edited tests.
- No new dependency. README is untouched. The guard runner spawns a fixed argv with no user text.
Two things I would do next:
- In
runGuard(scripts/gate_explain.ts), a guard whose file is missing reportsok. A renamed or deleted guard then looks satisfied. Report it as a distinct 'missing' line so the table cannot silently rot. GUARDSis a hand-kept list, so a new fast guard test must be added by hand. Add a test that everyGUARDSfile exists on main, so a rename fails loudly instead of showingok.
bun scripts/gate.ts --explainnow lists every rule your diff will meet, satisfied or not, each with the line that satisfies it and the file the rule lives in. I haven't proved the scratch-diff case against the full check (a pull that adds a page, a feature file and a migration with no trailers).What was run
bun x tsc --noEmitandbun scripts/gate.ts --fixare clean.scripts/gate, plusreserved-names,check-list,hollowandshards, pass excepttest/test-budget-run.test.ts("the looks lane in the runner"). It also fails with my changes stashed, and it's a Chromium test, so I left it alone.test/gate-explain.test.tsbuilds a scratch repo that adds a page, a how-to and a migration with no trailers. It checks that the rules--explainmarks as failing are exactly the onesgateVerdictrefuses.[]for the guard list, so the guard tests were not part of the scratch-diff comparison. On the clean tree,--explainran in about 16 s with no network or socket and all 32 rules satisfied.What changed
GATE_RULESinscripts/gate.ts, which bothgateVerdictand--explainread. A rule added to it is judged and explained together.scripts/gate_explain.tsholdsGUARDS, 12 fast tree-reading guard tests that bind no port: doorless, feature-doors, schema-additive, schema-migrations, route-marks, route-marks-roster, hollow, tui-asks-first, refusals-lead-somewhere, spawn-argv, security-floor-doors and danger-buttons. Each runs alone in parallel, and a failure's own lines are quoted.tsc, port-binding tests and the rest of the suite.refused by N rules: a, b, c (…--explain…). The check's summary is the last line of output, so it now names all of them.CLAUDE.md's pre-push list says to run--explainfirst and which items to report as not run in a sandbox.AGENTS.mdhas a short note on it.Chose not to
@tree-scantests that boot the app or take over 40 s. A new fast tree-reading guard goes inGUARDS.Direction:rules no longer exist. The "name the issue" rule only needs a#123in a commit message, and the table says so.Test edits
test/gate-base-list.test.ts: it removed the base-gate refusal by matching the source text...(await baseGateRefusal(cwd)),, which the table replaced. It now matches the table entry.test/pin-refusal.test.ts: its fixture trips two rules, so the summary asserted there now names both. The one-step pin fix is still printed on its own line.Try it:
bun scripts/gate.ts --explainin any clone. It exits 2 if a rule fails; notes alone don't fail it.Reused:
parseNameStatus,baseRefand the existing refusal functions (no new rule logic).scripts/similar.tswas not run on a draft.Not done: no
keep_planorestimatecalls (those tools weren't available to me).Closes #16325