fix(import): guard file collection against symlink cycles (#358)#361
Merged
Conversation
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.
Closes #358
Summary
Prevent
collectFiles()from re-entering directory symlinks that resolve to a directory already active in the current traversal, eliminating hangs and stack/path overflows during import conflict comparison, diff rendering, and mtime scans.Approach
Selected Option 2 — balanced cycle-safe traversal. Resolve each directory to its canonical realpath, track canonical paths active in the current recursion chain, and skip recursive re-entry. Remove paths after their subtree completes so distinct non-cyclic symlink aliases remain independently visible to file comparison.
Decision Record
collectFiles()followed directory symlinks throughstat()and recursively calledwalk()without tracking canonical directories. A self- or ancestor-referential link repeatedly re-entered the same directory until filesystem path limits or resource exhaustion interrupted the import operation.npx vitest run src/import-skills.test.ts -t "terminates when identical trees contain self-referential symlinks" --testTimeout=5000confirmed red for the stated reason (expected false to be true) → regression testsrc/import-skills.test.tsnow passes.Analyzed at:
fix/358-guard-collectfiles-symlink-cycles @ b6f715c(2026-07-11)Changes
src/importer.tscollectFiles()recursion, skip cyclic re-entry, and preserve traversal through completed non-cyclic aliases.src/import-skills.test.tsTest Results
npm test)npx vitest run tests/e2e/node-e2e.test.ts)npm run typecheck)npm run buildand pre-push hook)Acceptance Criteria Verification
npx vitest run src/import-skills.test.ts -t "terminates when identical trees contain self-referential symlinks" --testTimeout=5000→ fixed →src/import-skills.test.tsregression test passes.compares each non-cyclic symlink path when targets are sharedtest verifies completed aliases remain traversable.src/import-skills.test.tscreates self-links through the cross-platformcreateDirSymlink()helper and confirms identical cyclic trees terminate and compare equal.