fix: eliminate dead export false positives#10
Merged
Conversation
Two bugs caused ~33% false positive rate in find_dead_exports:
1. Duplicate imports to same target silently dropped — second import's
symbols never entered consumed set (e.g., `import type {X}` after
`import {A,B,C}` from same file)
2. Same-file calls invisible — parser excluded intra-file calls,
analyzer only checked import edges
Fixes:
- Graph: merge duplicate edge symbols (both graphology + edges[] array)
- Parser: remove same-file call exclusion guard
- Analyzer: integrate call graph into consumed symbols check with
class method normalization (ClassName.method → ClassName)
7 regression tests covering: truly dead exports, type-only imports,
duplicate import merge, same-file calls, class methods, mixed
dead/alive, edge merge sync.
- graph: replace silent `if (existing)` guard with invariant assertion - graph: extract merge values as consts for order-safe mutation - test: assert `main` is dead in same-file call test (negative case) - test: add call-graph-only class test (no import edge) - test: verify all graphology attrs in edge merge sync test
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.
Summary
Fixes #6 —
find_dead_exportshad ~33% false positive rate (2/6). Two root causes:import type {SearchIndex}afterimport {createSearchIndex, ...})registerTools()called withinstartMcpServer()was flagged deadChanges
src/graph/index.tsedges[]array)src/parser/index.tsdeclRelPath !== callerFileguard — include same-file calls incallSitessrc/analyzer/index.tsClassName.method→ClassName)src/analyzer/index.test.tsSemantics change
Verification
Self-analysis after fix:
SearchIndex— NOT flagged dead (was false positive)registerTools— NOT flagged dead (was false positive)tokenize— NOT flagged dead (same-file call bycreateSearchIndex)detectEntryPoints— NOT flagged dead (same-file call bytraceProcesses)Test plan