fix(go): credit package-level test coverage instead of name-pairing only#633
Open
aliscott wants to merge 1 commit into
Open
fix(go): credit package-level test coverage instead of name-pairing only#633aliscott wants to merge 1 commit into
aliscott wants to merge 1 commit into
Conversation
Go compiles a directory as one package and 'go test' reports coverage package-wide: a test file can exercise any identifier in its package regardless of which file defines it. The Go mapper only paired foo_test.go -> foo.go by name, so files covered by a package's suite under a different test filename (e.g. ingest_test.go covering plan.go, verify.go, run.go) were flagged untested_module. Adds an optional plural map_test_to_sources language hook consumed by naming_based_mapping and get_test_files_for_prod, and implements it for Go as same-directory production files. Languages without the hook are unaffected.
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.
Problem
Go's test-coverage mapping only pairs test files to production files by name (
foo_test.go->foo.go). But Go compiles a directory as one package andgo testreports coverage package-wide: a test file can exercise any identifier in its package regardless of which file defines it.On a real Go repo this produced a cluster of false
untested_modulefindings:internal/ingest/ingest_test.go(a 1,000-line suite) coversplan.go(91% bygo tool cover),verify.go(100%),match.go(90%) - yet all were flagged as untested because no file namedplan_test.goexists. Test health scored 38% on a package with 90 passing tests.A blind-review subagent independently flagged the same thing: "the detector flags files like plan.go, verify.go, match.go as 'untested modules' because they lack matching *_test.go filenames, but Go package-level tests cover them well".
Fix
map_test_to_sources(test_path, production_set) -> set[str]language hook, consumed bynaming_based_mappingandget_test_files_for_prod. Languages that don't define it are unaffected._test.gofile maps to every production.gofile in its directory. This mirrors the language's own semantics - both in-package and external (package foo_test) test files compile and run against exactly that package, andgo test -coverattributes coverage package-wide.Verified against the same Go repo: false positives drop from 25 to 11 findings (the remainder are genuinely untested packages), test health 43.8% -> 81.1%.
Tests added:
tests/lang/go/test_go_test_coverage.py: package-wide mapping, non-test files ignoredtests/detectors/coverage/test_test_coverage_mapping_import_and_logic.py: engine credits whole Go package; absent hook is a no-op for other languagespytest desloppify/tests/lang/go/ desloppify/tests/detectors/coverage/- 200 passed. Full suite: 2916 passed; the 3test_bash_unused_imports.pyfailures also occur on a clean checkout in this environment (macOS bash) and are unrelated.