Skip to content

fix: support src-layout Python projects in test_coverage detector#489

Closed
AreboursTLS wants to merge 1 commit intopeteromallet:mainfrom
AreboursTLS:fix/src-layout-test-coverage
Closed

fix: support src-layout Python projects in test_coverage detector#489
AreboursTLS wants to merge 1 commit intopeteromallet:mainfrom
AreboursTLS:fix/src-layout-test-coverage

Conversation

@AreboursTLS
Copy link
Contributor

@AreboursTLS AreboursTLS commented Mar 19, 2026

Problem

In Python projects using src/ layout (where production code lives under src/package_name/), the test_coverage detector fails to link test files to source files.

resolve_import_spec converts import specs like mypackage.foo to mypackage/foo.py, but production files are stored as src/mypackage/foo.py. The candidates never match.

_build_prod_by_module creates module aliases with a src. prefix (e.g. src.mypackage.foo) that import specs from tests never include.

This causes all modules in src-layout projects to be flagged as untested_critical even when comprehensive test suites exist that import them.

Fix

  1. resolve_import_spec (languages/python/test_coverage.py): After checking direct candidates against production_files, also try src/-prefixed candidates.
  2. _build_prod_by_module (engine/detectors/coverage/mapping_analysis.py): Strip src/ prefix from relative paths before computing module names, so the index maps argos_toolkit.foo instead of src.argos_toolkit.foo.

Testing

  • All 5495 existing tests pass.
  • Verified against a real src-layout project (argos-toolkit): test health detection went from broken (0%) to correctly detecting 22.0% coverage.

resolve_import_spec now tries src/-prefixed candidates when direct
module-path candidates don't match any production file. This handles
the common src-layout pattern (e.g. src/argos_toolkit/foo.py).

_build_prod_by_module now strips the 'src/' prefix from relative paths
before computing module names, so the module index maps
'argos_toolkit.foo' instead of 'src.argos_toolkit.foo'.
@AreboursTLS AreboursTLS force-pushed the fix/src-layout-test-coverage branch from eebf9df to 30a686e Compare March 19, 2026 18:06
@peteromallet
Copy link
Owner

Thanks for the fix, @AreboursTLS! The src-layout gap is real — PEP 621 projects with src/package_name/ structure were getting missed by the coverage mapping.

Cherry-picked both changes into 0.9.12 as commit 36805343:

  • resolve_import_spec now tries src/-prefixed candidates when direct match fails
  • _build_prod_by_module strips the src/ prefix before computing module names

One minor adjustment: moved _SRC_PREFIXES to module level as a constant (was function-local in the PR).

All tests pass. Thanks for the clean, targeted fix!

peteromallet added a commit that referenced this pull request Mar 21, 2026
resolve_import_spec now tries src/-prefixed candidates when direct match
fails, and _build_prod_by_module strips the src/ prefix from relative
paths before computing module names. Both changes are needed so that
src-layout projects (PEP 621) correctly map tests to production files.

Adjustments: moved _SRC_PREFIXES to module-level constant (was function-local)
Cherry-picked from PR #489 by @AreboursTLS
Co-Authored-By: AreboursTLS <AreboursTLS@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
peteromallet added a commit that referenced this pull request Mar 21, 2026
…ues #494-#490

Stage 1 assessments, Stage 2 challenges/advocacy, and Stage 3 execution
for the current batch of open PRs and issues. Backfilled Stage 2 files
for older items that only had Stage 1 results.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
stuckvgn pushed a commit to Open-Paws/desloppify that referenced this pull request Mar 21, 2026
resolve_import_spec now tries src/-prefixed candidates when direct match
fails, and _build_prod_by_module strips the src/ prefix from relative
paths before computing module names. Both changes are needed so that
src-layout projects (PEP 621) correctly map tests to production files.

Adjustments: moved _SRC_PREFIXES to module-level constant (was function-local)
Cherry-picked from PR peteromallet#489 by @AreboursTLS
Co-Authored-By: AreboursTLS <AreboursTLS@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.6 (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.

2 participants