fix(hooks): run the gate from a local dependency, not npx - #688
Merged
Merged
Conversation
The 1.39.2 hook shelled to `npx --yes code-foundry@<version>` on every commit. Two problems, both observed rather than anticipated: - The gate's exit status was discarded. `if npx ...; then exit 0; fi` followed by an unconditional `git diff --cached --check` meant a failing gate fell through to the fallback and the commit went through. In this repository a commit carrying an unused import passed the hook, which printed the oxlint finding and landed anyway. - `fleet-manifest.mjs` installs `core.hooksPath` and makes the hook executable in every managed consumer worktree, so the npx call ran on every commit in every fleet worktree, and broke the fleet upgrade test. The hook now prefers a runtime the repository already depends on: `node_modules/.bin/code-foundry`, then a vendored `src/runtime.mjs`. Nothing is fetched at commit time. A repository opts into the gate by depending on code-foundry; one that does not keeps the whitespace guard and stays offline. The fallback is last, so a failing gate can no longer be swallowed. Four tests, all hermetic: no npx or registry reference; a depended-on gate that exits 7 fails the commit; no dependency falls back to the whitespace guard; and that guard still blocks trailing whitespace.
0xPlayerOne
marked this pull request as ready for review
October 1, 2026 19:21
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #684, which shipped in 1.39.2 and does not work.
Two defects, both observed
The gate's exit status was discarded.
The gate itself exits 1 correctly. A failing gate took the
ifas false,fell through to the whitespace check, passed, and the commit landed. Caught
in this repository: a commit carrying an unused import ran the hook, which
printed the oxlint finding, and the commit still succeeded.
The fleet paid for it on every commit.
fleet-manifest.mjs:491setscore.hooksPathand chmods the hook executable in every managed consumerworktree, so the npx invocation ran in each of them — and it broke the
fleet upgrade test (
test/fleet-manifest.test.mjs, 2/2 with the change,0/2 without).
The fix
The hook prefers a runtime the repository already depends on:
node_modules/.bin/code-foundrysrc/runtime.mjsNothing is fetched at commit time. A repository opts into the gate by
depending on code-foundry; one that does not keeps the whitespace guard and
stays offline. The fallback is last, so a failing gate can no longer be
swallowed.
This also resolves the concern that the hook was injected into every
consumer as noise: with no dependency present it does one
git diff --cached --checkand exits.Tests
Four, all hermetic and no network:
npxor registry reference in the generated hookThe exit-status test is the regression guard: it fails against the 1.39.2
template and passes here.
Verification
566 tests pass, 0 fail. Lint, format, and type-check clean.