Skip to content

fix(scanner): traverse symlinked dirs in resolveEncodedProjectPath + add tests - #21

Closed
nandanadileep wants to merge 1 commit into
mcpware:mainfrom
nandanadileep:fix/issue-17-add-tests-resolve-encoded-path
Closed

fix(scanner): traverse symlinked dirs in resolveEncodedProjectPath + add tests#21
nandanadileep wants to merge 1 commit into
mcpware:mainfrom
nandanadileep:fix/issue-17-add-tests-resolve-encoded-path

Conversation

@nandanadileep

Copy link
Copy Markdown

Summary

Fixes the remaining gap in #17 by addressing a secondary bug discovered while writing tests, and adds a dedicated test suite to prevent regressions.

Root causes fixed

Bug 1 — already merged (9588e8a): Greedy resolver couldn't match directory names containing underscores (e.g. My_Projects → encoded as My-Projects). Fixed with DFS + normalization.

Bug 2 — this PR: readdir with withFileTypes: true returns Dirent objects. Dirent.isDirectory() returns false for symlinks even when they point to directories. On macOS /tmp is a symlink to /private/tmp, so the DFS dead-ended at / without ever matching tmp. Any project path under a symlinked directory silently resolved to null.

Fix: Change the filter from e.isDirectory() to e.isDirectory() || e.isSymbolicLink(). The subsequent readdir/exists calls already follow symlinks transparently, so no other changes are needed.

Also exports resolveEncodedProjectPath to enable direct unit testing.

Tests added (tests/unit/test-resolve-encoded-path.mjs)

8 tests covering the exact scenarios from the issue report:

Scenario Covers
Simple flat path Baseline
Nested two-level path Baseline
Non-existent path → null Baseline
Directory name with underscore (My_Projects) Issue #17 case 1
Deep path with underscore mid-level (Parent_Dir) Issue #17 case 1
Directory name with hyphen (my-org) Issue #17 case 2
Mixed underscore + hyphen (core_repos/my-tool) Backtracking
No matching segments → null Backtracking

All 113 unit tests pass.

Test plan

  • node --test tests/unit/test-resolve-encoded-path.mjs — 8/8 pass
  • node --test tests/unit/*.mjs — 113/113 pass
  • Manually verified on macOS where /tmp → /private/tmp reproduces bug 2

Closes #17

…loses #17)

Two changes to resolveEncodedProjectPath:

1. Include symlinks when listing directory candidates.
   readdir withFileTypes returns Dirent objects whose isDirectory() returns
   false for symlinks even when they point to directories. On macOS /tmp is
   a symlink to /private/tmp, so the DFS could never match any path under
   /tmp. Fix: filter with isDirectory() || isSymbolicLink() so the resolver
   descends through symlinked dirs. The subsequent readdir/exists calls
   already follow symlinks transparently.

2. Export the function so it can be unit-tested directly.

Adds tests/unit/test-resolve-encoded-path.mjs with 8 tests covering:
  - Baseline paths (no special characters)
  - Underscore in directory name (encoded same as hyphen — issue #17 case 1)
  - Hyphen in directory name (ambiguous segment boundary — issue #17 case 2)
  - Mixed underscore + hyphen path requiring DFS backtracking
  - Non-existent encoded path → null
@ithiria894

Copy link
Copy Markdown
Member

Thanks for the symlink traversal fix. I ported the bug fix onto the current Claude harness adapter rather than merging this branch directly, since this PR conflicted with the scanner refactor.

Merged replacement: #29

What carried over:

  • encoded project path resolution now traverses symlinked directories
  • added direct regression coverage for symlinked project paths

@ithiria894 ithiria894 closed this Apr 28, 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.

resolveEncodedProjectPath fails when directory names contain underscores or hyphens

2 participants