Files
OmniRoute/tests/unit/cache-control-claude-providers.test.ts
Diego Rodrigues de Sa e Souza c61cdc30aa fix(providers): switch minimax from claude to openai format so images work (#9463)
* fix(providers): switch minimax from claude to openai format so images work

The Anthropic-compatible /anthropic/v1/messages endpoint rejects image
input with 403. MiniMax's OpenAI-compatible /v1/chat/completions endpoint
supports image_url natively for MiniMax-M3.

- minimax + minimax-cn: format claude→openai, baseUrl→/v1/chat/completions
- Remove Anthropic-Version header + ?beta=true suffix (not needed for openai)
- Remove minimax/minimax-cn from ?beta=true executor case
- Update cache-control tests (openai format uses different caching path)
- Fix reasoning-split test names (no longer claude format)

TDD: 2 registry tests assert format=openai (red→green).
Refs: Hermes Agent #15715, MiniMax OpenAI-compatible API docs.

* fix(sse): re-align stream-readiness-policy tests with minimax's openai format

PR #9463 switched minimax/minimax-cn from claude to openai format so images
work. The stream-readiness bump for Claude-format replicas is keyed off the
registry's format field (single source of truth), so minimax legitimately
falls out of that group now. Swap the "Claude-format replica" test fixtures
to agentrouter (still format: "claude") and add explicit coverage that
minimax no longer gets the claude_format_heavy_reasoning bump.

---------

Co-authored-by: diegosouzapw <diegosouzapw@users.noreply.github.com>
2026-08-11 07:25:28 -03:00

163 lines
5.2 KiB
TypeScript

import { describe, test } from "node:test";
import assert from "node:assert/strict";
import {
providerSupportsCaching,
shouldPreserveCacheControl,
} from "../../open-sse/utils/cacheControlPolicy.ts";
describe("Cache Control Policy - Claude Protocol Providers", () => {
test("providerSupportsCaching returns true for Claude-format providers", () => {
// Known caching providers
assert.equal(providerSupportsCaching("claude", "claude"), true);
assert.equal(providerSupportsCaching("anthropic", "claude"), true);
assert.equal(providerSupportsCaching("zai", "claude"), true);
assert.equal(providerSupportsCaching("deepseek", "openai"), true);
// Claude-protocol providers NOT in CACHING_PROVIDERS set
// These should be detected via targetFormat
assert.equal(providerSupportsCaching("bailian-coding-plan", "claude"), true);
assert.equal(providerSupportsCaching("glm", "claude"), true);
// minimax/minimax-cn use openai format (#3110 / image 403 fix);
// caching support for their OpenAI-compatible endpoint is TBD
assert.equal(providerSupportsCaching("minimax", "openai"), false);
assert.equal(providerSupportsCaching("minimax-cn", "openai"), false);
assert.equal(providerSupportsCaching("kimi-coding", "claude"), true);
// #3955 — OpenAI / Codex use automatic prefix caching (no cache_control needed).
assert.equal(providerSupportsCaching("openai", "openai"), true);
assert.equal(providerSupportsCaching("codex", "openai"), true);
// Non-caching providers
assert.equal(providerSupportsCaching("gemini", "gemini"), false);
});
test("shouldPreserveCacheControl preserves for Claude-format providers with Claude Code client", () => {
const claudeCodeUA = "Claude-Code/1.0.0";
// Claude-protocol providers should preserve cache_control
assert.equal(
shouldPreserveCacheControl({
userAgent: claudeCodeUA,
isCombo: false,
targetProvider: "bailian-coding-plan",
targetFormat: "claude",
settings: { alwaysPreserveClientCache: "auto" },
}),
true
);
assert.equal(
shouldPreserveCacheControl({
userAgent: claudeCodeUA,
isCombo: false,
targetProvider: "glm",
targetFormat: "claude",
settings: { alwaysPreserveClientCache: "auto" },
}),
true
);
assert.equal(
shouldPreserveCacheControl({
userAgent: claudeCodeUA,
isCombo: false,
targetProvider: "zai",
targetFormat: "claude",
settings: { alwaysPreserveClientCache: "auto" },
}),
true
);
// minimax now uses openai format — caching behavior may differ;
// cache_control preservation depends on whether it joins CACHING_PROVIDERS
assert.equal(
shouldPreserveCacheControl({
userAgent: claudeCodeUA,
isCombo: false,
targetProvider: "minimax",
targetFormat: "openai",
settings: { alwaysPreserveClientCache: "auto" },
}),
false
);
});
test("shouldPreserveCacheControl respects user override 'always'", () => {
const regularUA = "Mozilla/5.0";
// Even with non-Claude Code client, 'always' should preserve
assert.equal(
shouldPreserveCacheControl({
userAgent: regularUA,
isCombo: false,
targetProvider: "bailian-coding-plan",
targetFormat: "claude",
settings: { alwaysPreserveClientCache: "always" },
}),
true
);
});
test("shouldPreserveCacheControl respects user override 'never'", () => {
const claudeCodeUA = "Claude-Code/1.0.0";
// Even with Claude Code client, 'never' should not preserve
assert.equal(
shouldPreserveCacheControl({
userAgent: claudeCodeUA,
isCombo: false,
targetProvider: "bailian-coding-plan",
targetFormat: "claude",
settings: { alwaysPreserveClientCache: "never" },
}),
false
);
});
test("shouldPreserveCacheControl does not preserve for non-Claude Code clients in auto mode", () => {
const regularUA = "Mozilla/5.0";
assert.equal(
shouldPreserveCacheControl({
userAgent: regularUA,
isCombo: false,
targetProvider: "bailian-coding-plan",
targetFormat: "claude",
settings: { alwaysPreserveClientCache: "auto" },
}),
false
);
});
test("shouldPreserveCacheControl does not preserve for non-Claude format providers", () => {
const claudeCodeUA = "Claude-Code/1.0.0";
// gemini is non-Claude-format and has no prompt caching (openai/codex now do, #3955).
assert.equal(
shouldPreserveCacheControl({
userAgent: claudeCodeUA,
isCombo: false,
targetProvider: "gemini",
targetFormat: "gemini",
settings: { alwaysPreserveClientCache: "auto" },
}),
false
);
});
test("shouldPreserveCacheControl treats CC-compatible providers like other Claude providers in auto mode", () => {
const claudeCodeUA = "Claude-Code/1.0.0";
assert.equal(
shouldPreserveCacheControl({
userAgent: claudeCodeUA,
isCombo: false,
targetProvider: "anthropic-compatible-cc-cm",
targetFormat: "claude",
settings: { alwaysPreserveClientCache: "auto" },
}),
true
);
});
});