Files
OmniRoute/tests/unit/opencode-limit-output-10940.test.ts
Praveen K Palaniswamy 65e81158ab fix(ollama): route models by advertised capability (#11088)
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.
2026-08-23 11:45:01 -03:00

86 lines
3.2 KiB
TypeScript

import { describe, it } from "node:test";
import assert from "node:assert";
/**
* Regression guard for #10940: OpenCode rejects a generated config with
* "Missing key provider.omniroute.models.{model}.limit.output" whenever a
* model has no catalog metadata (no `context_length`, no
* `max_output_tokens`) and no existing user override. `limit.output` is a
* REQUIRED field in OpenCode's v1 provider schema, so it must always be
* emitted — even when nothing is known about the model.
*/
describe("opencode config generator — limit.output always emitted (#10940)", () => {
function makeCatalogResponse(models: unknown[]): unknown {
return { object: "list", data: models };
}
function stubFetchOnce(body: unknown, status = 200) {
const original = globalThis.fetch;
// @ts-ignore — globalThis.fetch signature is compatible for our purposes
globalThis.fetch = (async () => {
return new Response(JSON.stringify(body), {
status,
headers: { "content-type": "application/json" },
});
}) as typeof fetch;
return {
restore: () => {
globalThis.fetch = original;
},
};
}
it("RED-proving case: a model with NO context_length and NO max_output_tokens still gets a numeric limit.output", async () => {
// This model has no metadata whatsoever beyond its id — exactly the
// shape that used to leave `entry.limit` undefined entirely (issue #10940).
const stub = stubFetchOnce(
makeCatalogResponse([{ id: "metadataless-model", owned_by: "someProvider" }])
);
try {
const { generateOpencodeConfig } = await import(
"../../src/lib/cli-helper/config-generator/opencode.ts"
);
const out = await generateOpencodeConfig({
baseUrl: "http://localhost:20128",
apiKey: "sk-test",
});
const cfg = JSON.parse(out);
const entry = cfg.provider.omniroute.models["metadataless-model"];
assert.ok(entry, "model entry must exist in the generated config");
assert.ok(entry.limit, "entry.limit must be present even without catalog metadata");
assert.strictEqual(
typeof entry.limit.output,
"number",
`entry.limit.output must be a number, got ${JSON.stringify(entry.limit?.output)}`
);
assert.ok(entry.limit.output > 0, "entry.limit.output must be a positive number");
// context defaults to 128k when unknown to satisfy OpenCode's required limit.context schema (#11035).
assert.strictEqual(entry.limit.context, 128_000);
} finally {
stub.restore();
}
});
it("honors the catalog's max_output_tokens when present", async () => {
const stub = stubFetchOnce(
makeCatalogResponse([
{ id: "has-output-meta", owned_by: "someProvider", max_output_tokens: 4096 },
])
);
try {
const { generateOpencodeConfig } = await import(
"../../src/lib/cli-helper/config-generator/opencode.ts"
);
const out = await generateOpencodeConfig({
baseUrl: "http://localhost:20128",
apiKey: "sk-test",
});
const cfg = JSON.parse(out);
const entry = cfg.provider.omniroute.models["has-output-meta"];
assert.strictEqual(entry.limit.output, 4096);
} finally {
stub.restore();
}
});
});