Files
OmniRoute/tests/unit/api/compression/compression-api.test.ts
Diego Rodrigues de Sa e Souza 743be29852 feat(compression): RTK compression roadmap (#1889)
* chore(rtk): initialize compression roadmap branch

* feat(compression): add RTK engine and compression combos

Introduce RTK command-aware tool-output compression alongside
stacked RTK -> Caveman pipelines for mixed prompt contexts.

Add engine registration, declarative RTK filter packs, language-aware
Caveman rule loading, compression combo persistence and assignments,
analytics grouped by engine/combo, and new MCP/API endpoints for
configuration, previews, filters, and combo management.

Expose the new capabilities in the dashboard with dedicated Context &
Cache pages for Caveman, RTK, and compression combos, and update docs,
i18n strings, migrations, and tests to cover the expanded compression
surface.

* feat(compression): expand RTK DSL, filter catalog, and recovery APIs

Add RTK parity features across the compression pipeline, dashboard,
and management APIs. This expands the built-in filter catalog, adds
trust-gated custom filter loading, inline filter verification, code
stripping, smarter detection, and optional redacted raw-output
retention for authenticated recovery.

Also extend Caveman with file-based multilingual rule packs, localized
output-mode instructions, stricter preview/config schemas, engine
registry metadata, analytics fields, and broad unit test coverage for
RTK, rule loading, and stacked compression behavior.

* fix(auth): protect oauth routes and health reset operations

Require authenticated dashboard access for OAuth endpoints that can
create or import provider connections when login enforcement is
enabled.

Move `/api/monitoring/health` to the readonly public route list so
safe methods remain public while DELETE now returns 401 for anonymous
requests.

Also update Next.js native `.node` handling to avoid webpack parse
failures from external packages such as ngrok and keytar, and add
coverage for the new auth behavior.

* build(compression): ship RTK rule and filter assets with app bundles

Include compression JSON assets in Next output tracing, prepublish copies,
and pack artifact policy checks so standalone and packaged builds can
load RTK filters and caveman rule packs at runtime.

Also harden compression runtime behavior by resolving alternate asset
directories, scoping rule cache entries by source path, carrying RTK raw
output pointers through stacked runs, degrading oversized preview diffs,
and applying combo language/output mode defaults during chat routing.

Add coverage for packaging rules, provider-scoped model parsing, smart
truncate edge cases, raw output retention, and combo-driven compression
behavior.

* docs(workflows): update local repo paths to OmniRoute

Replace outdated `/home/diegosouzapw/dev/proxys/9router` references
with the current `OmniRoute` directory across deploy, release, and
version bump workflow guides so local command examples match the
renamed repository layout

* feat(compression): complete RTK parity coverage

* test(build): align next config assertions

---------

Co-authored-by: diegosouzapw <diego.souza.pw@gmail.com>
2026-05-03 00:37:08 -03:00

110 lines
3.6 KiB
TypeScript

import { describe, it, beforeEach, afterEach } from "node:test";
import assert from "node:assert/strict";
import { fileURLToPath } from "node:url";
import { dirname, join } 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);
});
});