fix(merge-batch-graphs): extend tested_by linker to cross-dir src/↔tests/ layouts (#302)#393
Open
tirth8205 wants to merge 1 commit into
Open
fix(merge-batch-graphs): extend tested_by linker to cross-dir src/↔tests/ layouts (#302)#393tirth8205 wants to merge 1 commit into
tirth8205 wants to merge 1 commit into
Conversation
…sts/ layouts (Egonex-AI#302) On standard Python `src/pkg/foo.py` ↔ `tests/test_foo.py` layouts (and the equivalent JS/TS `src/pkg/foo.ts` ↔ `__tests__/foo.test.ts`), the existing path-convention linker emitted 0 supplemental edges because its exact-path candidate list cannot enumerate every production subdir from a test path alone — `tests/test_foo.py` only generates `tests/foo.py`, `foo.py`, `src/foo.py`, `app/foo.py`, `lib/foo.py`, none of which include `src/pkg/`. Add a Tier-B fallback inside `link_tests` that runs only when the exact-path list misses: build a `basename → [production paths]` index up front, then look up the production basename and pick the highest- scoring candidate. Scoring prefers same-dir > matching-tail mirror > flat-tests-into-`src/` > `pkg/`-without-`src/` > weak last-resort, with shortest-path and lexicographic tie-breakers for determinism. Go's same-dir `pkg/foo.go ↔ pkg/foo_test.go` and Maven-style `src/main/...` ↔ `src/test/...` remain handled by the Tier-A exact-path list — Tier B is strictly additive. Pass-1 LLM-emitted edges still win over the fallback. Adds 15 new unit tests covering Python flat-tests-into-`src/pkg/`, the no-`src/` variant, the `_test.py` suffix form, TS `__tests__/` ↔ `src/pkg/`, the TS extension family fallback, deterministic tie-breaking on basename collisions, Pass-1 coexistence, and regression coverage for Go same-dir and TS sibling pairings. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
tested_bylinker so standard Pythonsrc/pkg/foo.py↔tests/test_foo.py(and JS/TSsrc/pkg/foo.ts↔__tests__/foo.test.ts) layouts actually produce supplemental edges instead of zero — fixestested_bypath-convention linker emits 0 supplemental edges on standardsrc/↔tests/layouts #302.production_candidates) runs first, so existing sibling, walkout, and mirrored pairings keep their precise semantics. Tier B only fires when Tier A misses.tests/X/...↔src/X/...) > flat-tests anywhere undersrc//app//lib/> non-src/repo > weak last-resort. Tie-breakers: shortest path then lexicographic, for determinism.Root cause
The original
production_candidatesenumerates candidate paths from the test's filename and dir alone, so for a flattests/test_foo.pyit can only generatetests/foo.py,foo.py,src/foo.py,app/foo.py,lib/foo.py. None of those reachsrc/pkg/foo.py. The fix indexes production files by basename so that lookup can findsrc/pkg/foo.pyregardless of subdir depth, then scores each candidate against the test path to pick the most plausible pairing.Test plan
python3 -m unittest tests.skill.understand.test_merge_batch_graphs— all 84 tests pass (69 pre-existing + 15 new).CrossDirBasenameFallbackTestsclass covers:src/pkg/foo.py↔ flattests/test_foo.py(bothtest_*prefix and*_testsuffix forms)pkg/foo.py(nosrc/prefix) ↔tests/test_foo.pysrc/over scripts; alphabetical among equal-rank candidates)_test.goregression coverage (Tier A still owns this case)tests/via Tier Bsrc/pkg/foo.ts↔__tests__/foo.test.tsandtests/foo.test.ts.test.tsfalling back to a.tsxproduction file via the extension familysrc/foo.ts↔src/foo.test.tsregressionCloses #302