mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-31 12:22:14 +03:00
* docs(compression): design spec for the unified compression config panel
Engine-centric central panel (single source for master + per-engine on/off + level),
default pipeline derived from the engines map; Combos page owns named ordered pipelines +
active-profile selection; per-engine pages keep only detailed config. Phased: (1) core
consolidation + Model A migration, (2) named profiles + active selector, (3) per-request
x-omniroute-compression header.
* docs(compression): Phase 1 implementation plan for the unified config panel
12 TDD tasks: engine catalog, engines map + activeComboId, deriveDefaultPlan,
migration 102 + backfill, resolveCompressionPlan, runtime wiring, API, default-combo
shim, the engine-grid panel, consolidation, menu. Ends with a recap + the pending
follow-ups (Phase 2 named profiles/active selector, Phase 3 header, deferred items).
* feat(compression): engine catalog metadata (levels, single-mode, order)
* feat(compression): add engines map + activeComboId to CompressionConfig
* feat(compression): deriveDefaultPlan (engines map -> mode/pipeline)
Pure function that converts a per-engine EngineToggle map + masterEnabled
flag into a { mode, stackedPipeline } plan: off when master is off or no
engines on; single-mode when exactly one single-mode engine is enabled;
stacked (sorted by stackPriority) otherwise.
* feat(compression): persist+backfill engines map and activeComboId (migration 102)
* feat(compression): resolveCompressionPlan precedence resolver (header>override>active>default)
* feat(compression): selectCompressionStrategy uses resolveCompressionPlan
* feat(api): settings/compression carries engines map + activeComboId
Extends compressionSettingsUpdateSchema with engines (Record<string,{enabled:boolean,level?:string}>)
and activeComboId (string|null) so the PUT route accepts and persists these fields.
GET already returns the full getCompressionSettings() object which includes both fields.
TDD: added route round-trip tests (PUT+GET) for engines, activeComboId, null clear,
and schema rejection of invalid engines shape.
* refactor(compression): default-combo route is a read-only shim (default derived from engines)
* feat(dashboard): engine-grid compression panel (single source for on/off + level)
* refactor(dashboard): remove duplicate compression toggles; per-engine pages keep only detailed config
* feat(compression): unified panel menu order + derived-pipeline integration coverage
* fix(compression): import ENGINE_IDS via types re-export so it resolves under vitest
The bare "@omniroute/open-sse/.../engineCatalog.ts" specifier resolves under tsc/tsx
but not under vitest's MCP config: Vite externalizes a brand-new open-sse module to
Node, which can't load the .ts subpath. types.ts is already in Vite's graph, so route
ENGINE_IDS through its re-export. Fixes 3 failing MCP vitest suites (cacheTools,
dbHealthTool, essentialTools).
* fix(compression): engines map drives dispatch only when explicitly panel-saved
Code-review finding: the legacy seeded default combo (present on every install via
migration 042/043) was silently overriding a panel-configured engines map — the
default-combo block in chatCore set compressionComboApplied=true, skipping the
engines-map override, so an operator's panel toggles were ignored.
Gate the engines-map path on a new runtime-only CompressionConfig.enginesExplicit
(true when a stored engines row exists). Panel-saved installs: the engines map is
authoritative (deriveDefaultPlanFromConfig + new enginesMapDerivesStackedPipeline
guard the chatCore default-combo block). Legacy/backfilled installs: the map is
display-only and dispatch stays on the historical defaultMode/default-combo path —
zero behaviour change until the operator opts in via the panel.
Also documents why resolveCacheAwareConfig's getCacheAwareStrategy(config.defaultMode)
arg is safe (skipSystemPrompt is mode-independent).
* docs(compression): add MDX frontmatter + escape inline brace to fix fumadocs build
docs/compression/**/*.md is compiled as MDX by the Next build (fumadocs,
source.config.ts). The two planning docs lacked the required `title`
frontmatter (build error: 'title: expected string, received undefined') and the
design doc had a bare {rtk,caveman} that MDX parsed as a JSX expression. Adds
frontmatter matching the sibling docs and backticks the brace. Fixes the
dast-smoke build step.
214 lines
7.7 KiB
TypeScript
214 lines
7.7 KiB
TypeScript
import { describe, it, beforeEach, afterEach, after } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { fileURLToPath } from "node:url";
|
|
import { dirname, join } from "node:path";
|
|
import fs from "node:fs";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
|
|
describe("Compression Settings API Schema Validation", () => {
|
|
const compressionModeValues = [
|
|
"off",
|
|
"lite",
|
|
"standard",
|
|
"aggressive",
|
|
"ultra",
|
|
"rtk",
|
|
"stacked",
|
|
];
|
|
|
|
it("should validate all compression mode values", () => {
|
|
assert.deepStrictEqual(compressionModeValues, [
|
|
"off",
|
|
"lite",
|
|
"standard",
|
|
"aggressive",
|
|
"ultra",
|
|
"rtk",
|
|
"stacked",
|
|
]);
|
|
});
|
|
|
|
it("should validate caveman config structure", () => {
|
|
const defaultCavemanConfig = {
|
|
enabled: true,
|
|
compressRoles: ["user"],
|
|
skipRules: [],
|
|
minMessageLength: 50,
|
|
preservePatterns: [],
|
|
};
|
|
|
|
assert.equal(defaultCavemanConfig.enabled, true);
|
|
assert.deepStrictEqual(defaultCavemanConfig.compressRoles, ["user"]);
|
|
assert.equal(Array.isArray(defaultCavemanConfig.skipRules), true);
|
|
assert.equal(defaultCavemanConfig.minMessageLength, 50);
|
|
assert.equal(Array.isArray(defaultCavemanConfig.preservePatterns), true);
|
|
});
|
|
|
|
it("should validate full compression config structure", () => {
|
|
const defaultConfig = {
|
|
enabled: false,
|
|
defaultMode: "off",
|
|
autoTriggerTokens: 0,
|
|
cacheMinutes: 5,
|
|
preserveSystemPrompt: true,
|
|
comboOverrides: {},
|
|
cavemanConfig: {
|
|
enabled: true,
|
|
compressRoles: ["user"],
|
|
skipRules: [],
|
|
minMessageLength: 50,
|
|
preservePatterns: [],
|
|
},
|
|
ultra: {
|
|
enabled: false,
|
|
compressionRate: 0.5,
|
|
minScoreThreshold: 0.3,
|
|
slmFallbackToAggressive: true,
|
|
maxTokensPerMessage: 0,
|
|
},
|
|
};
|
|
|
|
assert.equal(defaultConfig.enabled, false);
|
|
assert.ok(compressionModeValues.includes(defaultConfig.defaultMode));
|
|
assert.equal(typeof defaultConfig.autoTriggerTokens, "number");
|
|
assert.equal(typeof defaultConfig.cacheMinutes, "number");
|
|
assert.equal(typeof defaultConfig.preserveSystemPrompt, "boolean");
|
|
assert.equal(typeof defaultConfig.comboOverrides, "object");
|
|
assert.equal(typeof defaultConfig.cavemanConfig, "object");
|
|
assert.equal(typeof defaultConfig.ultra, "object");
|
|
assert.equal(defaultConfig.ultra.compressionRate, 0.5);
|
|
});
|
|
|
|
it("should validate all caveman compression rules are defined", async () => {
|
|
const { CAVEMAN_RULES } =
|
|
await import("../../../../open-sse/services/compression/cavemanRules.ts");
|
|
assert.ok(Array.isArray(CAVEMAN_RULES));
|
|
assert.ok(CAVEMAN_RULES.length >= 29, `Expected >= 29 rules, got ${CAVEMAN_RULES.length}`);
|
|
for (const rule of CAVEMAN_RULES) {
|
|
assert.ok(rule.name && typeof rule.name === "string", `Rule must have a name`);
|
|
assert.ok(rule.pattern instanceof RegExp, `Rule ${rule.name} must have a RegExp pattern`);
|
|
assert.ok(
|
|
typeof rule.replacement === "string" || typeof rule.replacement === "function",
|
|
`Rule ${rule.name} must have string or function replacement`
|
|
);
|
|
assert.ok(
|
|
rule.pattern.source !== "^$" || rule.replacement !== "",
|
|
`Rule ${rule.name} must not be a no-op (empty pattern + empty replacement)`
|
|
);
|
|
}
|
|
});
|
|
|
|
it("should validate compression modes cover all CavemanConfig roles", () => {
|
|
const validRoles = ["user", "assistant", "system"];
|
|
for (const role of validRoles) {
|
|
assert.ok(validRoles.includes(role), `Role ${role} should be valid`);
|
|
}
|
|
assert.equal(validRoles.length, 3);
|
|
});
|
|
});
|
|
|
|
// ─── Route round-trip: engines map + activeComboId ─────────────────────────
|
|
// Mirrors the mcp-accessibility-config test harness: allocate a temp DATA_DIR,
|
|
// import route + DB modules, tear down in after().
|
|
|
|
const TEST_DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), "omniroute-compression-route-"));
|
|
const ORIGINAL_DATA_DIR = process.env.DATA_DIR;
|
|
process.env.DATA_DIR = TEST_DATA_DIR;
|
|
|
|
const core = await import("../../../../src/lib/db/core.ts");
|
|
const route = await import("../../../../src/app/api/settings/compression/route.ts");
|
|
|
|
function makeRequest(method: string, body?: unknown): Request {
|
|
return new Request("http://localhost/api/settings/compression", {
|
|
method,
|
|
headers: body !== undefined ? { "content-type": "application/json" } : {},
|
|
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
}) as any;
|
|
}
|
|
|
|
describe("settings/compression route — engines + activeComboId", () => {
|
|
beforeEach(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
|
fs.mkdirSync(TEST_DATA_DIR, { recursive: true });
|
|
});
|
|
|
|
after(() => {
|
|
core.resetDbInstance();
|
|
fs.rmSync(TEST_DATA_DIR, { recursive: true, force: true });
|
|
if (ORIGINAL_DATA_DIR === undefined) delete process.env.DATA_DIR;
|
|
else process.env.DATA_DIR = ORIGINAL_DATA_DIR;
|
|
});
|
|
|
|
it("PUT engines map persists and GET returns engines + activeComboId", async () => {
|
|
const putRes = await route.PUT(
|
|
makeRequest("PUT", { engines: { rtk: { enabled: true, level: "standard" } } })
|
|
);
|
|
assert.equal(putRes.status, 200);
|
|
|
|
// Fresh DB handle so we read from storage, not from the write-path return value.
|
|
core.resetDbInstance();
|
|
|
|
const getRes = await route.GET(makeRequest("GET"));
|
|
assert.equal(getRes.status, 200);
|
|
const body = await getRes.json();
|
|
|
|
assert.equal(
|
|
body.engines?.rtk?.enabled,
|
|
true,
|
|
"engines.rtk.enabled should be true after PUT"
|
|
);
|
|
assert.equal(
|
|
body.engines?.rtk?.level,
|
|
"standard",
|
|
"engines.rtk.level should be 'standard' after PUT"
|
|
);
|
|
// activeComboId is always present (null by default)
|
|
assert.ok("activeComboId" in body, "GET response must include activeComboId");
|
|
});
|
|
|
|
it("PUT activeComboId persists and is returned by GET", async () => {
|
|
const putRes = await route.PUT(makeRequest("PUT", { activeComboId: "combo-abc" }));
|
|
assert.equal(putRes.status, 200);
|
|
|
|
core.resetDbInstance();
|
|
|
|
const getRes = await route.GET(makeRequest("GET"));
|
|
assert.equal(getRes.status, 200);
|
|
const body = await getRes.json();
|
|
assert.equal(body.activeComboId, "combo-abc");
|
|
});
|
|
|
|
it("PUT activeComboId:null clears the active combo", async () => {
|
|
// First set it, then clear.
|
|
await route.PUT(makeRequest("PUT", { activeComboId: "combo-to-clear" }));
|
|
core.resetDbInstance();
|
|
await route.PUT(makeRequest("PUT", { activeComboId: null }));
|
|
core.resetDbInstance();
|
|
|
|
const getRes = await route.GET(makeRequest("GET"));
|
|
assert.equal(getRes.status, 200);
|
|
const body = await getRes.json();
|
|
assert.equal(body.activeComboId, null);
|
|
});
|
|
|
|
it("PUT with invalid engines shape is rejected by schema validation (400)", async () => {
|
|
// engines values must have an `enabled` boolean — passing a string should fail the schema.
|
|
const putRes = await route.PUT(
|
|
makeRequest("PUT", { engines: { rtk: { enabled: "yes" } } })
|
|
);
|
|
assert.equal(putRes.status, 400);
|
|
const body = await putRes.json();
|
|
// Validation failures use { error: { message, details } } via validateBody helper.
|
|
assert.ok(body.error !== null && typeof body.error === "object", "error should be an object");
|
|
const errorMessage: string =
|
|
typeof body.error === "string" ? body.error : (body.error?.message ?? JSON.stringify(body.error));
|
|
assert.ok(!errorMessage.includes("at /"), "error must not contain a stack trace");
|
|
});
|
|
});
|