Skip to content

Commit 2eee711

Browse files
committed
test: add realtime tool output serialization edge cases
Add focused realtime serialization coverage for _serialize_tool_output. - serialize None as JSON null - serialize lists as JSON arrays - serialize dataclass instances via asdict - fall back to string output for raw bytes
1 parent 756fa43 commit 2eee711

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tests/realtime/test_session.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,27 @@ def __str__(self) -> str:
15051505

15061506
assert _serialize_tool_output(BrokenDataclass(lock=threading.Lock())) == "broken-dataclass"
15071507

1508+
def test_serialize_tool_output_serializes_none_as_json_null(self) -> None:
1509+
assert _serialize_tool_output(None) == "null"
1510+
1511+
def test_serialize_tool_output_serializes_lists_as_json(self) -> None:
1512+
value = ["hello", 1, True, None]
1513+
1514+
assert _serialize_tool_output(value) == json.dumps(value)
1515+
1516+
def test_serialize_tool_output_serializes_dataclass_instances(self) -> None:
1517+
@dataclasses.dataclass
1518+
class ToolResult:
1519+
label: str
1520+
values: list[int]
1521+
1522+
assert _serialize_tool_output(ToolResult(label="demo", values=[1, 2])) == json.dumps(
1523+
{"label": "demo", "values": [1, 2]}
1524+
)
1525+
1526+
def test_serialize_tool_output_returns_string_for_bytes(self) -> None:
1527+
assert _serialize_tool_output(b"abc") == "b'abc'"
1528+
15081529
@pytest.mark.asyncio
15091530
async def test_mixed_tool_types_filtering(self, mock_model, mock_agent):
15101531
"""Test that function tools and handoffs are properly separated"""

0 commit comments

Comments
 (0)