mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-02 05:12:11 +03:00
OmniRoute is an intelligent API gateway that unifies 20+ AI providers behind a single OpenAI-compatible endpoint. Features include intelligent routing with 6 strategies, multi-format translation (OpenAI/Claude/Gemini/Responses API), circuit breakers, semantic caching, combo fallback chains, real-time health monitoring, and a full dashboard with provider management, analytics, and CLI tool integration. Key highlights: - 20+ providers (Claude Code, Codex, Gemini CLI, GitHub Copilot, iFlow, Qwen, Kiro, etc.) - 6 routing strategies (Fill First, Round Robin, P2C, Random, Least Used, Cost Optimized) - Export/Import database backup with full archive support - Translator Playground with 4 modes (Playground, Chat Tester, Test Bench, Live Monitor) - 100% TypeScript across src/ and open-sse/ - Docker support with multi-stage builds - Comprehensive documentation and 9 dashboard screenshots
103 lines
4.1 KiB
JavaScript
103 lines
4.1 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const {
|
|
wildcardMatch,
|
|
getSpecificity,
|
|
resolveWildcardAlias,
|
|
resolveModel,
|
|
} = await import("../../open-sse/services/wildcardRouter.ts");
|
|
|
|
// ─── wildcardMatch ──────────────────────────────────────────────────────────
|
|
|
|
test("wildcardMatch: exact match", () => {
|
|
assert.equal(wildcardMatch("gpt-4o", "gpt-4o"), true);
|
|
});
|
|
|
|
test("wildcardMatch: star catches all", () => {
|
|
assert.equal(wildcardMatch("anything", "*"), true);
|
|
});
|
|
|
|
test("wildcardMatch: prefix star", () => {
|
|
assert.equal(wildcardMatch("claude-sonnet-4-20250514", "claude-*"), true);
|
|
assert.equal(wildcardMatch("gpt-4o", "claude-*"), false);
|
|
});
|
|
|
|
test("wildcardMatch: middle star", () => {
|
|
assert.equal(wildcardMatch("claude-sonnet-4-20250514", "claude-*-4*"), true);
|
|
assert.equal(wildcardMatch("claude-haiku-4-20250514", "claude-*-4*"), true);
|
|
});
|
|
|
|
test("wildcardMatch: question mark single char", () => {
|
|
assert.equal(wildcardMatch("gpt-4o", "gpt-?o"), true);
|
|
assert.equal(wildcardMatch("gpt-4o", "gpt-??"), true);
|
|
assert.equal(wildcardMatch("gpt-4o", "gpt-???"), false);
|
|
});
|
|
|
|
test("wildcardMatch: case insensitive", () => {
|
|
assert.equal(wildcardMatch("GPT-4o", "gpt-*"), true);
|
|
});
|
|
|
|
test("wildcardMatch: null/empty", () => {
|
|
assert.equal(wildcardMatch(null, "*"), false);
|
|
assert.equal(wildcardMatch("model", null), false);
|
|
});
|
|
|
|
// ─── getSpecificity ─────────────────────────────────────────────────────────
|
|
|
|
test("getSpecificity: more specific > less specific", () => {
|
|
assert.ok(getSpecificity("claude-sonnet-4") > getSpecificity("claude-*"));
|
|
assert.ok(getSpecificity("claude-sonnet-*") > getSpecificity("claude-*"));
|
|
assert.ok(getSpecificity("*") < getSpecificity("claude-*"));
|
|
});
|
|
|
|
test("getSpecificity: exact > wildcard", () => {
|
|
assert.ok(getSpecificity("claude-sonnet-4-20250514") > getSpecificity("claude-sonnet-4-*"));
|
|
});
|
|
|
|
// ─── resolveWildcardAlias ───────────────────────────────────────────────────
|
|
|
|
test("resolveWildcardAlias: picks most specific match", () => {
|
|
const aliases = [
|
|
{ pattern: "claude-*", target: "generic-claude" },
|
|
{ pattern: "claude-sonnet-*", target: "sonnet-claude" },
|
|
{ pattern: "claude-sonnet-4-*", target: "sonnet4-claude" },
|
|
];
|
|
const result = resolveWildcardAlias("claude-sonnet-4-20250514", aliases);
|
|
assert.equal(result.target, "sonnet4-claude");
|
|
});
|
|
|
|
test("resolveWildcardAlias: returns null for no match", () => {
|
|
const aliases = [{ pattern: "gpt-*", target: "openai" }];
|
|
assert.equal(resolveWildcardAlias("claude-sonnet-4", aliases), null);
|
|
});
|
|
|
|
test("resolveWildcardAlias: handles empty/null", () => {
|
|
assert.equal(resolveWildcardAlias("model", null), null);
|
|
assert.equal(resolveWildcardAlias("model", []), null);
|
|
assert.equal(resolveWildcardAlias(null, []), null);
|
|
});
|
|
|
|
// ─── resolveModel ───────────────────────────────────────────────────────────
|
|
|
|
test("resolveModel: exact alias takes priority", () => {
|
|
const exact = { "my-claude": "claude-sonnet-4-20250514" };
|
|
const wildcards = [{ pattern: "my-*", target: "generic" }];
|
|
assert.equal(resolveModel("my-claude", exact, wildcards), "claude-sonnet-4-20250514");
|
|
});
|
|
|
|
test("resolveModel: falls back to wildcard", () => {
|
|
const exact = {};
|
|
const wildcards = [{ pattern: "my-*", target: "wildcard-match" }];
|
|
assert.equal(resolveModel("my-model", exact, wildcards), "wildcard-match");
|
|
});
|
|
|
|
test("resolveModel: returns original if no match", () => {
|
|
assert.equal(resolveModel("unknown", {}, []), "unknown");
|
|
});
|
|
|
|
test("resolveModel: works with Map for exact aliases", () => {
|
|
const exact = new Map([["alias1", "target1"]]);
|
|
assert.equal(resolveModel("alias1", exact, []), "target1");
|
|
});
|