Files
OmniRoute/tests/unit/chatcore-claude-effort-variant.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

176 lines
6.9 KiB
TypeScript

// tests/unit/chatcore-claude-effort-variant.test.ts
// Characterization of applyClaudeEffortVariant — the Claude effort-suffix normalization extracted
// from handleChatCore (chatCore god-file decomposition, #3501). The VS Code "Effort" slider
// advertises claude-...-{low,medium,high,xhigh,max}; Anthropic has no such model, so the suffix is
// stripped to the base id and surfaced as reasoning_effort. Locks: the direct-Claude-lane
// unconditional strip (claude / claude-code-compatible), the predicate-gated strip for any other
// provider serving a real Claude model, the in-place body mutation (model + reasoning_effort), the
// sourceFormat==="claude" skip, the explicit-effort-wins rule, and the returned effectiveModel/log.
import { test } from "node:test";
import assert from "node:assert/strict";
import { applyClaudeEffortVariant } from "../../open-sse/handlers/chatCore/claudeEffortVariant.ts";
import { FORMATS } from "../../open-sse/translator/formats.ts";
test("claude provider + effort suffix → strips to base, mutates body model + reasoning_effort, returns log", () => {
const body: Record<string, unknown> = { model: "claude-sonnet-4-high", messages: [] };
const r = applyClaudeEffortVariant({
provider: "claude",
effectiveModel: "claude-sonnet-4-high",
body,
sourceFormat: FORMATS.OPENAI,
});
assert.equal(r.effectiveModel, "claude-sonnet-4");
assert.equal(body.model, "claude-sonnet-4");
assert.equal(body.reasoning_effort, "high");
assert.match(String(r.log), /stripped "-high" → claude-sonnet-4 \(reasoning_effort=high\)/);
});
test("claude-code-compatible provider triggers the same stripping", () => {
const body: Record<string, unknown> = { model: "claude-opus-4-xhigh", messages: [] };
const r = applyClaudeEffortVariant({
provider: "anthropic-compatible-cc-default",
effectiveModel: "claude-opus-4-xhigh",
body,
sourceFormat: FORMATS.OPENAI,
});
assert.equal(r.effectiveModel, "claude-opus-4");
assert.equal(body.model, "claude-opus-4");
assert.equal(body.reasoning_effort, "xhigh");
});
test("sourceFormat 'claude' strips the model but does NOT inject reasoning_effort", () => {
const body: Record<string, unknown> = { model: "claude-sonnet-4-medium", messages: [] };
const r = applyClaudeEffortVariant({
provider: "claude",
effectiveModel: "claude-sonnet-4-medium",
body,
sourceFormat: FORMATS.CLAUDE,
});
assert.equal(r.effectiveModel, "claude-sonnet-4");
assert.equal(body.model, "claude-sonnet-4");
assert.equal(body.reasoning_effort, undefined);
});
test("an explicit client reasoning_effort wins (not overwritten)", () => {
const body: Record<string, unknown> = {
model: "claude-sonnet-4-low",
reasoning_effort: "high",
messages: [],
};
const r = applyClaudeEffortVariant({
provider: "claude",
effectiveModel: "claude-sonnet-4-low",
body,
sourceFormat: FORMATS.OPENAI,
});
assert.equal(r.effectiveModel, "claude-sonnet-4");
assert.equal(body.reasoning_effort, "high"); // unchanged
});
test("explicit effort nested under reasoning.effort also wins", () => {
const body: Record<string, unknown> = {
model: "claude-sonnet-4-low",
reasoning: { effort: "medium" },
messages: [],
};
const r = applyClaudeEffortVariant({
provider: "claude",
effectiveModel: "claude-sonnet-4-low",
body,
sourceFormat: FORMATS.OPENAI,
});
assert.equal(body.reasoning_effort, undefined); // explicit reasoning.effort present → no injection
assert.equal(r.effectiveModel, "claude-sonnet-4");
});
test("no effort suffix → no change, no log", () => {
const body: Record<string, unknown> = { model: "claude-sonnet-4", messages: [] };
const r = applyClaudeEffortVariant({
provider: "claude",
effectiveModel: "claude-sonnet-4",
body,
sourceFormat: FORMATS.OPENAI,
});
assert.equal(r.effectiveModel, "claude-sonnet-4");
assert.equal(body.model, "claude-sonnet-4");
assert.equal(body.reasoning_effort, undefined);
assert.equal(r.log, null);
});
test("non-claude provider is a no-op even with an effort suffix", () => {
const body: Record<string, unknown> = { model: "gpt-5-high", messages: [] };
const r = applyClaudeEffortVariant({
provider: "openai",
effectiveModel: "gpt-5-high",
body,
sourceFormat: FORMATS.OPENAI,
});
assert.equal(r.effectiveModel, "gpt-5-high");
assert.equal(body.model, "gpt-5-high");
assert.equal(body.reasoning_effort, undefined);
assert.equal(r.log, null);
});
test("non-claude provider serving a real Claude model strips the effort suffix", () => {
const body: Record<string, unknown> = { model: "claude-sonnet-5-high", messages: [] };
const r = applyClaudeEffortVariant({
provider: "vertex",
effectiveModel: "claude-sonnet-5-high",
body,
sourceFormat: FORMATS.OPENAI,
});
assert.equal(r.effectiveModel, "claude-sonnet-5");
assert.equal(body.model, "claude-sonnet-5");
assert.equal(body.reasoning_effort, "high");
});
test("safety guard: non-claude provider with a non-Claude model ending in a suffix word is left unchanged", () => {
const body: Record<string, unknown> = { model: "custom-model-high", messages: [] };
const r = applyClaudeEffortVariant({
provider: "some-other-provider",
effectiveModel: "custom-model-high",
body,
sourceFormat: FORMATS.OPENAI,
});
assert.equal(r.effectiveModel, "custom-model-high");
assert.equal(body.model, "custom-model-high");
assert.equal(body.reasoning_effort, undefined);
assert.equal(r.log, null);
});
test("claude-code-compatible provider strips even an unregistered model id (direct lane short-circuits the predicate)", () => {
// Proves the "unconditional strip, zero regression" claim: isDirectClaudeLane short-circuits
// the `||`, so isKnownClaudeEffortBaseModel() is never consulted for claude/CC-compatible
// providers — unlike the safety-guard case above, which requires the predicate to pass.
const body: Record<string, unknown> = {
model: "totally-unregistered-model-xyz-high",
messages: [],
};
const r = applyClaudeEffortVariant({
provider: "anthropic-compatible-cc-default",
effectiveModel: "totally-unregistered-model-xyz-high",
body,
sourceFormat: FORMATS.OPENAI,
});
assert.equal(r.effectiveModel, "totally-unregistered-model-xyz");
assert.equal(body.model, "totally-unregistered-model-xyz");
assert.equal(body.reasoning_effort, "high");
});
test("no-think alias's explicit reasoning_effort:none is not overwritten by a stripped effort suffix", () => {
const body: Record<string, unknown> = {
model: "claude-sonnet-5-high",
reasoning_effort: "none",
messages: [],
};
const r = applyClaudeEffortVariant({
provider: "vertex",
effectiveModel: "claude-sonnet-5-high",
body,
sourceFormat: FORMATS.OPENAI,
});
assert.equal(r.effectiveModel, "claude-sonnet-5");
assert.equal(body.model, "claude-sonnet-5");
assert.equal(body.reasoning_effort, "none");
});