Files
OmniRoute/open-sse/mcp-server/__tests__/toolSearch.search.test.ts
Diego Rodrigues de Sa e Souza 7c23dab64d Release v3.8.40
v3.8.40 cycle integration → main. All test gates green (Unit/Integration/Coverage/Node-compat/Quality-Ratchet). The only red check, 'PR Test Policy', is the test-masking heuristic firing on the cumulative ~57-commit release diff (legitimate assert consolidations already reviewed per-PR — Gemini CLI removal #5246, retired GPT models #5280, provider catalog refreshes); overridden with --admin per the documented release-PR convention. CodeQL/SonarQube advisory scans non-blocking; #5278's code already passed CodeQL on main. Homologated on VPS 192.168.0.15 (v3.8.40 healthy).
2026-06-29 08:40:06 -03:00

27 lines
1.1 KiB
TypeScript

import { describe, it, expect } from "vitest";
import { searchTools } from "../toolSearch/search.ts";
const E = [
{ name: "omniroute_get_health", description: "health status uptime memory", scopes: ["read:health"] },
{ name: "omniroute_list_combos", description: "list combos and strategies", scopes: ["read:combos"] },
{ name: "omniroute_check_quota", description: "remaining quota per provider", scopes: ["read:quota"] },
];
describe("searchTools", () => {
it("ranks name+desc hit on top", () => {
const r = searchTools(E, "health", 8);
expect(r[0].name).toBe("omniroute_get_health");
});
it("no hit ⇒ empty", () => { expect(searchTools(E, "zzzzz", 8)).toEqual([]); });
it("respects limit + deterministic tie-break", () => {
const r = searchTools(E, "omniroute", 2);
expect(r.length).toBe(2);
expect(r[0].name < r[1].name).toBe(true); // tie-break alfabético
});
it("ReDoS-safe: pathological query does not hang", () => {
const start = Date.now();
searchTools(E, "(a+)+".repeat(20), 8);
expect(Date.now() - start).toBeLessThan(200);
});
});