fix: read TESTED_BY edges in the parser's direction everywhere#598
Open
SHudici wants to merge 1 commit into
Open
fix: read TESTED_BY edges in the parser's direction everywhere#598SHudici wants to merge 1 commit into
SHudici wants to merge 1 commit into
Conversation
The parser emits TESTED_BY as production -> test (parser.py, all five language blocks): source is the tested symbol, target is the test. Half the consumers read the edge the other way around (test -> production), so they silently returned nothing on real graphs: - tools/query.py tests_for: queried incoming edges of the production node and returned edge sources. Real graphs never have TESTED_BY edges targeting production code, so the edge-based path always came up empty and only the test_<name> naming fallback ever fired. - graph.py get_transitive_tests (direct, bare-name fallback, and transitive blocks): same inversion, so direct and transitive test coverage was always empty. This also silently zeroed the test coverage factor in compute_risk_score, which calls it. - graph.py load_flow_adjacency: has_tested_by collected edge targets (the tests) instead of sources (the tested code), so flow criticality's tested_count was always 0. - changes.py test-gap detection: checked incoming edges, so every changed function was flagged as a test gap regardless of coverage. - enrich.py: the Tests: context line never listed anything. - refactor.py dead-code detection: has_test_refs looked for incoming TESTED_BY edges and bare-name matches on the target column; both are impossible under the emitted direction. Test references are the node's outgoing TESTED_BY edges (with a bare-source fallback, since the edge source inherits an unresolved CALLS target name). Consumers that already read the emitted direction (risk_index in tools/build.py, knowledge gaps and suggested questions in analysis.py, review context in tools/review.py) are unchanged. Test seeds in test_changes, test_enrich, test_graph and test_integration_v2 seeded the inverted direction to match the inverted consumers; they now seed what the parser emits. New regression tests pin the direction at both ends: the parser must emit production -> test (test_parser), and tests_for must find a test whose name defeats the naming-convention fallback, via the edge alone (test_tools). Co-Authored-By: Claude Fable 5 <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.
Problem
The parser emits
TESTED_BYedges as production → test (source= the code under test,target= the test function). Several consumers read the edge in the opposite direction, so they silently return nothing:query_graph(pattern="tests_for")looked for incoming edges on the production node and returned the wrong endpoint.graph.get_transitive_testsqueriedtarget_qualified = ?for the production node in all three lookup blocks (direct, bare-name fallback, transitive).changes.pycounted "tested" nodes from incoming edges →tests_forcontext in change reviews was empty.enrich.py's Tests block andrefactor.py's test-reference augmentation read the reverse direction as well.Some call sites already read the correct direction (
build.py,analysis.py,review.py,communities.py), which is how the inconsistency stayed invisible: half the features worked, half quietly returned empty results.Fix
Read
TESTED_BYbysource_qualified(production) and taketarget_qualified(test) everywhere, matching the parser. Test seeds that encoded the inverted direction were flipped to the parser's real output, and two end-to-end regression tests pin the direction:test_tested_by_edges_point_from_production_to_test(parser level)TestQueryGraphTestsFor(tool level, with a test name that deliberately defeats the name-matching fallback so only the edge lookup can find it)Notes
resolve_bare_call_targetsupgrades bareCALLStargets to qualified names but does not touchTESTED_BYsources that inherited a bare name from an unresolved cross-file call.refactor.pykeeps its plausibility-checked bare-name fallback for exactly that case. Two natural follow-up PRs if you want them: extending bare-name resolution toTESTED_BY, and a canonicalGraphStore.get_tests_of()accessor so the direction knowledge lives in one place instead of each consumer's SQL.Testing
Full suite: 1412 passed / 0 failed on Windows 11; the new regression tests fail on main and pass here.
🤖 Generated with Claude Code