From fa198c59a42b472409fa43579e9857cc2828cb60 Mon Sep 17 00:00:00 2001 From: haelyra <49814733+haelyra@users.noreply.github.com> Date: Thu, 19 Nov 2026 15:22:51 -0500 Subject: [PATCH] test: secure temporary fixtures without filesystem forwarding wrappers --- tests/hooks/workspace-formatter.test.js | 2 +- tests/lib/claude-settings.test.js | 11 ++--------- tests/lib/eval-harness/replay.test.js | 7 ++++--- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/tests/hooks/workspace-formatter.test.js b/tests/hooks/workspace-formatter.test.js index ee57f3ad8..58819f445 100644 --- a/tests/hooks/workspace-formatter.test.js +++ b/tests/hooks/workspace-formatter.test.js @@ -67,7 +67,7 @@ test('Stop batches files from sibling packages under their shared formatter', () const hook = loadHook('stop-format-typecheck.js', calls); const sessionId = `workspace-format-${process.pid}-${Date.now()}`; const accumulator = path.join(os.tmpdir(), `ecc-edited-${sessionId}.txt`); - fs.writeFileSync(accumulator, files.join('\n') + '\n'); + fs.writeFileSync(accumulator, files.join('\n') + '\n', { flag: 'wx', mode: 0o600 }); try { const input = JSON.stringify({ session_id: sessionId }); assert.strictEqual(hook.run(input), input); diff --git a/tests/lib/claude-settings.test.js b/tests/lib/claude-settings.test.js index ac02ffada..0c9d55399 100644 --- a/tests/lib/claude-settings.test.js +++ b/tests/lib/claude-settings.test.js @@ -401,24 +401,18 @@ function runTests() { if (test('settings snapshots request BigInt stats and reject inodes that collide as Numbers', () => { const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'claude-settings-bigint-identity-')); const settingsPath = path.join(tempDir, 'settings.json'); - const originalOpenSync = fs.openSync; const originalFstatSync = fs.fstatSync; const originalLstatSync = fs.lstatSync; - let settingsDescriptor; let sawBigIntFstat = false; let sawBigIntLstat = false; const descriptorIno = 9007199254740992n; const pathIno = 9007199254740993n; try { fs.writeFileSync(settingsPath, '{"theme":"initial"}\n'); - fs.openSync = function(targetPath, ...args) { - const descriptor = originalOpenSync.call(fs, targetPath, ...args); - if (targetPath === settingsPath) settingsDescriptor = descriptor; - return descriptor; - }; + const settingsIdentity = fs.statSync(settingsPath, { bigint: true }); fs.fstatSync = function(descriptor, options) { const stats = originalFstatSync.call(fs, descriptor, options); - if (descriptor !== settingsDescriptor) return stats; + if (stats.dev !== settingsIdentity.dev || stats.ino !== settingsIdentity.ino) return stats; sawBigIntFstat = options && options.bigint === true; return deriveStats(stats, { ino: typeof stats.ino === 'bigint' ? descriptorIno : Number(descriptorIno), @@ -446,7 +440,6 @@ function runTests() { theme: 'initial', }); } finally { - fs.openSync = originalOpenSync; fs.fstatSync = originalFstatSync; fs.lstatSync = originalLstatSync; fs.rmSync(tempDir, { recursive: true, force: true }); diff --git a/tests/lib/eval-harness/replay.test.js b/tests/lib/eval-harness/replay.test.js index 301ddc0c6..b74b51e5c 100644 --- a/tests/lib/eval-harness/replay.test.js +++ b/tests/lib/eval-harness/replay.test.js @@ -60,9 +60,10 @@ test('an interrupted recording preserves the prior replayable fixture', () => { const store = new replay.FixtureStore(dir); const existing = store.put('read_inventory', { sku: 'x' }, { count: 1 }); const before = fs.readFileSync(store.pathFor(existing.key)); - fs.writeFileSync = (destination, data, options) => { - // Simulate a write that reaches disk only partially before exhausting space. - write(destination, data.slice(0, 10), options); + fs.writeFileSync = (destination, data) => { + // Atomic publication writes through an already-owned descriptor. + assert.strictEqual(typeof destination, 'number'); + fs.writeSync(destination, data.slice(0, 10), undefined, 'utf8'); throw Object.assign(new Error('disk full'), { code: 'ENOSPC' }); }; try {