mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 15:47:28 +00:00
test: tighten openrouter provider assertions
This commit is contained in:
@@ -30,18 +30,18 @@ describe("openrouter provider hooks", () => {
|
||||
kind: "video_generation",
|
||||
});
|
||||
|
||||
expect(providers).toEqual([expect.objectContaining({ id: "openrouter" })]);
|
||||
expect(speechProviders).toEqual([expect.objectContaining({ id: "openrouter" })]);
|
||||
expect(mediaProviders).toEqual([expect.objectContaining({ id: "openrouter" })]);
|
||||
expect(imageProviders).toEqual([expect.objectContaining({ id: "openrouter" })]);
|
||||
expect(videoProviders).toEqual([expect.objectContaining({ id: "openrouter" })]);
|
||||
expect(modelCatalogProvider.liveCatalog).toEqual(expect.any(Function));
|
||||
expect(providers.map((provider) => provider.id)).toEqual(["openrouter"]);
|
||||
expect(speechProviders.map((provider) => provider.id)).toEqual(["openrouter"]);
|
||||
expect(mediaProviders.map((provider) => provider.id)).toEqual(["openrouter"]);
|
||||
expect(imageProviders.map((provider) => provider.id)).toEqual(["openrouter"]);
|
||||
expect(videoProviders.map((provider) => provider.id)).toEqual(["openrouter"]);
|
||||
expect(modelCatalogProvider.liveCatalog).toBeTypeOf("function");
|
||||
});
|
||||
|
||||
it("includes current Kimi models in the bundled catalog", () => {
|
||||
expect(buildOpenrouterProvider().models?.map((model) => model.id)).toEqual(
|
||||
expect.arrayContaining(["moonshotai/kimi-k2.6", "moonshotai/kimi-k2.5"]),
|
||||
);
|
||||
const modelIds = buildOpenrouterProvider().models?.map((model) => model.id) ?? [];
|
||||
expect(modelIds).toContain("moonshotai/kimi-k2.6");
|
||||
expect(modelIds).toContain("moonshotai/kimi-k2.5");
|
||||
});
|
||||
|
||||
it("uses the canonical prefixed OpenRouter auto model id", () => {
|
||||
@@ -50,9 +50,9 @@ describe("openrouter provider hooks", () => {
|
||||
});
|
||||
|
||||
it("does not include retired stealth models in the bundled catalog", () => {
|
||||
expect(buildOpenrouterProvider().models?.map((model) => model.id)).not.toEqual(
|
||||
expect.arrayContaining(["openrouter/hunter-alpha", "openrouter/healer-alpha"]),
|
||||
);
|
||||
const modelIds = buildOpenrouterProvider().models?.map((model) => model.id) ?? [];
|
||||
expect(modelIds).not.toContain("openrouter/hunter-alpha");
|
||||
expect(modelIds).not.toContain("openrouter/healer-alpha");
|
||||
});
|
||||
|
||||
it("keeps stale Hunter Alpha configs out of OpenRouter proxy reasoning", () => {
|
||||
@@ -137,58 +137,49 @@ describe("openrouter provider hooks", () => {
|
||||
it("canonicalizes stale OpenRouter /v1 config and runtime metadata", async () => {
|
||||
const provider = await registerSingleProviderPlugin(openrouterPlugin);
|
||||
|
||||
expect(
|
||||
provider.normalizeConfig?.({
|
||||
provider: "openrouter",
|
||||
providerConfig: {
|
||||
api: "openai-completions",
|
||||
baseUrl: "https://openrouter.ai/v1/",
|
||||
models: [],
|
||||
},
|
||||
} as never),
|
||||
).toMatchObject({
|
||||
baseUrl: "https://openrouter.ai/api/v1",
|
||||
});
|
||||
const normalizedConfig = provider.normalizeConfig?.({
|
||||
provider: "openrouter",
|
||||
providerConfig: {
|
||||
api: "openai-completions",
|
||||
baseUrl: "https://openrouter.ai/v1/",
|
||||
models: [],
|
||||
},
|
||||
} as never);
|
||||
expect(normalizedConfig?.baseUrl).toBe("https://openrouter.ai/api/v1");
|
||||
|
||||
expect(
|
||||
provider.normalizeResolvedModel?.({
|
||||
const normalizedGptModel = provider.normalizeResolvedModel?.({
|
||||
provider: "openrouter",
|
||||
model: {
|
||||
provider: "openrouter",
|
||||
model: {
|
||||
provider: "openrouter",
|
||||
id: "openai/gpt-5.4",
|
||||
name: "openai/gpt-5.4",
|
||||
api: "openai-completions",
|
||||
baseUrl: "https://openrouter.ai/v1",
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: 200_000,
|
||||
maxTokens: 8192,
|
||||
},
|
||||
} as never),
|
||||
).toMatchObject({
|
||||
baseUrl: "https://openrouter.ai/api/v1",
|
||||
});
|
||||
id: "openai/gpt-5.4",
|
||||
name: "openai/gpt-5.4",
|
||||
api: "openai-completions",
|
||||
baseUrl: "https://openrouter.ai/v1",
|
||||
reasoning: true,
|
||||
input: ["text", "image"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: 200_000,
|
||||
maxTokens: 8192,
|
||||
},
|
||||
} as never);
|
||||
expect(normalizedGptModel?.baseUrl).toBe("https://openrouter.ai/api/v1");
|
||||
|
||||
expect(
|
||||
provider.normalizeResolvedModel?.({
|
||||
const normalizedHunterModel = provider.normalizeResolvedModel?.({
|
||||
provider: "openrouter",
|
||||
model: {
|
||||
provider: "openrouter",
|
||||
model: {
|
||||
provider: "openrouter",
|
||||
id: "openrouter/hunter-alpha",
|
||||
name: "Hunter Alpha",
|
||||
api: "openai-completions",
|
||||
baseUrl: "https://openrouter.ai/api/v1",
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: 1_048_576,
|
||||
maxTokens: 65_536,
|
||||
},
|
||||
} as never),
|
||||
).toMatchObject({
|
||||
reasoning: false,
|
||||
});
|
||||
id: "openrouter/hunter-alpha",
|
||||
name: "Hunter Alpha",
|
||||
api: "openai-completions",
|
||||
baseUrl: "https://openrouter.ai/api/v1",
|
||||
reasoning: true,
|
||||
input: ["text"],
|
||||
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
||||
contextWindow: 1_048_576,
|
||||
maxTokens: 65_536,
|
||||
},
|
||||
} as never);
|
||||
expect(normalizedHunterModel?.reasoning).toBe(false);
|
||||
|
||||
expect(
|
||||
provider.normalizeTransport?.({
|
||||
@@ -235,13 +226,8 @@ describe("openrouter provider hooks", () => {
|
||||
expect(baseStreamFn).toHaveBeenCalledOnce();
|
||||
const firstCall = baseStreamFn.mock.calls[0];
|
||||
const firstModel = firstCall?.[0];
|
||||
expect(firstModel).toMatchObject({
|
||||
compat: {
|
||||
openRouterRouting: {
|
||||
order: ["moonshot"],
|
||||
},
|
||||
},
|
||||
});
|
||||
const compat = (firstModel as { compat?: { openRouterRouting?: { order?: unknown } } }).compat;
|
||||
expect(compat?.openRouterRouting?.order).toEqual(["moonshot"]);
|
||||
});
|
||||
|
||||
it("does not inject OpenRouter reasoning for Hunter Alpha", async () => {
|
||||
@@ -323,20 +309,18 @@ describe("openrouter provider hooks", () => {
|
||||
{},
|
||||
);
|
||||
|
||||
expect(capturedPayload).toMatchObject({
|
||||
thinking: { type: "enabled" },
|
||||
reasoning_effort: "xhigh",
|
||||
messages: [
|
||||
{ role: "user", content: "read file" },
|
||||
{
|
||||
role: "assistant",
|
||||
tool_calls: [{ id: "call_1", type: "function" }],
|
||||
reasoning_content: "",
|
||||
},
|
||||
{ role: "tool", content: "ok" },
|
||||
{ role: "assistant", content: "done", reasoning_content: "" },
|
||||
],
|
||||
});
|
||||
expect(capturedPayload?.thinking).toEqual({ type: "enabled" });
|
||||
expect(capturedPayload?.reasoning_effort).toBe("xhigh");
|
||||
expect(capturedPayload?.messages).toEqual([
|
||||
{ role: "user", content: "read file" },
|
||||
{
|
||||
role: "assistant",
|
||||
tool_calls: [{ id: "call_1", type: "function" }],
|
||||
reasoning_content: "",
|
||||
},
|
||||
{ role: "tool", content: "ok" },
|
||||
{ role: "assistant", content: "done", reasoning_content: "" },
|
||||
]);
|
||||
expect(baseStreamFn).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
@@ -486,10 +470,8 @@ describe("openrouter provider hooks", () => {
|
||||
{},
|
||||
);
|
||||
|
||||
expect(capturedPayload).toMatchObject({
|
||||
messages: [{ role: "user", content: "Return JSON." }],
|
||||
reasoning: { effort: "high" },
|
||||
});
|
||||
expect(capturedPayload?.messages).toEqual([{ role: "user", content: "Return JSON." }]);
|
||||
expect(capturedPayload?.reasoning).toEqual({ effort: "high" });
|
||||
expect(baseStreamFn).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
@@ -552,6 +534,6 @@ describe("openrouter provider hooks", () => {
|
||||
expect(payloads[0]?.messages).toHaveLength(2);
|
||||
expect(payloads[0]).not.toHaveProperty("reasoning");
|
||||
expect(payloads[1]?.messages).toHaveLength(2);
|
||||
expect(payloads[1]).toMatchObject({ reasoning: { effort: "high" } });
|
||||
expect(payloads[1]?.reasoning).toEqual({ effort: "high" });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user