mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-09-17 04:12: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.
84 lines
2.6 KiB
TypeScript
84 lines
2.6 KiB
TypeScript
// Regression guard for #10223: DeepSeek's SSE encoder bug leaks response-ID
|
|
// fragments into `request_id`, producing suspiciously long (200+ char) values.
|
|
// The transformer never reads `request_id` for its own output, but it must
|
|
// strip a corrupted one (logging that it did) and must NOT touch a normal,
|
|
// well-behaved provider's request_id.
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
const { createResponsesApiTransformStream } = await import(
|
|
"../../open-sse/transformer/responsesTransformer.ts"
|
|
);
|
|
|
|
const encoder = new TextEncoder();
|
|
const decoder = new TextDecoder();
|
|
|
|
async function runTransformStream(chunks, logger = null) {
|
|
const stream = createResponsesApiTransformStream(logger, 3000, {});
|
|
const writer = stream.writable.getWriter();
|
|
const reader = stream.readable.getReader();
|
|
|
|
const output = [];
|
|
const readerTask = (async () => {
|
|
while (true) {
|
|
const { value, done } = await reader.read();
|
|
if (done) break;
|
|
output.push(decoder.decode(value));
|
|
}
|
|
})();
|
|
|
|
for (const chunk of chunks) {
|
|
await writer.write(encoder.encode(chunk));
|
|
}
|
|
await writer.close();
|
|
await readerTask;
|
|
|
|
return output.join("");
|
|
}
|
|
|
|
function makeMockLogger() {
|
|
const inputs = [];
|
|
return {
|
|
inputs,
|
|
logInput: (event) => inputs.push(event),
|
|
logOutput: () => {},
|
|
flush: () => {},
|
|
};
|
|
}
|
|
|
|
test("BUG #10223: a corrupted (>=200 char) request_id is stripped and logged", async () => {
|
|
const corruptedId = "r".repeat(250);
|
|
const logger = makeMockLogger();
|
|
|
|
await runTransformStream(
|
|
[
|
|
`data: {"id":"chatcmpl_1","request_id":"${corruptedId}","choices":[{"index":0,"delta":{"content":"Hi"}}]}\n\n`,
|
|
'data: {"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}\n\n',
|
|
],
|
|
logger
|
|
);
|
|
|
|
const stripLog = logger.inputs.find(
|
|
(entry) => typeof entry === "string" && entry.includes("stripped corrupted request_id")
|
|
);
|
|
assert.ok(stripLog, "logger.logInput should be called noting the corrupted request_id was stripped");
|
|
assert.match(stripLog, /\(250 chars\)/);
|
|
});
|
|
|
|
test("a normal (<200 char) request_id is left untouched — no strip logged", async () => {
|
|
const logger = makeMockLogger();
|
|
|
|
await runTransformStream(
|
|
[
|
|
'data: {"id":"chatcmpl_1","request_id":"req_normal_12345","choices":[{"index":0,"delta":{"content":"Hi"}}]}\n\n',
|
|
'data: {"choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}\n\n',
|
|
],
|
|
logger
|
|
);
|
|
|
|
const stripLog = logger.inputs.find(
|
|
(entry) => typeof entry === "string" && entry.includes("stripped corrupted request_id")
|
|
);
|
|
assert.equal(stripLog, undefined, "a normal-length request_id must never be stripped");
|
|
});
|