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.
90 lines
3.2 KiB
TypeScript
90 lines
3.2 KiB
TypeScript
// Characterization of buildNonStreamingResponseHeaders — the cache-MISS response header builder
|
|
// extracted from handleChatCore's non-streaming success path (chatCore god-file decomposition,
|
|
// #3501). attachOmniRouteMetaHeaders + now are injected so the static headers, the meta payload,
|
|
// and the optional compression header are observable. Locks: Content-Type + cache MISS, latencyMs =
|
|
// now - startTime, and the compression header only when meta is present.
|
|
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const { buildNonStreamingResponseHeaders } =
|
|
await import("../../open-sse/handlers/chatCore/nonStreamingResponseHeaders.ts");
|
|
|
|
function makeDeps(now = 1000) {
|
|
const metaCalls: Array<{ headers: Record<string, string>; meta: Record<string, unknown> }> = [];
|
|
const deps = {
|
|
attachOmniRouteMetaHeaders: (
|
|
headers: Record<string, string>,
|
|
meta: Record<string, unknown>
|
|
) => {
|
|
metaCalls.push({ headers, meta });
|
|
headers["x-omniroute-meta"] = "attached";
|
|
},
|
|
now: () => now,
|
|
} as Parameters<typeof buildNonStreamingResponseHeaders>[1];
|
|
return { deps, metaCalls };
|
|
}
|
|
|
|
function baseArgs(overrides: Record<string, unknown> = {}) {
|
|
return {
|
|
provider: "openai",
|
|
model: "gpt-x",
|
|
startTime: 600,
|
|
responseUsage: { prompt_tokens: 5 },
|
|
estimatedCost: 0.0012,
|
|
requestId: "req-1",
|
|
compressionResponseMeta: undefined,
|
|
...overrides,
|
|
} as Parameters<typeof buildNonStreamingResponseHeaders>[0];
|
|
}
|
|
|
|
function acceptsAttachMetaInputContract(args: {
|
|
responseUsage: Record<string, unknown> | null | undefined;
|
|
requestId: string | null | undefined;
|
|
}) {
|
|
return args;
|
|
}
|
|
|
|
test("builder input types match the metadata attachment contract", () => {
|
|
acceptsAttachMetaInputContract(baseArgs());
|
|
});
|
|
|
|
test("static headers: Content-Type json + cache MISS", () => {
|
|
const { deps } = makeDeps();
|
|
const h = buildNonStreamingResponseHeaders(baseArgs(), deps);
|
|
assert.equal(h["Content-Type"], "application/json");
|
|
// cache marker key/value
|
|
assert.ok(Object.values(h).includes("MISS"));
|
|
});
|
|
|
|
test("meta receives provider/model/cacheHit false/latency/usage/cost/requestId", () => {
|
|
const { deps, metaCalls } = makeDeps(1000);
|
|
buildNonStreamingResponseHeaders(baseArgs({ startTime: 600 }), deps);
|
|
assert.equal(metaCalls.length, 1);
|
|
const meta = metaCalls[0].meta;
|
|
assert.equal(meta.provider, "openai");
|
|
assert.equal(meta.model, "gpt-x");
|
|
assert.equal(meta.cacheHit, false);
|
|
assert.equal(meta.latencyMs, 400); // now 1000 - startTime 600
|
|
assert.deepEqual(meta.usage, { prompt_tokens: 5 });
|
|
assert.equal(meta.costUsd, 0.0012);
|
|
assert.equal(meta.requestId, "req-1");
|
|
});
|
|
|
|
test("no compression meta → no compression header", () => {
|
|
const { deps } = makeDeps();
|
|
const h = buildNonStreamingResponseHeaders(
|
|
baseArgs({ compressionResponseMeta: undefined }),
|
|
deps
|
|
);
|
|
assert.ok(!Object.values(h).includes("engine:x"));
|
|
});
|
|
|
|
test("compression meta present → compression header set to that value", () => {
|
|
const { deps } = makeDeps();
|
|
const h = buildNonStreamingResponseHeaders(
|
|
baseArgs({ compressionResponseMeta: "engine:x; source=header" }),
|
|
deps
|
|
);
|
|
assert.ok(Object.values(h).includes("engine:x; source=header"));
|
|
});
|