Skip to content

fix: preserve import graph edges for relative file paths - #895

Closed
Mgldvd wants to merge 1 commit into
peteromallet:mainfrom
Mgldvd:fix/relative-import-graph
Closed

Mgldvd wants to merge 1 commit into
peteromallet:mainfrom
Mgldvd:fix/relative-import-graph

Conversation

@Mgldvd

@Mgldvd Mgldvd commented Oct 26, 2026

Copy link
Copy Markdown

Tree-sitter dependency graphs drop every internal edge when a file finder returns project-relative paths. A JavaScript scan therefore reports imported modules as orphaned and loses coverage propagation: the same nine-module project had zero edges before this fix and 27 afterward.

Canonicalize file paths for matching while preserving the caller's graph keys and edge representation. Pass an absolute source path to import resolvers so scans rooted in a subdirectory do not duplicate the relative path prefix. Regression tests cover relative and absolute file lists with both project-root and nested scan paths.

Validation: 13 focused import tests pass; Ruff and diff checks pass. The full desloppify/tests/ suite reports 5,812 passed, 5 skipped, and two existing failures of the shared review dry-run prompt assertion (Previously flagged issues); the same assertion fails with the original graph module restored. Tested using Python 3.12 and tree-sitter-language-pack 1.6.2. Verified the corrected graph against the original JavaScript project.

Copilot AI balanced review requested due to automatic review settings October 26, 2026 16:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Dereferencing symlinked source paths changes source-relative include lookup and can drop valid dependency edges.

1 open issue
What changed in this PR

This PR restores internal dependency edges when tree-sitter scans receive project-relative file paths, preserving caller-provided graph keys for downstream analysis.

Changes:

  • Canonicalizes paths when matching resolved imports to scanned files.
  • Passes absolute source paths to import resolvers.
  • Adds regression coverage for relative and absolute file lists with project-root and nested scans.
File Description
desloppify/​tests/​lang/​common/​test_treesitter_relative_graph.py Tests graph keys, dependency edges, and counts across four path combinations.
desloppify/​languages/​_framework/​treesitter/​imports/​graph.py Normalizes import matching while retaining original graph keys.

Review effort: Balanced


resolved = spec.resolve_import(import_text, filepath, scan_path)
resolved = spec.resolve_import(
import_text, str(Path(filepath).resolve()), scan_path
github-actions Bot added a commit to citizenadam/desloppify that referenced this pull request Oct 26, 2026
@Mgldvd Mgldvd closed this Oct 26, 2026
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.

2 participants