test: guard broken-symlink tests so the suite passes on Windows#2176
Conversation
Four test cases create a dangling symlink with fs.symlinkSync() to exercise statSync catch branches, but did not guard for platforms where symlink creation is not permitted. On Windows without Developer Mode / admin rights, fs.symlinkSync throws EPERM, so these tests fail and `npm test` is red: - tests/ci/validators.test.js (Round 73, validate-commands skill entry) - tests/lib/session-manager.test.js (Round 83, getAllSessions) - tests/lib/session-manager.test.js (Round 84, getSessionById) - tests/lib/utils.test.js (Round 84, findFiles) Wrap each symlinkSync in try/catch and skip cleanly on failure, mirroring the existing convention already used in this repo (validators.test.js Round 57 and hooks/config-protection.test.js). On Linux/macOS and admin Windows the symlink still succeeds and the tests run unchanged; only the unsupported-symlink path now skips instead of failing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Too many files changed? Review this PR in Change Stack to see how the pieces fit before you dive in. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThree test files add defensive try/catch around broken-symlink creation: when fs.symlinkSync fails with EPERM/EACCES the tests log a skip message, remove temporary resources, and return early; other symlink errors are rethrown. ChangesTest symlink resilience across test suite
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/ci/validators.test.js`:
- Around line 2580-2590: The current catch around fs.symlinkSync(brokenLink)
swallows all errors; change it to catch the error object (e.g., catch (err)) and
only perform the "(skipped — symlinks not supported)" path
(cleanupTestDir/testDir, cleanupTestDir(agentsDir), fs.rmSync(skillsDir) and
return) when err.code is 'EPERM' or 'EACCES'; for any other err rethrow it so
real failures aren't masked. Reference: the try block calling
fs.symlinkSync('/nonexistent/target/path', brokenLink) and the variables
brokenLink, testDir, agentsDir, skillsDir.
In `@tests/lib/session-manager.test.js`:
- Around line 1387-1395: The try/catch around fs.symlinkSync that currently
skips the test for any thrown error should only swallow known permission-related
errors; update the catch to inspect the thrown error (from fs.symlinkSync when
creating the brokenSymlink in sessionsDir) and only perform the skip path
(console.log and fs.rmSync(isoHome...); return) when error.code is 'EPERM' or
'EACCES'; for any other error rethrow it. Apply the same change to the other
block around fs.symlinkSync (the later block referenced at lines ~1432-1440) so
unexpected failures are not silently ignored.
In `@tests/lib/utils.test.js`:
- Around line 1420-1426: The catch block around symlink creation currently
swallows all errors; change it to catch the error object (e) and only treat
e.code === 'EPERM' or e.code === 'EACCES' as expected permission failures to
skip the test (log the message, clean up tmpDir and return), but rethrow any
other errors so real failures aren't hidden; locate the try/catch around
symlinkSync and tmpDir in tests/lib/utils.test.js and implement this conditional
error handling.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ac05bc03-ed71-43f2-9fa1-90c5d103e16d
📒 Files selected for processing (3)
tests/ci/validators.test.jstests/lib/session-manager.test.jstests/lib/utils.test.js
Address CodeRabbit review: the catch blocks swallowed every error, which could mask a real test/setup failure as a false skip. Inspect err.code and only take the skip path for EPERM/EACCES (symlink creation blocked, e.g. Windows without Developer Mode); rethrow anything else so genuine failures still surface. Per the repo coding guideline: never silently swallow errors. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR. |
|
Thanks for the review! Addressed in 0dc9692 — all four catch blocks now inspect |
…an-m#2176) * test: guard broken-symlink tests so the suite passes on Windows Four test cases create a dangling symlink with fs.symlinkSync() to exercise statSync catch branches, but did not guard for platforms where symlink creation is not permitted. On Windows without Developer Mode / admin rights, fs.symlinkSync throws EPERM, so these tests fail and `npm test` is red: - tests/ci/validators.test.js (Round 73, validate-commands skill entry) - tests/lib/session-manager.test.js (Round 83, getAllSessions) - tests/lib/session-manager.test.js (Round 84, getSessionById) - tests/lib/utils.test.js (Round 84, findFiles) Wrap each symlinkSync in try/catch and skip cleanly on failure, mirroring the existing convention already used in this repo (validators.test.js Round 57 and hooks/config-protection.test.js). On Linux/macOS and admin Windows the symlink still succeeds and the tests run unchanged; only the unsupported-symlink path now skips instead of failing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * test: only skip symlink tests on EPERM/EACCES, rethrow other errors Address CodeRabbit review: the catch blocks swallowed every error, which could mask a real test/setup failure as a false skip. Inspect err.code and only take the skip path for EPERM/EACCES (symlink creation blocked, e.g. Windows without Developer Mode); rethrow anything else so genuine failures still surface. Per the repo coding guideline: never silently swallow errors. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Problem
Four test cases create a dangling symlink with
fs.symlinkSync()(to exercisestatSynccatch branches) without guarding for platforms where symlink creation isn't permitted. On Windows without Developer Mode / admin rights,fs.symlinkSyncthrowsEPERM, so these tests fail andnpm testis red on Windows:tests/ci/validators.test.jstests/lib/session-manager.test.jstests/lib/session-manager.test.jstests/lib/utils.test.jsReproduction (Windows 11, Node 24, non-admin)
Same
EPERMfailure in the session-manager (×2) and utils rounds.Fix
Wrap each
symlinkSyncintry/catchand skip cleanly on failure, mirroring the convention already used in this repo — seetests/ci/validators.test.jsRound 57 andtests/hooks/config-protection.test.js:On Linux/macOS and admin Windows the symlink still succeeds and the tests run exactly as before; only the unsupported-symlink path now skips instead of failing. Test-only change — no runtime/source behavior is affected.
Verification
After the change, on the same Windows machine:
The guarded tests print
(skipped — symlinks not supported).npx eslinton the three files andscripts/ci/check-unicode-safety.jsboth pass.Notes / out of scope
tests/scripts/trae-install.test.jsalso usessymlinkSync, but that file is already skipped wholesale on Windows ("Trae shell scripts are Unix-only"), so it does not fail — intentionally left untouched.tests/integration/hooks.test.jsand a slowtests/lib/agent-compress.test.js.🤖 Generated with Claude Code
Summary by cubic
Guarded dangling-symlink tests so the suite passes on Windows where symlink creation needs admin/Developer Mode. When
fs.symlinkSyncthrowsEPERM/EACCES, tests skip and clean up; other errors rethrow to avoid masking real failures.fs.symlinkSyncin try/catch intests/ci/validators.test.js,tests/lib/session-manager.test.js(×2), andtests/lib/utils.test.js; onEPERM/EACCESlog skip, clean up, and return; otherwise rethrow.Written for commit 0dc9692. Summary will update on new commits.
Summary by CodeRabbit