Skip to content

feat(health): answer "what tests this" from the graph when no coverage exists - #1749

Merged
swati510 merged 1 commit into
mainfrom
feat/graph-inferred-test-map
Aug 19, 2026
Merged

swati510 merged 1 commit into
mainfrom
feat/graph-inferred-test-map

Conversation

@RaghavChamadiya

Copy link
Copy Markdown
Member

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_run came back empty, impacted_tests said "run the full suite", and untested_hotspot fell 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:

File Filename convention Graph
ingestion/call_resolver.py nothing 7 test files
analysis/dead_code/analyzer.py nothing 9
pipeline/persist.py nothing 23
mcp_server/tool_answer/answer.py nothing 18
analysis/pr_blast.py nothing 3
analysis/health/engine.py tests/unit/distill/test_engine.py 6, all under tests/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 inferred at 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_coverage behind 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_depth defaults to 1 because that was measured. Dogfooded against a real coverage run --contexts=test, on a slice where per-test attribution was complete and both sides saw the same 38 test files:

max_depth reach precision reach recall run-list precision run-list hit rate
1 (default) 72.1% 30.4% 93.1% 96.8%
2 40.7% 45.1% 73.8% 97.9%
3 17.1% 45.1% n/a n/a

Both 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=2 stays a keyword argument for repositories whose tests import a package facade.

Behaviour

  • untested_hotspot suppresses 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.
  • The persisted has_test_file widens 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 gains tests_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's impacted_tests gains basis and status: "inferred". missing_tests stays empty there because reaching carries no line attribution.
  • _find_test_gaps and _check_test_gap both consult the graph before the filename pattern, so the two heuristics that answered this question differently now share an answer.
  • repowise impacted-tests reports candidates with a via marker: changed-test (the changed file is itself a test), import-graph, or filename-pattern.

Compatibility

repowise impacted-tests --format json renames guessed_tests to inferred_tests. The bucket no longer holds only filename guesses, so the old name described the wrong contents; each entry carries via to say which tier answered.

HEALTH_ANALYZER_VERSION moves 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 IN query over the same edge table pr_blast already 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-tests with no coverage map named the three test files reaching the changed file, including the one written for that change.

…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.
@repowise-bot

repowise-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

✅ Health of changed files: 4.5 → 5.3 (+0.7)
🚨 Change risk: high, riskier than 89% of this repo's commits.

📋 At a glance
4 files changed health · 5 hotspots touched · 6 new findings introduced · 5 files with recent fix history.

Files & modules (2)
  • packages (6 files)
    • .../analysis/pr_blast.py
    • .../tool_risk/assessment.py
    • .../mcp_server/tool_change_risk.py
    • .../biomarkers/untested_hotspot.py
    • .../health/engine.py
    • .../tool_risk/get_risk.py
  • tests (2 files)
    • .../health/test_coverage_biomarkers.py
    • .../mcp/test_risk.py

✅ Health gate: passed

📌 Before you merge

  • Run .../health/test_code_age_volatility.py, .../health/test_error_handling.py, .../health/test_ff_track_d_exceptions.py, .../health/test_file_nloc.py (+8 more): they import the changed files
🔎 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
Loading

Solid arrows: code that imports the changed files (63 direct dependents, from the last indexed snapshot). Dashed: history/tests.

🔥 Hotspots touched (5)

  • .../biomarkers/untested_hotspot.py: 0 commits/90d, 2 dependents
  • .../health/engine.py: 36 commits/90d, 12 dependents
  • .../health/test_coverage_biomarkers.py: 1 commits/90d, 0 dependents
2 more
  • .../tool_risk/assessment.py: 7 commits/90d, 6 dependents
  • .../mcp/test_risk.py: 5 commits/90d, 2 dependents

📊 See the full report for this PR
Your repo map with this PR's blast radius lit up, every caller of the contracts it changes, and health before and after. No sign-in. · ⭐ Star Repowise · 📥 Install bot · Silence on a single PR with [skip repowise] in the title · Per-repo toggle on repowise.dev/settings?tab=bot · Updated 2026-08-19 15:37 UTC

@swati510
swati510 merged commit d439f99 into main Aug 19, 2026
9 checks passed
@swati510
swati510 deleted the feat/graph-inferred-test-map branch August 19, 2026 15:46
swati510 pushed a commit that referenced this pull request Aug 19, 2026
…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.
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.

2 participants