mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-20 13:52:28 +03:00
Carries `context_length` through the MCP `list_models_catalog` projection when the upstream model record has it, and omits it otherwise (#12776). Covered by the new case in `mcp-model-catalog.test.ts`. Validated in one consolidated batch of this series (37 PRs boarded together on `release/v3.8.51`): `typecheck:core`, `check:open-sse-typecheck` and `check:dashboard-typecheck` clean; ESLint clean on every changed file; file-size, complexity, cognitive-complexity, changelog-integrity, docs-counts, docs-sync and migration-numbering gates green (only the pre-existing `open-sse/utils/stream.ts` file-size red remains, inherited from the base); 3,743 focused `node:test` cases plus 34 vitest cases green. Thanks @KooshaPari!
175 lines
5.2 KiB
TypeScript
175 lines
5.2 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { getMcpModelsCatalog } from "../../open-sse/mcp-server/server.ts";
|
|
|
|
test("getMcpModelsCatalog aggregates only active connection model endpoints", async () => {
|
|
const calls: string[] = [];
|
|
|
|
const result = await getMcpModelsCatalog(
|
|
{},
|
|
{
|
|
listProviderConnections: async () => [
|
|
{ id: "conn-github", provider: "github", isActive: true },
|
|
{ id: "conn-codex", provider: "codex", isActive: false },
|
|
],
|
|
fetchJson: async (path: string) => {
|
|
calls.push(path);
|
|
if (path === "/api/providers/conn-github/models?excludeHidden=true") {
|
|
return {
|
|
source: "api",
|
|
models: [
|
|
{ id: "gpt-4.1", owned_by: "github", supportedEndpoints: ["chat"] },
|
|
{
|
|
id: "text-embedding-3-small",
|
|
owned_by: "github",
|
|
supportedEndpoints: ["embeddings"],
|
|
},
|
|
],
|
|
};
|
|
}
|
|
|
|
throw new Error(`Unexpected path: ${path}`);
|
|
},
|
|
}
|
|
);
|
|
|
|
assert.deepEqual(calls, ["/api/providers/conn-github/models?excludeHidden=true"]);
|
|
assert.deepEqual(result, {
|
|
models: [
|
|
{
|
|
id: "gpt-4.1",
|
|
provider: "github",
|
|
capabilities: ["chat"],
|
|
status: "available",
|
|
pricing: undefined,
|
|
},
|
|
{
|
|
id: "text-embedding-3-small",
|
|
provider: "github",
|
|
capabilities: ["embedding"],
|
|
status: "available",
|
|
pricing: undefined,
|
|
},
|
|
],
|
|
source: "api",
|
|
});
|
|
});
|
|
|
|
test("getMcpModelsCatalog exposes codex default thinking effort when no override is stored", async () => {
|
|
const result = await getMcpModelsCatalog(
|
|
{ provider: "codex" },
|
|
{
|
|
listProviderConnections: async () => [
|
|
{
|
|
id: "conn-codex",
|
|
provider: "codex",
|
|
isActive: true,
|
|
providerSpecificData: {},
|
|
},
|
|
],
|
|
fetchJson: async () => ({
|
|
source: "api",
|
|
models: [{ id: "gpt-5.5", owned_by: "codex", supportedEndpoints: ["chat"] }],
|
|
}),
|
|
}
|
|
);
|
|
|
|
assert.equal(result.models.length, 1);
|
|
assert.equal(result.models[0]?.thinkingEffort, "medium");
|
|
});
|
|
|
|
// #12776 — context_length must be carried through the MCP catalog projection
|
|
test("getMcpModelsCatalog includes context_length when present", async () => {
|
|
const result = await getMcpModelsCatalog(
|
|
{},
|
|
{
|
|
listProviderConnections: async () => [
|
|
{ id: "conn-1", provider: "openai", isActive: true },
|
|
],
|
|
fetchJson: async () => ({
|
|
source: "api",
|
|
models: [
|
|
{ id: "gpt-4.1", owned_by: "openai", context_length: 1048576 },
|
|
{ id: "text-embedding-3-small", owned_by: "openai" },
|
|
],
|
|
}),
|
|
}
|
|
);
|
|
|
|
const gpt = result.models.find((m) => m.id === "gpt-4.1");
|
|
const emb = result.models.find((m) => m.id === "text-embedding-3-small");
|
|
|
|
assert.equal(gpt?.context_length, 1048576, "context_length carried from upstream");
|
|
assert.equal(emb?.context_length, undefined, "omitted when upstream has no context_length");
|
|
});
|
|
|
|
test("getMcpModelsCatalog exposes stored thinking effort overrides", async () => {
|
|
const result = await getMcpModelsCatalog(
|
|
{ provider: "gemini-web" },
|
|
{
|
|
listProviderConnections: async () => [
|
|
{
|
|
id: "conn-gemini-web",
|
|
provider: "gemini-web",
|
|
isActive: true,
|
|
providerSpecificData: { thinkingEffort: "extended" },
|
|
},
|
|
],
|
|
fetchJson: async () => ({
|
|
source: "api",
|
|
models: [{ id: "gemini-3.1-pro", owned_by: "gemini-web", supportedEndpoints: ["chat"] }],
|
|
}),
|
|
}
|
|
);
|
|
|
|
assert.equal(result.models.length, 1);
|
|
assert.equal(result.models[0]?.thinkingEffort, "extended");
|
|
});
|
|
|
|
test("getMcpModelsCatalog resolves provider aliases to active connection ids", async () => {
|
|
const calls: string[] = [];
|
|
|
|
const result = await getMcpModelsCatalog(
|
|
{ provider: "gh", capability: "chat" },
|
|
{
|
|
listProviderConnections: async () => [
|
|
{ id: "conn-github", provider: "github", isActive: true },
|
|
{ id: "conn-codex", provider: "codex", isActive: true },
|
|
],
|
|
fetchJson: async (path: string) => {
|
|
calls.push(path);
|
|
return {
|
|
source: "api",
|
|
models: [{ id: "gpt-4.1", owned_by: "github", supportedEndpoints: ["chat"] }],
|
|
};
|
|
},
|
|
}
|
|
);
|
|
|
|
assert.deepEqual(calls, ["/api/providers/conn-github/models?excludeHidden=true"]);
|
|
assert.equal(result.models.length, 1);
|
|
assert.equal(result.models[0]?.provider, "github");
|
|
assert.deepEqual(result.models[0]?.capabilities, ["chat"]);
|
|
});
|
|
|
|
test("getMcpModelsCatalog returns empty result when requested provider has no active connection", async () => {
|
|
const result = await getMcpModelsCatalog(
|
|
{ provider: "github" },
|
|
{
|
|
listProviderConnections: async () => [
|
|
{ id: "conn-codex", provider: "codex", isActive: true },
|
|
],
|
|
fetchJson: async () => {
|
|
throw new Error("fetchJson should not be called without a matching active provider");
|
|
},
|
|
}
|
|
);
|
|
|
|
assert.deepEqual(result, {
|
|
models: [],
|
|
source: "provider_connections",
|
|
warning: "No active connections found for provider 'github'.",
|
|
});
|
|
});
|