fix(eval-harness): preserve fixtures when recording fails

This commit is contained in:
Rudy Celekli committed 2026-11-18 00:55:35 -05:00
1 parent 3f14a103a8
commit f4261bd83c
2 files changed
+27 -1

No files matched your search

+2 -1
View File
@@ -18,6 +18,7 @@
const fs = require('fs');
const path = require('path');
const { writeFileAtomic } = require('../atomic-write');
const { canonicalJson, hashValue } = require('./canonical');
const envelope = require('./envelope');
@@ -57,7 +58,7 @@ class FixtureStore {
response_hash: hashValue(response),
response,
};
fs.writeFileSync(this.pathFor(key), canonicalJson(record) + '\n', 'utf8');
writeFileAtomic(this.pathFor(key), canonicalJson(record) + '\n');
return record;
}
+25
View File
@@ -53,6 +53,31 @@ test('replay mode never calls the implementation and fails closed on a missing f
}
});
test('an interrupted recording preserves the prior replayable fixture', () => {
const dir = tempDir('interrupted-record');
const write = fs.writeFileSync;
try {
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);
throw Object.assign(new Error('disk full'), { code: 'ENOSPC' });
};
try {
assert.throws(() => store.put('read_inventory', { sku: 'x' }, { count: 2 }), { code: 'ENOSPC' });
} finally {
fs.writeFileSync = write;
}
assert.deepStrictEqual(fs.readFileSync(store.pathFor(existing.key)), before);
assert.deepStrictEqual(store.get('read_inventory', { sku: 'x' }).response, { count: 1 });
assert.deepStrictEqual(fs.readdirSync(dir), [existing.key + '.json']);
} finally {
cleanup(dir);
}
});
test('a hash-mismatched or corrupt fixture fails closed', () => {
const dir = tempDir('mismatch');
try {