Skip to content

coverage/ in _SKIP_DIRS silently drops real Python packages named 'coverage' (same class as #1666 snapshots / #2058 env) #2339

Closed

Description

@nathanschram

Summary

"coverage" is an unconditional entry in graphify/detect.py::_SKIP_DIRS, and _is_noise_dir matches directory names at any depth. In a Python repo where coverage is a legitimate package name, this silently drops real source from the graph — no warning, no entry in skipped_sensitive, nothing in the report.

In our repo (~2,700 tracked code files) it removed an entire 5-module production package (auditor_toolkit/assurance/coverage/, ~51 KB) that the rest of the codebase imports from. The graph looked complete: the package's dependents are present, so queries return plausible neighbours while the package itself simply doesn't exist as nodes. We only found it by diffing git ls-files against the distinct source_file values in graph.json.

Repro

from pathlib import Path
from graphify.extract import collect_files
collect_files(Path("auditor_toolkit/assurance/coverage"))   # -> []

The directory holds __init__.py, impact.py, inventory.py, mapping.py, summary.py. Nothing is gitignored (git check-ignore reports none of them), and .graphifyignore doesn't mention them.

Why this is the same bug class you've already fixed twice

The comment on the entry is # Vitest/Istanbul/nyc HTML reports (#870) — a JS-ecosystem artefact directory. But the pruning is unconditional and language-agnostic, so it also removes Python/Go/Rust packages that happen to be called coverage.

This is exactly the shape of two fixes already in detect.py:

coverage hasn't been given the same treatment. The existing _has_venv_markers / _JS_SNAPSHOT_TEST_ROOTS gating helpers are the precedent.

Suggested fix

Gate coverage (and probably lcov-report) on actual coverage-artefact evidence rather than the name alone. A generated coverage-report dir is easy to positively identify — e.g. any of index.html + base.css/prettify.js (Istanbul), lcov.info, coverage-final.json, clover.xml, coverage.xml — whereas a source package contains __init__.py / *.py / *.go / mod.rs and no report artefacts.

A cheaper variant that would also have caught this: treat a directory containing an __init__.py (or any recognised source-manifest file) as source regardless of name.

Workaround note for other users

There is currently no include-override: .graphifyignore can only ever exclude more, and .graphifyinclude was removed in #2112. So a repo hitting this has to rename the package or patch _SKIP_DIRS — neither is great when the name is part of a public API.

Lower-priority observation from the same audit

While diffing coverage we also hit a divergence worth flagging separately: _parse_gitignore_line strips inline # comments, but git does not — git only treats # as a comment at line start, so *_backup_*.py # temp scripts is a literal pattern matching nothing for git, while graphify parses it as *_backup_*.py and excludes real files. Not necessarily wrong (the stricter reading is arguably more useful), but it means graphify's corpus can be a strict subset of what git tracks in a way that's invisible unless you go looking. Happy to open that as its own issue if useful.


Environment: graphifyy via pipx, Python 3.12, Linux. Repo is ~2,700 code files + ~2,100 docs, graph ~60k nodes / 125k edges.

Activity

  1. Rishet11 commented on Jul 31, 2026

    @Rishet11
    Contributor

    Reproduced, and the root cause is the unconditional skip-list rather than the walk.

    "coverage" and "lcov-report" sit in _SKIP_DIRS (graphify/detect.py:798), and _is_noise_dir (detect.py:851-853) returns True on a bare name match at any depth with no evidence check. So a real Python package named coverage/ is pruned before anything looks inside it:

    $ tree /tmp/cov-repro
    main.py                      # import coverage
    coverage/__init__.py
    coverage/impact.py
    
    >>> detect(Path("/tmp/cov-repro"))["files"]
    {"code": ["/private/tmp/cov-repro/main.py"], ...}   # coverage/*.py silently gone
    >>> _is_noise_dir("coverage", Path("/tmp/cov-repro"))
    True
    

    Same class as #1666/#2058, which is also where the fix pattern already lives: env/.env/*_env and snapshots were moved out of the unconditional set and are pruned only on real evidence (_has_venv_markers at detect.py:828, the *.snap / _JS_SNAPSHOT_TEST_ROOTS gate at detect.py:861-873). coverage/lcov-report never got that treatment.

    Two things I want to flag beyond the report:

    1. visual-tests/visual-test (detect.py:799) and dist-protected (detect.py:802) are pruned the same unconditional way and are plausible real directory names. I will look at whether they belong in the same gate rather than fixing only coverage.
    2. tests/test_detect.py:675 (test_detect_skips_coverage_dir) plants index.html under coverage/lcov-report/, so evidence-based gating keeps that test green — it is not locking the current behavior.

    Planning to gate on real coverage-report markers (lcov.info, coverage-final.json, clover.xml, coverage.xml, index.html+base.css/prettify.js) and keep the directory when none are present. Claiming this one; will open a PR against v8.

  2. safishamsi commented on Aug 1, 2026

    @safishamsi
    Member

    Fixed in v0.9.32. The coverage/ prune is now gated on coverage-report artefacts, so a real Python package named coverage/ is kept. Thanks for flagging it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions