mirror of
https://github.com/affaan-m/ECC.git
synced 2026-11-23 00:05:27 +00:00
test: secure temporary fixtures without filesystem forwarding wrappers
This commit is contained in:
3 files changed
+7
-13
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user