fix(api): require boolean stream values
Validate the OpenAI-compatible stream flag before choosing the response mode so string values such as "false" are rejected instead of enabling SSE. Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
122a0f5d6f
commit
12c2c95cbb
2 files changed
+27
-1
No files matched your search
@@ -171,6 +171,29 @@ async def test_stream_default_is_false(aiohttp_client) -> None:
|
||||
assert body["object"] == "chat.completion"
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_AIOHTTP, reason="aiohttp not installed")
|
||||
@pytest.mark.asyncio
|
||||
async def test_stream_rejects_non_boolean_values(aiohttp_client) -> None:
|
||||
"""The OpenAI-compatible stream flag must be a JSON boolean."""
|
||||
agent = MagicMock()
|
||||
agent.process_direct = AsyncMock(return_value="normal reply")
|
||||
agent.aclose = AsyncMock()
|
||||
|
||||
app = create_app(agent, model_name="m", api_key=API_KEY)
|
||||
client = await aiohttp_client(app)
|
||||
|
||||
resp = await client.post(
|
||||
"/v1/chat/completions",
|
||||
headers=AUTH_HEADERS,
|
||||
json={"messages": [{"role": "user", "content": "hi"}], "stream": "false"},
|
||||
)
|
||||
|
||||
assert resp.status == 400
|
||||
body = await resp.json()
|
||||
assert body["error"]["message"] == "stream must be a boolean"
|
||||
agent.process_direct.assert_not_called()
|
||||
|
||||
|
||||
@pytest.mark.skipif(not HAS_AIOHTTP, reason="aiohttp not installed")
|
||||
@pytest.mark.asyncio
|
||||
async def test_stream_sse_chunk_ids_are_consistent(aiohttp_client) -> None:
|
||||
|
||||
Reference in new issue
Block a user