|
8 | 8 | from a2a.types import ( |
9 | 9 | AgentCapabilities, |
10 | 10 | AgentCard, |
| 11 | + MessageSendConfiguration, |
11 | 12 | Message, |
12 | 13 | Part, |
13 | 14 | Role, |
@@ -115,3 +116,82 @@ async def test_send_message_non_streaming_agent_capability_false( |
115 | 116 | assert not mock_transport.send_message_streaming.called |
116 | 117 | assert len(events) == 1 |
117 | 118 | assert events[0][0].id == 'task-789' |
| 119 | + |
| 120 | + |
| 121 | +@pytest.mark.asyncio |
| 122 | +async def test_send_message_uses_callsite_configuration_partial_override_non_streaming( |
| 123 | + base_client: BaseClient, mock_transport: MagicMock, sample_message: Message |
| 124 | +): |
| 125 | + base_client._config.streaming = False |
| 126 | + mock_transport.send_message.return_value = Task( |
| 127 | + id='task-cfg-ns-1', |
| 128 | + context_id='ctx-cfg-ns-1', |
| 129 | + status=TaskStatus(state=TaskState.completed), |
| 130 | + ) |
| 131 | + |
| 132 | + cfg = MessageSendConfiguration(history_length=2) |
| 133 | + events = [ev async for ev in base_client.send_message(sample_message, configuration=cfg)] |
| 134 | + |
| 135 | + mock_transport.send_message.assert_called_once() |
| 136 | + assert not mock_transport.send_message_streaming.called |
| 137 | + assert len(events) == 1 and events[0][0].id == 'task-cfg-ns-1' |
| 138 | + |
| 139 | + params = mock_transport.send_message.await_args.args[0] |
| 140 | + assert params.configuration.history_length == 2 |
| 141 | + assert params.configuration.blocking == (not base_client._config.polling) |
| 142 | + assert params.configuration.accepted_output_modes == base_client._config.accepted_output_modes |
| 143 | + |
| 144 | + |
| 145 | +@pytest.mark.asyncio |
| 146 | +async def test_send_message_ignores_none_fields_in_callsite_configuration_non_streaming( |
| 147 | + base_client: BaseClient, mock_transport: MagicMock, sample_message: Message |
| 148 | +): |
| 149 | + base_client._config.streaming = False |
| 150 | + mock_transport.send_message.return_value = Task( |
| 151 | + id='task-cfg-ns-2', |
| 152 | + context_id='ctx-cfg-ns-2', |
| 153 | + status=TaskStatus(state=TaskState.completed), |
| 154 | + ) |
| 155 | + |
| 156 | + cfg = MessageSendConfiguration(history_length=None, blocking=None) |
| 157 | + events = [ev async for ev in base_client.send_message(sample_message, configuration=cfg)] |
| 158 | + |
| 159 | + mock_transport.send_message.assert_called_once() |
| 160 | + assert len(events) == 1 and events[0][0].id == 'task-cfg-ns-2' |
| 161 | + |
| 162 | + params = mock_transport.send_message.await_args.args[0] |
| 163 | + assert params.configuration.history_length is None |
| 164 | + assert params.configuration.blocking == (not base_client._config.polling) |
| 165 | + assert params.configuration.accepted_output_modes == base_client._config.accepted_output_modes |
| 166 | + |
| 167 | + |
| 168 | +@pytest.mark.asyncio |
| 169 | +async def test_send_message_uses_callsite_configuration_partial_override_streaming( |
| 170 | + base_client: BaseClient, mock_transport: MagicMock, sample_message: Message |
| 171 | +): |
| 172 | + base_client._config.streaming = True |
| 173 | + base_client._card.capabilities.streaming = True |
| 174 | + |
| 175 | + async def create_stream(*args, **kwargs): |
| 176 | + yield Task( |
| 177 | + id='task-cfg-s-1', |
| 178 | + context_id='ctx-cfg-s-1', |
| 179 | + status=TaskStatus(state=TaskState.completed), |
| 180 | + ) |
| 181 | + |
| 182 | + mock_transport.send_message_streaming.return_value = create_stream() |
| 183 | + |
| 184 | + cfg = MessageSendConfiguration(history_length=0) |
| 185 | + events = [ev async for ev in base_client.send_message(sample_message, configuration=cfg)] |
| 186 | + |
| 187 | + mock_transport.send_message_streaming.assert_called_once() |
| 188 | + assert not mock_transport.send_message.called |
| 189 | + assert len(events) == 1 |
| 190 | + first = events[0][0] if isinstance(events[0], tuple) else events[0] |
| 191 | + assert first.id == 'task-cfg-s-1' |
| 192 | + |
| 193 | + params = mock_transport.send_message_streaming.call_args.args[0] |
| 194 | + assert params.configuration.history_length == 0 |
| 195 | + assert params.configuration.blocking == (not base_client._config.polling) |
| 196 | + assert params.configuration.accepted_output_modes == base_client._config.accepted_output_modes |
| 197 | + |
0 commit comments