Repository navigation
fix(test): avoid slow and incorrect test discovery in large checkouts - #131382
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Ready to land the reviewed head Exact-head CI run 33133828532 and Workflow Sanity run 33133801491 passed. Native review validation and Local Node 24.20.0 proof: One isolated Codex review at default P0 scope found no accepted/actionable findings. ClawSweeper's latest comment is still a review-started placeholder, with no findings or rank-up moves to address. Full repository tests were not rerun locally for this bounded tooling repair; no provider/channel/GUI proof is claimed because product runtime is unchanged. |
|
Merged via squash.
|
Additional instructions
Keep Allow edits from maintainers enabled for this PR.
What Problem This Solves
Fixes an issue where developers running targeted tests could spend minutes discovering helper dependents, causing the planner's own startup hook to exceed its 180-second limit and skip all 84 tests. In large checkouts, test discovery could also silently include the wrong files: untracked tests in changed-source impact plans, and ignored tests in explicit glob selections.
Why This Change Was Made
The targeted import scanner searched the repository separately for each term of each reverse-import node and repeatedly parsed overlapping candidates. It now searches once per uncached frontier and shares parsed import edges with the existing full-graph fallback. Each term retains its own candidate membership, so the existing broad-term cap, central-helper first-success rule, direct-only tooling scan, stop-at-test boundary, and literal-reference checks remain intact. Patterns travel on stdin to avoid the operating system's argument-size limit.
Both affected Git inventories could exceed Node's default 1 MiB output buffer and silently fall back to a directory walk, changing their membership rules. Import discovery now reuses the existing scoped, bounded 16 MiB planner inventory implementation. Explicit glob discovery retains its distinct tracked-plus-untracked, exclude-ignored contract and uses the same finite bound.
Provenance: the per-node scan and import-inventory query without an explicit output bound are traceable to
dd4613a26870e6b0b1183becd7ebb17432a60ca5(May 16, 2026; code author and committer @vincentkoc; no PR traced). The structure was carried forward by #117407 (tooling discovery, August 1) and #122572 (ripgrep optimization, August 12), both authored and merged by @steipete. This establishes code ancestry, not when repository growth first made the failures observable.This removes the duplicate import-graph inventory query, per-node importer cache, and repeated parsing paths. A blanket full-graph replacement was evaluated but rejected because it slowed a narrow cold target and changed selected coverage. No timeout increase, new configuration, dependency change, or forced test environment is involved.
Tooling LOC: +177 / −167 (net +10); tests: +92 / −0. The remaining tooling growth owns batched per-term selection and bounded stdin transport while consolidating inventory and parsing ownership. Product runtime code is unchanged.
User Impact
Developers get faster targeted-test planning with the same selected coverage. Changed-source impact remains tracked-only; explicit globs still include newly authored untracked tests while respecting ignored files. There are no product configuration, protocol, storage, or user-facing runtime changes.
Evidence
Two authentic regressions use a real Git index larger than 1 MiB, with index-only padding instead of thousands of physical fixture files:
Preservation tests cover converging/cyclic import frontiers, same-basename isolation, stopping at test boundaries, live-test exclusion, direct-only tooling imports, and exact literal tooling references.
On the same source base and Node 24.20.0, all seven saved complete before/after plan objects and SHA-256 digests match. The four original startup calls changed as follows:
Total: 154.782 → 26.088 seconds, with 76 → 9 searches. The broad helper retains all 766 entries across 42 plans. An explicit owner, workflow literal references, and a separate narrow helper process also retain identical plans. Warm calls issue no subprocesses; fixed Git inventory queries exit successfully without ENOBUFS. These are observed standalone timings, not timing assertions or portable performance guarantees.
Validation on the unchanged production patch:
node scripts/run-vitest.mjs src/scripts/test-projects.test.ts: 84 passed, 32.56 seconds, fresh worker with no preceding test file and the original four-call hook order unchanged. The original Node 24 hook exceeded 180 seconds.node scripts/run-vitest.mjs test/scripts/test-projects.test.ts: 305 passed, original case order, 189.85 seconds.test/scripts/test-extension.test.ts: 158 passed in the same-production grouped run. That grouped run exposed an incorrect ordering assumption in the new inventory fixture; exact membership was corrected and the complete 305-case planner file rerun successfully. No production ordering was changed.node scripts/check-changed.mjs --base HEAD^ --head HEAD -- scripts/test-projects.test-support.mts scripts/lib/extension-test-plan.mts test/scripts/test-projects.test.ts: passed on commit63c62a28990f0dab590f8ab1948acd98daeb5ba0, including script/root-test typechecks, formatting, targeted lint, and selected guards.The real planner and real Git/ripgrep commands were exercised locally. This change does not involve a provider/channel API, product Gateway, or graphical interface; no live-provider or GUI proof is claimed.
AI-assisted implementation and review with Codex.