mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-04 06:12:10 +03:00
Add unit tests for strategy selector (17), lite compression (20), stats module (11), and DB module (7). Add integration tests for full compression pipeline (6). All 61 tests pass. Remove broken integration test files from previous WIP. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
126 lines
4.1 KiB
TypeScript
126 lines
4.1 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import {
|
|
selectCompressionStrategy,
|
|
getEffectiveMode,
|
|
applyCompression,
|
|
checkComboOverride,
|
|
shouldAutoTrigger,
|
|
} from "../../../open-sse/services/compression/strategySelector.ts";
|
|
import type { CompressionConfig } from "../../../open-sse/services/compression/types.ts";
|
|
|
|
const baseConfig: CompressionConfig = {
|
|
enabled: true,
|
|
defaultMode: "lite",
|
|
autoTriggerTokens: 0,
|
|
cacheMinutes: 5,
|
|
preserveSystemPrompt: true,
|
|
comboOverrides: {},
|
|
};
|
|
|
|
describe("checkComboOverride", () => {
|
|
it("returns null when comboId is null", () => {
|
|
assert.equal(checkComboOverride(baseConfig, null), null);
|
|
});
|
|
|
|
it("returns null when comboOverrides is empty", () => {
|
|
assert.equal(checkComboOverride(baseConfig, "my-combo"), null);
|
|
});
|
|
|
|
it("returns mode when combo override exists", () => {
|
|
const config = { ...baseConfig, comboOverrides: { "my-combo": "off" as const } };
|
|
assert.equal(checkComboOverride(config, "my-combo"), "off");
|
|
});
|
|
|
|
it("returns null for non-existent combo", () => {
|
|
const config = { ...baseConfig, comboOverrides: { "other-combo": "lite" as const } };
|
|
assert.equal(checkComboOverride(config, "my-combo"), null);
|
|
});
|
|
});
|
|
|
|
describe("shouldAutoTrigger", () => {
|
|
it("returns false when autoTriggerTokens is 0", () => {
|
|
assert.equal(shouldAutoTrigger(baseConfig, 5000), false);
|
|
});
|
|
|
|
it("returns false when tokens below threshold", () => {
|
|
const config = { ...baseConfig, autoTriggerTokens: 1000 };
|
|
assert.equal(shouldAutoTrigger(config, 500), false);
|
|
});
|
|
|
|
it("returns true when tokens at threshold", () => {
|
|
const config = { ...baseConfig, autoTriggerTokens: 1000 };
|
|
assert.equal(shouldAutoTrigger(config, 1000), true);
|
|
});
|
|
|
|
it("returns true when tokens above threshold", () => {
|
|
const config = { ...baseConfig, autoTriggerTokens: 1000 };
|
|
assert.equal(shouldAutoTrigger(config, 1500), true);
|
|
});
|
|
});
|
|
|
|
describe("getEffectiveMode", () => {
|
|
it("returns off when not enabled", () => {
|
|
const config = { ...baseConfig, enabled: false };
|
|
assert.equal(getEffectiveMode(config, null, 100), "off");
|
|
});
|
|
|
|
it("returns default mode when no overrides", () => {
|
|
assert.equal(getEffectiveMode(baseConfig, null, 100), "lite");
|
|
});
|
|
|
|
it("returns combo override mode when present", () => {
|
|
const config = {
|
|
...baseConfig,
|
|
defaultMode: "off" as const,
|
|
comboOverrides: { "my-combo": "lite" as const },
|
|
};
|
|
assert.equal(getEffectiveMode(config, "my-combo", 100), "lite");
|
|
});
|
|
|
|
it("returns lite when auto-trigger threshold reached", () => {
|
|
const config = { ...baseConfig, defaultMode: "off" as const, autoTriggerTokens: 1000 };
|
|
assert.equal(getEffectiveMode(config, null, 1500), "lite");
|
|
});
|
|
|
|
it("combo override takes precedence over auto-trigger", () => {
|
|
const config = {
|
|
...baseConfig,
|
|
defaultMode: "off" as const,
|
|
autoTriggerTokens: 100,
|
|
comboOverrides: { "my-combo": "off" as const },
|
|
};
|
|
assert.equal(getEffectiveMode(config, "my-combo", 500), "off");
|
|
});
|
|
});
|
|
|
|
describe("selectCompressionStrategy", () => {
|
|
it("returns effective mode", () => {
|
|
assert.equal(selectCompressionStrategy(baseConfig, null, 100), "lite");
|
|
});
|
|
});
|
|
|
|
describe("applyCompression", () => {
|
|
it("returns unchanged body for off mode", () => {
|
|
const body = { messages: [{ role: "user", content: "test" }] };
|
|
const result = applyCompression(body, "off");
|
|
assert.equal(result.compressed, false);
|
|
assert.equal(result.stats, null);
|
|
assert.deepEqual(result.body, body);
|
|
});
|
|
|
|
it("applies lite compression for lite mode", () => {
|
|
const body = { messages: [{ role: "user", content: "test\n\n\n\nmessage" }] };
|
|
const result = applyCompression(body, "lite");
|
|
assert.equal(result.compressed, true);
|
|
assert.ok(result.stats);
|
|
assert.equal(result.stats.mode, "lite");
|
|
});
|
|
|
|
it("returns unchanged body for standard mode (Phase 2)", () => {
|
|
const body = { messages: [{ role: "user", content: "test" }] };
|
|
const result = applyCompression(body, "standard");
|
|
assert.equal(result.compressed, false);
|
|
});
|
|
});
|