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

One command tells a contributor every rule their change will meet, before the… #16520

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

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).

Notes

shipped production is serving it deploy 7d09344

opened this

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 --noEmit and bun scripts/gate.ts --fix are clean.
  • The 44 test files that import scripts/gate, plus reserved-names, check-list, hollow and shards, pass except test/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.ts builds a scratch repo that adds a page, a how-to and a migration with no trailers. It checks that the rules --explain marks as failing are exactly the ones gateVerdict refuses.
  • That test passes [] for the guard list, so the guard tests were not part of the scratch-diff comparison. On the clean tree, --explain ran 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_RULES in scripts/gate.ts, which both gateVerdict and --explain read. 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.ts holds GUARDS, 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 --explain first and which items to report as not run in a sandbox. AGENTS.md has 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-scan tests that boot the app or take over 40 s. A new fast tree-reading guard goes in GUARDS.
  • Direction rule: the issue's "pipeline first" and Direction: rules no longer exist. The "name the issue" rule only needs a #123 in 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).

Closes #16325

1 earlier comment · 1 event
commented

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 --noEmit and bun scripts/gate.ts --fix are clean.
  • The 44 test files that import scripts/gate, plus reserved-names, check-list, hollow and shards, pass except test/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.ts builds a scratch repo that adds a page, a how-to and a migration with no trailers. It checks that the rules --explain marks as failing are exactly the ones gateVerdict refuses.
  • That test passes [] for the guard list, so the guard tests were not part of the scratch-diff comparison. On the clean tree, --explain ran 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_RULES in scripts/gate.ts, which both gateVerdict and --explain read. 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.ts holds GUARDS, 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 --explain first and which items to report as not run in a sandbox. AGENTS.md has 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-scan tests that boot the app or take over 40 s. A new fast tree-reading guard goes in GUARDS.
  • Direction rule: the issue's "pipeline first" and Direction: rules no longer exist. The "name the issue" rule only needs a #123 in 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).

Changes requested — before the latest push

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.

  1. The guard half of --explain has no test. runGuard is never run by test/gate-explain.test.ts. The scratch-diff test passes [] as the guard list, and the other test only calls render and failureLines on hand-made verdicts. Delete runGuard, or break the spawn or its exit-code mapping, and every test stays green. Add a test that runs explain with a one-entry guards list pointing at a tiny failing test file in a temp dir and a passing one. It should assert that the failing one shows as FAILS with its said lines, that the passing one shows as ok, 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 makes explain return 2.
  2. gateVerdict now runs all 20 rules concurrently with Promise.all; it used to run them in sequence. Several rules shell out to git and read the clone, and some read process.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 (a for loop 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 of GateRule as an inline type. Import the GateRule type instead, so there is one definition.
  • In failureLines the 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.
commented

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.ts runs explain with 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 FAILS with its said: lines.
    • The passing and the missing ones show as ok.
    • A mix that includes the failing one makes explain return 2.
    • Passing and missing guards alone return 0.
  • Rules run in sequence. gateVerdict is back to a for loop that awaits each rule, so the execution order is the old one, not just the output order. I made explain sequential for its gate rules too. Only the guard test files still run concurrently, as separate bun test processes that share no state.
  • Smaller points.
    • explain() takes GateRule as a type import, so there is one definition.
    • The failureLines filter has parentheses around the && clause.
    • The full --explain text 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

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: --explain lists 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:

  1. In runGuard (scripts/gate_explain.ts), a guard whose file is missing reports ok. A renamed or deleted guard then looks satisfied. Report it as a distinct 'missing' line so the table cannot silently rot.
  2. GUARDS is a hand-kept list, so a new fast guard test must be added by hand. Add a test that every GUARDS file exists on main, so a rename fails loudly instead of showing ok.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs