Skip to content

Emit test_ref facts for Go so test-only symbols aren't reported dead - #89

Merged
dejo1307 merged 1 commit into
mainfrom
fix/go-testref-extractor
Jul 10, 2026
Merged

Emit test_ref facts for Go so test-only symbols aren't reported dead#89
dejo1307 merged 1 commit into
mainfrom
fix/go-testref-extractor

Conversation

@dejo1307

Copy link
Copy Markdown
Collaborator

A production function whose only caller is its own _test.go was reported as high-confidence dead code. Two gates caused it, and fixing either alone is a no-op: the walker collects an ignored file for reference-only extraction only when it matches a test glob, and runTestRefExtractors skips extractors that don't implement plugin.TestRefExtractor.

  • config.Default().TestGlobs gains "**/*_test.go". Go's bare suffix is safe: the toolchain defines any *_test.go as a test file, so no production file can collide with it the way _test.rb did (v97).
  • goextractor implements ExtractTestRefs, resolving targets with the production resolvers (flattenSelector/collectLocalTypes/resolveChain). A reference from a test is therefore spelled exactly as one from production, and inherits goBuiltins filtering — a package-level min shadowing the builtin is still not credited, from either side. Copying Ruby's identifier-level walker would have rescued unrelated symbols by bare name, trading false positives for false negatives.
  • Deliberately no OwnsFile: plugin.FileOwner is what opts an extractor into the incremental cache, and adding it would move .go files out of the shared partition that keys every other extractor. ExtractTestRefs filters internally.

cacheVersion v100 + cachecov entry. go_sample gains a_test.go (in-package) and a_ext_test.go (package a_test) to pin both Go test idioms; the latter calls a dedicated Gamma rather than Alpha, whose dependent count TestE2E_ImpactAnalysis asserts — a test_ref counts as a graph dependent, which is a separate pre-existing defect in god-class/hotspots.

A production function whose only caller is its own _test.go was reported as
high-confidence dead code. Two gates caused it, and fixing either alone is a
no-op: the walker collects an ignored file for reference-only extraction only
when it matches a test glob, and runTestRefExtractors skips extractors that
don't implement plugin.TestRefExtractor.

- config.Default().TestGlobs gains "**/*_test.go". Go's bare suffix is safe:
  the toolchain defines any *_test.go as a test file, so no production file can
  collide with it the way _test.rb did (v97).
- goextractor implements ExtractTestRefs, resolving targets with the production
  resolvers (flattenSelector/collectLocalTypes/resolveChain). A reference from a
  test is therefore spelled exactly as one from production, and inherits
  goBuiltins filtering — a package-level min shadowing the builtin is still not
  credited, from either side. Copying Ruby's identifier-level walker would have
  rescued unrelated symbols by bare name, trading false positives for false
  negatives.
- Deliberately no OwnsFile: plugin.FileOwner is what opts an extractor into the
  incremental cache, and adding it would move .go files out of the shared
  partition that keys every other extractor. ExtractTestRefs filters internally.

cacheVersion v100 + cachecov entry. go_sample gains a_test.go (in-package) and
a_ext_test.go (package a_test) to pin both Go test idioms; the latter calls a
dedicated Gamma rather than Alpha, whose dependent count TestE2E_ImpactAnalysis
asserts — a test_ref counts as a graph dependent, which is a separate
pre-existing defect in god-class/hotspots.
@dejo1307
dejo1307 merged commit 099496d into main Jul 10, 2026
4 checks passed
@dejo1307
dejo1307 deleted the fix/go-testref-extractor branch July 17, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant