mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-19 21:32:20 +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.
124 lines
4.0 KiB
TypeScript
124 lines
4.0 KiB
TypeScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { createChatPipelineHarness } from "../integration/_chatPipelineHarness.ts";
|
|
|
|
const harness = await createChatPipelineHarness("chat-early-schema-6412");
|
|
const { buildRequest, handleChat, resetStorage } = harness;
|
|
|
|
test.beforeEach(async () => {
|
|
await resetStorage();
|
|
});
|
|
|
|
test.after(async () => {
|
|
await harness.cleanup();
|
|
});
|
|
|
|
/**
|
|
* Regression guard for #6412 — schema validation of scalar params (temperature,
|
|
* top_p, max_tokens, n) MUST run BEFORE provider/model resolution. Previously,
|
|
* a bad `temperature: "not-a-number"` combined with an unknown provider
|
|
* returned 404 "model_not_found" — hiding the real schema error.
|
|
*/
|
|
|
|
interface ChatTestRequestBody {
|
|
model: string;
|
|
messages: Array<{ role: string; content: string }>;
|
|
// Intentionally loose: these are the scalar params under test, and several
|
|
// cases below deliberately pass the WRONG runtime type (e.g. temperature as
|
|
// a string) to prove schema validation catches it before provider lookup.
|
|
temperature?: unknown;
|
|
top_p?: unknown;
|
|
max_tokens?: unknown;
|
|
n?: unknown;
|
|
}
|
|
|
|
interface ChatTestResponsePayload {
|
|
error?: unknown;
|
|
}
|
|
|
|
async function postChat(body: ChatTestRequestBody) {
|
|
const response = await handleChat(buildRequest({ body }));
|
|
const payload = (await response.json()) as ChatTestResponsePayload;
|
|
return { status: response.status, payload };
|
|
}
|
|
|
|
test("bad temperature (string) on unknown provider → 400, not 404", async () => {
|
|
const { status, payload } = await postChat({
|
|
model: "nonexistent-provider/nonexistent-model",
|
|
messages: [{ role: "user", content: "hi" }],
|
|
temperature: "not-a-number",
|
|
});
|
|
assert.equal(status, 400);
|
|
assert.match(JSON.stringify(payload.error), /temperature/i);
|
|
});
|
|
|
|
test("out-of-range temperature (5.0) on unknown provider → 400, not 404", async () => {
|
|
const { status, payload } = await postChat({
|
|
model: "nonexistent-provider/nonexistent-model",
|
|
messages: [{ role: "user", content: "hi" }],
|
|
temperature: 5.0,
|
|
});
|
|
assert.equal(status, 400);
|
|
assert.match(JSON.stringify(payload.error), /temperature/i);
|
|
});
|
|
|
|
test("bad top_p (string) → 400", async () => {
|
|
const { status, payload } = await postChat({
|
|
model: "nonexistent-provider/nonexistent-model",
|
|
messages: [{ role: "user", content: "hi" }],
|
|
top_p: "bad",
|
|
});
|
|
assert.equal(status, 400);
|
|
assert.match(JSON.stringify(payload.error), /top_p/i);
|
|
});
|
|
|
|
test("bad max_tokens (negative) → 400", async () => {
|
|
const { status, payload } = await postChat({
|
|
model: "nonexistent-provider/nonexistent-model",
|
|
messages: [{ role: "user", content: "hi" }],
|
|
max_tokens: -1,
|
|
});
|
|
assert.equal(status, 400);
|
|
assert.match(JSON.stringify(payload.error), /max_tokens/i);
|
|
});
|
|
|
|
test("bad n (0) → 400", async () => {
|
|
const { status, payload } = await postChat({
|
|
model: "nonexistent-provider/nonexistent-model",
|
|
messages: [{ role: "user", content: "hi" }],
|
|
n: 0,
|
|
});
|
|
assert.equal(status, 400);
|
|
assert.match(JSON.stringify(payload.error), /n:/);
|
|
});
|
|
|
|
test("valid params (temperature=0.7) on unknown provider still 404 (provider lookup runs after schema ok)", async () => {
|
|
const { status, payload } = await postChat({
|
|
model: "nonexistent-provider/nonexistent-model",
|
|
messages: [{ role: "user", content: "hi" }],
|
|
temperature: 0.7,
|
|
max_tokens: 100,
|
|
});
|
|
assert.ok(
|
|
status === 404 || status === 401,
|
|
`schema-ok unknown provider should 404 or 401, got ${status}`
|
|
);
|
|
assert.match(
|
|
JSON.stringify(payload.error),
|
|
/model_not_found|No active credentials|unauthorized|authentication/i
|
|
);
|
|
});
|
|
|
|
test("params omitted entirely → schema passes, no false 400", async () => {
|
|
const { status } = await postChat({
|
|
model: "nonexistent-provider/nonexistent-model",
|
|
messages: [{ role: "user", content: "hi" }],
|
|
});
|
|
// Auth may run before catalog lookup (401) or catalog may 404 the unknown model.
|
|
assert.ok(
|
|
status === 404 || status === 401,
|
|
`expected routing 404/401 after schema pass-through, got ${status}`
|
|
);
|
|
});
|