ci(fork-sync): add fork-boundary mock baseline + clean stale allowlist (#2436)#2445
Merged
alexey-pelykh merged 1 commit intomainfrom Apr 20, 2026
Merged
Conversation
#2436) Extends scripts/check-stub-debt.mjs with a second baseline-gated counter alongside the existing @ts-expect-error counter (ADR 0005 H5). The new counter tracks vi.mock/vi.doMock calls in test files that target modules under src/agents/ or src/middleware/ — the test-side cause of #2408-class regressions that H7's AST classifier cannot see (H7 only examines production code). Rationale: tests that mock fork-boundary modules can mask production throwing-stubs — the test exercises the mock while production hits a broken stub. The baseline creates a friction point at PR time where new mocks must be categorized in the PR description: isolation, performance, or stub-placeholder (the last being a RED FLAG). Re-scope history: original #2436 proposed three baselines. 360 evaluation on 2026-04-20 rejected the other two as redundant with H7 or noise-heavy: Rejected: .never-return-baseline — mostly tracks legitimate typed error-throw helpers; H7 already catches the malicious subset Rejected: .fork-boundary-stub-baseline — H7's forkMessagePattern calibration signal already catches these Accepted: .fork-boundary-mock-baseline — unique value, test-side signal neither H7 nor H9 can see Also in this PR: remove stale .throwing-stub-callers-allowlist entry for resolveAgentRuntimeOrThrow. That function was restored to a real typed implementation in commit d4a01b9; the allowlist entry had become a silent pre-approval for future regression. Gate was explicitly reporting it as stale via --inventory. Changes: - scripts/check-stub-debt.mjs: dual-counter refactor + vi.mock detection via regex, .js→.ts resolution, fork-boundary prefix match - .fork-boundary-mock-baseline: seeded at 134 (current count) - .throwing-stub-callers-allowlist: remove stale #2408 entry - CONTRIBUTING.md: new § Fork-boundary mocks documenting the three categorization buckets with references to ADR 0005 H8 Verification: - node scripts/check-stub-debt.mjs -> 12 and 134 pass, exit 0 - node scripts/check-throwing-stub-callers.mjs --inventory -> 0 stale - pnpm check -> clean - Fresh-context adversarial validation (session 93f1a611) found 3 blocking findings; all fixed + re-validated CLEAN - Fresh-context polish (session be0ec76b) applied DRY/idiomatic refactors across 2 iterations, output unchanged HQ ADR 0005 H8 description updated in parallel (hq commit 33d248d) with sunset-review trigger: 6 months post-ship, evaluate whether the mock-reason categorization is providing real signal or has become rubber-stamped. If rubber-stamped, defer to H7+H9 alone and remove this gate.
This was referenced Apr 21, 2026
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.
Summary
Extends
scripts/check-stub-debt.mjs(ADR 0005 H8) with a second baseline-gated counter:vi.mock/vi.doMockcalls targetingsrc/agents/orsrc/middleware/. Closes the test-side gap in the #2408-class defense that H7 (production-side AST classifier) cannot see. Also cleans up a stale.throwing-stub-callers-allowlistentry forresolveAgentRuntimeOrThrow(restored to real implementation in commitd4a01b9190).Why this counter
Tests that mock fork-boundary modules can mask production throwing-stubs. The test exercises the mock; production hits a broken stub. This is the underlying cause of #2408 and the #2337 cascade.
H7 (PR #2444) catches production-side throwing stubs at PR time via 4-signal AST classification. It cannot see test files. H8 creates a test-side friction point: new
vi.mocks targeting fork-boundary modules bump the baseline and must be categorized in the PR description:See CONTRIBUTING.md § Fork-boundary mocks for detailed guidance.
Re-scope history
Original #2436 proposed three baselines. 360 evaluation on 2026-04-20 (post-H7 ship):
.never-return-baseline— grep-inflated (24 raw hits → only ~6-8 real function: neverreturns); mostly tracks legitimate typed error-throw helpers; H7 catches the malicious subset.fork-boundary-stub-baseline— H7'sforkMessagePatterncalibration signal already catches fork-attributed throw stubs; redundant dual-ceremony.fork-boundary-mock-baseline— unique value; test-side signal neither H7 nor H9 can seeHQ ADR 0005 H8 description updated in parallel (hq commit
33d248d) with a sunset-review trigger: 6 months post-ship, evaluate whether the mock-reason categorization is providing real signal or has become rubber-stamped.Changes
scripts/check-stub-debt.mjs: dual-counter refactor; new helpers (resolveForkBoundaryMock,findForkBoundaryMocks,readBaseline,reportCounter). Catches bothvi.mockandvi.doMock. Scans test files AND test-adjacent fixture files (.test-helpers.ts,.test-mocks.ts,.mocks.ts,.e2e-mocks.ts)..fork-boundary-mock-baseline: seeded at134(current count)..throwing-stub-callers-allowlist: remove staleresolveAgentRuntimeOrThrowentry. Gate was explicitly reporting it as stale; the function is now a real typed implementation. Removing the entry revokes a silent pre-approval for future regression.CONTRIBUTING.md: new § Fork-boundary mocks section.Verification
node scripts/check-stub-debt.mjs→stub-debt check passed: 12 == baseline 12.+fork-boundary-mock check passed: 134 == baseline 134.node scripts/check-throwing-stub-callers.mjs --inventory→0 violations+0 stale(post-cleanup)pnpm check→ clean (format + typecheck + lint + custom gates)93f1a611): initial FINDINGS on 3 gaps (ratchet-down filename,vi.doMockregex miss,.mocks.ts/.e2e-mocks.tssuffix miss) — all fixed, re-validated CLEANbe0ec76b): CLEAN after 2 iterations applying DRY / idiomatic refactors (matchAll, .some(), removed dead absolute-path branch, spread operator for inventory field propagation). Output unchanged (12/134 still pass).Cascade impact
H8 delivered. Unblocks Phase 3 (#2441 composite gate) once #2437 (H9) also lands.
Test plan
vi.doMocknow caught (2 previously-missed calls in inventory).mocks.ts/.e2e-mocks.tsnow scanned (3 previously-missed mocks in inventory)pnpm checkcleanCloses #2436.