Files
OmniRoute/tests/unit/8189-classifier-compat-auto-narrow.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

97 lines
4.2 KiB
TypeScript

/**
* Regression test for #8189 — "auto" claudeClassifierCompat mode was over-broad.
*
* shouldDefaultAllowClassifier() previously treated `stop_sequences` containing the
* literal token `</block>` as sufficient PROOF of a Claude Code classifier request in
* "auto" mode, with no correlation to the classifier's system-prompt marker. Any
* unrelated Claude-format (/v1/messages) request that merely happened to set
* stop_sequences=["</block>"] (e.g. an app generating markup with a stop token) was
* silently short-circuited with a synthetic ALLOW response — WITHOUT ever calling the
* configured provider.
*
* Fix: in "auto" mode, the SECURITY_MONITOR_MARKER system-prompt text is now a
* necessary condition. `stop_sequences` alone is no longer sufficient.
*
* Follow-up (#9276): "always" mode previously short-circuited EVERY Claude-format
* request unconditionally, regardless of signal shape. That let a normal chat
* request through /v1/messages be silently swallowed by an operator's "always"
* opt-in. The unconditional `if (mode === "always") return true` branch was
* removed — "always" now requires the same SECURITY_MONITOR_MARKER as "auto".
*/
import test from "node:test";
import assert from "node:assert/strict";
import { shouldDefaultAllowClassifier } from "../../open-sse/handlers/chatCore/claudeClassifierCompat.ts";
import { FORMATS } from "../../open-sse/translator/formats.ts";
test("issue #8189: 'auto' mode fires on stop_sequences alone, with NO security-monitor marker present — over-broad trigger", () => {
const body = {
model: "aug/claude-sonnet-4.6",
max_tokens: 20,
stop_sequences: ["</block>"],
system: "You are a helpful assistant that writes CMS page templates.",
messages: [{ role: "user", content: "Write a <block>...</block> template" }],
};
const result = shouldDefaultAllowClassifier(FORMATS.CLAUDE, body, "auto");
assert.equal(
result,
false,
"auto mode must not short-circuit a request that merely happens to set stop_sequences=['</block>'] for unrelated reasons and carries no security-monitor marker"
);
});
test("issue #8189: 'auto' mode still short-circuits when the security-monitor marker is present, even without stop_sequences", () => {
const body = {
system: [
{
type: "text",
text: "You are a security monitor for autonomous AI coding agents. Evaluate the following action.",
},
],
stop_sequences: [],
messages: [{ role: "user", content: "<transcript>Bash rm -rf /</transcript>" }],
};
assert.equal(
shouldDefaultAllowClassifier(FORMATS.CLAUDE, body, "auto"),
true,
"marker-present must still short-circuit even without stop_sequences"
);
});
test("issue #9276: 'always' mode does NOT short-circuit without the security-monitor marker (narrowed to match 'auto')", () => {
const body = {
system: "You are a helpful assistant that writes CMS page templates.",
stop_sequences: ["</block>"],
messages: [{ role: "user", content: "hello" }],
};
assert.equal(
shouldDefaultAllowClassifier(FORMATS.CLAUDE, body, "always"),
false,
"mode='always' must NOT short-circuit a request with no security-monitor marker, even " +
"with stop_sequences=['</block>'] — #9276 removed the unconditional always-mode return"
);
});
test("issue #9276: 'always' mode still short-circuits when the security-monitor marker is present (operator opted in)", () => {
const body = {
system:
"You are a security monitor for autonomous AI coding agents. Evaluate the following action.",
stop_sequences: [],
messages: [{ role: "user", content: "<transcript>Bash rm -rf /</transcript>" }],
};
assert.equal(
shouldDefaultAllowClassifier(FORMATS.CLAUDE, body, "always"),
true,
"mode='always' must still short-circuit when the security-monitor marker is present"
);
});
test("issue #8189: 'off' mode (shipped default) never short-circuits", () => {
const body = {
system: [{ type: "text", text: "You are a security monitor for autonomous AI coding agents." }],
stop_sequences: ["</block>"],
};
assert.equal(shouldDefaultAllowClassifier(FORMATS.CLAUDE, body, "off"), false);
assert.equal(shouldDefaultAllowClassifier(FORMATS.CLAUDE, body, undefined), false);
});