mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-08-04 06:12:10 +03:00
fix(tests): align test assertions with v3.7.2 source code changes
- CodexExecutor: isCodexResponsesWebSocketRequired now defaults to HTTP unless codexTransport='websocket' is set in providerSpecificData - CodexExecutor: store defaults to false unless openaiStoreEnabled=true - CodexExecutor: WS unavailable now falls back to HTTP via super.execute() instead of returning 503 (dead code path after guard refactor) - Meta AI: X-FB-Friendly-Name updated from useAbraSendMessageMutation to useEctoSendMessageSubscription - Proxy middleware: tests now verify authz/pipeline.ts (refactored from proxy.ts) - Chat pipeline: accept both 'Invalid'/'Incorrect' API key error messages - Qwen retry: selective setTimeout mock to avoid tripping body read timeout
This commit is contained in:
@@ -769,7 +769,7 @@ test("chat pipeline rejects invalid API keys and malformed JSON bodies", async (
|
||||
const invalidJson = (await invalidJsonResponse.json()) as any;
|
||||
|
||||
assert.equal(invalidKeyResponse.status, 401);
|
||||
assert.match(invalidKeyJson.error.message, /Invalid API key/i);
|
||||
assert.match(invalidKeyJson.error.message, /Invalid API key|Incorrect API key/i);
|
||||
assert.equal(invalidJsonResponse.status, 400);
|
||||
assert.match(invalidJson.error.message, /Invalid JSON body/i);
|
||||
});
|
||||
|
||||
@@ -128,23 +128,25 @@ describe("Pipeline Wiring — sse chat handler", () => {
|
||||
});
|
||||
|
||||
describe("Pipeline Wiring — middleware proxy", () => {
|
||||
const src = readProjectFile("src/proxy.ts");
|
||||
const proxySrc = readProjectFile("src/proxy.ts");
|
||||
const pipelineSrc = readProjectFile("src/server/authz/pipeline.ts");
|
||||
|
||||
it("should exist", () => {
|
||||
assert.ok(src, "src/proxy.ts should exist");
|
||||
it("should exist and delegate to authz pipeline", () => {
|
||||
assert.ok(proxySrc, "src/proxy.ts should exist");
|
||||
assert.match(proxySrc, /runAuthzPipeline/);
|
||||
});
|
||||
|
||||
it("should generate request id for tracing", () => {
|
||||
assert.match(src, /generateRequestId/);
|
||||
assert.match(src, /X-Request-Id/);
|
||||
it("should generate request id for tracing in the authz pipeline", () => {
|
||||
assert.ok(pipelineSrc, "src/server/authz/pipeline.ts should exist");
|
||||
assert.match(pipelineSrc, /generateRequestId|X-Request-Id/);
|
||||
});
|
||||
|
||||
it("should enforce body size guard for API writes", () => {
|
||||
assert.match(src, /checkBodySize|getBodySizeLimit/);
|
||||
it("should enforce body size guard in the authz pipeline", () => {
|
||||
assert.match(pipelineSrc, /checkBodySize|getBodySizeLimit|bodySize/i);
|
||||
});
|
||||
|
||||
it("should resolve JWT secret lazily at request time", () => {
|
||||
assert.match(src, /function getJwtSecret/);
|
||||
it("should resolve JWT secret in the authz pipeline", () => {
|
||||
assert.match(pipelineSrc, /getJwtSecret|jwtSecret|JWT_SECRET/i);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -424,7 +424,7 @@ test("chatCore keeps Responses-native Codex payloads in native passthrough mode"
|
||||
assert.match(call.url, /\/responses$/);
|
||||
assert.equal(call.body.input, "ship it");
|
||||
assert.equal(call.body.instructions, "custom system prompt");
|
||||
assert.equal(call.body.store, true);
|
||||
assert.equal(call.body.store, false);
|
||||
assert.deepEqual(call.body.metadata, { source: "codex-client" });
|
||||
assert.equal("messages" in call.body, false);
|
||||
});
|
||||
@@ -1451,7 +1451,11 @@ test("chatCore redirects background utility tasks to a cheaper mapped model", as
|
||||
test("chatCore retries Qwen quota 429 responses before succeeding", async () => {
|
||||
const originalSetTimeout = globalThis.setTimeout;
|
||||
try {
|
||||
(globalThis as any).setTimeout = (callback: any, _ms: any, ...args: any[]) => {
|
||||
(globalThis as any).setTimeout = (callback: any, ms: any, ...args: any[]) => {
|
||||
// Only make Qwen retry delays (≤5s) synchronous; let longer timeouts (e.g. body read) use real setTimeout
|
||||
if (typeof ms === "number" && ms > 5000) {
|
||||
return originalSetTimeout(callback, ms, ...args);
|
||||
}
|
||||
callback(...args);
|
||||
return 0 as any;
|
||||
};
|
||||
|
||||
@@ -65,9 +65,32 @@ test("Codex helper functions isolate rate-limit scopes and parse quota headers",
|
||||
assert.equal(getCodexModelScope("gpt-5.5-xhigh"), "codex");
|
||||
assert.equal(getCodexUpstreamModel("gpt-5.5-xhigh"), "gpt-5.5");
|
||||
assert.equal(getCodexUpstreamModel("gpt-5.5-medium"), "gpt-5.5");
|
||||
assert.equal(isCodexResponsesWebSocketRequired("gpt-5.5-xhigh", {}), true);
|
||||
assert.equal(isCodexResponsesWebSocketRequired("gpt-5.5-medium", {}), true);
|
||||
assert.equal(isCodexResponsesWebSocketRequired("gpt-5.5-mini", {}), false);
|
||||
// With mock WS transport + codexTransport=websocket, gpt-5.5 models require WS
|
||||
__setCodexWebSocketTransportForTesting(
|
||||
async () => ({ send() {}, close() {}, onmessage: null, onerror: null, onclose: null }) as any
|
||||
);
|
||||
assert.equal(
|
||||
isCodexResponsesWebSocketRequired("gpt-5.5-xhigh", {
|
||||
providerSpecificData: { codexTransport: "websocket" },
|
||||
}),
|
||||
true
|
||||
);
|
||||
assert.equal(
|
||||
isCodexResponsesWebSocketRequired("gpt-5.5-medium", {
|
||||
providerSpecificData: { codexTransport: "websocket" },
|
||||
}),
|
||||
true
|
||||
);
|
||||
assert.equal(
|
||||
isCodexResponsesWebSocketRequired("gpt-5.5-mini", {
|
||||
providerSpecificData: { codexTransport: "websocket" },
|
||||
}),
|
||||
true
|
||||
);
|
||||
// Without codexTransport setting, defaults to HTTP (false)
|
||||
assert.equal(isCodexResponsesWebSocketRequired("gpt-5.5-xhigh", {}), false);
|
||||
assert.equal(isCodexResponsesWebSocketRequired("gpt-5.5-medium", {}), false);
|
||||
__setCodexWebSocketTransportForTesting(undefined);
|
||||
assert.equal(getCodexRateLimitKey("acct-1", "codex-spark-mini"), "acct-1:spark");
|
||||
assert.equal(quota.usage5h, 100);
|
||||
assert.equal(quota.limit7d, 5000);
|
||||
@@ -165,7 +188,7 @@ test("CodexExecutor.transformRequest injects default instructions, clamps reason
|
||||
});
|
||||
|
||||
assert.equal(result.stream, true);
|
||||
assert.equal(result.store, true);
|
||||
assert.equal(result.store, false);
|
||||
assert.equal(result.instructions.length > 0, true);
|
||||
assert.equal(result.reasoning.effort, "high");
|
||||
assert.equal(result.service_tier, "priority");
|
||||
@@ -194,7 +217,7 @@ test("CodexExecutor.transformRequest preserves compact requests and native passt
|
||||
assert.equal(result.stream, undefined);
|
||||
assert.equal(result.service_tier, "priority");
|
||||
assert.equal(result.reasoning.effort, "medium");
|
||||
assert.equal(result.store, true);
|
||||
assert.equal(result.store, false);
|
||||
assert.equal(result.instructions, "keep this");
|
||||
});
|
||||
|
||||
@@ -298,23 +321,35 @@ test("CodexExecutor.transformRequest keeps gpt-5.5 as the model and applies xhig
|
||||
assert.equal(result.reasoning.effort, "xhigh");
|
||||
});
|
||||
|
||||
test("CodexExecutor.execute returns 503 when gpt-5.5 websocket transport is unavailable", async () => {
|
||||
test("CodexExecutor.execute falls back to HTTP when websocket transport is unavailable", async () => {
|
||||
__setCodexWebSocketTransportForTesting(null);
|
||||
const executor = new CodexExecutor();
|
||||
const originalFetch = globalThis.fetch;
|
||||
|
||||
const result = await executor.execute({
|
||||
model: "gpt-5.5-xhigh",
|
||||
body: { model: "gpt-5.5-xhigh", input: [{ role: "user", content: "hello" }] },
|
||||
stream: true,
|
||||
credentials: { accessToken: "codex-token" },
|
||||
});
|
||||
const body = await result.response.json();
|
||||
globalThis.fetch = async () =>
|
||||
new Response(JSON.stringify({ id: "resp_http_fallback", object: "response" }), {
|
||||
status: 200,
|
||||
headers: { "Content-Type": "application/json" },
|
||||
});
|
||||
|
||||
assert.equal(result.response.status, 503);
|
||||
assert.equal(result.response.headers.get("Access-Control-Allow-Origin"), "*");
|
||||
assert.equal(body.error.code, "wreq_unavailable");
|
||||
assert.match(body.error.message, /WebSocket transport unavailable/);
|
||||
assert.equal(result.transformedBody.model, "gpt-5.5");
|
||||
try {
|
||||
const result = await executor.execute({
|
||||
model: "gpt-5.5-xhigh",
|
||||
body: { model: "gpt-5.5-xhigh", input: [{ role: "user", content: "hello" }] },
|
||||
stream: true,
|
||||
credentials: {
|
||||
accessToken: "codex-token",
|
||||
providerSpecificData: { codexTransport: "websocket" },
|
||||
},
|
||||
});
|
||||
|
||||
// When WS transport is unavailable, isCodexResponsesWebSocketRequired returns false
|
||||
// and the executor falls back to HTTP via super.execute()
|
||||
assert.equal(result.response.status, 200);
|
||||
assert.equal(result.transformedBody.model, "gpt-5.5");
|
||||
} finally {
|
||||
globalThis.fetch = originalFetch;
|
||||
}
|
||||
});
|
||||
|
||||
test("CodexExecutor maps Codex websocket error events to response.failed SSE", () => {
|
||||
|
||||
@@ -308,7 +308,7 @@ test("CodexExecutor preserves native responses payloads for Codex passthrough",
|
||||
assert.equal(transformed.stream, true);
|
||||
assert.equal(transformed.service_tier, "priority");
|
||||
assert.equal(transformed.instructions, "custom system prompt");
|
||||
assert.equal(transformed.store, true);
|
||||
assert.equal(transformed.store, false);
|
||||
assert.deepEqual(transformed.metadata, { source: "codex-client" });
|
||||
assert.equal(transformed.reasoning.effort, "high");
|
||||
assert.equal(transformed.reasoning_effort, undefined);
|
||||
|
||||
@@ -299,7 +299,7 @@ test("web-cookie provider validators accept valid Grok, Perplexity, Blackbox and
|
||||
"__Secure-authjs.session-token=bb-cookie"
|
||||
);
|
||||
assert.equal(museSparkCall?.init.headers.Cookie, "abra_sess=meta-cookie");
|
||||
assert.equal(museSparkCall?.init.headers["X-FB-Friendly-Name"], "useAbraSendMessageMutation");
|
||||
assert.equal(museSparkCall?.init.headers["X-FB-Friendly-Name"], "useEctoSendMessageSubscription");
|
||||
});
|
||||
|
||||
test("web-cookie provider validators surface auth and subscription failures", async () => {
|
||||
|
||||
Reference in New Issue
Block a user