test: make directory identity mocks safe for Windows inodes

This commit is contained in:
Affaan Mustafa committed 2026-09-15 14:21:57 -04:00
1 parent 563e70ab92
commit 37f2bbf6c9
1 file changed
+15 -1
+15 -1
View File
@@ -34,10 +34,24 @@ function mockEnumeration(context, entriesFor) {
function changedIdentity(stats) {
const changed = Object.assign(Object.create(Object.getPrototypeOf(stats)), stats);
changed.ino = typeof stats.ino === 'bigint' ? stats.ino + 1n : stats.ino + 1;
// Windows inode numbers can exceed safe integer precision, so adding 1 may be a no-op.
const zero = typeof stats.ino === 'bigint' ? 0n : 0;
const one = typeof stats.ino === 'bigint' ? 1n : 1;
changed.ino = stats.ino === zero ? one : zero;
return changed;
}
test('identity mock changes inode values beyond safe integer precision', () => {
for (const ino of [0, 1, 2 ** 60, 0n, 1n, 2n ** 60n]) {
const stats = { ino, dev: 1, mode: 16877 };
const changed = changedIdentity(stats);
assert.notEqual(changed.ino, stats.ino);
assert.equal(typeof changed.ino, typeof stats.ino);
assert.equal(changed.dev, stats.dev);
assert.equal(changed.mode, stats.mode);
}
});
function samePath(left, right) {
const normalize = value => path.resolve(value).toLowerCase();
return normalize(left) === normalize(right);