mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
Compress MCP registry and list metadata descriptions for tools, prompts, resources, and resource templates while keeping tool-response bodies unchanged. Expose those savings in compression status as `mcp_metadata_estimate` metadata rather than provider usage. Add Caveman rule-pack support for custom regex flags and match-specific replacement maps, update English rules for upstream parity, and tighten article and pleasantry handling. Also process RTK multipart text blocks independently so mixed media content compresses safely without duplicating output.
159 lines
6.0 KiB
TypeScript
159 lines
6.0 KiB
TypeScript
import { describe, it, before } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { mkdtempSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
|
|
const tmpDir = mkdtempSync(join(tmpdir(), "omniroute-mcp-test-"));
|
|
process.env.DATA_DIR = tmpDir;
|
|
|
|
const {
|
|
handleCompressionStatus,
|
|
handleCompressionConfigure,
|
|
handleSetCompressionEngine,
|
|
handleListCompressionCombos,
|
|
handleCompressionComboStats,
|
|
} = await import("../../../open-sse/mcp-server/tools/compressionTools.ts");
|
|
const {
|
|
compressionConfigureTool,
|
|
compressionStatusTool,
|
|
setCompressionEngineTool,
|
|
listCompressionCombosTool,
|
|
compressionComboStatsTool,
|
|
} = await import("../../../open-sse/mcp-server/schemas/tools.ts");
|
|
|
|
describe("compression MCP tool schemas", () => {
|
|
it("uses canonical read/write compression scopes", () => {
|
|
assert.deepEqual(compressionStatusTool.scopes, ["read:compression"]);
|
|
assert.deepEqual(compressionConfigureTool.scopes, ["write:compression"]);
|
|
assert.deepEqual(setCompressionEngineTool.scopes, ["write:compression"]);
|
|
assert.deepEqual(listCompressionCombosTool.scopes, ["read:compression"]);
|
|
assert.deepEqual(compressionComboStatsTool.scopes, ["read:compression"]);
|
|
});
|
|
});
|
|
|
|
describe("handleCompressionStatus", () => {
|
|
it("returns an object with enabled field", async () => {
|
|
const result = await handleCompressionStatus({});
|
|
assert.ok("enabled" in result);
|
|
assert.equal(typeof result.enabled, "boolean");
|
|
});
|
|
|
|
it("returns strategy string", async () => {
|
|
const result = await handleCompressionStatus({});
|
|
assert.equal(typeof result.strategy, "string");
|
|
});
|
|
|
|
it("returns settings with maxTokens number", async () => {
|
|
const result = await handleCompressionStatus({});
|
|
assert.ok("settings" in result);
|
|
assert.equal(typeof result.settings.maxTokens, "number");
|
|
});
|
|
|
|
it("returns settings with targetRatio 0.7", async () => {
|
|
const result = await handleCompressionStatus({});
|
|
assert.equal(result.settings.targetRatio, 0.7);
|
|
});
|
|
|
|
it("returns analytics with totalRequests number", async () => {
|
|
const result = await handleCompressionStatus({});
|
|
assert.ok("analytics" in result);
|
|
assert.equal(typeof result.analytics.totalRequests, "number");
|
|
});
|
|
|
|
it("returns analytics with tokensSaved number", async () => {
|
|
const result = await handleCompressionStatus({});
|
|
assert.equal(typeof result.analytics.tokensSaved, "number");
|
|
});
|
|
|
|
it("returns cacheStats as null or object", async () => {
|
|
const result = await handleCompressionStatus({});
|
|
assert.ok(result.cacheStats === null || typeof result.cacheStats === "object");
|
|
});
|
|
|
|
it("returns analytics compressedRequests as number", async () => {
|
|
const result = await handleCompressionStatus({});
|
|
assert.equal(typeof result.analytics.compressedRequests, "number");
|
|
});
|
|
|
|
it("labels MCP description savings as metadata estimates, not provider usage", async () => {
|
|
const result = await handleCompressionStatus({});
|
|
assert.equal(result.analytics.mcpDescriptionCompression.source, "mcp_metadata_estimate");
|
|
assert.equal(result.analytics.mcpDescriptionCompression.notProviderUsage, true);
|
|
assert.equal(typeof result.analytics.mcpDescriptionCompression.charsBefore, "number");
|
|
assert.equal(typeof result.analytics.mcpDescriptionCompression.charsAfter, "number");
|
|
});
|
|
});
|
|
|
|
describe("handleCompressionConfigure", () => {
|
|
it("returns success=true when called with empty args", async () => {
|
|
const result = await handleCompressionConfigure({});
|
|
assert.equal(result.success, true);
|
|
});
|
|
|
|
it("returns settings object after configure", async () => {
|
|
const result = await handleCompressionConfigure({});
|
|
assert.ok("settings" in result);
|
|
assert.equal(typeof result.settings.enabled, "boolean");
|
|
});
|
|
|
|
it("returns updated object", async () => {
|
|
const result = await handleCompressionConfigure({ enabled: true });
|
|
assert.ok("updated" in result);
|
|
});
|
|
|
|
it("sets enabled=false and returns success", async () => {
|
|
const result = await handleCompressionConfigure({ enabled: false });
|
|
assert.equal(result.success, true);
|
|
});
|
|
|
|
it("sets strategy and returns success", async () => {
|
|
const result = await handleCompressionConfigure({ strategy: "aggressive" });
|
|
assert.equal(result.success, true);
|
|
});
|
|
|
|
it("sets RTK and stacked strategies", async () => {
|
|
const rtkResult = await handleCompressionConfigure({ strategy: "rtk" });
|
|
const stackedResult = await handleCompressionConfigure({ strategy: "stacked" });
|
|
assert.equal(rtkResult.success, true);
|
|
assert.equal(stackedResult.success, true);
|
|
});
|
|
|
|
it("sets maxTokens and returns success", async () => {
|
|
const result = await handleCompressionConfigure({ maxTokens: 8000 });
|
|
assert.equal(result.success, true);
|
|
assert.ok("updated" in result);
|
|
});
|
|
|
|
it("returns settings.maxTokens as number", async () => {
|
|
const result = await handleCompressionConfigure({ maxTokens: 2000 });
|
|
assert.equal(typeof result.settings.maxTokens, "number");
|
|
});
|
|
|
|
it("returns settings.targetRatio as 0.7", async () => {
|
|
const result = await handleCompressionConfigure({});
|
|
assert.equal(result.settings.targetRatio, 0.7);
|
|
});
|
|
});
|
|
|
|
describe("compression MCP RTK/combo tools", () => {
|
|
it("sets RTK engine through MCP", async () => {
|
|
const result = await handleSetCompressionEngine({ engine: "rtk", rtkIntensity: "aggressive" });
|
|
assert.equal(result.success, true);
|
|
assert.equal(result.settings.defaultMode, "rtk");
|
|
assert.equal((result.settings.rtkConfig as { intensity?: string }).intensity, "aggressive");
|
|
});
|
|
|
|
it("lists compression combos", async () => {
|
|
const result = await handleListCompressionCombos();
|
|
assert.ok(Array.isArray(result.combos));
|
|
assert.ok(result.combos.length >= 1);
|
|
});
|
|
|
|
it("returns combo stats summary", async () => {
|
|
const result = await handleCompressionComboStats({ since: "all" });
|
|
assert.ok("byCompressionCombo" in result);
|
|
assert.ok("byEngine" in result);
|
|
});
|
|
});
|