Skip to content

fix: test_coverage detector — naming mapping + importer count#498

Closed
Imwm82 wants to merge 1 commit intopeteromallet:mainfrom
Imwm82:main
Closed

fix: test_coverage detector — naming mapping + importer count#498
Imwm82 wants to merge 1 commit intopeteromallet:mainfrom
Imwm82:main

Conversation

@Imwm82
Copy link

@Imwm82 Imwm82 commented Mar 22, 2026

Summary

Fixes two bugs in the test_coverage detector:

Bug 1: map_test_to_source (TypeScript)

The first loop compared candidate basenames against the TEST file basename instead of the SOURCE basename, so the comparison always failed and the function skipped to the fallback loop.

# Before (broken): compares candidate against test basename → never matches
for prod in production_set:
    prod_base = os.path.basename(prod)
    for c in candidates:
        if os.path.basename(c) == prod_base:  # always false
            return prod

# After (fixed): compare candidate basename against source basename
for c in candidates:
    c_base = os.path.basename(c)
    for prod in production_set:
        if c_base == os.path.basename(prod):  # correct
            return prod

Bug 2: importer_count

Only counted production-file importers, ignoring test-file importers entirely. Combined both for accurate blast-radius assessment.

Impact

For the CoQ Tracking System project:

  • Test health: 3.7% -> 73.8%
  • Strict score: 81.7 -> 86.8
  • Test issues: 40 open -> 11 open (all genuine)

Bug 1 — map_test_to_source: The first loop compared candidate basenames
against the TEST file basename (e.g. "Foo.test.tsx") instead of the SOURCE
basename (e.g. "Foo.tsx"), so the comparison always failed and the
function skipped to the fallback loop. Fixed: compare candidate basename
against source basename.

Bug 2 — importer_count: Only counted production-file importers, ignoring
test-file importers entirely. Combined both for accurate blast-radius
assessment in issue severity.
@peteromallet
Copy link
Owner

Thanks for looking into the test_coverage detector, @Imwm82.

After reviewing the diff carefully, I'm not going to merge this — here's why:

Bug 1 (map_test_to_source): The existing code at test_coverage.py:233-237 iterates production_set, sets prod_base = os.path.basename(prod), then checks os.path.basename(c) == prod_base. This already correctly compares candidate basenames against production basenames. The PR's change swaps the loop nesting order and removes the redundant prod in production_set check, but the end result is semantically equivalent — it's a no-op refactor rather than a bug fix.

Bug 2 (importer_count): The existing code intentionally counts only production-file importers for blast-radius assessment. Adding test-file importers would inflate priority scores for well-tested files — the opposite of what we want. A file that's heavily tested should not appear riskier because of that.

If you're seeing unexpected test_health scores in your project, I'd be happy to look at a concrete example — there may be a different root cause. Thanks again for the investigation.

@peteromallet peteromallet added the release:v0.9.13 Included in v0.9.13 label Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:v0.9.13 Included in v0.9.13

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants