Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/quality/eslint-suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2033,7 +2033,7 @@
},
"tests/integration/chatcore-compression-integration.test.ts": {
"@typescript-eslint/no-explicit-any": {
"count": 9
"count": 8
},
"@typescript-eslint/no-unused-vars": {
"count": 4
Expand Down
2 changes: 1 addition & 1 deletion config/quality/file-size-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@
"_rebaseline_2026_09_04_12737_codex_ws_premature_close_tests": "PR #12737 own test growth: executor-codex.test.ts 1465->1620 (+155, entirely this PR's diff — regression coverage for the premature WebSocket close fix: emits terminal response.failed with code upstream_websocket_closed when the socket closes before any terminal event, and proves no second terminal event fires after a normal post-response.completed close).",
"_rebaseline_pr4613_compatible_provider_groups": "Reconcile #4613 already-merged growth: providers-page-utils.test.ts 1004->1052 (+48, buildCompatibleProviderGroups partition unit test). Fast-gate PR->release does not run check:file-size, so this surfaced post-merge.",
"tests/integration/chat-pipeline.test.ts": 1756,
"tests/integration/chatcore-compression-integration.test.ts": 1214,
"tests/integration/chatcore-compression-integration.test.ts": 1145,
"tests/unit/account-fallback-service.test.ts": 2086,
"tests/unit/batch_api.test.ts": 1353,
"tests/unit/cc-compatible-provider.test.ts": 1225,
Expand Down
103 changes: 17 additions & 86 deletions tests/integration/chatcore-compression-integration.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
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";
import { createTempDataDir } from "../_setup/tempDataDir.ts";

const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-compression-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const { dir: TEST_DATA_DIR, cleanup } = createTempDataDir("omniroute-compression-");
process.env.REQUIRE_API_KEY = "false";
process.env.API_KEY_SECRET = process.env.API_KEY_SECRET || "test-compression-secret";

Expand All @@ -19,6 +17,7 @@ const compressionAnalyticsDb = await import("../../src/lib/db/compressionAnalyti
const { handleChatCore } = await import("../../open-sse/handlers/chatCore.ts");
const { estimateTokens, getTokenLimit } = await import("../../open-sse/services/contextManager.ts");
const { resetAllCircuitBreakers } = await import("../../src/shared/utils/circuitBreaker.ts");
const { waitForCallLogSaves, closeCallLogSaves } = await import("../../src/lib/usage/callLogs.ts");

const originalFetch = globalThis.fetch;

Expand All @@ -27,6 +26,8 @@ async function resetStorage() {
resetAllCircuitBreakers();
readCacheDb.invalidateDbCache();
await new Promise((resolve) => setTimeout(resolve, 20));
// The previous test's call log is saved in the background; it must land before the reset.
assert.ok(await waitForCallLogSaves(30_000), "the previous test's call-log saves should finish");
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
Expand All @@ -38,10 +39,10 @@ test.beforeEach(async () => {

test.after(async () => {
globalThis.fetch = originalFetch;
core.closeDbInstance();
try {
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
} catch {}
// Drain the last test's in-flight save, then stop the writer before the database closes.
assert.ok(await waitForCallLogSaves(30_000), "the last test's call-log save should finish");
await closeCallLogSaves(2_000);
await cleanup();
});

test("chatCore integration: compressContext called proactively when context exceeds 85% threshold", async () => {
Expand Down Expand Up @@ -612,11 +613,11 @@ test("chatCore integration: assigned compression combo applies language packs an
},
languageConfig: {
enabled: true,
// autoDetect would read the (English) user turn and resolve back to "en",
// so the pack under test has to be pinned explicitly.
// autoDetect is disabled here, so the detector never runs. With the global default
// language "en", pt-BR output can only come from the combo's language packs.
autoDetect: false,
defaultLanguage: "pt-BR",
enabledPacks: ["pt-BR"],
defaultLanguage: "en",
enabledPacks: ["en"],
},
});

Expand Down Expand Up @@ -724,11 +725,11 @@ test("chatCore integration: default stacked compression combo applies for unassi
},
languageConfig: {
enabled: true,
// autoDetect would read the (English) user turn and resolve back to "en",
// so the pack under test has to be pinned explicitly.
// autoDetect is disabled here, so the detector never runs. With the global default
// language "en", pt-BR output can only come from the combo's language packs.
autoDetect: false,
defaultLanguage: "pt-BR",
enabledPacks: ["pt-BR"],
defaultLanguage: "en",
enabledPacks: ["en"],
},
});

Expand Down Expand Up @@ -983,76 +984,6 @@ test("chatCore integration: modular compression records analytics row best-effor
}
});

test("chatCore integration: caveman output mode skipped when compression is globally disabled", async () => {
const provider = "openai";
const model = "gpt-4";

await compressionDb.updateCompressionSettings({
enabled: false,
defaultMode: "off",
autoTriggerTokens: 0,
cavemanOutputMode: {
enabled: true,
intensity: "full",
autoClarity: true,
},
});

const connection = await providersDb.createProviderConnection({
provider,
apiKey: "test-key",
isActive: true,
});

let capturedBody: any = null;
globalThis.fetch = async (_url: string | URL | Request, init?: RequestInit) => {
if (init?.body) {
capturedBody = JSON.parse(init.body as string);
}
return new Response(
JSON.stringify({
choices: [{ message: { role: "assistant", content: "ok" } }],
usage: { prompt_tokens: 20, completion_tokens: 4, total_tokens: 24 },
}),
{
status: 200,
headers: { "content-type": "application/json" },
}
);
};

try {
const result = await handleChatCore({
body: {
model,
stream: false,
messages: [{ role: "user", content: "Summarize this implementation." }],
},
modelInfo: { provider, model },
credentials: { apiKey: "test-key" },
log: { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} },
clientRawRequest: { endpoint: "/v1/chat/completions", headers: new Map() },
connectionId: connection.id,
onCredentialsRefreshed: () => {},
onRequestSuccess: () => {},
onStreamFailure: () => {},
onDisconnect: () => {},
userAgent: "test-agent",
comboName: null,
});

assert.ok(result.success, "Request should succeed");
assert.equal(
capturedBody.messages[0].role,
"user",
"No system message should be injected when compression is disabled"
);
assert.doesNotMatch(capturedBody.messages[0].content ?? "", /Output Styles/);
} finally {
globalThis.fetch = originalFetch;
}
});

test("chatCore integration: caveman output mode injected when both compression and output mode are enabled", async () => {
const provider = "openai";
const model = "gpt-4";
Expand Down
74 changes: 55 additions & 19 deletions tests/integration/test-model-compression-off-6240.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
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";
import { createTempDataDir } from "../_setup/tempDataDir.ts";

const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-testmodel-compression-"));
process.env.DATA_DIR = TEST_DATA_DIR;
const { dir: TEST_DATA_DIR, cleanup } = createTempDataDir("omniroute-testmodel-compression-");
process.env.REQUIRE_API_KEY = "false";
process.env.API_KEY_SECRET = process.env.API_KEY_SECRET || "test-testmodel-compression-secret";

Expand All @@ -28,6 +26,9 @@ const readCacheDb = await import("../../src/lib/db/readCache.ts");
const compressionDb = await import("../../src/lib/db/compression.ts");
const { handleChatCore } = await import("../../open-sse/handlers/chatCore.ts");
const { resetAllCircuitBreakers } = await import("../../src/shared/utils/circuitBreaker.ts");
const { OUTPUT_STYLE_MARKER } =
await import("../../open-sse/services/compression/outputStyles/apply.ts");
const { waitForCallLogSaves, closeCallLogSaves } = await import("../../src/lib/usage/callLogs.ts");

const originalFetch = globalThis.fetch;

Expand All @@ -36,6 +37,8 @@ async function resetStorage() {
resetAllCircuitBreakers();
readCacheDb.invalidateDbCache();
await new Promise((resolve) => setTimeout(resolve, 20));
// The previous test's call log is saved in the background; it must land before the reset.
assert.ok(await waitForCallLogSaves(30_000), "the previous test's call-log saves should finish");
core.resetDbInstance();
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
Expand All @@ -47,12 +50,11 @@ test.beforeEach(async () => {

test.after(async () => {
globalThis.fetch = originalFetch;
core.closeDbInstance();
try {
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
} catch {
// best-effort cleanup
}
// Drain the last test's in-flight save before closing, so it lands instead of erroring.
assert.ok(await waitForCallLogSaves(30_000), "the last test's call-log save should finish");
// Stops the call-log writer too, which otherwise keeps the process alive for its idle timeout.
await closeCallLogSaves(2_000);
await cleanup();
});

async function runChatCore(opts: {
Expand Down Expand Up @@ -146,18 +148,15 @@ test("chatCore: x-omniroute-compression: off suppresses Output Styles injection
connectionId: connection.id,
headers: new Headers({ "x-omniroute-compression": "off" }),
});
const testModelFirstMessage = testModelBody.capturedBody?.messages?.[0];
assert.ok(
!testModelFirstMessage || testModelFirstMessage.role !== "system",
"Test-model request (compression:off) must not receive an injected Output Styles system message"
);
const anyMessageHasMarker = (testModelBody.capturedBody?.messages ?? []).some((m) =>
(m?.content ?? "").includes("OmniRoute Output Styles")
assert.deepEqual(
testModelBody.capturedBody?.messages,
[{ role: "user", content: "ping" }],
"Test-model request (compression:off) must reach upstream with its messages untouched"
);
assert.equal(
anyMessageHasMarker,
JSON.stringify(testModelBody.capturedBody).includes(OUTPUT_STYLE_MARKER),
false,
"No message in the compression:off request should carry the Output Styles marker"
"No part of the compression:off request should carry the Output Styles marker"
);
});

Expand Down Expand Up @@ -217,3 +216,40 @@ test("chatCore: a per-key opt-out wins over request headers and Output Styles (#
assert.deepEqual(disabled.capturedBody?.messages, [{ role: "user", content: originalContent }]);
assert.equal(disabled.response.headers.get("x-omniroute-compression"), "off; source=off");
});

test("chatCore: caveman output mode skipped when compression is globally disabled", async () => {
await compressionDb.updateCompressionSettings({
enabled: false,
defaultMode: "off",
autoTriggerTokens: 0,
cavemanOutputMode: {
enabled: true,
intensity: "full",
autoClarity: true,
},
});

const connection = await providersDb.createProviderConnection({
provider: "openai",
apiKey: "test-key",
isActive: true,
});

const { capturedBody } = await runChatCore({
provider: "openai",
model: "gpt-4",
connectionId: connection.id,
headers: new Headers(),
messageContent: "Summarize this implementation.",
});
assert.deepEqual(
capturedBody?.messages,
[{ role: "user", content: "Summarize this implementation." }],
"The messages should reach upstream untouched when compression is disabled"
);
assert.equal(
JSON.stringify(capturedBody).includes(OUTPUT_STYLE_MARKER),
false,
"No output-style instruction should reach upstream when compression is disabled"
);
});
Loading
Loading