55
66from a2a .client .transports .grpc import GrpcTransport
77from a2a .extensions .common import HTTP_EXTENSION_HEADER
8+ from a2a .utils .constants import VERSION_HEADER , PROTOCOL_VERSION_CURRENT
89from a2a .types import a2a_pb2
910from a2a .types .a2a_pb2 import (
1011 AgentCapabilities ,
@@ -217,10 +218,11 @@ async def test_send_message_task_response(
217218 mock_grpc_stub .SendMessage .assert_awaited_once ()
218219 _ , kwargs = mock_grpc_stub .SendMessage .call_args
219220 assert kwargs ['metadata' ] == [
221+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
220222 (
221223 HTTP_EXTENSION_HEADER .lower (),
222224 'https://example.com/test-ext/v3' ,
223- )
225+ ),
224226 ]
225227 assert response .HasField ('task' )
226228 assert response .task .id == sample_task .id
@@ -266,10 +268,11 @@ async def test_send_message_message_response(
266268 mock_grpc_stub .SendMessage .assert_awaited_once ()
267269 _ , kwargs = mock_grpc_stub .SendMessage .call_args
268270 assert kwargs ['metadata' ] == [
271+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
269272 (
270273 HTTP_EXTENSION_HEADER .lower (),
271274 'https://example.com/test-ext/v1,https://example.com/test-ext/v2' ,
272- )
275+ ),
273276 ]
274277 assert response .HasField ('message' )
275278 assert response .message .message_id == sample_message .message_id
@@ -315,10 +318,11 @@ async def test_send_message_streaming( # noqa: PLR0913
315318 mock_grpc_stub .SendStreamingMessage .assert_called_once ()
316319 _ , kwargs = mock_grpc_stub .SendStreamingMessage .call_args
317320 assert kwargs ['metadata' ] == [
321+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
318322 (
319323 HTTP_EXTENSION_HEADER .lower (),
320324 'https://example.com/test-ext/v1,https://example.com/test-ext/v2' ,
321- )
325+ ),
322326 ]
323327 # Responses are StreamResponse proto objects
324328 assert responses [0 ].HasField ('message' )
@@ -350,10 +354,11 @@ async def test_get_task(
350354 mock_grpc_stub .GetTask .assert_awaited_once_with (
351355 a2a_pb2 .GetTaskRequest (id = f'{ sample_task .id } ' , history_length = None ),
352356 metadata = [
357+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
353358 (
354359 HTTP_EXTENSION_HEADER .lower (),
355360 'https://example.com/test-ext/v1,https://example.com/test-ext/v2' ,
356- )
361+ ),
357362 ],
358363 )
359364 assert response .id == sample_task .id
@@ -378,10 +383,11 @@ async def test_list_tasks(
378383 mock_grpc_stub .ListTasks .assert_awaited_once_with (
379384 params ,
380385 metadata = [
386+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
381387 (
382388 HTTP_EXTENSION_HEADER .lower (),
383389 'https://example.com/test-ext/v1,https://example.com/test-ext/v2' ,
384- )
390+ ),
385391 ],
386392 )
387393 assert result .total_size == 2
@@ -405,10 +411,11 @@ async def test_get_task_with_history(
405411 id = f'{ sample_task .id } ' , history_length = history_len
406412 ),
407413 metadata = [
414+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
408415 (
409416 HTTP_EXTENSION_HEADER .lower (),
410417 'https://example.com/test-ext/v1,https://example.com/test-ext/v2' ,
411- )
418+ ),
412419 ],
413420 )
414421
@@ -433,7 +440,8 @@ async def test_cancel_task(
433440 mock_grpc_stub .CancelTask .assert_awaited_once_with (
434441 a2a_pb2 .CancelTaskRequest (id = f'{ sample_task .id } ' ),
435442 metadata = [
436- (HTTP_EXTENSION_HEADER .lower (), 'https://example.com/test-ext/v3' )
443+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
444+ (HTTP_EXTENSION_HEADER .lower (), 'https://example.com/test-ext/v3' ),
437445 ],
438446 )
439447 assert response .status .state == TaskState .TASK_STATE_CANCELED
@@ -462,10 +470,11 @@ async def test_create_task_push_notification_config_with_valid_task(
462470 mock_grpc_stub .CreateTaskPushNotificationConfig .assert_awaited_once_with (
463471 request ,
464472 metadata = [
473+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
465474 (
466475 HTTP_EXTENSION_HEADER .lower (),
467476 'https://example.com/test-ext/v1,https://example.com/test-ext/v2' ,
468- )
477+ ),
469478 ],
470479 )
471480 assert response .task_id == sample_task_push_notification_config .task_id
@@ -524,10 +533,11 @@ async def test_get_task_push_notification_config_with_valid_task(
524533 id = config_id ,
525534 ),
526535 metadata = [
536+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
527537 (
528538 HTTP_EXTENSION_HEADER .lower (),
529539 'https://example.com/test-ext/v1,https://example.com/test-ext/v2' ,
530- )
540+ ),
531541 ],
532542 )
533543 assert response .task_id == sample_task_push_notification_config .task_id
@@ -577,10 +587,11 @@ async def test_list_task_push_notification_configs(
577587 mock_grpc_stub .ListTaskPushNotificationConfigs .assert_awaited_once_with (
578588 a2a_pb2 .ListTaskPushNotificationConfigsRequest (task_id = 'task-1' ),
579589 metadata = [
590+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
580591 (
581592 HTTP_EXTENSION_HEADER .lower (),
582593 'https://example.com/test-ext/v1,https://example.com/test-ext/v2' ,
583- )
594+ ),
584595 ],
585596 )
586597 assert len (response .configs ) == 1
@@ -609,10 +620,11 @@ async def test_delete_task_push_notification_config(
609620 id = 'config-1' ,
610621 ),
611622 metadata = [
623+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
612624 (
613625 HTTP_EXTENSION_HEADER .lower (),
614626 'https://example.com/test-ext/v1,https://example.com/test-ext/v2' ,
615- )
627+ ),
616628 ],
617629 )
618630
@@ -623,32 +635,47 @@ async def test_delete_task_push_notification_config(
623635 (
624636 None ,
625637 None ,
626- None ,
638+ [( VERSION_HEADER . lower (), PROTOCOL_VERSION_CURRENT )] ,
627639 ), # Case 1: No initial, No input
628640 (
629641 ['ext1' ],
630642 None ,
631- [(HTTP_EXTENSION_HEADER .lower (), 'ext1' )],
643+ [
644+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
645+ (HTTP_EXTENSION_HEADER .lower (), 'ext1' ),
646+ ],
632647 ), # Case 2: Initial, No input
633648 (
634649 None ,
635650 ['ext2' ],
636- [(HTTP_EXTENSION_HEADER .lower (), 'ext2' )],
651+ [
652+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
653+ (HTTP_EXTENSION_HEADER .lower (), 'ext2' ),
654+ ],
637655 ), # Case 3: No initial, Input
638656 (
639657 ['ext1' ],
640658 ['ext2' ],
641- [(HTTP_EXTENSION_HEADER .lower (), 'ext2' )],
659+ [
660+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
661+ (HTTP_EXTENSION_HEADER .lower (), 'ext2' ),
662+ ],
642663 ), # Case 4: Initial, Input (override)
643664 (
644665 ['ext1' ],
645666 ['ext2' , 'ext3' ],
646- [(HTTP_EXTENSION_HEADER .lower (), 'ext2,ext3' )],
667+ [
668+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
669+ (HTTP_EXTENSION_HEADER .lower (), 'ext2,ext3' ),
670+ ],
647671 ), # Case 5: Initial, Multiple inputs (override)
648672 (
649673 ['ext1' , 'ext2' ],
650674 ['ext3' ],
651- [(HTTP_EXTENSION_HEADER .lower (), 'ext3' )],
675+ [
676+ (VERSION_HEADER .lower (), PROTOCOL_VERSION_CURRENT ),
677+ (HTTP_EXTENSION_HEADER .lower (), 'ext3' ),
678+ ],
652679 ), # Case 6: Multiple initial, Single input (override)
653680 ],
654681)
0 commit comments