Skip to content

Fix skipOnWinForEPERM: check ret.stderr, not ret.code, for EPERM - #1272

Open
hikmetba-bit wants to merge 1 commit into
shelljs:mainfrom
hikmetba-bit:fix/skipOnWinForEPERM-check-stderr
Open

hikmetba-bit wants to merge 1 commit into
shelljs:mainfrom
hikmetba-bit:fix/skipOnWinForEPERM-check-stderr

Conversation

@hikmetba-bit

Copy link
Copy Markdown

Summary

Fixes #867.

skipOnWinForEPERM tests /EPERM:/ against ret.code, but ret.code is just the numeric exit code (e.g. 1); the actual error message text ("EPERM: operation not permitted, symlink ...") is on ret.stderr (see ShellString in src/common.js: that.stderr = stderr; that.code = code;). The regex against a number can never match, so on a non-admin Windows machine (where creating a symlink raises EPERM) the helper never detects it and falls through to run testCase() anyway, against a symlink that was never created — exactly the class of local Windows test failures reported in the issue.

Reproduced live on this Windows machine:

const ret = shell.ln('-s', 'file1.txt', 'linkfile2');
ret.code   // 1
ret.stderr // "ln: EPERM: operation not permitted, symlink 'file1.txt' -> '...'"
/EPERM:/.test(ret.code)   // false (buggy check)
/EPERM:/.test(ret.stderr) // true  (correct check)

Second bug this surfaces

Once skipOnWinForEPERM actually detects EPERM and skips testCase(), the test runs zero assertions — which AVA treats as a failure (Test finished without running any assertions). This was never observable before, since the detection never worked.

Gave skipOnWinForEPERM the test's t so it can call t.pass() on the skip path, and updated all 7 call sites (test/ln.js ×4, test/cp.js ×3) to pass it.

Testing

  • Reproduced the exact bug live on this (non-admin) Windows machine, as shown above.
  • Mutation check: reverted just the ret.code → ret.stderr line and confirmed test/ln.js fails with the same real assertion failures the issue reports (Value is not truthy: false on fs.existsSync(...)), not just a skip.
  • With the full fix: npx ava test/ln.js test/cp.js — all pass, with Got EPERM when testing symlinks on Windows. Assuming non-admin environment and skipping test. printed and the test correctly marked passed (not "0 assertions" failed).
  • Full suite npx ava: 1 pre-existing, unrelated failure (find › -L flag, folder is symlinked — a checked-in symlink test fixture that isn't a real symlink after a Windows git checkout; reproduced identically on unmodified main), everything else green.
  • npx eslint on the changed files: clean.

🤖 Generated with Claude Code

skipOnWinForEPERM tests /EPERM:/ against ret.code, but ret.code is
just the numeric exit code (e.g. 1); the actual error message text
("EPERM: operation not permitted, symlink ...") is on ret.stderr (see
ShellString in src/common.js). The regex against a number can never
match, so on a non-admin Windows machine (where creating a symlink
raises EPERM) the helper never detects it and falls through to run
testCase() anyway, against a symlink that was never created -- exactly
the class of local Windows test failures reported in shelljs#867.

Reproduced live on this Windows machine: shell.ln('-s', ...) fails
with EPERM as expected, ret.code is 1 (never matches), ret.stderr
contains the full "EPERM: ..." message.

Fixing the check surfaces a second, previously-unobservable bug: once
skipOnWinForEPERM actually skips testCase(), the test runs zero
assertions, which AVA treats as a failure. Give skipOnWinForEPERM the
test's `t` so it can call t.pass() on the skip path, and update all 7
call sites (test/ln.js, test/cp.js) to pass it.

Fixes shelljs#867.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Comment thread test/utils/utils.js
function skipOnWinForEPERM(action, t, testCase) {
const ret = action();
const error = ret.code;
// ret.code is the numeric exit code; the EPERM message text is on

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can remove this comment. I think the commit message is the better place to document this since it's about comparing the before/after effect of your PR.

@nfischer nfischer added the test label Oct 4, 2026
@codecov

codecov Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.10%. Comparing base (f364da6) to head (6e708fb).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1272   +/-   ##
=======================================
  Coverage   97.10%   97.10%           
=======================================
  Files          36       36           
  Lines        1518     1518           
=======================================
  Hits         1474     1474           
  Misses         44       44           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows test failures on local machine

2 participants