-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Bug
When using codegraph roles --role dead -T, symbols whose only callers are in test files get classified as dead because -T (exclude tests) removes all their incoming edges, resulting in fanIn === 0.
The classifyRoles function in src/graph/classifiers/roles.js (line 46-49) uses this logic:
if (node.fanIn === 0 && !node.isExported) {
role = 'dead';
} else if (node.fanIn === 0 && node.isExported) {
role = 'entry';
}So an exported symbol with 0 fan-in (after test exclusion) is classified as entry, not dead. This part is correct.
However, non-exported symbols that are only called from tests get classified as dead when -T is used — even if they serve an important internal role. For example, a helper function used extensively in test infrastructure but not in production code would be flagged as dead.
Expected Behavior
The -T flag should exclude test files from output/display, but the fan-in calculation for role classification should still account for test-file edges (or at minimum, the dead role should note that the symbol has test-only callers rather than zero callers).
Current Behavior
-T filters test files from the graph edges before classification, so test-only-called symbols appear to have fanIn === 0 and are classified as dead.
Suggested Approach
Consider one of:
- Compute fan-in on the full graph, then apply
-Tfiltering only to the output - Add a distinct role like
test-onlyfor symbols that have callers exclusively in test files - Annotate
deadresults with a flag indicating whether test-file callers exist