Files
OmniRoute/tests/unit/no-thinking-alias.test.ts
Will Gordon 4795825513 fix(sse): make Claude effort/no-think catalog variants dispatchable on every provider (#9006)
* fix(executors): route Claude-via-Vertex through native rawPredict with real streaming

Claude models on Vertex AI were being sent through the generic OpenAI-
compatible partner endpoint, which 404s/errors for Claude on at least
some projects. Route them through Vertex's native Anthropic Messages
API (publishers/anthropic/.../rawPredict) instead, stripping the
body-level model field rawPredict rejects and injecting the required
anthropic_version field.

rawPredict only ever returns a complete JSON body, never real SSE
framing, so streaming requests now get a genuine Anthropic-format SSE
stream synthesized from that JSON (message_start/content_block_*/
message_delta/message_stop), which the existing claude-to-openai
response translator already knows how to parse.

Also fixes two response-format resolution bugs that silently dropped
a custom model's DB-stored targetFormat override whenever the model
id also existed in the static provider registry (as claude-sonnet-4-6
and claude-opus-4-7 do under vertex): resolveModelOrError had its own
ad-hoc resolution that never consulted the override, and even once
fixed, executeChatWithBreaker discarded the correctly-resolved format
before handleChatCore's own resolution ran a second time.

* docs: add changelog fragment for #8909

* refactor(sse): extract shared Claude effort-model predicate

* fix(sse): strip Claude effort-suffix ids for any provider serving a real Claude model

* fix(sse): keep no-think and CC-discovery catalog variant roots unprefixed

* fix(dashboard): re-qualify no-think playground model ids correctly

* fix(sse): scope Vertex 404s to a per-model lockout via passthroughModels

* docs: add changelog fragment for the Claude catalog/dispatch fix

* fix(sse): align regex naming and changelog formatting

* fix(sse): clarify effort-variant strip comment and add cross-module drift guard

* fix(sse): disambiguate Vertex connection-wide vs per-model 403s

* docs: document Vertex 403 disambiguation in changelog fragment

* fix(sse): correlate reason and resource within the same ErrorInfo detail

* fix(sse): extract Vertex error classifier and rebaseline frozen file sizes

* test: register vertex-passthrough-model-lockout in stryker tap.testFiles

* fix(sse): reconciles rebase-onto-tip drift for 9006

Two categories of inherited base-branch breakage surfaced when
rebasing onto release/v3.8.50's latest tip, both confirmed unrelated
to this PR's own diff:

- check:file-size: base.ts and chat.ts drifted further past their
  frozen caps via already-merged commits (7163081f5 and others) that
  didn't rebaseline after growing them. Documented and bumped in
  file-size-baseline.json.
- chat-helpers.test.ts: two gpt-5.5 routing assertions predate #9275
  (fix(routing): bare model ids route to codex first), which
  deliberately made gpt-5.5 route to codex unconditionally, regardless
  of which other providers are active. Confirmed via #9275's own
  commit message and code comments this is intentional, not a
  regression; verified reproducible on the raw base tip alone, with
  no changes from this PR involved. Updated both assertions and their
  names to match the new, intentional default.

* ci: re-trigger checks after GitHub Actions incident (2026-08-07, resolved)

* ci: re-trigger checks (previous push event was dropped)

* fix(quality): rebaseline combo-routing-engine.test.ts own-comment growth

The ALL_ACCOUNTS_INACTIVE->ALL_TARGETS_SKIPPED fix (a32aed738) added explanatory comments (+7 lines), pushing the file past its frozen 3457 cap. CI's PR-mode check:file-size caught it; local check-file-size.mjs was not re-run after that specific commit.
2026-08-11 10:02:48 -03:00

187 lines
8.4 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert/strict";
import {
NO_THINKING_PREFIX,
isNoThinkingAlias,
stripNoThinkingAlias,
toNoThinkingAlias,
shouldExposeNoThinkingAlias,
appendNoThinkingVariants,
applyNoThinkingAlias,
} from "../../open-sse/utils/noThinkingAlias.ts";
// ── prefix predicates ────────────────────────────────────────────────────────
test("NO_THINKING_PREFIX is the documented gateway prefix", () => {
assert.equal(NO_THINKING_PREFIX, "no-think/");
});
test("isNoThinkingAlias detects the prefix only", () => {
assert.equal(isNoThinkingAlias("no-think/anthropic/claude-opus-4-5"), true);
assert.equal(isNoThinkingAlias("anthropic/claude-opus-4-5"), false);
assert.equal(isNoThinkingAlias("claude-opus-4-5"), false);
// non-strings never match
assert.equal(isNoThinkingAlias(undefined as unknown as string), false);
assert.equal(isNoThinkingAlias(123 as unknown as string), false);
});
test("stripNoThinkingAlias unwraps the prefix and passes plain ids through", () => {
assert.equal(
stripNoThinkingAlias("no-think/anthropic/claude-opus-4-5"),
"anthropic/claude-opus-4-5"
);
assert.equal(stripNoThinkingAlias("claude-opus-4-5"), "claude-opus-4-5");
});
test("toNoThinkingAlias round-trips with stripNoThinkingAlias", () => {
const real = "anthropic/claude-sonnet-4-6";
const alias = toNoThinkingAlias(real);
assert.equal(alias, "no-think/anthropic/claude-sonnet-4-6");
assert.equal(isNoThinkingAlias(alias), true);
assert.equal(stripNoThinkingAlias(alias), real);
});
// ── request-side suppression ─────────────────────────────────────────────────
test("applyNoThinkingAlias rewrites the model and disables thinking (Claude format)", () => {
const body: Record<string, unknown> = {
model: "no-think/anthropic/claude-opus-4-5",
thinking: { type: "enabled", budget_tokens: 8000 },
reasoning_effort: "high",
messages: [],
};
const res = applyNoThinkingAlias(body, { claudeFormat: true });
assert.equal(res.applied, true);
assert.equal(res.realModel, "anthropic/claude-opus-4-5");
assert.equal(body.model, "anthropic/claude-opus-4-5");
assert.deepEqual(body.thinking, { type: "disabled" });
assert.ok(!("reasoning_effort" in body), "reasoning_effort must be stripped");
});
test("applyNoThinkingAlias expresses reasoning_effort:none without a thinking block (OpenAI format)", () => {
const body: Record<string, unknown> = {
model: "no-think/openai/gpt-5.4",
reasoning_effort: "high",
reasoning: { effort: "high" },
messages: [],
};
const res = applyNoThinkingAlias(body, { claudeFormat: false });
assert.equal(res.applied, true);
assert.equal(body.model, "openai/gpt-5.4");
assert.ok(!("thinking" in body), "no Claude thinking block on an OpenAI body");
// #6879: a thinks-by-default OpenAI-shape model must carry reasoning_effort:"none"
// explicitly (not merely have the field deleted), so suppression actually takes
// effect downstream; the Responses-shaped `reasoning` object is still dropped.
assert.equal(
body.reasoning_effort,
"none",
"reasoning_effort must express none, not be stripped"
);
assert.ok(!("reasoning" in body), "reasoning object must be dropped");
});
test("applyNoThinkingAlias is a no-op for plain models", () => {
const body: Record<string, unknown> = {
model: "anthropic/claude-opus-4-5",
thinking: { type: "enabled" },
};
const res = applyNoThinkingAlias(body, { claudeFormat: true });
assert.equal(res.applied, false);
assert.equal(body.model, "anthropic/claude-opus-4-5");
assert.deepEqual(
body.thinking,
{ type: "enabled" },
"thinking is left untouched when not an alias"
);
});
test("applyNoThinkingAlias ignores a malformed prefix-only model", () => {
const body: Record<string, unknown> = { model: "no-think/" };
const res = applyNoThinkingAlias(body, { claudeFormat: true });
assert.equal(res.applied, false);
assert.equal(body.model, "no-think/", "left untouched when nothing follows the prefix");
});
// ── catalog gating ───────────────────────────────────────────────────────────
const entry = (id: string, owned_by = "anthropic") => ({ id, object: "model", owned_by });
test("shouldExposeNoThinkingAlias accepts a Claude reasoning model that honors disabled", () => {
assert.equal(shouldExposeNoThinkingAlias(entry("claude-opus-4-5")), true);
assert.equal(shouldExposeNoThinkingAlias(entry("anthropic/claude-sonnet-4-6")), true);
});
test("shouldExposeNoThinkingAlias rejects models where suppression is meaningless", () => {
// gpt-4o does not support thinking
assert.equal(shouldExposeNoThinkingAlias(entry("gpt-4o", "openai")), false);
// fable-5 rejects thinking.type:disabled — a no-thinking variant would be a lie
assert.equal(shouldExposeNoThinkingAlias(entry("claude-fable-5")), false);
// combos are virtual, never aliased
assert.equal(shouldExposeNoThinkingAlias(entry("my-combo", "combo")), false);
// never double-alias
assert.equal(shouldExposeNoThinkingAlias(entry("no-think/anthropic/claude-opus-4-5")), false);
});
test("appendNoThinkingVariants adds one variant per eligible model and preserves the rest", () => {
const models = [entry("claude-opus-4-5"), entry("gpt-4o", "openai"), entry("claude-fable-5")];
const out = appendNoThinkingVariants(models);
const ids = out.map((m) => m.id);
assert.ok(ids.includes("no-think/claude-opus-4-5"), "eligible model gets a variant");
assert.ok(!ids.includes("no-think/gpt-4o"), "non-thinking model has no variant");
assert.ok(!ids.includes("no-think/claude-fable-5"), "reject-disabled model has no variant");
assert.equal(out.length, models.length + 1, "exactly one variant appended");
// originals preserved up front
assert.deepEqual(out.slice(0, 3), models);
});
test("appendNoThinkingVariants returns the same array reference when nothing is eligible", () => {
const models = [entry("gpt-4o", "openai")];
assert.equal(appendNoThinkingVariants(models), models);
});
test("appendNoThinkingVariants normalizes alias prefix to canonical when aliasToCanonical map is provided", () => {
const models = [entry("cc/claude-opus-4-5")];
const aliasToCanonical = { cc: "claude" };
const out = appendNoThinkingVariants(models, aliasToCanonical);
const ids = out.map((m) => m.id);
assert.ok(ids.includes("no-think/claude/claude-opus-4-5"), "uses canonical prefix");
assert.ok(!ids.includes("no-think/cc/claude-opus-4-5"), "alias prefix not used");
});
test("appendNoThinkingVariants keeps alias prefix when no map is provided", () => {
const models = [entry("cc/claude-opus-4-5")];
const out = appendNoThinkingVariants(models);
const ids = out.map((m) => m.id);
assert.ok(ids.includes("no-think/cc/claude-opus-4-5"), "alias prefix preserved");
});
test("appendNoThinkingVariants keeps root bare even when id carries a provider prefix", () => {
const models = [entry("vertex/claude-opus-4-5", "vertex")];
const out = appendNoThinkingVariants(models);
const variant = out.find((m) => m.id === "no-think/vertex/claude-opus-4-5");
assert.ok(variant, "variant with the fully-qualified id must exist");
assert.equal(
variant!.root,
"no-think/claude-opus-4-5",
"root must be bare (no embedded provider segment), matching the effort-variant convention"
);
});
test("shouldExposeNoThinkingAlias rejects an already effort-suffixed id", () => {
assert.equal(shouldExposeNoThinkingAlias(entry("vertex/claude-sonnet-5-high")), false);
assert.equal(shouldExposeNoThinkingAlias(entry("claude-opus-4-5-xhigh")), false);
});
test("appendNoThinkingVariants does not synthesize a no-think variant of an effort variant", () => {
// Simulates the real pipeline order in catalogResponse.ts: appendClaudeEffortVariants
// runs first and produces an id like this before appendNoThinkingVariants ever sees it.
const models = [entry("vertex/claude-sonnet-5-high")];
const out = appendNoThinkingVariants(models);
assert.equal(out, models, "no variant should be added for an effort-suffixed id");
assert.ok(
!out.some((m) => m.id === "no-think/vertex/claude-sonnet-5-high"),
"the incoherent combined id must never be advertised"
);
});