Files
ECC/tests/lib/helpers/symlink-support.js
Brian 434ded9b9d test: drive trySymlink through injected deps instead of patching globals
Review on #3830 pointed out that the helper's tests replaced methods on
the shared fs and console objects, which AGENTS.md rules out, and that
the recording arrays were mutated with push.

trySymlink now takes an optional deps argument in the shape
collectResources already uses, `(deps.symlinkSync || fs.symlinkSync)`,
so the refusal branches can be driven without touching anything shared.
The 13 existing call sites pass at most three arguments and are
unchanged. The recorders rebuild their arrays rather than appending.

Also adds a case that omits deps entirely, so the default dependency is
still covered rather than only the injected one.

Re-verified by mutation: emptying UNSUPPORTED_CODES, returning true
unconditionally, removing the rethrow, dropping the skip notice, and
ignoring the injected stand-in each fail 2 to 4 of the 8 cases.
2026-10-31 13:46:14 -04:00

26 lines
875 B
JavaScript

'use strict';
const fs = require('fs');
const UNSUPPORTED_CODES = new Set(['EPERM', 'EACCES', 'ENOSYS']);
// Creating symlinks needs Developer Mode or admin rights on Windows, and some
// filesystems have no symlink support at all. Returns false (after logging a
// skip notice) when the OS refuses; rethrows anything else.
//
// deps follows the injection shape collectResources already uses, so the
// refusal branches can be driven without replacing methods on the shared fs
// and console objects.
function trySymlink(target, linkPath, type, deps = {}) {
try {
(deps.symlinkSync || fs.symlinkSync)(target, linkPath, type);
return true;
} catch (error) {
if (!UNSUPPORTED_CODES.has(error.code)) throw error;
(deps.log || console.log)(' (symlink unsupported on this platform; skipping)');
return false;
}
}
module.exports = { trySymlink };