Repository navigation
feat(health): answer "what tests this" from the graph when no coverage exists - #1749
Conversation
…e exists The per-test coverage map only ever existed if you ingested a report with contexts. Most repositories never do, so `tests_to_run` came back empty, `impacted_tests` said "run the full suite", and `untested_hotspot` fell back to matching filenames. Matching filenames fails both ways. Of this repository's six worst bug-magnet files, five have no file named for them anywhere under tests/ and read as untested, while the graph names 7, 9, 23, 18 and 3 test files importing them. The sixth is worse: analysis/health/engine.py was called tested because the convention matched tests/unit/distill/test_engine.py on basename alone, a different subsystem's engine. The dependency graph already records which test files import which source files. New `analysis/test_reachability.py` reads that relation as a second signal beside the measured one. It is labelled `inferred` at every surface, never blended with measured coverage, and never turned into a percentage: importing a module is not exercising it, so it over-claims, which makes it sound as a floor and unsound as a quantity. Nothing is persisted. Writing inferred rows into `test_coverage` behind a marker column would work until a reader forgot to check the marker, which is issue #1739's exact shape, and the relation is a transitive closure (tests reach 1,630 of 2,509 production files here) that goes stale the moment the graph moves. It is a bounded walk over rows already indexed instead. max_depth defaults to 1 because that was measured, not assumed. Dogfooded against a real `coverage run --contexts=test` over a slice with complete per-test attribution, both sides seeing the same 38 test files: depth 1: reach precision 72.1%, recall 30.4%; run-list precision 93.1% depth 2: reach precision 40.7%, recall 45.1%; run-list precision 73.8% depth 3: reach precision 17.1% (269 claims, same 46 confirmations) The filename convention scores 23.5% recall on that set, so depth 1 beats it on recall while resting on a recorded edge. max_depth=2 stays available for repos whose tests import a package facade. Surfaces: - `untested_hotspot` suppresses on a graph-reaching test as well as a paired test file. 74 of this repo's 110 standing findings clear, 18 of them critical. - The persisted `has_test_file` widens to the union, since the MCP payload documents it as "does something test this file" and every UI renders it "has tests"/"untested". Leaving it filename-only left the file table and the biomarker disagreeing about the same file. - `get_risk`'s directive gains `tests_to_run_basis` (measured/inferred/none), and falls back to the graph when the map is empty or silent about a file. - `get_change_risk`'s `impacted_tests` gains `basis` and `status: "inferred"`. `missing_tests` stays empty there: reaching carries no line attribution. - `_find_test_gaps` and `_check_test_gap` both consult the graph before the filename pattern, so the two heuristics of #1740 now share an answer. - `repowise impacted-tests` reports candidates with a `via` marker (changed-test / import-graph / filename-pattern). The `--format json` key `guessed_tests` becomes `inferred_tests`, since the bucket no longer holds only guesses. Indexing cost is 27ms once per health run on a 3,700-file repository, computed in one multi-source walk and cached. Per-change queries are one IN query over the edge table pr_blast already reads. HEALTH_ANALYZER_VERSION moves to 2: both stored values are wrong on an older index, in the direction that accuses a tested file.
|
✅ Health of changed files: 4.5 → 5.3 (+0.7) 📋 At a glance Files & modules (2)
✅ Health gate: passed 📌 Before you merge
🔎 More signals (2)🗺️ Change map flowchart LR
subgraph PR ["Changed in this PR (2 modules)"]
m_packages["packages (8 files)"]:::changed
m_tests["tests (1 file)"]:::changed
end
d_packages["packages"]
m_tests -->|1 file| d_packages
classDef changed fill:#dbeafe,stroke:#1d4ed8,color:#1e3a5f
classDef warn fill:#fef3c7,stroke:#b45309,color:#78350f
classDef guard fill:#dcfce7,stroke:#15803d,color:#14532d
Solid arrows: code that imports the changed files (63 direct dependents, from the last indexed snapshot). Dashed: history/tests. 🔥 Hotspots touched (5)
2 more
📊 See the full report for this PR |
…ed (#1757) The core has answered "does a test reach this file" from the graph since #1749, and from the call graph since #1755. None of it reached the web layer: `/health/coverage` read only the measured `test_coverage` table, so a repo with no ingested report got an empty summary on a question the graph could already answer. The route now falls back to the inferred map under `basis: "inferred"`. The two bases never share a field. On the inferred basis `summary`, `files` and `modules` come back empty and the answer rides in `inferred`, so a consumer cannot render derived data through the measured code path by accident, and `basis` is the only thing that distinguishes "nothing measured this" from "measured at zero". Nothing derives a percentage from it: reaching is a file-level fact with no line attribution, so a ratio would be a coverage figure the data cannot support. A test asserts that over the serialized payload rather than field by field, so a future field under a different name fails it too. The repo-wide question reuses the forward walk `files_reached_by_tests` rather than seeding the attributed reverse walk with every file. That walk runs a query per level per seed and is built for a change's files; this is the batch question and is one multi-source search. Sharing the walk also means the map can never disagree with the `untested_hotspot` biomarker, which reads the same function. `call_graph_from_db` is the loader that gets it the same `CallGraphView` from SQL that the health engine builds from NetworkX - a loader, not a second walk. `/health/tests-reaching?file_path=` answers which tests reach one file, with `via` separating `call-graph` from the weaker `import-graph`. One seed, which is the shape the attributed walk was built for. Counts stay repo-wide when `limit` trims the list, matching `modules_total`. Test files are dropped from their own map. Both degrade to `basis: "none"` - the honest unknown - rather than raising, as `pr_blast` already does.
What
Answer "what tests this file?" from the dependency graph when no coverage report has been ingested.
The per-test coverage map only exists if you run your suite under per-test recording and ingest the report. Most repositories never do, so
tests_to_runcame back empty,impacted_testssaid "run the full suite", anduntested_hotspotfell back to matching filenames.Filename matching fails in both directions. Of this repository's six worst bug-magnet files, five have no file named for them anywhere under
tests/and so read as untested:ingestion/call_resolver.pyanalysis/dead_code/analyzer.pypipeline/persist.pymcp_server/tool_answer/answer.pyanalysis/pr_blast.pyanalysis/health/engine.pytests/unit/distill/test_engine.pytests/unit/health/The last row is the worse failure: the convention matches on basename alone, so it paired the health engine with the distill engine's tests and called the file tested on the strength of a name collision.
How
New
core/analysis/test_reachability.py. A test file that imports a source file reaches it, which the graph already records from parsing. Two walks: a multi-source forward walk for the whole-repo question the health pass asks, and an attributed reverse walk for the per-change question.Importing is not executing, so this over-claims, in a known direction. That makes it sound as a floor ("something reaches this, do not call it untested") and unsound as a quantity. It is labelled
inferredat every surface and never blended with measured coverage. Where a coverage report exists the graph is not consulted at all.Nothing is persisted. Writing inferred rows into
test_coveragebehind a marker column works until one reader forgets to check the marker, and the relation is a transitive closure (tests reach 1,630 of 2,509 production files here) that goes stale the moment an import changes. It is a bounded walk over rows already indexed instead.Accuracy
max_depthdefaults to 1 because that was measured. Dogfooded against a realcoverage run --contexts=test, on a slice where per-test attribution was complete and both sides saw the same 38 test files:max_depthBoth uses want precision. A false "something reaches this" suppresses a real finding, and a false entry in a run-list sends someone to run a test that cannot fail for their change. By depth 3 the closure has begun to blow up: 269 claims for the same 46 confirmations.
The filename convention it sits beside scores 23.5% recall on the same set, so depth 1 beats it on recall while resting on a recorded edge rather than a name. The two are unioned, not ranked.
max_depth=2stays a keyword argument for repositories whose tests import a package facade.Behaviour
untested_hotspotsuppresses on a graph-reaching test as well as on a paired test file. On this repository's index that clears 74 of 110 standing findings, 18 of them graded critical.has_test_filewidens to the union. The MCP payload documents it as "does something test this file" and every UI renders it "has tests" / "untested", so leaving it filename-only left the file table and the biomarker disagreeing about the same file.get_risk's directive gainstests_to_run_basis(measured/inferred/none) and falls back to the graph when the map is empty or silent about a file. Only the inferred list is exclude-filtered, since its entries are repo paths while measured entries are test node ids.get_change_risk'simpacted_testsgainsbasisandstatus: "inferred".missing_testsstays empty there because reaching carries no line attribution._find_test_gapsand_check_test_gapboth consult the graph before the filename pattern, so the two heuristics that answered this question differently now share an answer.repowise impacted-testsreports candidates with aviamarker:changed-test(the changed file is itself a test),import-graph, orfilename-pattern.Compatibility
repowise impacted-tests --format jsonrenamesguessed_teststoinferred_tests. The bucket no longer holds only filename guesses, so the old name described the wrong contents; each entry carriesviato say which tier answered.HEALTH_ANALYZER_VERSIONmoves to 2. Both stored values are wrong on an index built before this, and wrong in the direction that accuses a tested file, so the next update with changed files re-scores rather than waiting out the decay timer.Cost
27 ms once per health run on this 3,700-file repository, computed in one multi-source walk and cached, so indexing time is unchanged. Per-change queries are one
INquery over the same edge tablepr_blastalready reads.Verification
13,869 unit tests pass. Two pre-existing failures remain on this machine (
test_pascal_no_class_metrics,test_tokenize_file_pascal_normalizes_identifiers_and_literals), confirmed to fail identically on a clean tree because the Pascal grammar is not installed locally.New tests cover both walks over real graph rows, the edge-type filter, the depth bound, the test-files-are-leaves rule, per-seed attribution, the biomarker suppression and its controls, the shared test-gap floor at both call sites, the three-tier CLI classification, and the two MCP fields.
Dogfooded end to end against this repository's own index:
repowise impacted-testswith no coverage map named the three test files reaching the changed file, including the one written for that change.