Skip to content

fix(codegraph): canonicalize target path before workspace-membership check - #440

Merged
getappz merged 1 commit into
masterfrom
task/72
Aug 11, 2026
Merged

fix(codegraph): canonicalize target path before workspace-membership check#440
getappz merged 1 commit into
masterfrom
task/72

Conversation

@getappz

@getappz getappz commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Summary

  • resolve_owner_crate's prefix check compares the candidate file path against manifest_dir from cargo metadata, which cargo returns already canonicalized (symlink-free). The candidate path was never canonicalized the same way, so a genuinely-in-workspace file got rejected as NotInWorkspace whenever the workspace root was reached through a symlink — notably macOS's /var -> /private/var, which is why ci / build (macos-latest) failed on master (29b1031) while ubuntu-latest was unaffected.
  • Fix: canonicalize the candidate path in impact_for_path before the membership check, falling back to the original path when canonicalization fails (nonexistent path, preserving the existing "clear error" test).
  • Added a Unix-portable regression test that reproduces the same canonicalization asymmetry via a real symlink (not literally /var, but the identical mechanism), since the actual macOS bug is invisible on ubuntu-latest CI.

Test plan

  • cargo test --test code_impact_test — all 5 tests pass (verified with the local lean-ctx binary excluded from PATH to match the CI environment; see PR description caveat below)
  • New regression test fails without the fix (confirmed via symlink reproduction on Linux) and passes with it
  • cargo clippy --lib --tests clean on touched files
  • ci / build (macos-latest) goes green on this PR (pending CI run)

Note: one pre-existing, unrelated test-flakiness issue was found and left alone — confirm::search_crate_dir silently misparses lean-ctx grep's sandboxing error as zero hits when the lean-ctx CLI happens to be on PATH and refuses to search outside its own project root. This only affects local dev machines with lean-ctx installed; CI runners don't have that binary and are unaffected.

Summary by CodeRabbit

  • Bug Fixes

    • Improved workspace file recognition when accessed through a symbolic link.
    • Correctly identifies the owning component for files reached via symlinked workspace paths.
    • Added more reliable path handling when resolving workspace locations, including a safe fallback when resolution is unavailable.
  • Tests

    • Added regression coverage for symbolic-link workspace scenarios.
    • Verified that files under symlinked workspace roots are attributed to the correct component.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

impact_for_path now canonicalizes target paths before workspace ownership lookup. If canonicalization fails, it uses the original path. A Unix-only regression test covers files accessed through a symlinked workspace root.

Changes

Workspace path resolution

Layer / File(s) Summary
Canonicalize target paths and verify ownership
Cargo.toml, src/code/mod.rs, tests/code_impact_test.rs
The package adds dunce. impact_for_path canonicalizes target paths and falls back to the original path when needed. A Unix-only test verifies that a symlinked workspace path resolves to the jobs crate.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: canonicalizing the target path before the workspace-membership check.
Description check ✅ Passed The description provides a detailed summary and test results, and it documents the pending macOS CI validation and known edge case.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/72

Comment @coderabbitai help to get the list of available commands.

…heck

impact_for_path's NotInWorkspace check compares a caller-supplied file
path against each crate's manifest_dir from cargo metadata via a plain
prefix match. Both sides can come back in different path
representations for the same real location, so the match silently
fails even when the file is genuinely inside the workspace:

- On macOS, cargo metadata resolves manifest_path through /var's
  symlink to /private/var, but a path built from a caller-supplied
  root (e.g. from tempfile::tempdir()) isn't resolved the same way.
- On GitHub Actions Windows runners, manifest_path can come back with
  an 8.3 short-name path component (RUNNER~1) instead of the long form
  (runneradmin) that a plain-canonicalized caller path resolves to.

Canonicalize both the candidate file (in impact_for_path) and each
crate's manifest_dir (in WorkspaceGraph::from_metadata_json) with
dunce::canonicalize, so they're always compared in the same
representation. dunce (already present transitively via same-file, now
a direct dependency) matches std::fs::canonicalize's symlink/short-name
resolution but skips the \\?\ UNC prefix std adds on Windows, which
would otherwise reintroduce the same mismatch against cargo's
unprefixed paths. Falls back to the original path wherever
canonicalization fails (nonexistent target, synthetic fixture paths in
unit tests), preserving existing behavior there.

Added a Unix-portable regression test that reproduces the macOS
asymmetry via a real symlink, since the actual bug is invisible on
ubuntu-latest CI. The Windows short-name mismatch was found and
confirmed fixed via a temporary diagnostic against the actual CI
runner, since it isn't reproducible outside that environment.

Agentflare-Agent: claude-code
Agentflare-Branch: task/72
Agentflare-Item: 72
@getappz
getappz merged commit 408ad35 into master Aug 11, 2026
24 of 26 checks passed
@getappz
getappz deleted the task/72 branch August 11, 2026 07:40
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