Skip to content

test: guard broken-symlink tests so the suite passes on Windows#2176

Merged
affaan-m merged 2 commits into
affaan-m:mainfrom
JOhnsonKC201:test/guard-windows-symlink-tests
Jun 7, 2026
Merged

test: guard broken-symlink tests so the suite passes on Windows#2176
affaan-m merged 2 commits into
affaan-m:mainfrom
JOhnsonKC201:test/guard-windows-symlink-tests

Conversation

@JOhnsonKC201

@JOhnsonKC201 JOhnsonKC201 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Problem

Four test cases create a dangling symlink with fs.symlinkSync() (to exercise statSync catch branches) without guarding for platforms where symlink creation isn't permitted. On Windows without Developer Mode / admin rights, fs.symlinkSync throws EPERM, so these tests fail and npm test is red on Windows:

File Round Test
tests/ci/validators.test.js 73 skips unreadable skill directory entries (broken symlink)
tests/lib/session-manager.test.js 83 getAllSessions skips broken symlink .tmp files gracefully
tests/lib/session-manager.test.js 84 getSessionById returns null when matching session is a broken symlink
tests/lib/utils.test.js 84 findFiles skips broken symlinks that match the pattern

Reproduction (Windows 11, Node 24, non-admin)

$ node tests/ci/validators.test.js
  ✗ skips unreadable skill directory entries without error (broken symlink)
    Error: EPERM: operation not permitted, symlink 'C:\nonexistent\target\path' -> '...\broken-skill'
  Results: Passed: 164, Failed: 1

Same EPERM failure in the session-manager (×2) and utils rounds.

Fix

Wrap each symlinkSync in try/catch and skip cleanly on failure, mirroring the convention already used in this repo — see tests/ci/validators.test.js Round 57 and tests/hooks/config-protection.test.js:

try {
  fs.symlinkSync('/nonexistent/...', linkPath);
} catch {
  // Skip on systems that don't support symlinks (e.g. Windows without
  // Developer Mode / admin rights, where symlinkSync throws EPERM).
  console.log('    (skipped — symlinks not supported)');
  /* clean up temp dirs */ return;
}

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:

tests/ci/validators.test.js        Results: Passed: 165, Failed: 0   (was 164/1)
tests/lib/session-manager.test.js  Results: Passed: 169, Failed: 0   (was 167/2)
tests/lib/utils.test.js            Failed: 0                         (was 1)

The guarded tests print (skipped — symlinks not supported). npx eslint on the three files and scripts/ci/check-unicode-safety.js both pass.

Notes / out of scope

  • tests/scripts/trae-install.test.js also uses symlinkSync, but that file is already skipped wholesale on Windows ("Trae shell scripts are Unix-only"), so it does not fail — intentionally left untouched.
  • Separately observed on Windows (not addressed here, possible follow-ups): a timeout-enforcement test in tests/integration/hooks.test.js and a slow tests/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.symlinkSync throws EPERM/EACCES, tests skip and clean up; other errors rethrow to avoid masking real failures.

  • Bug Fixes
    • Wrapped fs.symlinkSync in try/catch in tests/ci/validators.test.js, tests/lib/session-manager.test.js (×2), and tests/lib/utils.test.js; on EPERM/EACCES log skip, clean up, and return; otherwise rethrow.
    • No source/runtime changes; behavior unchanged on systems where symlinks work.

Written for commit 0dc9692. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Tests
    • Improved test resilience on systems where creating symlinks is restricted. Tests that attempt to create broken symlinks now catch unsupported errors, log a skip, clean up temporary test artifacts, and return early instead of failing. When symlink creation succeeds, original assertions still run—improving cross-platform reliability of the test suite.

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>
@JOhnsonKC201 JOhnsonKC201 requested a review from affaan-m as a code owner June 6, 2026 05:15
@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Too many files changed? Review this PR in Change Stack to see how the pieces fit before you dive in.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2f1fc265-0af8-4963-8c3f-de87f731ee9d

📥 Commits

Reviewing files that changed from the base of the PR and between 9e51371 and 0dc9692.

📒 Files selected for processing (3)
  • tests/ci/validators.test.js
  • tests/lib/session-manager.test.js
  • tests/lib/utils.test.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/lib/utils.test.js

📝 Walkthrough

Walkthrough

Three 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.

Changes

Test symlink resilience across test suite

Layer / File(s) Summary
Wrap symlink creation in try/catch for resilience
tests/ci/validators.test.js, tests/lib/session-manager.test.js, tests/lib/utils.test.js
Four broken-symlink tests (Round 73 in validators.test.js, Round 83 and 84 in session-manager.test.js, and Round 84 in utils.test.js) now guard fs.symlinkSync with try/catch; on EPERM/EACCES they log a skip, clean temporary directories, and return early; other errors are rethrown.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I wrapped the symlinks safe and warm,
So tests won't tumble in a storm,
If Windows frowns and perms deny,
We tidy up and wave goodbye,
Hops of joy — the suite stays calm and warm.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: guarding broken-symlink tests so the test suite passes on Windows, which directly matches the PR's primary objective.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7113b5b and 9e51371.

📒 Files selected for processing (3)
  • tests/ci/validators.test.js
  • tests/lib/session-manager.test.js
  • tests/lib/utils.test.js

Comment thread tests/ci/validators.test.js
Comment thread tests/lib/session-manager.test.js
Comment thread tests/lib/utils.test.js Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

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-tools

ecc-tools Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

@JOhnsonKC201

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Addressed in 0dc9692 — all four catch blocks now inspect err.code and only take the skip path on EPERM/EACCES (symlink creation blocked, e.g. Windows without Developer Mode), rethrowing any other error so genuine failures aren't masked. Re-verified on Windows: the four tests skip cleanly, suites report Failed: 0, and eslint passes on the three files.

@affaan-m affaan-m merged commit 40673a8 into affaan-m:main Jun 7, 2026
3 checks passed
syarfandi pushed a commit to syarfandi/ECC that referenced this pull request Jun 9, 2026
…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>
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.

2 participants