Files
OmniRoute/tests/unit/cline-force-stream.test.ts
Bl0ck 097226b617 fix(codex): normalize non-stream responses (#11951)
Boarded with #11954/#11953/#11952/#11948 in one combined worktree: typecheck:core, check:file-size, check:changelog-integrity, check:complexity, check:cognitive-complexity, check:cycles all green; 85/85 focused tests pass. Confirmed the codex registry entry was missing forceStream: true while every other JSON-only-client provider (cline, clinepass, ghe-copilot, kimi, zed-hosted, chatgpt-web-codex) already has it. Clean reuse of the existing bridge, no Codex-specific response handling needed. Thanks!
2026-08-30 05:09:48 -03:00

50 lines
2.6 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { REGISTRY } from "@omniroute/open-sse/config/providers/index.ts";
import { resolveStreamFlag } from "@omniroute/open-sse/utils/aiSdkCompat.ts";
// Cline / ClinePass only implement upstream streaming — a non-streaming request
// returns "generateText is not implemented" / an empty body. They carry
// `forceStream: true` so chatCore forces the UPSTREAM request to stream
// (`upstreamStream = stream || isClaudeCodeCompatible || providerRequiresStreaming`)
// even when the client wants JSON. The client-facing `stream` flag stays as the
// client sent it, so the `if (!stream)` branch drains the forced upstream SSE and
// converts it back to JSON via readNonStreamingResponseBody. Regression guard for
// the "cline model test → generateText is not implemented / STREAM_EARLY_EOF" bug
// (live-verified on the VPS: stream:true works, stream:false failed). (#6126)
test("cline provider is flagged forceStream (streaming-only upstream)", () => {
assert.equal(REGISTRY.cline?.forceStream, true);
});
test("clinepass provider is flagged forceStream (streaming-only upstream)", () => {
assert.equal(REGISTRY.clinepass?.forceStream, true);
});
test("codex provider is flagged forceStream because /responses always streams upstream", () => {
assert.equal(REGISTRY.codex?.forceStream, true);
});
test("upstreamStream is forced true for a forceStream provider even when the client sent stream:false", () => {
// Mirror the chatCore wiring: providerRequiresStreaming derives from the
// registry flag, and upstreamStream ORs it in so the upstream always streams.
for (const provider of ["cline", "codex"] as const) {
const providerRequiresStreaming = REGISTRY[provider]?.forceStream === true;
const isClaudeCodeCompatible = false;
const clientStream = false; // client asked for JSON
const upstreamStream = clientStream || isClaudeCodeCompatible || providerRequiresStreaming;
assert.equal(upstreamStream, true, provider);
}
});
test("client-facing stream stays false for a stream:false JSON caller (so SSE→JSON conversion runs)", () => {
// chatCore MUST NOT pass providerRequiresStreaming into resolveStreamFlag:
// a stream:false client keeps stream=false so the `if (!stream)` branch drains
// the forced upstream SSE and returns JSON. Forcing stream=true here would skip
// that conversion and yield STREAM_EARLY_EOF for JSON callers.
assert.equal(resolveStreamFlag(false, "application/json", "openai"), false);
// A stream:true client still streams end-to-end.
assert.equal(resolveStreamFlag(true, "application/json", "openai"), true);
});