mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-13 18:32:12 +03:00
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.
163 lines
5.2 KiB
TypeScript
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
|
|
);
|
|
});
|
|
});
|