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

The gate runs from the base commit's gate script, so a pull cannot loosen the check that judges it #15284

Merged opened this

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

Merged

If a pull takes a test file out of the gate, the base commit's gate now refuses it, and the refusal names the file. Until now a pull that edited scripts/gate.ts was judged by that edited copy.

Notes

shipped production is serving it deploy 3fede26

opened this

If a pull takes a test file out of the gate, the base commit's gate now refuses it, and the refusal names the file. Until now a pull that edited scripts/gate.ts was judged by that edited copy. Before the pull's own check command runs, the forge writes the base commit's scripts/gate.ts into the checkout as scripts/.gate-base.ts and runs it with --base-only. That copy compares the test files the base gates with the ones the pull gates. Every file the pull still has but no longer gates (a new EXCLUDED entry) is refused:

test/b.test.ts is in the base's gate and this pull takes it out of it

The refusal ends with the owner's path: an owner pushes the exclusion to the default branch themselves, which no agent can. Deleting the refusal from the pull's own gate doesn't help, because the base's copy is what runs. A pull that only adds a test file passes, and the new file is gated in the same push.

What to look at:

  • src/checks/base_gate.ts (new): puts the base's step in front of the check command, and only when the base's gate has baseGateRefusal. Other repositories' scripts/gate.ts, and this one's older versions, are left alone.
  • src/checks/run_tier.ts: reads the base's scripts/gate.ts, writes it into the checkout and runs the base step first. It does this for both the local cell and a Job. It only happens when the forge gives the check a base (FORGE_CHECK_BASE).
  • scripts/gate.ts: baseGateRefusal and the --base-only mode. The pull's own gateVerdict runs the same comparison, so the refusal also shows up locally. A first version made bun scripts/gate.ts hang: the script re-imported its own file and ran itself again. The pull's own gate now passes its list in directly, and the default skips importing itself.
  • test/gate-base-list.test.ts (new): builds real git repos with this gate at the base. Covered:
    • a pull that adds test/b.test.ts to EXCLUDED and deletes the refusal from its own gate is refused by the base copy, exit 2, b named and a not;
    • the pull's own gate refuses the same pull;
    • a pull that only adds a file passes;
    • a deleted test file is not refused;
    • the command wrapping happens only when the base's gate has the mark.

    Without the change the file fails, since its module and function don't exist.

  • docs/features/gate-bypass.md: describes the behaviour and what is not done.

What I left out:

  • Trust: the base's script still imports the pull's src/ modules and reads the pull's list through the pull's gateFiles. A pull that rewrites gateFiles to lie is caught only by review.
  • Coverage: a test file deleted outright is not refused, since its diff shows it. A check handed to a runner (tier_runner.ts) still runs the pull's command without the base step. The rest of gateVerdict still runs from the pull's tree.
  • Quarantine: the nightly quarantine pull is now refused too, so an owner has to land it.
  • No forge-level test: nothing drives runTier end to end to show the base step runs first. The wiring is the few lines above plus the withBaseGate unit test.

Checks run here: bun scripts/gate.ts --fix exited 0. It printed three "one implementation?" notes about small test helpers, which are not refusals and were left as they are. bun x tsc --noEmit passed. I ran these tests and they pass:

  • test/gate-base-list.test.ts
  • test/check-list.test.ts
  • test/check-script-readers.test.ts
  • test/gate-bypass.test.ts
  • test/check-pod-too-small.test.ts
  • test/check-disk-used.test.ts

scripts/fast.ts reported the diff too broad to name tests, so I picked these; the forge runs the full check on push. Nothing on a page changed, so there are no review steps.

To try it locally: commit a pull that adds an EXCLUDED entry for an existing test, copy the base's scripts/gate.ts to scripts/.gate-base.ts, then run FORGE_CHECK_BASE=<base> bun scripts/.gate-base.ts --base-only. It exits 2 and names the file.

🤖 Generated with Claude Code

Closes #15255

1 earlier comment · 1 event
commented

If a pull takes a test file out of the gate, the base commit's gate now refuses it, and the refusal names the file. Until now a pull that edited scripts/gate.ts was judged by that edited copy. Before the pull's own check command runs, the forge writes the base commit's scripts/gate.ts into the checkout as scripts/.gate-base.ts and runs it with --base-only. That copy compares the test files the base gates with the ones the pull gates. Every file the pull still has but no longer gates (a new EXCLUDED entry) is refused:

test/b.test.ts is in the base's gate and this pull takes it out of it

The refusal ends with the owner's path: an owner pushes the exclusion to the default branch themselves, which no agent can. Deleting the refusal from the pull's own gate doesn't help, because the base's copy is what runs. A pull that only adds a test file passes, and the new file is gated in the same push.

What to look at:

  • src/checks/base_gate.ts (new): puts the base's step in front of the check command, and only when the base's gate has baseGateRefusal. Other repositories' scripts/gate.ts, and this one's older versions, are left alone.
  • src/checks/run_tier.ts: reads the base's scripts/gate.ts, writes it into the checkout and runs the base step first. It does this for both the local cell and a Job. It only happens when the forge gives the check a base (FORGE_CHECK_BASE).
  • scripts/gate.ts: baseGateRefusal and the --base-only mode. The pull's own gateVerdict runs the same comparison, so the refusal also shows up locally. A first version made bun scripts/gate.ts hang: the script re-imported its own file and ran itself again. The pull's own gate now passes its list in directly, and the default skips importing itself.
  • test/gate-base-list.test.ts (new): builds real git repos with this gate at the base. Covered:
    • a pull that adds test/b.test.ts to EXCLUDED and deletes the refusal from its own gate is refused by the base copy, exit 2, b named and a not;
    • the pull's own gate refuses the same pull;
    • a pull that only adds a file passes;
    • a deleted test file is not refused;
    • the command wrapping happens only when the base's gate has the mark.

    Without the change the file fails, since its module and function don't exist.

  • docs/features/gate-bypass.md: describes the behaviour and what is not done.

What I left out:

  • Trust: the base's script still imports the pull's src/ modules and reads the pull's list through the pull's gateFiles. A pull that rewrites gateFiles to lie is caught only by review.
  • Coverage: a test file deleted outright is not refused, since its diff shows it. A check handed to a runner (tier_runner.ts) still runs the pull's command without the base step. The rest of gateVerdict still runs from the pull's tree.
  • Quarantine: the nightly quarantine pull is now refused too, so an owner has to land it.
  • No forge-level test: nothing drives runTier end to end to show the base step runs first. The wiring is the few lines above plus the withBaseGate unit test.

Checks run here: bun scripts/gate.ts --fix exited 0. It printed three "one implementation?" notes about small test helpers, which are not refusals and were left as they are. bun x tsc --noEmit passed. I ran these tests and they pass:

  • test/gate-base-list.test.ts
  • test/check-list.test.ts
  • test/check-script-readers.test.ts
  • test/gate-bypass.test.ts
  • test/check-pod-too-small.test.ts
  • test/check-disk-used.test.ts

scripts/fast.ts reported the diff too broad to name tests, so I picked these; the forge runs the full check on push. Nothing on a page changed, so there are no review steps.

To try it locally: commit a pull that adds an EXCLUDED entry for an existing test, copy the base's scripts/gate.ts to scripts/.gate-base.ts, then run FORGE_CHECK_BASE=<base> bun scripts/.gate-base.ts --base-only. It exits 2 and names the file.

🤖 Generated with Claude Code

Changes requested — before the latest push

Two things to fix, in order.

  1. The guard can still be loosened by the pull it judges. The base copy runs treeGate(resolve(cwd), "head"), which imports the PULL's scripts/gate.ts and takes its gateFiles as the head list. A pull that edits gateFiles (or the pull-side helpers the base script imports from src/) to return the full list to the comparison, while the real run skips the file, passes. The pull's own docs list this under Not done and leave it to review, but the issue title is that a pull cannot loosen the check that judges it. Compute the head list inside the base copy from the pull data alone (read the pull's EXCLUDED/gate plan as text or via the base's own functions on the pull's file list), not by importing the pull's code.
  2. The new wiring in run_tier.ts has no test that would fail without it: nothing shows runTier writes scripts/.gate-base.ts and runs it before the check, only the pure withBaseGate string test. Add a runTier-level test (it has an options.checkStep seam) asserting the step the check receives starts with the base gate and that the base file holds the base commit's content. Also the tier_runner path runs the pull's command with no base step, so a pull handed to a runner is not guarded; wire it or say in the issue it is a follow-up and open that issue.

Smaller: a test file deleted outright is not refused, though box 1 says a pull that removes a file from the list fails; decide and either refuse it or state why not in the issue.

commented

Before the pull's check runs, the forge runs the base commit's copy of scripts/gate.ts. That copy now works out the pull's gate list without running any of the pull's code. Before this change it imported the pull's scripts/gate.ts, so a pull could rewrite gateFiles and pass the comparison.

How the base copy reads the pull's list (scripts/gate.ts, baseGateRefusal):

  • It takes the files the pull's EXCLUDED names straight from the text of the pull's scripts/gate.ts (excludedIn), and applies the base's own gateFiles to the pull's test files.
  • It refuses a pull whose EXCLUDED is not a plain list of { file: "…" } entries, such as a spread or a function call.
  • It refuses a pull that changes the code that builds the list (isLooksFile through gateFiles, compared as text with the base's by listingCode). So the list it checks is the one the pull's gate actually runs.
  • The pull's own gate runs the same check.

Tests:

  • test/gate-base-list.test.ts covers four refusals: a pull that edits gateFiles to drop a file while leaving EXCLUDED alone, an EXCLUDED that is not a plain list, the text reader itself, and the existing case of adding an exclusion.
  • test/check-base-gate-step.test.ts goes through the checks service and runTier. It shows the pull's fast check runs bun scripts/.gate-base.ts --base-only && … and that this file holds the base commit's scripts/gate.ts. Without the wiring in run_tier.ts the step comes through unprefixed and the test fails.

What still gets past it:

  • Runners: a check handed to a runner (tier_runner.ts) still runs the pull's command without the base step. That is the follow-up #15287: the runner checks out the commit itself, so the forge can't write the file into its tree the way runTier does.
  • Deleted test files: a test file the pull deletes outright is still not refused. Refusing it would refuse every pull that merges two test files into one, and the deletion shows in the diff. I gave this reasoning on #15255.
  • The pull's own test runner: scripts/test-shards.ts, which runs the list, comes from the pull, so a pull that edits it to skip files is caught only by review. docs/features/gate-bypass.md lists this under "Not done", along with the runner path.

Checks run: bun scripts/gate.ts --fix and bun x tsc --noEmit are clean. fast.ts couldn't pick tests for a scripts/gate.ts change, so I ran the test/gate* files, the new test, and the other tests that use scripts/gate.ts. One test fails: the looks-lane test in test/test-budget-run.test.ts. It fails the same way with my changes removed, because Chromium doesn't start in this sandbox.

To try it, edit gateFiles on a branch so it skips a test file, then run bun scripts/.gate-base.ts --base-only with FORGE_CHECK_BASE set to the base commit. It exits 2 with "this pull changes how the gate's list is made".

🤖 Generated with Claude Code

Approved

Earlier ask (the base copy imported the pull's gate, so a pull could rewrite gateFiles and pass) is met. The base copy now reads the pull's EXCLUDED as text, applies its own gateFiles, and refuses a pull that changes the listing code or whose EXCLUDED is not a plain list. Both cases have tests. The new tests cover the refusal naming the file, the add-only pull, and the runTier wiring through the checks service. The how-to is in docs/features/gate-bypass.md, not README. No page changed, so no review steps are needed. I could not read the diff since db561fd89aa1 because the clone lacks that commit, so I judged from the change shown. Next, non-blocking: (1) land #15287 so runner-handled checks get the base step; (2) have the shard runner (scripts/test-shards.ts) also take its list from the base.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs