diff --git a/src/data-state-files.test.ts b/src/data-state-files.test.ts new file mode 100644 index 0000000..d40d1c7 --- /dev/null +++ b/src/data-state-files.test.ts @@ -0,0 +1,43 @@ +import fs from 'fs'; +import os from 'os'; +import path from 'path'; + +import { afterEach, describe, expect, it } from 'vitest'; + +import { listUnexpectedDataStateFiles } from './data-state-files.js'; + +const tempDirs: string[] = []; + +function makeTempDir(): string { + const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ejclaw-data-state-')); + tempDirs.push(tempDir); + return tempDir; +} + +afterEach(() => { + for (const tempDir of tempDirs.splice(0)) { + fs.rmSync(tempDir, { force: true, recursive: true }); + } +}); + +describe('listUnexpectedDataStateFiles', () => { + it('allows known runtime state files', () => { + const dataDir = makeTempDir(); + fs.writeFileSync(path.join(dataDir, 'token-rotation-state.json'), '{}'); + fs.writeFileSync(path.join(dataDir, 'codex-rotation-state.json'), '{}'); + fs.writeFileSync(path.join(dataDir, 'codex-warmup-state.json'), '{}'); + fs.writeFileSync(path.join(dataDir, 'claude-usage-cache.json'), '{}'); + fs.writeFileSync(path.join(dataDir, 'restart-context.abc.json'), '{}'); + + expect(listUnexpectedDataStateFiles(dataDir)).toEqual([]); + }); + + it('reports unsupported legacy state files', () => { + const dataDir = makeTempDir(); + fs.writeFileSync(path.join(dataDir, 'router_state.json'), '{}'); + + expect(listUnexpectedDataStateFiles(dataDir)).toEqual([ + 'router_state.json', + ]); + }); +}); diff --git a/src/data-state-files.ts b/src/data-state-files.ts index 420e416..db6cff1 100644 --- a/src/data-state-files.ts +++ b/src/data-state-files.ts @@ -4,6 +4,7 @@ import path from 'path'; const ALLOWED_DATA_JSON_PATTERNS = [ /^token-rotation-state\.json$/, /^codex-rotation-state\.json$/, + /^codex-warmup-state\.json$/, /^claude-usage-cache\.json$/, /^restart-context\..+\.json$/, ];