Files
OmniRoute/tests/unit/vendor-default-thinking-effort.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

116 lines
5.1 KiB
TypeScript

/**
* Regression guard for the vendor-declared default reasoning effort.
*
* OpenRouter's /api/v1/models declares for reasoning-only models (measured on
* `stealth/ox-alpha`): `reasoning:{mandatory:true, default_enabled:true,
* default_effort:"max", supported_efforts:["max","high","low"]}`. Discovery
* previously captured `supported_efforts` (#7694) but dropped `default_effort`,
* and the OpenAI dispatch path (#6879 `applyDefaultReasoningEffort`) only ever
* consulted static `ModelSpec.defaultReasoningEffort` + suffix aliases — so a
* request with no reasoning field could reach a model that returns an empty
* response without an explicit effort (`upstream_empty_response`).
*
* Fix: `normalizeDiscoveredModels` captures `reasoning.default_effort`
* (normalized onto the canonical vocabulary: `max` → `xhigh`) as
* `defaultThinkingEffort`, and `applyDefaultReasoningEffort` accepts it as the
* lowest-priority default — behind a `-{effort}` suffix alias and behind a static
* operator-configured `ModelSpec.defaultReasoningEffort`.
*/
import test from "node:test";
import assert from "node:assert/strict";
import { normalizeDiscoveredModels } from "@/lib/providerModels/modelDiscovery";
import { applyDefaultReasoningEffort } from "../../open-sse/services/defaultReasoningEffort.ts";
import { MODEL_SPECS } from "../../src/shared/constants/modelSpecs.ts";
// ---------------------------------------------------------------------------
// Discovery capture
// ---------------------------------------------------------------------------
test("maps OpenRouter reasoning.default_effort onto defaultThinkingEffort", () => {
const [model] = normalizeDiscoveredModels([
{
id: "stealth/ox-alpha",
context_length: 1048576,
reasoning: {
mandatory: true,
default_enabled: true,
default_effort: "max",
supported_efforts: ["max", "high", "low"],
},
},
]);
assert.equal(model.id, "stealth/ox-alpha");
// `max` is normalized onto the canonical vocabulary (`xhigh`), same mapping the
// supported-efforts list already applies.
assert.equal(model.defaultThinkingEffort, "xhigh");
assert.deepEqual(model.supportedThinkingEfforts, ["xhigh", "high", "low"]);
});
test("a canonical default_effort passes through unchanged", () => {
const [model] = normalizeDiscoveredModels([
{ id: "vendor/model", reasoning: { default_effort: "low" } },
]);
assert.equal(model.defaultThinkingEffort, "low");
});
test("a flat defaultThinkingEffort (import format) stays authoritative over the nested shape", () => {
const [model] = normalizeDiscoveredModels([
{ id: "vendor/model", defaultThinkingEffort: "low", reasoning: { default_effort: "high" } },
]);
assert.equal(model.defaultThinkingEffort, "low");
});
test("a malformed reasoning.default_effort degrades to unset (one bad record never fails the sync)", () => {
const [model] = normalizeDiscoveredModels([
{ id: "vendor/model", reasoning: { default_effort: 42 } },
]);
assert.equal(model.defaultThinkingEffort, undefined);
});
test("no reasoning metadata -> defaultThinkingEffort unset", () => {
const [model] = normalizeDiscoveredModels([{ id: "vendor/model" }]);
assert.equal(model.defaultThinkingEffort, undefined);
});
// ---------------------------------------------------------------------------
// Dispatch injection (lowest-priority default)
// ---------------------------------------------------------------------------
test("injects the vendor-declared default when no reasoning field and no other default exists", () => {
const body = { model: "stealth/ox-alpha", messages: [] };
const result = applyDefaultReasoningEffort(body, "stealth/ox-alpha", null, "xhigh");
assert.equal(result.reasoning_effort, "xhigh");
});
test("a suffix-resolved effort (#7694) wins over the vendor default", () => {
const body = { model: "stealth/ox-alpha-low", messages: [] };
const result = applyDefaultReasoningEffort(body, "stealth/ox-alpha", "low", "xhigh");
assert.equal(result.reasoning_effort, "low");
});
test("an explicit client reasoning_effort still wins over the vendor default", () => {
const body = { model: "stealth/ox-alpha", messages: [], reasoning_effort: "low" };
const result = applyDefaultReasoningEffort(body, "stealth/ox-alpha", null, "xhigh");
assert.equal(result.reasoning_effort, "low");
});
test("no vendor default and no other default -> no injection (regression, same reference)", () => {
const body = { model: "vendor/plain-model", messages: [] };
const result = applyDefaultReasoningEffort(body, "vendor/plain-model", null, null);
assert.equal(result, body);
});
test("an operator ModelSpec.defaultReasoningEffort wins over the vendor default", () => {
const FIXTURE_MODEL_ID = "__test_vendor_default_reasoning_effort_model__";
MODEL_SPECS[FIXTURE_MODEL_ID] = { defaultReasoningEffort: "none" };
try {
const body = { model: FIXTURE_MODEL_ID, messages: [] };
const result = applyDefaultReasoningEffort(body, FIXTURE_MODEL_ID, null, "xhigh");
assert.equal(result.reasoning_effort, "none");
} finally {
delete MODEL_SPECS[FIXTURE_MODEL_ID];
}
});