test(proxy): a mocked request is not an Anthropic caller

Agent: shiqing-desktop-085b2e
This commit is contained in:
Simin Yuan 2026-11-03 05:37:43 +08:00
parent a1dc3507e8
commit f7c145ade1

View file

@ -7,6 +7,8 @@ event and is skipped, so a failure delivered that way never reaches the caller.
from __future__ import annotations
import json
from typing import cast
from unittest.mock import MagicMock
import pytest
from starlette.requests import Request
@ -33,6 +35,16 @@ def test_openai_paths_are_left_alone() -> None:
assert not _streams_anthropic_events(None)
def test_a_request_without_a_real_path_is_not_anthropic() -> None:
"""A mocked or partial request must not be read as an Anthropic caller."""
class _MockedRequest:
url = MagicMock()
assert not _streams_anthropic_events(cast(Request, _MockedRequest()))
assert not _streams_anthropic_events(cast(Request, MagicMock()))
def test_anthropic_frame_is_an_error_event_without_done() -> None:
frames = _anthropic_sse_error_frames({"message": "boom", "type": "internal_server_error", "code": "500"})