11from __future__ import annotations
22
33import json
4- from typing import Any
4+ from typing import Any , cast
55
66import pytest
77
88from agents .realtime .model_inputs import RealtimeModelSendSessionUpdate
99from agents .realtime .openai_realtime import OpenAIRealtimeWebSocketModel
10+ from agents .realtime .config import RealtimeSessionModelSettings
11+ from websockets .asyncio .client import ClientConnection
1012
1113
1214class _DummyWS :
1315 def __init__ (self ) -> None :
1416 self .sent : list [str ] = []
1517
16- async def send (self , data : str ) -> None : # type: ignore[override]
18+ async def send (self , data : str ) -> None :
1719 self .sent .append (data )
1820
1921
@@ -22,9 +24,9 @@ async def test_session_update_flattens_audio_and_modalities() -> None:
2224 model = OpenAIRealtimeWebSocketModel ()
2325 # Inject a dummy websocket so send() works without a network
2426 dummy = _DummyWS ()
25- model ._websocket = dummy # type: ignore[attr-defined]
27+ model ._websocket = cast ( ClientConnection , dummy )
2628
27- settings = {
29+ settings : dict [ str , object ] = {
2830 "model_name" : "gpt-realtime" ,
2931 "modalities" : ["text" , "audio" ],
3032 "input_audio_format" : "pcm16" ,
@@ -36,7 +38,11 @@ async def test_session_update_flattens_audio_and_modalities() -> None:
3638 "max_output_tokens" : 2048 ,
3739 }
3840
39- await model .send_event (RealtimeModelSendSessionUpdate (session_settings = settings ))
41+ await model .send_event (
42+ RealtimeModelSendSessionUpdate (
43+ session_settings = cast (RealtimeSessionModelSettings , settings )
44+ )
45+ )
4046
4147 # One session.update should have been sent
4248 assert dummy .sent , "no websocket messages were sent"
@@ -68,7 +74,7 @@ async def _fake_interrupt(event: Any) -> None:
6874 called ["interrupt" ] = True
6975
7076 # Prevent network use; _websocket only needed for other paths
71- model ._websocket = _DummyWS () # type: ignore[attr-defined]
77+ model ._websocket = cast ( ClientConnection , _DummyWS ())
7278 monkeypatch .setattr (model , "_send_interrupt" , _fake_interrupt )
7379
7480 # This event previously triggered an interrupt; now it should be ignored
0 commit comments