mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-06 23:32:12 +03:00
Validated in local merge-train (devbox-vm-06-dev002) @ combined-tip (FAST gates: typecheck/complexity/cognitive/changelog/vitest — only pre-existing audit.test.ts flake). Evidence: /home/diegosouzapw/dev/proxys/OmniRoute/.claude/worktrees/merge-train-20260805-222248-suite.log
41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { estimateFinalInputTokens } from "../../open-sse/handlers/chatCore/contextEstimation.ts";
|
|
import { estimateTokens } from "../../open-sse/services/contextManager.ts";
|
|
|
|
test("estimateFinalInputTokens counts nested request contents and auxiliary fields", () => {
|
|
const contents = [{ role: "user", parts: [{ text: "nested Gemini request" }] }];
|
|
const tools = [{ name: "lookup", description: "find a record" }];
|
|
const body = {
|
|
request: { contents },
|
|
tools,
|
|
system: "system prompt",
|
|
instructions: 42,
|
|
};
|
|
|
|
assert.equal(
|
|
estimateFinalInputTokens(body),
|
|
estimateTokens(contents) +
|
|
estimateTokens(tools) +
|
|
estimateTokens(body.system) +
|
|
estimateTokens(body.instructions)
|
|
);
|
|
});
|
|
|
|
test("estimateFinalInputTokens ignores a malformed nested request and uses input", () => {
|
|
const input = [{ role: "user", content: "fallback input" }];
|
|
const body = {
|
|
request: "not an object",
|
|
input,
|
|
};
|
|
|
|
assert.equal(estimateFinalInputTokens(body), estimateTokens(input));
|
|
});
|
|
|
|
test("estimateTokens accepts the unknown JSON values it already serializes", () => {
|
|
assert.equal(estimateTokens(true), 1);
|
|
assert.equal(estimateTokens(42), 1);
|
|
assert.equal(estimateTokens(undefined), 0);
|
|
});
|