test(context): isolate context-manager suite from local DATA_DIR (#8596)

Pin the unit suite to a temp data directory before imports so getTokenLimit
resolves against the registry fallback instead of a developer models.dev sync.
This commit is contained in:
AmirHossein Rezaei
2026-07-28 01:37:23 +03:30
committed by GitHub
parent df9550fce9
commit d54a659804
2 changed files with 16 additions and 0 deletions

View File

@@ -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

View File

@@ -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 ─────────────────────────────────────────────────────────