Skip to content

Commit 5d48dd4

Browse files
g97iulio1609Copilot
andcommitted
fix: make test handler async & cover all exception branches
- Make on_list_tools handler async to satisfy pyright type checking - Extend exception test to cover prompt and resource callbacks (hits lines 503-504 and 508-509 for 100% coverage) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 87c2fbd commit 5d48dd4

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

tests/client/test_list_changed_callbacks.py

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ async def test_tool_list_changed_callback():
2222
async def on_tools_changed() -> None:
2323
callback_called.set()
2424

25+
async def _list_tools(_ctx: object, _params: object) -> types.ListToolsResult:
26+
return types.ListToolsResult(tools=[])
27+
2528
server = Server(
2629
name="ListChangedServer",
27-
on_list_tools=lambda _ctx, _params: types.ListToolsResult(tools=[]),
30+
on_list_tools=_list_tools,
2831
)
2932

3033
server_to_client_send, server_to_client_receive = anyio.create_memory_object_stream[SessionMessage](5)
@@ -261,19 +264,28 @@ async def run_server():
261264
server_to_client_receive,
262265
client_to_server_send,
263266
tool_list_changed_callback=bad_callback,
267+
prompt_list_changed_callback=bad_callback,
268+
resource_list_changed_callback=bad_callback,
264269
) as session:
265270
await session.initialize()
266271

267-
await server_to_client_send.send(
268-
SessionMessage(
269-
message=types.JSONRPCNotification(
270-
jsonrpc="2.0",
271-
**types.ToolListChangedNotification().model_dump(by_alias=True, mode="json", exclude_none=True),
272-
),
272+
# Send all three notification types — all callbacks will raise,
273+
# but the session should survive.
274+
for notification_cls in (
275+
types.ToolListChangedNotification,
276+
types.PromptListChangedNotification,
277+
types.ResourceListChangedNotification,
278+
):
279+
await server_to_client_send.send(
280+
SessionMessage(
281+
message=types.JSONRPCNotification(
282+
jsonrpc="2.0",
283+
**notification_cls().model_dump(by_alias=True, mode="json", exclude_none=True),
284+
),
285+
)
273286
)
274-
)
275287

276-
# Session should still be alive — verify by listing tools
288+
# Session should still be alive — verify by waiting for processing
277289
await anyio.sleep(0.1)
278290

279291
tg.cancel_scope.cancel()

0 commit comments

Comments
 (0)