fix(detect): gate coverage/ pruning on report artefacts (#2339) - #2351
Closed
MANOJ21K wants to merge 1 commit into
Closed
fix(detect): gate coverage/ pruning on report artefacts (#2339)#2351MANOJ21K wants to merge 1 commit into
MANOJ21K wants to merge 1 commit into
Conversation
…s#2339) "coverage" was an unconditional _SKIP_DIRS entry and _is_noise_dir matches directory names at any depth, so a repo where coverage is a legitimate package name lost the whole package from the graph — no warning, no skipped_sensitive entry, nothing in the report. The failure is quiet in the worst way: the package's dependents survive, so queries keep returning plausible neighbours while the package itself has no nodes. The entry's comment cites Vitest/Istanbul/nyc HTML reports (Graphify-Labs#870), but the pruning is language-agnostic, so it also removes Python/Go/Rust packages that happen to be called coverage. detect.py has been fixed twice for this exact shape — Graphify-Labs#1666 gated a bare snapshots/ on real .snap evidence, Graphify-Labs#2058 gated env/.env/*_env on real virtualenv markers — so this applies the established pattern rather than a new mechanism. _has_coverage_artifacts() mirrors _has_venv_markers(): same OSError guard, same "cannot verify, keep a possibly-real code dir" contract when no parent is available. Evidence is a file a coverage tool actually writes (lcov.info, coverage-final.json, clover.xml, coverage.xml, cobertura-coverage.xml, jacoco.xml, .coverage, index.html) or an lcov-report/ / html-report/ subtree, covering lcov, nyc/Istanbul, coverage.py, JaCoCo and Cobertura. lcov-report stays unconditional: it has no false-positive class, so gating it would add filesystem probes for no benefit — the same split Graphify-Labs#1666 made between the unambiguous __snapshots__ and the bare snapshots.
Collaborator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2339.
Problem
"coverage"is an unconditional entry indetect.py::_SKIP_DIRS, and_is_noise_dirmatches directory names at any depth. In a repo where
coverageis a legitimate packagename, the whole package is dropped from the graph — no warning, no
skipped_sensitiveentry, nothing in the report.
The failure is quiet in the worst way: the package's dependents are still there, so
queries return plausible neighbours while the package itself simply doesn't exist as
nodes. The reporter only found it by diffing
git ls-filesagainst the distinctsource_filevalues ingraph.json.Same bug class as #1666 and #2058
The comment on the entry is
# Vitest/Istanbul/nyc HTML reports (#870)— a JS-ecosystemartefact directory — but the pruning is unconditional and language-agnostic.
detect.pyhas already been fixed twice for exactly this shape:snapshotsdir is a Jest artefact only when it holds.snapfiles or sits under a JS test root; elsewhere it's a real code namespace.
env/.env/*_envis pruned only on real virtualenv evidence(
pyvenv.cfg,bin/activate,lib/python*,conda-meta/).coveragehadn't been given the same treatment. This PR applies the existing patternrather than inventing a new mechanism.
Fix
coveragemoves out of the unconditional_SKIP_DIRSset into an evidence-gatedbranch in
_is_noise_dir, backed by a new_has_coverage_artifacts()helper writtento match
_has_venv_markers()(sameOSErrorguard, same "cannot verify → keep apossibly-real code dir" contract when no parent is passed).
lcov.info,coverage-final.json,coverage-summary.json,clover.xml,coverage.xml,cobertura-coverage.xml,jacoco.xml,.coverage,index.html— or anlcov-report//html-report/subtree. That covers lcov, nyc/Istanbul, coverage.py, JaCoCo and Cobertura.
lcov-reportstays unconditional. It has no false-positive class — no package isever named that — so gating it would only add filesystem probes for no benefit. Only
the ambiguous bare name is gated, mirroring how
__snapshots__stayed unconditionalin Ruby: stable subset of files yields zero nodes in full-repo runs (0.9.6) — each extracts fine in isolation #1666 while
snapshotswas gated.Reproduction
The reporter's repro, before and after (
auditor_toolkit/assurance/coverage/holding__init__.py,impact.py,inventory.py,mapping.py,summary.py, with a genuineIstanbul report at
webapp/coverage/in the same tree):The generated
webapp/coverage/report is still pruned in the "after" walk — itsprettify.jsnever enters the corpus — so #870 is not regressed.Tests
tests/test_detect.py, following thetest_detect_keeps_snapshots_code_namespaceprecedent. Three of them fail on clean
v8:test_detect_keeps_coverage_code_namespace— acoverage/package with real modulessurvives a
detect()scan.test_collect_files_keeps_coverage_code_namespace— the issue as reported, viacollect_files, both as the walk target and through the repo root, with a real reportdir alongside that must still be skipped.
test_is_noise_dir_coverage_is_evidence_gated— the gate directly: name alone isn'tenough, artefact evidence prunes, no-parent keeps,
lcov-reportstill unconditional.test_detect_skips_coverage_dir_by_lcov_info— guard: a single artefact file with nolcov-report/subtree is still enough to prune.The existing
test_detect_skips_coverage_dir(#870) passes unchanged.uv run pytest tests/ -q→ 3903 passed, 3 skipped (baseline onv8is 3899 passed,3 skipped — the delta is exactly these four tests, no regressions).
Noted but not fixed here
The reporter also flagged that
_parse_gitignore_linestrips inline#comments whilegit only treats
#as a comment at line start, so*_backup_*.py # temp scriptsexcludes real files for graphify but matches nothing for git. That's a separate
divergence in a different function and belongs in its own issue/PR.