mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-13 18:32:12 +03:00
Landed with the design call resolved per the owner's pick — **option 1**: the synced store is now endpoint-agnostic (persistDiscoveredModels and managedModelImport no longer drop non-chat models at write time), and chat selectability moved to read time (auto-pool expansion in autoStrategy applies filterChatSelectableModels; the models-route projection already had its chatOnly filter). Your discovery test now passes end-to-end (3/3): /api/show capabilities persist per connection and image/embedding requests route through the advertising host. Reconciliation notes: conflicted areas merged onto the current tip (adobe discovery import, requestedModel preflight signature, resolvedProvider fast-path coexists with the synced-route override — explicit resolution wins); carried base-red drains (#10055 memoization, #11071 test variants) dropped as already-landed; the managed-model-import exclusion test was propagated to the new contract (image/video models persist; the read filter still hides them from chat pickers — pinned by a new assertion). Full battery: 205/206 focused (the one red is a confirmed periodic-timer timing flake on the loaded devbox — 20/20 isolated), autoCombo vitest 30/30, combo suites 46/46, gates + typecheck clean. Thank you @yourspraveen — the capability probe + routing design was right; it just needed the store contract opened up. Fixes #11087.
169 lines
7.4 KiB
TypeScript
169 lines
7.4 KiB
TypeScript
import { after, before, describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const { OpencodeExecutor } = await import("../../open-sse/executors/opencode.ts");
|
|
const { PROVIDER_MODELS } = await import("../../open-sse/config/providerModels.ts");
|
|
|
|
function createInput(model, stream = true, credentials = null) {
|
|
return {
|
|
model,
|
|
stream,
|
|
credentials,
|
|
body: {
|
|
model,
|
|
stream,
|
|
messages: [{ role: "user", content: "hello" }],
|
|
},
|
|
};
|
|
}
|
|
|
|
function createMockResponse() {
|
|
return new Response(JSON.stringify({ ok: true }), {
|
|
status: 200,
|
|
headers: { "Content-Type": "application/json" },
|
|
});
|
|
}
|
|
|
|
describe("OpencodeExecutor — premium model keyless gate (#8681)", () => {
|
|
let originalFetch: typeof globalThis.fetch;
|
|
|
|
before(() => {
|
|
originalFetch = globalThis.fetch;
|
|
globalThis.fetch = (async (_url: string, _options?: RequestInit) => {
|
|
return createMockResponse();
|
|
}) as typeof globalThis.fetch;
|
|
});
|
|
|
|
after(() => {
|
|
globalThis.fetch = originalFetch;
|
|
});
|
|
|
|
describe("isPremiumModel", () => {
|
|
it("returns false for known free models on opencode-zen", () => {
|
|
// Free models from the opencode (noauth) registry
|
|
assert.equal(OpencodeExecutor.isPremiumModel("big-pickle", "opencode-zen"), false);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("deepseek-v4-flash-free", "opencode-zen"), false);
|
|
});
|
|
|
|
it("returns false for models ending in -free on opencode-zen", () => {
|
|
assert.equal(OpencodeExecutor.isPremiumModel("mimo-v2.5-free", "opencode-zen"), false);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("nemotron-3-ultra-free", "opencode-zen"), false);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("north-mini-code-free", "opencode-zen"), false);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("hy3-free", "opencode-zen"), false);
|
|
});
|
|
|
|
it("returns true for premium models on opencode-zen", () => {
|
|
assert.equal(OpencodeExecutor.isPremiumModel("gpt-5", "opencode-zen"), true);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("gpt-5-nano", "opencode-zen"), true);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("claude-sonnet-4-5", "opencode-zen"), true);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("gemini-3-flash", "opencode-zen"), true);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("kimi-k2.6", "opencode-zen"), true);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("glm-5", "opencode-zen"), true);
|
|
});
|
|
|
|
it("returns true for ALL models on opencode-go (no free tier)", () => {
|
|
assert.equal(OpencodeExecutor.isPremiumModel("deepseek-v4-pro", "opencode-go"), true);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("kimi-k2.7-code", "opencode-go"), true);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("glm-5.2", "opencode-go"), true);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("deepseek-v4-flash-free", "opencode-go"), true);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("big-pickle", "opencode-go"), true);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("mimo-v2.5-free", "opencode-go"), true);
|
|
});
|
|
|
|
it("returns false for free models on the opencode (noauth) provider", () => {
|
|
assert.equal(OpencodeExecutor.isPremiumModel("deepseek-v4-flash-free", "opencode"), false);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("big-pickle", "opencode"), false);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("hy3-free", "opencode"), false);
|
|
});
|
|
|
|
it("returns true for premium models on the opencode (noauth) provider", () => {
|
|
assert.equal(OpencodeExecutor.isPremiumModel("gpt-5", "opencode"), true);
|
|
assert.equal(OpencodeExecutor.isPremiumModel("claude-sonnet-4-5", "opencode"), true);
|
|
});
|
|
|
|
it("returns true for unknown models on any opencode provider", () => {
|
|
assert.equal(OpencodeExecutor.isPremiumModel("unknown-random-model", "opencode-zen"), true);
|
|
});
|
|
});
|
|
|
|
describe("execute with keyless credentials", () => {
|
|
const zenExecutor = new OpencodeExecutor("opencode-zen");
|
|
|
|
it("returns 402 for premium model gpt-5 with keyless credentials", async () => {
|
|
const result = await zenExecutor.execute(createInput("gpt-5", true, null));
|
|
const response = result instanceof Response ? result : result.response;
|
|
const body = await response.json() as { error: { message: string } };
|
|
assert.equal(response.status, 402);
|
|
assert.ok(
|
|
body.error.message.includes("API key"),
|
|
`Expected message to mention "API key" — got: ${body.error.message}`
|
|
);
|
|
assert.ok(
|
|
!body.error.message.includes("Missing API key"),
|
|
"Should NOT be the raw upstream 'Missing API key' message"
|
|
);
|
|
});
|
|
|
|
it("returns 402 for premium model claude-sonnet-4-5 with keyless credentials", async () => {
|
|
const result = await zenExecutor.execute(createInput("claude-sonnet-4-5", true, null));
|
|
const response = result instanceof Response ? result : result.response;
|
|
assert.equal(response.status, 402);
|
|
});
|
|
|
|
it("allows free model deepseek-v4-flash-free with keyless credentials", async () => {
|
|
// Should reach the upstream fetch (mock returns 200)
|
|
const result = await zenExecutor.execute(createInput("deepseek-v4-flash-free", true, null));
|
|
const response = result instanceof Response ? result : result.response;
|
|
// Should NOT be 402 (the premium gate); should reach the mock fetch
|
|
assert.notEqual(response.status, 402);
|
|
});
|
|
|
|
it("allows free model big-pickle with keyless credentials", async () => {
|
|
const result = await zenExecutor.execute(createInput("big-pickle", true, null));
|
|
const response = result instanceof Response ? result : result.response;
|
|
assert.notEqual(response.status, 402);
|
|
});
|
|
});
|
|
|
|
describe("execute with valid key credentials", () => {
|
|
const zenExecutor = new OpencodeExecutor("opencode-zen");
|
|
|
|
it("allows premium model gpt-5 with a valid API key", async () => {
|
|
// Should reach the upstream fetch (mock returns 200)
|
|
const result = await zenExecutor.execute(createInput("gpt-5", true, { apiKey: "valid-key" }));
|
|
const response = result instanceof Response ? result : result.response;
|
|
assert.notEqual(response.status, 402);
|
|
});
|
|
|
|
it("allows premium model claude-sonnet-4-5 with a valid API key", async () => {
|
|
const result = await zenExecutor.execute(
|
|
createInput("claude-sonnet-4-5", true, { apiKey: "valid-key" })
|
|
);
|
|
const response = result instanceof Response ? result : result.response;
|
|
assert.notEqual(response.status, 402);
|
|
});
|
|
});
|
|
|
|
describe("execute with keyless credentials on opencode-go", () => {
|
|
const goExecutor = new OpencodeExecutor("opencode-go");
|
|
|
|
it("returns 402 for ANY model with keyless credentials (opencode-go has no free tier)", async () => {
|
|
const result = await goExecutor.execute(createInput("deepseek-v4-pro", true, null));
|
|
const response = result instanceof Response ? result : result.response;
|
|
assert.equal(response.status, 402);
|
|
});
|
|
});
|
|
|
|
describe("execute with valid key on opencode-go", () => {
|
|
const goExecutor = new OpencodeExecutor("opencode-go");
|
|
|
|
it("allows deepseek-v4-pro with a valid API key", async () => {
|
|
const result = await goExecutor.execute(
|
|
createInput("deepseek-v4-pro", true, { apiKey: "valid-key" })
|
|
);
|
|
const response = result instanceof Response ? result : result.response;
|
|
assert.notEqual(response.status, 402);
|
|
});
|
|
});
|
|
});
|