44from pathlib import Path
55from unittest .mock import Mock
66
7+ import pytest
78import voluptuous as vol
89
910from homeassistant .components import conversation
1415 _transform_stream ,
1516)
1617from homeassistant .core import HomeAssistant
18+ from homeassistant .exceptions import HomeAssistantError
1719from homeassistant .helpers import llm
1820
1921
@@ -344,7 +346,11 @@ async def stream() -> AsyncGenerator[dict]:
344346
345347async def test_transform_stream_starts_new_message_for_reasoning_item () -> None :
346348 """Test each reasoning item starts a separate assistant message."""
347- first_reasoning = {"id" : "reasoning_1" , "summary" : [], "type" : "reasoning" }
349+ first_reasoning = {
350+ "id" : "reasoning_1" ,
351+ "summary" : [{"type" : "summary_text" , "text" : "Checked the state." }],
352+ "type" : "reasoning" ,
353+ }
348354 second_reasoning = {"id" : "reasoning_2" , "summary" : [], "type" : "reasoning" }
349355
350356 async def stream () -> AsyncGenerator [dict ]:
@@ -387,7 +393,7 @@ async def stream() -> AsyncGenerator[dict]:
387393 "native" : {
388394 "encrypted_content" : None ,
389395 "id" : "reasoning_1" ,
390- "summary" : [],
396+ "summary" : [{ "type" : "summary_text" , "text" : "Checked the state." } ],
391397 "type" : "reasoning" ,
392398 }
393399 },
@@ -401,3 +407,31 @@ async def stream() -> AsyncGenerator[dict]:
401407 }
402408 },
403409 ]
410+
411+
412+ async def test_transform_stream_handles_spec_error_envelope () -> None :
413+ """Test streaming error events use the Open Responses error envelope."""
414+
415+ async def stream () -> AsyncGenerator [dict ]:
416+ yield {
417+ "error" : {
418+ "code" : "invalid_request" ,
419+ "message" : "Invalid tool result." ,
420+ "param" : "input" ,
421+ "type" : "invalid_request_error" ,
422+ },
423+ "sequence_number" : 0 ,
424+ "type" : "response.error" ,
425+ }
426+
427+ with pytest .raises (
428+ HomeAssistantError ,
429+ match = "Open Responses response error: Invalid tool result." ,
430+ ):
431+ [
432+ delta
433+ async for delta in _transform_stream (
434+ Mock (),
435+ stream (),
436+ )
437+ ]
0 commit comments