Files
OmniRoute/tests/unit/bypass-handler.test.mjs
diegosouzapw 592ca9b5c4 fix: remove hardcoded localhost default arg from GET /api/keys, unify coverage to single coverage/ dir, fix test to pass explicit Request
- Remove `new Request('http://localhost/api/keys')` default arg from GET handler in src/app/api/keys/route.ts (line 26)
- Fix api-key-reveal-route.test.mjs to pass explicit Request instead of calling GET() with no args
- Add --output-dir coverage to all c8 scripts in package.json
- Add coverage.reportsDirectory: 'coverage' to vitest.config.ts and vitest.mcp.config.ts
- Fix CHANGELOG.md structure (# Changelog + [Unreleased] to top)
- Remove 30+ stale coverage-* directories from project root
- Coverage: Statements 78.76% | Branches 72.75% | Functions 80.93% | Lines 78.76% (all thresholds passed)
2026-04-05 23:21:08 -03:00

86 lines
2.3 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
const { handleBypassRequest } = await import("../../open-sse/utils/bypassHandler.ts");
test("handleBypassRequest returns null for non-Claude clients or missing messages", () => {
assert.equal(handleBypassRequest({ messages: [] }, "gpt-5", "claude-cli/2.1.89"), null);
assert.equal(
handleBypassRequest(
{
messages: [{ role: "user", content: "Warmup" }],
},
"gpt-5",
{ broken: true }
),
null
);
assert.equal(
handleBypassRequest(
{
messages: [{ role: "user", content: "Warmup" }],
},
"gpt-5",
"curl/8.0"
),
null
);
});
test("handleBypassRequest returns a canned JSON response for warmup bypasses", async () => {
const result = handleBypassRequest(
{
stream: false,
messages: [{ role: "user", content: "Warmup" }],
},
"gpt-5-mini",
"claude-cli/2.1.89"
);
assert.ok(result);
assert.equal(result.success, true);
assert.equal(result.response.headers.get("content-type"), "application/json");
const payload = await result.response.json();
assert.equal(payload.model, "gpt-5-mini");
assert.equal(payload.choices[0].message.role, "assistant");
assert.match(payload.choices[0].message.content, /clear terminal/i);
});
test("handleBypassRequest returns an SSE response for title extraction bypasses", async () => {
const result = handleBypassRequest(
{
messages: [
{ role: "user", content: "ignored" },
{ role: "assistant", content: [{ type: "text", text: "{" }] },
],
},
"gpt-5",
"claude-cli/2.1.89"
);
assert.ok(result);
assert.equal(result.success, true);
assert.equal(result.response.headers.get("content-type"), "text/event-stream");
const body = await result.response.text();
assert.match(body, /data:/);
assert.match(body, /\[DONE\]/);
});
test("handleBypassRequest bypasses single-message count probes", async () => {
const result = handleBypassRequest(
{
stream: false,
messages: [{ role: "user", content: [{ type: "text", text: "count" }] }],
},
"gpt-4.1-mini",
"claude-cli/2.1.89"
);
assert.ok(result);
const payload = await result.response.json();
assert.equal(payload.usage.total_tokens, 2);
assert.equal(payload.choices[0].finish_reason, "stop");
});