mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
fix: Stream errors as simple JSON objects in ADK web server SSE
The ADK web server's /run_sse endpoint now yields a JSON object like {"error": "..."} when an exception occurs during event generation. The adk_web_server_client is updated to detect this error payload and raise a RuntimeError.
Close #4291
Co-authored-by: George Weale <gweale@google.com>
PiperOrigin-RevId: 863475838
This commit is contained in:
committed by
Copybara-Service
parent
d0102ecea3
commit
798d0053c8
@@ -224,6 +224,44 @@ async def test_run_agent():
|
||||
assert events[1].invocation_id == "test_invocation_2"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_agent_raises_on_streamed_error():
|
||||
client = AdkWebServerClient()
|
||||
|
||||
class MockStreamResponse:
|
||||
|
||||
def raise_for_status(self):
|
||||
pass
|
||||
|
||||
async def aiter_lines(self):
|
||||
yield 'data: {"error": "boom"}'
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
||||
pass
|
||||
|
||||
def mock_stream(*_args, **_kwargs):
|
||||
return MockStreamResponse()
|
||||
|
||||
with patch("httpx.AsyncClient") as mock_client_class:
|
||||
mock_client = AsyncMock()
|
||||
mock_client.stream = mock_stream
|
||||
mock_client_class.return_value = mock_client
|
||||
|
||||
request = RunAgentRequest(
|
||||
app_name="test_app",
|
||||
user_id="test_user",
|
||||
session_id="test_session",
|
||||
new_message=types.Content(role="user", parts=[types.Part(text="Hi")]),
|
||||
)
|
||||
|
||||
with pytest.raises(RuntimeError, match="boom"):
|
||||
async for _ in client.run_agent(request):
|
||||
pass
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_close():
|
||||
client = AdkWebServerClient()
|
||||
|
||||
Reference in New Issue
Block a user