@@ -200,11 +200,9 @@ async def test_send_request_skips_the_surface_gate_when_method_absent_at_version
200200@pytest .mark .anyio
201201async def test_create_message_tool_result_validation ():
202202 """Test tool_use/tool_result validation in create_message."""
203- dispatcher = StubDispatcher (
204- result = {"role" : "assistant" , "content" : [{"type" : "text" , "text" : "ok" }], "model" : "m" }
205- )
203+ outbound = StubOutbound (result = {"role" : "assistant" , "content" : [{"type" : "text" , "text" : "ok" }], "model" : "m" })
206204 session = _make_session (
207- dispatcher , capabilities = ClientCapabilities (sampling = SamplingCapability (tools = SamplingToolsCapability ()))
205+ outbound , capabilities = ClientCapabilities (sampling = SamplingCapability (tools = SamplingToolsCapability ()))
208206 )
209207 tool = types .Tool (name = "test_tool" , input_schema = {"type" : "object" })
210208 text = types .TextContent (type = "text" , text = "hello" )
@@ -213,7 +211,7 @@ async def test_create_message_tool_result_validation():
213211
214212 # Case 1: tool_result mixed with other content
215213 with pytest .raises (ValueError , match = "only tool_result content" ):
216- await session .create_message (
214+ await session .create_message ( # pyright: ignore[reportDeprecated]
217215 messages = [
218216 types .SamplingMessage (role = "user" , content = text ),
219217 types .SamplingMessage (role = "assistant" , content = tool_use ),
@@ -225,15 +223,15 @@ async def test_create_message_tool_result_validation():
225223
226224 # Case 2: tool_result without previous message
227225 with pytest .raises (ValueError , match = "requires a previous message" ):
228- await session .create_message (
226+ await session .create_message ( # pyright: ignore[reportDeprecated]
229227 messages = [types .SamplingMessage (role = "user" , content = tool_result )],
230228 max_tokens = 100 ,
231229 tools = [tool ],
232230 )
233231
234232 # Case 3: tool_result without previous tool_use
235233 with pytest .raises (ValueError , match = "do not match any tool_use" ):
236- await session .create_message (
234+ await session .create_message ( # pyright: ignore[reportDeprecated]
237235 messages = [
238236 types .SamplingMessage (role = "user" , content = text ),
239237 types .SamplingMessage (role = "user" , content = tool_result ),
@@ -244,7 +242,7 @@ async def test_create_message_tool_result_validation():
244242
245243 # Case 4: mismatched tool IDs
246244 with pytest .raises (ValueError , match = "ids of tool_result blocks and tool_use blocks" ):
247- await session .create_message (
245+ await session .create_message ( # pyright: ignore[reportDeprecated]
248246 messages = [
249247 types .SamplingMessage (role = "user" , content = text ),
250248 types .SamplingMessage (role = "assistant" , content = tool_use ),
@@ -259,7 +257,7 @@ async def test_create_message_tool_result_validation():
259257
260258 # Case 4b: earlier mismatched tool result with a later plain message
261259 with pytest .raises (ValueError , match = "ids of tool_result blocks and tool_use blocks" ):
262- await session .create_message (
260+ await session .create_message ( # pyright: ignore[reportDeprecated]
263261 messages = [
264262 types .SamplingMessage (role = "assistant" , content = tool_use ),
265263 types .SamplingMessage (
@@ -273,14 +271,14 @@ async def test_create_message_tool_result_validation():
273271 )
274272
275273 # Case 5: text-only message with tools (no tool_results) - passes validation
276- await session .create_message (
274+ await session .create_message ( # pyright: ignore[reportDeprecated]
277275 messages = [types .SamplingMessage (role = "user" , content = text )],
278276 max_tokens = 100 ,
279277 tools = [tool ],
280278 )
281279
282280 # Case 6: valid matching tool_result/tool_use IDs - passes validation
283- await session .create_message (
281+ await session .create_message ( # pyright: ignore[reportDeprecated]
284282 messages = [
285283 types .SamplingMessage (role = "user" , content = text ),
286284 types .SamplingMessage (role = "assistant" , content = tool_use ),
@@ -293,7 +291,7 @@ async def test_create_message_tool_result_validation():
293291 # Case 7: validation runs even without `tools` parameter
294292 # (tool loop continuation may omit tools while containing tool_result)
295293 with pytest .raises (ValueError , match = "do not match any tool_use" ):
296- await session .create_message (
294+ await session .create_message ( # pyright: ignore[reportDeprecated]
297295 messages = [
298296 types .SamplingMessage (role = "user" , content = text ),
299297 types .SamplingMessage (role = "user" , content = tool_result ),
@@ -303,10 +301,12 @@ async def test_create_message_tool_result_validation():
303301
304302 # Case 8: empty messages list - skips validation entirely
305303 no_tools_session = _make_session (
306- StubDispatcher (result = {"role" : "assistant" , "content" : {"type" : "text" , "text" : "ok" }, "model" : "m" }),
304+ StubOutbound (result = {"role" : "assistant" , "content" : {"type" : "text" , "text" : "ok" }, "model" : "m" }),
307305 capabilities = ClientCapabilities (sampling = SamplingCapability (tools = SamplingToolsCapability ())),
308306 )
309- await no_tools_session .create_message (messages = [], max_tokens = 100 )
307+ await no_tools_session .create_message ( # pyright: ignore[reportDeprecated]
308+ messages = [], max_tokens = 100
309+ )
310310
311311
312312@pytest .mark .anyio
0 commit comments