desloppify icon indicating copy to clipboard operation
desloppify copied to clipboard

orphaned / test_coverage importer_count still doesn't resolve @/ aliases (regression or incomplete fix of #42)

Open pinguinfuss opened this issue 4 months ago • 1 comments

#42 fixed @//~ alias resolution for the test-coverage-mapping code path (_parse_test_imports in detectors/test_coverage.py, via the new _resolve_ts_import, commit 7c871cf). That issue's body claimed the underlying dependency-graph builder (deps.py's ts_alias_resolver) already resolved @/ aliases correctly for orphaned-file detection — but that does not match current behavior. The importer_count field that feeds both the orphaned detector and test_coverage's untested_module/transitive_only classification still returns 0 for files that are exclusively imported via a @/ path alias, even though #42 is closed.

Current behavior

Repo: a TypeScript/Vite React app using the standard @/* → ./src/* path alias (configured in vite.config.ts resolve.alias + tsconfig.json paths), imports written like:

import { Button } from "@/components/ui/button";

desloppify scan on this repo reports:

orphaned::apps/.../src/components/ui/button.tsx
  "Orphaned file (47 LOC): zero importers, not an entry point"

test_coverage::apps/.../src/components/ui/button.tsx::untested_module
  "Untested module (47 LOC, 0 importers)"  (detail.importer_count: 0)

Ground truth:

grep -rl 'from "@/components/ui/button"' src --include="*.tsx" | wc -l
# → 192

192 real importers, all via the @/ alias — importer_count reports 0 in both detectors.

Impact

  • orphaned produces false positives for any file imported exclusively via a path alias — in this repo, 63 of 65 orphaned findings are files that are demonstrably imported (confirmed by grepping actual @/-prefixed import statements), not dead code.
  • test_coverage's untested_module classification is unreliable wherever the import style is alias-based: a file with real coverage gets bucketed as "0 importers, untested" instead of transitive_only (or correctly credited if actually tested), inflating the untested-module count and misdirecting triage priority.
  • In a repo where @/ is the dominant import style (Vite/Next.js/CRA convention), this affects the majority of findings in both detectors — in our case 403 of 489 open test_coverage issues (82%) are in the app that uses the alias, vs. the sibling app in the same monorepo that uses relative imports only and appears unaffected.

Environment

  • desloppify --version → desloppify 1.0
  • Python 3.12.3
  • Project: TypeScript/React (Vite), @/* → ./src/* alias in both tsconfig.json and vite.config.ts

pinguinfuss avatar Jul 21 '26 19:07 pinguinfuss

Another case of this on desloppify 1.0, with a likely root cause.

Repo: Next.js 16, no src/ folder. tsconfig.json:

"paths": { "@/*": ["./*"] }

languages/javascript/test_coverage.py (around line 137) resolves @/x as get_src_path() / "x". get_src_path() (base/discovery/paths.py) is project_root / os.environ.get("DESLOPPIFY_SRC", "src"). So import { f } from "@/lib/foo" in a test is looked up as src/lib/foo, which does not exist, and the test does not count toward lib/foo.ts. The tsconfig paths entry is never read.

Effect: test health read 5.6% on a repo whose tests import nearly every lib file through @/. Running with DESLOPPIFY_SRC=. brought it to 31.3%.

Workaround: export DESLOPPIFY_SRC=. before desloppify scan. Suggested fix: resolve aliases from compilerOptions.paths and baseUrl in tsconfig.json, falling back to src only when no mapping exists.

gigolajulian avatar Nov 10 '26 20:11 gigolajulian