mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-24 08:02:14 +03:00
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:
committed by
GitHub
parent
df9550fce9
commit
d54a659804
1
changelog.d/fixes/8568-context-manager-data-dir.md
Normal file
1
changelog.d/fixes/8568-context-manager-data-dir.md
Normal 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
|
||||||
@@ -1,8 +1,23 @@
|
|||||||
import test from "node:test";
|
import test from "node:test";
|
||||||
import assert from "node:assert/strict";
|
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 } =
|
const { compressContext, estimateTokens, getTokenLimit } =
|
||||||
await import("../../open-sse/services/contextManager.ts");
|
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 ─────────────────────────────────────────────────────────
|
// ─── estimateTokens ─────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user