Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.8 KB
Raw Blame
import { test } from "node:test";
import assert from "node:assert/strict";
import { smartFilterText } from "@omniroute/open-sse/services/compression/engines/mcpAccessibility/index.ts";
import { DEFAULT_MCP_ACCESSIBILITY_CONFIG } from "@omniroute/open-sse/services/compression/engines/mcpAccessibility/constants.ts";

test("collapses ≥30 sibling buttons into head + summary + tail", () => {
  const lines = [];
  for (let i = 0; i < 50; i++) {
    lines.push(`  - button "Item ${i}" [ref=e${i}]`);
  }
  const input = lines.join("\n").padEnd(3000, " ");
  const out = smartFilterText(input, DEFAULT_MCP_ACCESSIBILITY_CONFIG);
  assert.ok(out.includes("Item 0"), "keeps head");
  assert.ok(out.includes("Item 49"), "keeps tail");
  assert.ok(out.includes('similar "button" items omitted'), "summarizes middle");
  assert.ok(out.length < input.length, "compressed");
});

test("preserves [ref=eXX] anchors during truncation", () => {
  const huge = '  - button "X" [ref=e123]\n' + "a".repeat(60000);
  const out = smartFilterText(huge, DEFAULT_MCP_ACCESSIBILITY_CONFIG);
  assert.ok(out.includes("[ref=e123]"), "preserves refs even on truncate");
  assert.ok(out.length <= 50500, "respects maxTextChars + footer");
});

test('removes noise lines (- generic:, - text: "")', () => {
  const input = ['  - button "OK"', "  - generic:", '  - text: ""', '  - link "Sign in"']
    .join("\n")
    .padEnd(3000, " ");
  const out = smartFilterText(input, DEFAULT_MCP_ACCESSIBILITY_CONFIG);
  assert.ok(!out.includes("- generic:"), "drops generic noise");
  assert.ok(!out.match(/- text: ""/), "drops empty text noise");
  assert.ok(out.includes("button"), "keeps signal");
});

test("returns unchanged when below minLengthToProcess", () => {
  const small = "tiny";
  const out = smartFilterText(small, DEFAULT_MCP_ACCESSIBILITY_CONFIG);
  assert.equal(out, small);
});