Claude API
This commit is contained in:
41
test/InputWS.logDir.test.js
Normal file
41
test/InputWS.logDir.test.js
Normal file
@@ -0,0 +1,41 @@
|
||||
const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const initInputWS = require('../server/InputWS');
|
||||
|
||||
// Bug 4: logs/ directory must be ensured so the first appendFileSync() call
|
||||
// cannot crash on a fresh container/checkout.
|
||||
describe('InputWS.ensureLogDir', () => {
|
||||
function tmpPath() {
|
||||
return path.join(os.tmpdir(), `inputws-logtest-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
||||
}
|
||||
|
||||
test('creates a missing log directory', () => {
|
||||
const dir = tmpPath();
|
||||
expect(fs.existsSync(dir)).toBe(false);
|
||||
|
||||
initInputWS.ensureLogDir(dir);
|
||||
|
||||
expect(fs.existsSync(dir)).toBe(true);
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('creates nested directories recursively', () => {
|
||||
const base = tmpPath();
|
||||
const nested = path.join(base, 'a', 'b', 'logs');
|
||||
|
||||
initInputWS.ensureLogDir(nested);
|
||||
|
||||
expect(fs.existsSync(nested)).toBe(true);
|
||||
fs.rmSync(base, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
test('is idempotent when the directory already exists', () => {
|
||||
const dir = tmpPath();
|
||||
fs.mkdirSync(dir, { recursive: true });
|
||||
|
||||
expect(() => initInputWS.ensureLogDir(dir)).not.toThrow();
|
||||
expect(fs.existsSync(dir)).toBe(true);
|
||||
fs.rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user