graphify icon indicating copy to clipboard operation
graphify copied to clipboard

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

Open nathanschram opened this issue 4 months ago • 2 comments

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:

  • #1666 — a bare snapshots dir is a Jest artefact only when it actually holds snapshot files or sits under a JS test root; elsewhere it's a real code namespace, so pruning by name "silently dropped legitimate source from the graph".
  • #2058 — env/.env/*_env is pruned only on real virtualenv evidence (pyvenv.cfg, bin/activate, lib/python*, conda-meta/), because otherwise it "silently drops legitimate source with no trace".

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.

nathanschram avatar Jul 31 '26 05:07 nathanschram

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.

Rishet11 avatar Jul 31 '26 20:07 Rishet11

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.

safishamsi avatar Aug 01 '26 14:08 safishamsi