diff --git a/changelog.d/fixes/8568-context-manager-data-dir.md b/changelog.d/fixes/8568-context-manager-data-dir.md new file mode 100644 index 0000000000..9d342b5f40 --- /dev/null +++ b/changelog.d/fixes/8568-context-manager-data-dir.md @@ -0,0 +1 @@ +- fix(test): isolate `context-manager` unit tests on a temp `DATA_DIR` so `getTokenLimit` resolves against the registry fallback instead of the developer's local models.dev sync diff --git a/tests/unit/context-manager.test.ts b/tests/unit/context-manager.test.ts index bad89f19ea..776a3cdc25 100644 --- a/tests/unit/context-manager.test.ts +++ b/tests/unit/context-manager.test.ts @@ -1,8 +1,23 @@ import test from "node:test"; import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; + +const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-context-manager-")); +const ORIGINAL_DATA_DIR = process.env.DATA_DIR; +process.env.DATA_DIR = TEST_DATA_DIR; const { compressContext, estimateTokens, getTokenLimit } = await import("../../open-sse/services/contextManager.ts"); +const core = await import("../../src/lib/db/core.ts"); + +test.after(() => { + core.resetDbInstance(); + if (ORIGINAL_DATA_DIR === undefined) delete process.env.DATA_DIR; + else process.env.DATA_DIR = ORIGINAL_DATA_DIR; + fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true }); +}); // ─── estimateTokens ─────────────────────────────────────────────────────────