fix(server): chokidar fallback watches subfolders (#760) (#2904)#812
Merged
Conversation
* fix(server): chokidar fallback watches subfolders (#760) The file watcher prefers @parcel/watcher and falls back to chokidar whenever that native module can't load (every packaged desktop build today). The fallback's `ignored` predicate misclassified any subdirectory chokidar probed WITHOUT file stats — routing it through the file-only `isExcluded`, which default-excludes any non-`.md`/ non-asset name — so chokidar pruned every content subfolder and silently stopped watching it. External edits to docs in subfolders never reached the server; the graph, backlinks, and dead-link views stayed stale until a restart re-read from disk. Extract the predicate as `isChokidarPathIgnored` and lstat a stats-less path to resolve dir-vs-file before deciding (lstat matches followSymlinks:false); a path that can't be stat'd is admitted, not pruned, so a mid-scan delete still propagates. Add a `forceBackend` test seam to `startWatcher` (mirrors head-watcher) and cover the regression: a subfolder edit, a doc created in a brand-new subfolder after watch start, node_modules staying pruned, plus a predicate stats matrix. * fix(server): await chokidar `ready` so the watcher is live before startWatcher resolves The chokidar backend's live-subfolder tests were flaky on Linux CI — even the root-level control edit was missed. `chokidar.watch()` returns before its initial scan + per-directory inotify registration finish, so an edit made immediately after `startWatcher` resolved landed in the setup window and never fired (macOS FSEvents arms fast enough to hide it locally). Await chokidar's `ready` event before returning, bounded by a 10s cap so a pathological scan can't wedge boot. Also space the new-subfolder test's mkdir and write so the create isn't lost to the inotify addDir→subwatch race. * test(server): sentinel-anchor the node_modules-pruned negative assertion Address PR review: the excluded-subtree test replaced its fixed 600ms sleep with a sentinel edit to a watched file. Waiting for the sentinel to dispatch proves the watcher was live through the window, so the absent node_modules event is a real negative rather than a vacuous pass if the watcher never started. * test(server): anchor the new-subfolder sub-watch on the folder-create event The fixed 200ms sleep guessed at how long chokidar takes to arm a sub-watch on a freshly created directory — too short under load, wasted wall time when not. Waiting for the folder-create DiskEvent is the deterministic signal that the addDir was processed. --------- GitOrigin-RevId: 8b6d1d9bc0fbc9f84ca93d82192ee1dd421dcb73
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Copybara-translated 1 Inkeep OSS change. Rebase-merge this PR so the prepared commit lands directly on public main.