55known values must still resolve to their specific typed variant.
66"""
77
8+ from typing import get_type_hints
9+
810import pytest
911from pydantic import TypeAdapter , ValidationError
1012
13+ from acp import Client
1114from acp ._protocol_adapters import _mode_from_create_elicitation_request
15+ from acp .agent .connection import AgentSideConnection
1216from acp .exceptions import RequestError
1317from acp .schema import (
1418 AcceptElicitationResponse ,
1519 CreateElicitationRequest ,
1620 CreateElicitationResponse ,
1721 CreateOtherElicitationRequest ,
22+ ElicitationFormSessionMode ,
1823 ElicitationOtherPropertySchema ,
24+ ElicitationSchema ,
1925 ElicitationStringPropertySchema ,
2026 OtherElicitationResponse ,
2127 OtherMultiSelectItems ,
@@ -38,6 +44,31 @@ def test_custom_elicitation_response_falls_back_to_catchall() -> None:
3844 assert parsed .model_dump (by_alias = True )["until" ] == "later"
3945
4046
47+ def test_elicitation_return_annotation_matches_client () -> None :
48+ client_return = get_type_hints (Client .create_elicitation )["return" ]
49+ assert client_return == CreateElicitationResponse
50+ assert get_type_hints (AgentSideConnection .create_elicitation )["return" ] == client_return
51+
52+
53+ @pytest .mark .asyncio
54+ async def test_custom_elicitation_response_roundtrip (connect , client , monkeypatch : pytest .MonkeyPatch ) -> None :
55+ expected = OtherElicitationResponse .model_validate ({"action" : "x-snooze" , "until" : "later" })
56+
57+ async def create_elicitation (** kwargs ) -> OtherElicitationResponse :
58+ return expected
59+
60+ monkeypatch .setattr (client , "create_elicitation" , create_elicitation )
61+ agent_conn , client_conn = connect (use_unstable_protocol = True )
62+ async with agent_conn , client_conn :
63+ response = await agent_conn .create_elicitation (
64+ "Need input" ,
65+ ElicitationFormSessionMode (session_id = "sess" , requested_schema = ElicitationSchema (properties = {})),
66+ )
67+
68+ assert isinstance (response , OtherElicitationResponse )
69+ assert response == expected
70+
71+
4172def test_malformed_known_variant_is_rejected_not_catchall () -> None :
4273 # A "form" request missing the required requestedSchema must fail validation rather
4374 # than silently degrade to the catch-all (restores the schema's dropped `not` clause).
0 commit comments