fix(guard-push): make the gh availability probe injectable so its unit test is hermetic - #2222
fix(guard-push): make the gh availability probe injectable so its unit test is hermetic#2222BigSimmo wants to merge 1 commit into
Conversation
…t test is hermetic tests/guard-push.test.ts "inFlightCiGuard formats actionable blocked message" injects prViewer and runFetcher, but inFlightCiGuard still called the real ghIsAvailable() first, which spawns the gh binary. On a loaded machine that call was measured at 97s for `gh --version` (17s through a bare node spawn), so the test blew vitest's 30s limit and failed - a unit test held hostage by an external process it never asked for, and one that goes red for reasons that have nothing to do with the code under test. ghAvailable joins prViewer and runFetcher as an injectable dependency, defaulting to ghIsAvailable so production behaviour is unchanged. The two existing call sites inject `ghAvailable: () => true`. Two tests pin the behaviour so this cannot regress silently: one asserts the fail-open path when gh is unavailable AND that the PR is not consulted in that case, and one asserts the guard spawns nothing when every dependency is injected. The target test now runs in 1ms, down from a 30s timeout. Not fixed here, and reported rather than masked: "push-range parsing > keeps a Windows new-branch static command scoped to the PR side of an advanced main" also times out locally, taking 61s alone. That one is genuinely I/O-heavy - it writes 360 files with 96-character names into a real git repo and commits them - so it is slow on a loaded Windows Dev Drive rather than defective. Raising its timeout would be masking machine cost, not fixing a stubbing defect, so it is left for a separate decision. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in:24 minutes Limit details: You’ve used the included review currently available. Your 87 included PR review attempts over the past 7 days set your current allowance at 1 review per hour. Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab. How can I continue?Wait for the limit to reset, then comment An organization admin can change what happens after included review limits in Billing. How do review limits work?CodeRabbit enforces per-developer PR review limits within each organization. For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Comment |
This pull request has been ignored for the connected project Preview Branches by Supabase. |
BigSimmo
commented
Aug 21, 2026
@copilot resolve the merge conflicts on this branch. |
BigSimmo
commented
Aug 21, 2026
Closing as superseded, not abandoned: the same fix landed on I checked whether anything here was still additive before closing. It is not. #2209's fail-open test is stronger than the two I added — it throws if Root cause recorded for whoever hits this next: 🤖 Closed by Claude Code |
Summary
tests/guard-push.test.ts > inFlightCiGuard formats actionable blocked message with PR and run detailsfails locally withTest timed out in 30000ms.The test injects
prViewerandrunFetcher, butinFlightCiGuardcalls the realghIsAvailable()before reaching them, which spawns theghbinary. That is a local probe (gh --version), not a network call — but on a loaded machine it is not fast. Measured on this workstation while several worktrees were running suites:So a unit test that stubs every dependency it knows about was still hostage to an external process it never asked for, and went red for reasons unrelated to the code under test.
ghAvailablenow joinsprViewerandrunFetcheras an injectable dependency, defaulting toghIsAvailableso production behaviour is unchanged. The two existing call sites passghAvailable: () => true.Two tests pin the behaviour so it cannot regress quietly:
ghis unavailable, without consulting the PR — assertsok: true, thegh not availablenote, and thatprViewerwas never called.autoMergeGuardhas the same un-injectedghIsAvailable()call, but it takes no options object and has no direct unit test, so it is deliberately left alone rather than widened into an unrelated refactor.RAG impact: no retrieval behaviour change — this touches a git pre-push guard script and its unit test only; no retrieval, ranking, selection, ordering, or clinical surface is involved.
Verification
npx vitest run tests/guard-push.test.ts -t "inFlightCiGuard"— the target test now passes in 1ms, down from a 30s timeout. Both new tests pass in 0ms.npx prettier --write scripts/guard-push.mjs tests/guard-push.test.ts— both already conformant ("unchanged").npx eslint scripts/guard-push.mjs tests/guard-push.test.ts --max-warnings 0— exit 0.Not fixed here, reported rather than masked.
push-range parsing > keeps a Windows new-branch static command scoped to the PR side of an advanced mainalso times out locally, taking 61s when run alone — so it is not sibling contention. It is genuinely I/O-heavy: it writes 360 files with 96-character names into a real git repo, commits them, and diffs. That is slow on a loaded Windows ReFS Dev Drive, not a stubbing defect, and raising its timeout would hide machine cost rather than fix anything. Left for a separate decision; worth a ledger row.Clinical Governance Preflight
Clinical KB Database(sjrfecxgysukkwxsowpy)Notes
ghexactly as before, and still fails open when it is absent.gh --versionis itself worth noticing — it made every push in this session slow, since the pre-push guard invokesghseveral times. That is an environment issue, not something this PR addresses.