Skip to content

fix(watcher): auto-sync changes inside symlinked directories (#770)#784

Open
dengzhongyuan365-dev wants to merge 1 commit into
colbymchenry:mainfrom
dengzhongyuan365-dev:fix/issue-770-auto-sync-symbolic-links
Open

fix(watcher): auto-sync changes inside symlinked directories (#770)#784
dengzhongyuan365-dev wants to merge 1 commit into
colbymchenry:mainfrom
dengzhongyuan365-dev:fix/issue-770-auto-sync-symbolic-links

Conversation

@dengzhongyuan365-dev

Copy link
Copy Markdown

Summary

  • Fixes auto-sync for files inside symlinked directories — the file watcher (Linux inotify strategy) now follows directory symlinks when building its watch set
  • Adds symlink cycle detection using a visitedRealDirs Set, matching the indexer's existing pattern
  • Adjusts validatePathWithinRoot() to allow watcher-sourced paths through without rejecting symlinked targets outside the lexical root

Changes

File Change
src/sync/watcher.ts watchTree() now detects isSymbolicLink() entries, resolves real targets, and recursively watches directory symlinks
src/utils.ts Added allowSymlinkedDirs parameter to validatePathWithinRoot() — skips realpath check when true
src/extraction/index.ts All internal sync/index paths now pass allowSymlinkedDirs: true
__tests__/watcher.test.ts Added end-to-end integration test for symlinked directory auto-sync

Test Plan

  • All 1349 existing tests pass
  • New integration test verifies real fs.watch picks up changes inside a symlinked directory
  • Symlink cycle detection prevents infinite recursion

Fixes #770

@dengzhongyuan365-dev dengzhongyuan365-dev marked this pull request as ready for review June 11, 2026 03:39
…henry#770)

The file watcher (Linux inotify strategy) did not follow directory
symlinks when building its watch set, so a project dir symlinked into
the workspace root was silently invisible to the watcher.

Changes:

1. watcher.ts: watchTree() now detects isSymbolicLink() entries,
   resolves real targets with realpathSync(), and recursively watches
   directory symlinks. Guards against cycles with a visitedRealDirs Set
   — tracking regular dirs too so a symlink→already-visited-path is
   also detected. Mirrors the indexer's walk() in extraction/index.ts.

2. utils.ts: Added allowSymlinkedDirs parameter to validatePathWithinRoot().
   When true, skips the realpath check that would reject watched symlinks
   whose targets live outside the lexical project root. All internal
   sync/index paths pass true here; user-facing paths (MCP layer) keep
   the existing strict validation.

3. extraction/index.ts: All internal sync/index paths now pass
   allowSymlinkedDirs: true so the watcher can read files from
   symlinked directories.

4. __tests__/watcher.test.ts: Added integration test for symlinked
   directory auto-sync, plus a symlink-cycle detection test.

Signed-off-by: dengzhongyuan <dengzhongyuan@uniontech.com>
@dengzhongyuan365-dev dengzhongyuan365-dev force-pushed the fix/issue-770-auto-sync-symbolic-links branch from 4557ab8 to fa7ab38 Compare June 11, 2026 04:10
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.

Unable to auto sync symbol link file changes

1 participant