mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-14 10:52:17 +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.
193 lines
5.4 KiB
TypeScript
193 lines
5.4 KiB
TypeScript
import { describe, it } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const mod = await import("../../open-sse/services/reasoningCache.ts");
|
|
|
|
describe("reasoningCache helpers", () => {
|
|
describe("isDeepSeekReasoningModel", () => {
|
|
it("returns true for deepseek-v4 models with thinking enabled", () => {
|
|
assert.equal(
|
|
mod.isDeepSeekReasoningModel({
|
|
provider: "deepseek",
|
|
model: "deepseek-v4-flash",
|
|
thinkingEnabled: true,
|
|
}),
|
|
true
|
|
);
|
|
assert.equal(
|
|
mod.isDeepSeekReasoningModel({
|
|
provider: "deepseek",
|
|
model: "deepseek/v4-pro",
|
|
thinkingEnabled: true,
|
|
}),
|
|
true
|
|
);
|
|
});
|
|
|
|
it("returns false without thinkingEnabled", () => {
|
|
assert.equal(
|
|
mod.isDeepSeekReasoningModel({ provider: "deepseek", model: "deepseek-v4-flash" }),
|
|
false
|
|
);
|
|
assert.equal(
|
|
mod.isDeepSeekReasoningModel({
|
|
provider: "deepseek",
|
|
model: "deepseek-v4-flash",
|
|
thinkingEnabled: false,
|
|
}),
|
|
false
|
|
);
|
|
});
|
|
|
|
it("returns false for non-v4 models", () => {
|
|
assert.equal(
|
|
mod.isDeepSeekReasoningModel({
|
|
provider: "deepseek",
|
|
model: "deepseek-chat",
|
|
thinkingEnabled: true,
|
|
}),
|
|
false
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("requiresReasoningReplay", () => {
|
|
it("returns true for reasoning_content interleaved field", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({
|
|
provider: "any",
|
|
model: "any",
|
|
interleavedField: "reasoning_content",
|
|
}),
|
|
true
|
|
);
|
|
});
|
|
|
|
it("returns false for reasoning_details interleaved field", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({
|
|
provider: "moonshot",
|
|
model: "k3",
|
|
interleavedField: "reasoning_details",
|
|
}),
|
|
false
|
|
);
|
|
});
|
|
|
|
it("returns false for deepseek-reasoner", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({ provider: "deepseek", model: "deepseek-reasoner" }),
|
|
false
|
|
);
|
|
});
|
|
|
|
it("returns false for deepseek-r1", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({ provider: "deepseek", model: "deepseek-r1" }),
|
|
false
|
|
);
|
|
});
|
|
|
|
it("returns true for DeepSeek V4 thinking models", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({
|
|
provider: "deepseek",
|
|
model: "deepseek-v4-flash",
|
|
thinkingEnabled: true,
|
|
}),
|
|
true
|
|
);
|
|
});
|
|
|
|
it("returns true for known replay providers", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({ provider: "deepseek", model: "some-model" }),
|
|
true
|
|
);
|
|
});
|
|
|
|
it("returns true for Kimi Coding providers regardless of model alias", () => {
|
|
assert.equal(mod.requiresReasoningReplay({ provider: "kimi-coding", model: "k3" }), true);
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({ provider: "kimi-coding-apikey", model: "kimi-k2.6" }),
|
|
true
|
|
);
|
|
});
|
|
|
|
it("detects native Kimi thinking model IDs without matching unrelated aliases", () => {
|
|
for (const model of [
|
|
"k3",
|
|
"k3-256k",
|
|
"kimi-k3",
|
|
"kimi-k2",
|
|
"kimi-k2.6",
|
|
"kimi-k2.6-thinking",
|
|
"kimi-k2.7-code",
|
|
"kimi-k2.7-code-highspeed",
|
|
"moonshotai/kimi-k2.7-code",
|
|
]) {
|
|
assert.equal(mod.requiresReasoningReplay({ provider: "some-other", model }), true, model);
|
|
}
|
|
|
|
for (const model of ["moonshot-v1-8k", "kimi-latest"]) {
|
|
assert.equal(mod.requiresReasoningReplay({ provider: "some-other", model }), false, model);
|
|
}
|
|
});
|
|
|
|
it("keeps K3 and native Moonshot K2.7 replay explicit", () => {
|
|
for (const model of ["k3", "k3-256k", "kimi-k3", "kimi-k2.7-code"]) {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({
|
|
provider: "moonshot",
|
|
model,
|
|
allowLegacyFallback: false,
|
|
}),
|
|
true,
|
|
model
|
|
);
|
|
}
|
|
});
|
|
|
|
it("returns false when allowLegacyFallback is false and no explicit signal", () => {
|
|
assert.equal(
|
|
mod.requiresReasoningReplay({
|
|
provider: "unknown",
|
|
model: "unknown",
|
|
allowLegacyFallback: false,
|
|
}),
|
|
false
|
|
);
|
|
});
|
|
});
|
|
|
|
describe("cache operations", () => {
|
|
it("getReasoningCacheServiceStats returns expected shape", () => {
|
|
const stats = mod.getReasoningCacheServiceStats();
|
|
assert.equal(typeof stats.hits, "number");
|
|
assert.equal(typeof stats.misses, "number");
|
|
assert.equal(typeof stats.replays, "number");
|
|
assert.equal(typeof stats.memoryEntries, "number");
|
|
});
|
|
|
|
it("clearReasoningCacheAll returns a number", () => {
|
|
const cleared = mod.clearReasoningCacheAll();
|
|
assert.equal(typeof cleared, "number");
|
|
});
|
|
|
|
it("lookupReasoning returns null for unknown key", () => {
|
|
const result = mod.lookupReasoning("nonexistent-key-" + Date.now());
|
|
assert.equal(result, null);
|
|
});
|
|
|
|
it("deleteReasoningCacheEntry returns 0 for unknown key", () => {
|
|
const result = mod.deleteReasoningCacheEntry("nonexistent-" + Date.now());
|
|
assert.equal(result, 0);
|
|
});
|
|
|
|
it("cleanupReasoningCache returns a number", () => {
|
|
const cleaned = mod.cleanupReasoningCache();
|
|
assert.equal(typeof cleaned, "number");
|
|
});
|
|
});
|
|
});
|