Skip to content

fix(merge-batch-graphs): extend tested_by linker to cross-dir src/↔tests/ layouts (#302)#393

Open
tirth8205 wants to merge 1 commit into
Egonex-AI:mainfrom
tirth8205:fix/tested-by-cross-dir-linker
Open

fix(merge-batch-graphs): extend tested_by linker to cross-dir src/↔tests/ layouts (#302)#393
tirth8205 wants to merge 1 commit into
Egonex-AI:mainfrom
tirth8205:fix/tested-by-cross-dir-linker

Conversation

@tirth8205

Copy link
Copy Markdown
Contributor

Summary

  • Adds a basename-indexed Tier-B fallback to the path-convention tested_by linker so standard Python src/pkg/foo.pytests/test_foo.py (and JS/TS src/pkg/foo.ts__tests__/foo.test.ts) layouts actually produce supplemental edges instead of zero — fixes tested_by path-convention linker emits 0 supplemental edges on standard src/tests/ layouts #302.
  • Strictly additive: Tier A (the exact-path candidate list from production_candidates) runs first, so existing sibling, walkout, and mirrored pairings keep their precise semantics. Tier B only fires when Tier A misses.
  • Scoring intent: same-dir > matching-tail mirror (tests/X/...src/X/...) > flat-tests anywhere under src//app//lib/ > non-src/ repo > weak last-resort. Tie-breakers: shortest path then lexicographic, for determinism.
  • Pass-1 LLM-emitted (and inverted) edges still win — Tier B does not duplicate covered pairs.

Root cause

The original production_candidates enumerates candidate paths from the test's filename and dir alone, so for a flat tests/test_foo.py it can only generate tests/foo.py, foo.py, src/foo.py, app/foo.py, lib/foo.py. None of those reach src/pkg/foo.py. The fix indexes production files by basename so that lookup can find src/pkg/foo.py regardless 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).
  • New CrossDirBasenameFallbackTests class covers:
    • Python src/pkg/foo.py ↔ flat tests/test_foo.py (both test_* prefix and *_test suffix forms)
    • Python pkg/foo.py (no src/ prefix) ↔ tests/test_foo.py
    • Tier-A precedence preserved when both an exact-path candidate and a basename match exist
    • Deterministic tie-breakers when multiple production files share a basename (prefer src/ over scripts; alphabetical among equal-rank candidates)
    • Go same-dir _test.go regression coverage (Tier A still owns this case)
    • Go nested package paired against flat tests/ via Tier B
    • TS src/pkg/foo.ts__tests__/foo.test.ts and tests/foo.test.ts
    • TS .test.ts falling back to a .tsx production file via the extension family
    • Sibling src/foo.tssrc/foo.test.ts regression
    • No-prod-counterpart path (must not invent edges)
    • Test-only nodes (must not link test ↔ test)
    • Pass-1 LLM-paired edges suppress duplicate Tier-B supplements

Closes #302

…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tested_by path-convention linker emits 0 supplemental edges on standard src/tests/ layouts

1 participant