diff --git a/scripts/generate_types.sh b/scripts/generate_types.sh index ad76125f..897f7b00 100755 --- a/scripts/generate_types.sh +++ b/scripts/generate_types.sh @@ -39,6 +39,7 @@ uv run datamodel-codegen \ --no-alias echo "Formatting generated file with ruff..." +uv run ruff check --fix-only "$GENERATED_FILE" uv run ruff format "$GENERATED_FILE" echo "Codegen finished successfully." diff --git a/src/a2a/types.py b/src/a2a/types.py index 63db5e66..6dfca9ac 100644 --- a/src/a2a/types.py +++ b/src/a2a/types.py @@ -1,10 +1,11 @@ # generated by datamodel-codegen: -# filename: https://raw.githubusercontent.com/a2aproject/A2A/refs/heads/main/specification/json/a2a.json +# filename: https://raw.githubusercontent.com/a2aproject/A2A/refs/heads/uuid-fields/specification/json/a2a.json from __future__ import annotations from enum import Enum from typing import Any, Literal +from uuid import UUID from pydantic import Field, RootModel @@ -293,7 +294,7 @@ class DeleteTaskPushNotificationConfigParams(A2ABaseModel): Defines parameters for deleting a specific push notification configuration for a task. """ - id: str + id: UUID """ The unique identifier of the task. """ @@ -301,7 +302,7 @@ class DeleteTaskPushNotificationConfigParams(A2ABaseModel): """ Optional metadata associated with the request. """ - push_notification_config_id: str + push_notification_config_id: UUID """ The ID of the push notification configuration to delete. """ @@ -430,7 +431,7 @@ class GetTaskPushNotificationConfigParams(A2ABaseModel): Defines parameters for fetching a specific push notification configuration for a task. """ - id: str + id: UUID """ The unique identifier of the task. """ @@ -438,7 +439,7 @@ class GetTaskPushNotificationConfigParams(A2ABaseModel): """ Optional metadata associated with the request. """ - push_notification_config_id: str | None = None + push_notification_config_id: UUID | None = None """ The ID of the push notification configuration to retrieve. """ @@ -675,7 +676,7 @@ class ListTaskPushNotificationConfigParams(A2ABaseModel): Defines parameters for listing all push notification configurations associated with a task. """ - id: str + id: UUID """ The unique identifier of the task. """ @@ -828,7 +829,7 @@ class PushNotificationConfig(A2ABaseModel): """ Optional authentication details for the agent to use when calling the notification URL. """ - id: str | None = None + id: UUID | None = None """ A unique ID for the push notification configuration, set by the client to support multiple notification callbacks. @@ -879,7 +880,7 @@ class TaskIdParams(A2ABaseModel): Defines parameters containing a task ID, used for simple task operations. """ - id: str + id: UUID """ The unique identifier of the task. """ @@ -938,7 +939,7 @@ class TaskPushNotificationConfig(A2ABaseModel): """ The push notification configuration for this task. """ - task_id: str + task_id: UUID """ The ID of the task. """ @@ -953,7 +954,7 @@ class TaskQueryParams(A2ABaseModel): """ The number of most recent messages from the task's history to retrieve. """ - id: str + id: UUID """ The unique identifier of the task. """ @@ -1374,7 +1375,7 @@ class Artifact(A2ABaseModel): Represents a file, data structure, or other resource generated by an agent during a task. """ - artifact_id: str + artifact_id: UUID """ A unique identifier for the artifact within the scope of the task. """ @@ -1438,7 +1439,7 @@ class Message(A2ABaseModel): Represents a single message in the conversation between a user and an agent. """ - context_id: str | None = None + context_id: UUID | None = None """ The context identifier for this message, used to group related interactions. """ @@ -1450,7 +1451,7 @@ class Message(A2ABaseModel): """ The type of this object, used as a discriminator. Always 'message' for a Message. """ - message_id: str + message_id: UUID """ A unique identifier for the message, typically a UUID, generated by the sender. """ @@ -1463,7 +1464,7 @@ class Message(A2ABaseModel): An array of content parts that form the message body. A message can be composed of multiple parts of different types (e.g., text and files). """ - reference_task_ids: list[str] | None = None + reference_task_ids: list[UUID] | None = None """ A list of other task IDs that this message references for additional context. """ @@ -1471,7 +1472,7 @@ class Message(A2ABaseModel): """ Identifies the sender of the message. `user` for the client, `agent` for the service. """ - task_id: str | None = None + task_id: UUID | None = None """ The identifier of the task this message is part of. Can be omitted for the first message of a new task. """ @@ -1614,7 +1615,7 @@ class TaskArtifactUpdateEvent(A2ABaseModel): """ The artifact that was generated or updated. """ - context_id: str + context_id: UUID """ The context ID associated with the task. """ @@ -1630,7 +1631,7 @@ class TaskArtifactUpdateEvent(A2ABaseModel): """ Optional metadata for extensions. """ - task_id: str + task_id: UUID """ The ID of the task this artifact belongs to. """ @@ -1663,7 +1664,7 @@ class TaskStatusUpdateEvent(A2ABaseModel): This is typically used in streaming or subscription models. """ - context_id: str + context_id: UUID """ The context ID associated with the task. """ @@ -1683,7 +1684,7 @@ class TaskStatusUpdateEvent(A2ABaseModel): """ The new status of the task. """ - task_id: str + task_id: UUID """ The ID of the task that was updated. """ @@ -1861,7 +1862,7 @@ class Task(A2ABaseModel): """ A collection of artifacts generated by the agent during the execution of the task. """ - context_id: str + context_id: UUID """ A server-generated identifier for maintaining context across multiple related tasks or interactions. """ @@ -1869,7 +1870,7 @@ class Task(A2ABaseModel): """ An array of messages exchanged during the task, representing the conversation history. """ - id: str + id: UUID """ A unique identifier for the task, generated by the server for a new task. """ diff --git a/src/a2a/utils/proto_utils.py b/src/a2a/utils/proto_utils.py index e67f0dfa..67bb214e 100644 --- a/src/a2a/utils/proto_utils.py +++ b/src/a2a/utils/proto_utils.py @@ -32,10 +32,10 @@ def message(cls, message: types.Message | None) -> a2a_pb2.Message | None: if message is None: return None return a2a_pb2.Message( - message_id=message.message_id, + message_id=str(message.message_id), content=[ToProto.part(p) for p in message.parts], - context_id=message.context_id or '', - task_id=message.task_id or '', + context_id=str(message.context_id) if message.context_id else None, + task_id=str(message.task_id) if message.task_id else None, role=cls.role(message.role), metadata=ToProto.metadata(message.metadata), ) @@ -86,8 +86,8 @@ def file( @classmethod def task(cls, task: types.Task) -> a2a_pb2.Task: return a2a_pb2.Task( - id=task.id, - context_id=task.context_id, + id=str(task.id), + context_id=str(task.context_id), status=ToProto.task_status(task.status), artifacts=( [ToProto.artifact(a) for a in task.artifacts] @@ -129,7 +129,7 @@ def task_state(cls, state: types.TaskState) -> a2a_pb2.TaskState: @classmethod def artifact(cls, artifact: types.Artifact) -> a2a_pb2.Artifact: return a2a_pb2.Artifact( - artifact_id=artifact.artifact_id, + artifact_id=str(artifact.artifact_id), description=artifact.description, metadata=ToProto.metadata(artifact.metadata), name=artifact.name, @@ -155,7 +155,7 @@ def push_notification_config( else None ) return a2a_pb2.PushNotificationConfig( - id=config.id or '', + id=str(config.id) if config.id else None, url=config.url, token=config.token, authentication=auth_info, @@ -166,8 +166,8 @@ def task_artifact_update_event( cls, event: types.TaskArtifactUpdateEvent ) -> a2a_pb2.TaskArtifactUpdateEvent: return a2a_pb2.TaskArtifactUpdateEvent( - task_id=event.task_id, - context_id=event.context_id, + task_id=str(event.task_id), + context_id=str(event.context_id), artifact=ToProto.artifact(event.artifact), metadata=ToProto.metadata(event.metadata), append=event.append or False, @@ -179,8 +179,8 @@ def task_status_update_event( cls, event: types.TaskStatusUpdateEvent ) -> a2a_pb2.TaskStatusUpdateEvent: return a2a_pb2.TaskStatusUpdateEvent( - task_id=event.task_id, - context_id=event.context_id, + task_id=str(event.task_id), + context_id=str(event.context_id), status=ToProto.task_status(event.status), metadata=ToProto.metadata(event.metadata), final=event.final, diff --git a/src/a2a/utils/task.py b/src/a2a/utils/task.py index 60272367..0f66a51a 100644 --- a/src/a2a/utils/task.py +++ b/src/a2a/utils/task.py @@ -28,22 +28,10 @@ def new_task(request: Message) -> Task: if isinstance(part.root, TextPart) and not part.root.text: raise ValueError('TextPart content cannot be empty') - context_id_str = request.context_id - if context_id_str is not None: - try: - uuid.UUID(context_id_str) - context_id = context_id_str - except (ValueError, AttributeError, TypeError) as e: - raise ValueError( - f"Invalid context_id: '{context_id_str}' is not a valid UUID." - ) from e - else: - context_id = str(uuid.uuid4()) - return Task( status=TaskStatus(state=TaskState.submitted), - id=(request.task_id if request.task_id else str(uuid.uuid4())), - context_id=context_id, + id=request.task_id or uuid.uuid4(), + context_id=request.context_id or uuid.uuid4(), history=[request], ) diff --git a/tests/client/test_auth_middleware.py b/tests/client/test_auth_middleware.py index 4f53ca3f..6061d0a7 100644 --- a/tests/client/test_auth_middleware.py +++ b/tests/client/test_auth_middleware.py @@ -64,7 +64,7 @@ def build_success_response(request: httpx.Request) -> httpx.Response: jsonrpc='2.0', result=Message( kind='message', - message_id='message-id', + message_id='c222a603-645e-4c37-8f7b-e49f3ea80e9e', role=Role.agent, parts=[], ), @@ -75,7 +75,7 @@ def build_success_response(request: httpx.Request) -> httpx.Response: def build_message() -> Message: """Builds a minimal Message.""" return Message( - message_id='msg1', + message_id='87c8541d-f773-4825-bbb1-f518727231f2', role=Role.user, parts=[], ) diff --git a/tests/client/test_base_client.py b/tests/client/test_base_client.py index 7b1aacec..36ca6d19 100644 --- a/tests/client/test_base_client.py +++ b/tests/client/test_base_client.py @@ -42,7 +42,7 @@ def sample_agent_card(): def sample_message(): return Message( role=Role.user, - message_id='msg-1', + message_id='15957e91-63e6-40ac-8205-1d1ffb09a5b2', parts=[Part(root=TextPart(text='Hello'))], ) @@ -65,8 +65,8 @@ async def test_send_message_streaming( ): async def create_stream(*args, **kwargs): yield Task( - id='task-123', - context_id='ctx-456', + id='536ab032-6915-47d1-9909-4172dbee4aa0', + context_id='9f18b6e9-63c4-4d44-a8b8-f4648003b6b8', status=TaskStatus(state=TaskState.completed), ) @@ -77,7 +77,7 @@ async def create_stream(*args, **kwargs): mock_transport.send_message_streaming.assert_called_once() assert not mock_transport.send_message.called assert len(events) == 1 - assert events[0][0].id == 'task-123' + assert str(events[0][0].id) == '536ab032-6915-47d1-9909-4172dbee4aa0' @pytest.mark.asyncio @@ -86,8 +86,8 @@ async def test_send_message_non_streaming( ): base_client._config.streaming = False mock_transport.send_message.return_value = Task( - id='task-456', - context_id='ctx-789', + id='9368e3b5-c796-46cf-9318-6c73e1a37e58', + context_id='0a934875-fa22-4af0-8b40-79b13d46e4a6', status=TaskStatus(state=TaskState.completed), ) @@ -96,7 +96,7 @@ async def test_send_message_non_streaming( mock_transport.send_message.assert_called_once() assert not mock_transport.send_message_streaming.called assert len(events) == 1 - assert events[0][0].id == 'task-456' + assert str(events[0][0].id) == '9368e3b5-c796-46cf-9318-6c73e1a37e58' @pytest.mark.asyncio @@ -105,8 +105,8 @@ async def test_send_message_non_streaming_agent_capability_false( ): base_client._card.capabilities.streaming = False mock_transport.send_message.return_value = Task( - id='task-789', - context_id='ctx-101', + id='d7541723-0796-4231-8849-f6f137ea3bf8', + context_id='dab80cd1-224d-47cd-abd8-cc53101fb273', status=TaskStatus(state=TaskState.completed), ) @@ -115,4 +115,4 @@ async def test_send_message_non_streaming_agent_capability_false( mock_transport.send_message.assert_called_once() assert not mock_transport.send_message_streaming.called assert len(events) == 1 - assert events[0][0].id == 'task-789' + assert str(events[0][0].id) == 'd7541723-0796-4231-8849-f6f137ea3bf8' diff --git a/tests/client/test_client_task_manager.py b/tests/client/test_client_task_manager.py index fd626d2c..0d7797a1 100644 --- a/tests/client/test_client_task_manager.py +++ b/tests/client/test_client_task_manager.py @@ -27,8 +27,8 @@ def task_manager(): @pytest.fixture def sample_task(): return Task( - id='task123', - context_id='context456', + id='eede470e-ae8f-4910-ba05-085d45dc43c6', + context_id='9a84655d-3956-4410-ba58-2923639254bd', status=TaskStatus(state=TaskState.working), history=[], artifacts=[], @@ -38,7 +38,7 @@ def sample_task(): @pytest.fixture def sample_message(): return Message( - message_id='msg1', + message_id='87c8541d-f773-4825-bbb1-f518727231f2', role=Role.user, parts=[Part(root=TextPart(text='Hello'))], ) @@ -99,7 +99,8 @@ async def test_save_task_event_with_artifact_update( ): await task_manager.save_task_event(sample_task) artifact = Artifact( - artifact_id='art1', parts=[Part(root=TextPart(text='artifact content'))] + artifact_id='c9aa91c0-7f03-44dd-8ffe-6d168b48d3d5', + parts=[Part(root=TextPart(text='artifact content'))], ) artifact_update = TaskArtifactUpdateEvent( task_id=sample_task.id, @@ -119,14 +120,14 @@ async def test_save_task_event_creates_task_if_not_exists( task_manager: ClientTaskManager, ): status_update = TaskStatusUpdateEvent( - task_id='new_task', - context_id='new_context', + task_id='b3cd0887-5074-4534-8f02-172a36f304a0', + context_id='7f1ee76a-85ee-406d-856d-b9128ff7bb98', status=TaskStatus(state=TaskState.working), final=False, ) updated_task = await task_manager.save_task_event(status_update) assert updated_task is not None - assert updated_task.id == 'new_task' + assert str(updated_task.id) == 'b3cd0887-5074-4534-8f02-172a36f304a0' assert updated_task.status.state == TaskState.working @@ -162,7 +163,7 @@ def test_update_with_message_moves_status_message( task_manager: ClientTaskManager, sample_task: Task, sample_message: Message ): status_message = Message( - message_id='status_msg', + message_id='f82da050-9487-40eb-ae60-a9eda5dc20fc', role=Role.agent, parts=[Part(root=TextPart(text='Status'))], ) diff --git a/tests/client/test_grpc_client.py b/tests/client/test_grpc_client.py index c6481b37..fb0ed5e6 100644 --- a/tests/client/test_grpc_client.py +++ b/tests/client/test_grpc_client.py @@ -67,7 +67,7 @@ def sample_message_send_params() -> MessageSendParams: return MessageSendParams( message=Message( role=Role.user, - message_id='msg-1', + message_id='15957e91-63e6-40ac-8205-1d1ffb09a5b2', parts=[Part(root=TextPart(text='Hello'))], ) ) @@ -77,8 +77,8 @@ def sample_message_send_params() -> MessageSendParams: def sample_task() -> Task: """Provides a sample Task object.""" return Task( - id='task-1', - context_id='ctx-1', + id='1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7', + context_id='e1bbdfd5-8818-4200-873f-8124135770fe', status=TaskStatus(state=TaskState.completed), ) @@ -88,7 +88,7 @@ def sample_message() -> Message: """Provides a sample Message object.""" return Message( role=Role.agent, - message_id='msg-response', + message_id='a76b49b6-494b-47fb-b416-36e3f2d622da', parts=[Part(root=TextPart(text='Hi there'))], ) diff --git a/tests/client/test_jsonrpc_client.py b/tests/client/test_jsonrpc_client.py index 58feec25..0fa15c6f 100644 --- a/tests/client/test_jsonrpc_client.py +++ b/tests/client/test_jsonrpc_client.py @@ -79,15 +79,15 @@ ) MINIMAL_TASK: dict[str, Any] = { - 'id': 'task-abc', - 'contextId': 'session-xyz', + 'id': 'ea719c56-e398-425e-b02c-49fd77b7c156', + 'contextId': '598c0e6f-72c2-48fc-803a-15d693622c6f', 'status': {'state': 'working'}, 'kind': 'task', } MINIMAL_CANCELLED_TASK: dict[str, Any] = { - 'id': 'task-abc', - 'contextId': 'session-xyz', + 'id': 'ea719c56-e398-425e-b02c-49fd77b7c156', + 'contextId': '598c0e6f-72c2-48fc-803a-15d693622c6f', 'status': {'state': 'canceled'}, 'kind': 'task', } @@ -365,7 +365,9 @@ async def test_send_message_success( role=Role.agent, content='Hi there!' ) rpc_response = SendMessageSuccessResponse( - id='123', jsonrpc='2.0', result=success_response + id='5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', + jsonrpc='2.0', + result=success_response, ) response = httpx.Response( 200, json=rpc_response.model_dump(mode='json') @@ -390,7 +392,7 @@ async def test_send_message_error_response( ) error_response = InvalidParamsError() rpc_response = { - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'jsonrpc': '2.0', 'error': error_response.model_dump(exclude_none=True), } @@ -539,9 +541,9 @@ async def test_get_task_success( client = JsonRpcTransport( httpx_client=mock_httpx_client, agent_card=mock_agent_card ) - params = TaskQueryParams(id='task-abc') + params = TaskQueryParams(id='ea719c56-e398-425e-b02c-49fd77b7c156') rpc_response = { - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'jsonrpc': '2.0', 'result': MINIMAL_TASK, } @@ -567,9 +569,9 @@ async def test_cancel_task_success( client = JsonRpcTransport( httpx_client=mock_httpx_client, agent_card=mock_agent_card ) - params = TaskIdParams(id='task-abc') + params = TaskIdParams(id='ea719c56-e398-425e-b02c-49fd77b7c156') rpc_response = { - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'jsonrpc': '2.0', 'result': MINIMAL_CANCELLED_TASK, } @@ -596,13 +598,13 @@ async def test_set_task_callback_success( httpx_client=mock_httpx_client, agent_card=mock_agent_card ) params = TaskPushNotificationConfig( - task_id='task-abc', + task_id='ea719c56-e398-425e-b02c-49fd77b7c156', push_notification_config=PushNotificationConfig( url='http://callback.com' ), ) rpc_response = { - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'jsonrpc': '2.0', 'result': params.model_dump(mode='json'), } @@ -625,15 +627,15 @@ async def test_get_task_callback_success( client = JsonRpcTransport( httpx_client=mock_httpx_client, agent_card=mock_agent_card ) - params = TaskIdParams(id='task-abc') + params = TaskIdParams(id='ea719c56-e398-425e-b02c-49fd77b7c156') expected_response = TaskPushNotificationConfig( - task_id='task-abc', + task_id='ea719c56-e398-425e-b02c-49fd77b7c156', push_notification_config=PushNotificationConfig( url='http://callback.com' ), ) rpc_response = { - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'jsonrpc': '2.0', 'result': expected_response.model_dump(mode='json'), } @@ -763,7 +765,7 @@ async def test_get_card_with_extended_card_support( ) rpc_response = { - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'jsonrpc': '2.0', 'result': AGENT_CARD_EXTENDED.model_dump(mode='json'), } diff --git a/tests/client/test_legacy_client.py b/tests/client/test_legacy_client.py index 1bd9e4ae..fdfd4537 100644 --- a/tests/client/test_legacy_client.py +++ b/tests/client/test_legacy_client.py @@ -74,15 +74,15 @@ async def test_a2a_client_send_message( # Mock the underlying transport's send_message method mock_response_task = Task( - id='task-123', - context_id='ctx-456', + id='536ab032-6915-47d1-9909-4172dbee4aa0', + context_id='9f18b6e9-63c4-4d44-a8b8-f4648003b6b8', status=TaskStatus(state=TaskState.completed), ) client._transport.send_message = AsyncMock(return_value=mock_response_task) message = Message( - message_id='msg-123', + message_id='4a90ce5d-eda0-44be-afae-a709621eb63c', role=Role.user, parts=[Part(root=TextPart(text='Hello'))], ) @@ -91,7 +91,7 @@ async def test_a2a_client_send_message( ) response = await client.send_message(request) - assert response.root.result.id == 'task-123' + assert str(response.root.result.id) == '536ab032-6915-47d1-9909-4172dbee4aa0' @pytest.mark.asyncio @@ -101,15 +101,15 @@ async def test_a2a_grpc_client_get_task( client = A2AGrpcClient(grpc_stub=mock_grpc_stub, agent_card=grpc_agent_card) mock_response_task = Task( - id='task-456', - context_id='ctx-789', + id='9368e3b5-c796-46cf-9318-6c73e1a37e58', + context_id='0a934875-fa22-4af0-8b40-79b13d46e4a6', status=TaskStatus(state=TaskState.working), ) client.get_task = AsyncMock(return_value=mock_response_task) - params = TaskQueryParams(id='task-456') + params = TaskQueryParams(id='9368e3b5-c796-46cf-9318-6c73e1a37e58') response = await client.get_task(params) - assert response.id == 'task-456' + assert str(response.id) == '9368e3b5-c796-46cf-9318-6c73e1a37e58' client.get_task.assert_awaited_once_with(params) diff --git a/tests/integration/test_client_server_integration.py b/tests/integration/test_client_server_integration.py index 46907ee6..5e33858f 100644 --- a/tests/integration/test_client_server_integration.py +++ b/tests/integration/test_client_server_integration.py @@ -42,43 +42,45 @@ # --- Test Constants --- TASK_FROM_STREAM = Task( - id='task-123-stream', - context_id='ctx-456-stream', + id='0381ad4c-b528-443e-9bd4-fd21b18adf2d', + context_id='6a642495-71a9-44e8-ad9e-af3b6e645590', status=TaskStatus(state=TaskState.completed), kind='task', ) TASK_FROM_BLOCKING = Task( - id='task-789-blocking', - context_id='ctx-101-blocking', + id='91eca72b-a3cc-461a-bb13-45ffc06eb8d0', + context_id='7ca58a2e-4a27-4415-b8f7-6ab2361602c3', status=TaskStatus(state=TaskState.completed), kind='task', ) GET_TASK_RESPONSE = Task( - id='task-get-456', - context_id='ctx-get-789', + id='e71f6808-92b3-42fb-becf-5e95a3d6532f', + context_id='993fff08-67f2-4a4e-8844-3f9a5b17f216', status=TaskStatus(state=TaskState.working), kind='task', ) CANCEL_TASK_RESPONSE = Task( - id='task-cancel-789', - context_id='ctx-cancel-101', + id='4a68dd5f-c3fd-482e-a3f3-45bc00ac3b88', + context_id='62602584-1308-4775-ab53-047349df43f9', status=TaskStatus(state=TaskState.canceled), kind='task', ) CALLBACK_CONFIG = TaskPushNotificationConfig( - task_id='task-callback-123', + task_id='8fbb70a3-caad-413a-9b70-8acc37e8e885', push_notification_config=PushNotificationConfig( - id='pnc-abc', url='http://callback.example.com', token='' + id='028d975c-5deb-48b7-8352-a227ce665955', + url='http://callback.example.com', + token='', ), ) RESUBSCRIBE_EVENT = TaskStatusUpdateEvent( - task_id='task-resub-456', - context_id='ctx-resub-789', + task_id='5fb71ea7-5e1d-42f0-a7c7-d9b41290f37d', + context_id='8a9fff07-0c62-46ed-8927-522d3a74a216', status=TaskStatus(state=TaskState.working), final=False, ) @@ -230,7 +232,7 @@ async def test_http_transport_sends_message_streaming( message_to_send = Message( role=Role.user, - message_id='msg-integration-test', + message_id='11aec17b-882d-4c14-a1c3-629e04041bb5', parts=[Part(root=TextPart(text='Hello, integration test!'))], ) params = MessageSendParams(message=message_to_send) @@ -274,7 +276,7 @@ def channel_factory(address: str) -> Channel: message_to_send = Message( role=Role.user, - message_id='msg-grpc-integration-test', + message_id='11aec17b-882d-4c14-a1c3-629e04041bb5', parts=[Part(root=TextPart(text='Hello, gRPC integration test!'))], ) params = MessageSendParams(message=message_to_send) @@ -320,7 +322,7 @@ async def test_http_transport_sends_message_blocking( message_to_send = Message( role=Role.user, - message_id='msg-integration-test-blocking', + message_id='11aec17b-882d-4c14-a1c3-629e04041bb5', parts=[Part(root=TextPart(text='Hello, blocking test!'))], ) params = MessageSendParams(message=message_to_send) @@ -363,7 +365,7 @@ def channel_factory(address: str) -> Channel: message_to_send = Message( role=Role.user, - message_id='msg-grpc-integration-test-blocking', + message_id='11aec17b-882d-4c14-a1c3-629e04041bb5', parts=[Part(root=TextPart(text='Hello, gRPC blocking test!'))], ) params = MessageSendParams(message=message_to_send) diff --git a/tests/server/agent_execution/test_context.py b/tests/server/agent_execution/test_context.py index 5cecd892..220d4742 100644 --- a/tests/server/agent_execution/test_context.py +++ b/tests/server/agent_execution/test_context.py @@ -30,7 +30,11 @@ def mock_params(self, mock_message): @pytest.fixture def mock_task(self): """Fixture for a mock Task.""" - return Mock(spec=Task, id='task-123', context_id='context-456') + return Mock( + spec=Task, + id='536ab032-6915-47d1-9909-4172dbee4aa0', + context_id='context-456', + ) def test_init_without_params(self): """Test initialization without parameters.""" @@ -66,7 +70,7 @@ def test_init_with_params_no_ids(self, mock_params): def test_init_with_task_id(self, mock_params): """Test initialization with task ID provided.""" - task_id = 'task-123' + task_id = '536ab032-6915-47d1-9909-4172dbee4aa0' context = RequestContext(request=mock_params, task_id=task_id) assert context.task_id == task_id @@ -82,7 +86,7 @@ def test_init_with_context_id(self, mock_params): def test_init_with_both_ids(self, mock_params): """Test initialization with both task and context IDs provided.""" - task_id = 'task-123' + task_id = '536ab032-6915-47d1-9909-4172dbee4aa0' context_id = 'context-456' context = RequestContext( request=mock_params, task_id=task_id, context_id=context_id diff --git a/tests/server/agent_execution/test_simple_request_context_builder.py b/tests/server/agent_execution/test_simple_request_context_builder.py index 116f4011..8c7433c2 100644 --- a/tests/server/agent_execution/test_simple_request_context_builder.py +++ b/tests/server/agent_execution/test_simple_request_context_builder.py @@ -27,7 +27,7 @@ # Helper to create a simple message def create_sample_message( content='test message', - msg_id='msg1', + msg_id='87c8541d-f773-4825-bbb1-f518727231f2', role=Role.user, reference_task_ids=None, ): @@ -41,7 +41,9 @@ def create_sample_message( # Helper to create a simple task def create_sample_task( - task_id='task1', status_state=TaskState.submitted, context_id='ctx1' + task_id='13d5b8a8-62d7-4490-98c8-d3951b42702a', + status_state=TaskState.submitted, + context_id='06cc947f-8946-4bde-b776-165462407e57', ): return Task( id=task_id, @@ -84,8 +86,8 @@ async def test_build_basic_context_no_populate(self): ) params = MessageSendParams(message=create_sample_message()) - task_id = 'test_task_id_1' - context_id = 'test_context_id_1' + task_id = 'ea57b599-5bff-4f72-8376-6e47b1e3bac0' + context_id = '1a4bd17f-952b-4c19-9d5e-603ae0cab8cd' current_task = create_sample_task( task_id=task_id, context_id=context_id ) @@ -121,9 +123,9 @@ async def test_build_populate_true_with_reference_task_ids(self): builder = SimpleRequestContextBuilder( should_populate_referred_tasks=True, task_store=self.mock_task_store ) - ref_task_id1 = 'ref_task1' - ref_task_id2 = 'ref_task2_missing' - ref_task_id3 = 'ref_task3' + ref_task_id1 = '11aec17b-882d-4c14-a1c3-629e04041bb5' + ref_task_id2 = '2b36e08b-577a-42cd-b4ea-5c8048f7ab73' + ref_task_id3 = 'd6853c8e-834d-4877-be4c-aa2fec76f755' mock_ref_task1 = create_sample_task(task_id=ref_task_id1) mock_ref_task3 = create_sample_task(task_id=ref_task_id3) @@ -211,12 +213,15 @@ async def test_build_populate_true_reference_ids_empty_or_none(self): # To explicitly test None in Message, we'd have to bypass Pydantic default or modify helper. # For now, this covers the "no IDs to process" case. msg_with_no_refs = Message( - message_id='m2', role=Role.user, parts=[], referenceTaskIds=None + message_id='11aec17b-882d-4c14-a1c3-629e04041bb5', + role=Role.user, + parts=[], + referenceTaskIds=None, ) params_none_refs = MessageSendParams(message=msg_with_no_refs) request_context_none = await builder.build( params=params_none_refs, - task_id='t2', + task_id='10b55431-5f90-4c69-b1b8-a43e9b6510af', context_id='c2', task=None, context=server_call_context, @@ -234,7 +239,9 @@ async def test_build_populate_true_task_store_none(self): task_store=None, # Explicitly None ) params = MessageSendParams( - message=create_sample_message(reference_task_ids=['ref1']) + message=create_sample_message( + reference_task_ids=['11aec17b-882d-4c14-a1c3-629e04041bb5'] + ) ) server_call_context = ServerCallContext(user=UnauthenticatedUser()) @@ -256,7 +263,7 @@ async def test_build_populate_false_with_reference_task_ids(self): ) params = MessageSendParams( message=create_sample_message( - reference_task_ids=['ref_task_should_not_be_fetched'] + reference_task_ids=['11aec17b-882d-4c14-a1c3-629e04041bb5'] ) ) server_call_context = ServerCallContext(user=UnauthenticatedUser()) diff --git a/tests/server/apps/jsonrpc/test_jsonrpc_app.py b/tests/server/apps/jsonrpc/test_jsonrpc_app.py index 6b86e7e7..ddbcfe50 100644 --- a/tests/server/apps/jsonrpc/test_jsonrpc_app.py +++ b/tests/server/apps/jsonrpc/test_jsonrpc_app.py @@ -191,9 +191,9 @@ def mock_handler(self): handler = AsyncMock(spec=RequestHandler) handler.on_message_send.return_value = SendMessageResponse( root=SendMessageSuccessResponse( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', result=Message( - message_id='test', + message_id='d2c4511e-11e1-4cda-b3fd-c24cfe8a7119', role=Role.agent, parts=[Part(TextPart(text='response message'))], ), @@ -221,10 +221,10 @@ def test_request_with_single_extension(self, client, mock_handler): '/', headers=headers, json=SendMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams( message=Message( - message_id='1', + message_id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', role=Role.user, parts=[Part(TextPart(text='hi'))], ) @@ -246,10 +246,10 @@ def test_request_with_comma_separated_extensions( '/', headers=headers, json=SendMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams( message=Message( - message_id='1', + message_id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', role=Role.user, parts=[Part(TextPart(text='hi'))], ) @@ -273,10 +273,10 @@ def test_request_with_comma_separated_extensions_no_space( '/', headers=headers, json=SendMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams( message=Message( - message_id='1', + message_id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', role=Role.user, parts=[Part(TextPart(text='hi'))], ) @@ -300,10 +300,10 @@ def test_request_with_multiple_extension_headers( '/', headers=headers, json=SendMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams( message=Message( - message_id='1', + message_id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', role=Role.user, parts=[Part(TextPart(text='hi'))], ) @@ -322,9 +322,9 @@ def side_effect(request, context: ServerCallContext): context.activated_extensions.add('baz') return SendMessageResponse( root=SendMessageSuccessResponse( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', result=Message( - message_id='test', + message_id='d2c4511e-11e1-4cda-b3fd-c24cfe8a7119', role=Role.agent, parts=[Part(TextPart(text='response message'))], ), @@ -336,10 +336,10 @@ def side_effect(request, context: ServerCallContext): response = client.post( '/', json=SendMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams( message=Message( - message_id='1', + message_id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', role=Role.user, parts=[Part(TextPart(text='hi'))], ) diff --git a/tests/server/apps/jsonrpc/test_serialization.py b/tests/server/apps/jsonrpc/test_serialization.py index 1670bb96..ab2cda2a 100644 --- a/tests/server/apps/jsonrpc/test_serialization.py +++ b/tests/server/apps/jsonrpc/test_serialization.py @@ -163,7 +163,7 @@ def test_handle_unicode_characters(agent_card_with_api_key: AgentCard): 'message': { 'role': 'user', 'parts': [{'kind': 'text', 'text': unicode_text}], - 'message_id': 'msg-unicode', + 'message_id': '9a875406-2ebb-43d7-82e6-9f7c14d51cce', } }, } @@ -172,7 +172,7 @@ def test_handle_unicode_characters(agent_card_with_api_key: AgentCard): handler.on_message_send.return_value = Message( role=Role.agent, parts=[Part(root=TextPart(text=f'Received: {unicode_text}'))], - message_id='response-unicode', + message_id='d6853c8e-834d-4877-be4c-aa2fec76f755', ) response = client.post('/', json=unicode_payload) diff --git a/tests/server/apps/rest/test_rest_fastapi_app.py b/tests/server/apps/rest/test_rest_fastapi_app.py index ff463880..2a0b5a1a 100644 --- a/tests/server/apps/rest/test_rest_fastapi_app.py +++ b/tests/server/apps/rest/test_rest_fastapi_app.py @@ -146,7 +146,7 @@ async def test_send_message_success_message( ) -> None: expected_response = a2a_pb2.SendMessageResponse( msg=a2a_pb2.Message( - message_id='test', + message_id='d2c4511e-11e1-4cda-b3fd-c24cfe8a7119', role=a2a_pb2.Role.ROLE_AGENT, content=[ a2a_pb2.Part(text='response message'), @@ -154,7 +154,7 @@ async def test_send_message_success_message( ), ) request_handler.on_message_send.return_value = Message( - message_id='test', + message_id='d2c4511e-11e1-4cda-b3fd-c24cfe8a7119', role=Role.agent, parts=[Part(TextPart(text='response message'))], ) @@ -181,12 +181,12 @@ async def test_send_message_success_task( ) -> None: expected_response = a2a_pb2.SendMessageResponse( task=a2a_pb2.Task( - id='test_task_id', - context_id='test_context_id', + id='2cc58515-03ae-4122-a9a5-560507c822aa', + context_id='1a4bd17f-952b-4c19-9d5e-603ae0cab8cd', status=a2a_pb2.TaskStatus( state=a2a_pb2.TaskState.TASK_STATE_COMPLETED, update=a2a_pb2.Message( - message_id='test', + message_id='d2c4511e-11e1-4cda-b3fd-c24cfe8a7119', role=a2a_pb2.ROLE_AGENT, content=[ a2a_pb2.Part(text='response task message'), @@ -196,12 +196,12 @@ async def test_send_message_success_task( ), ) request_handler.on_message_send.return_value = Task( - id='test_task_id', - context_id='test_context_id', + id='2cc58515-03ae-4122-a9a5-560507c822aa', + context_id='1a4bd17f-952b-4c19-9d5e-603ae0cab8cd', status=TaskStatus( state=TaskState.completed, message=Message( - message_id='test', + message_id='d2c4511e-11e1-4cda-b3fd-c24cfe8a7119', role=Role.agent, parts=[Part(TextPart(text='response task message'))], ), diff --git a/tests/server/events/test_event_consumer.py b/tests/server/events/test_event_consumer.py index 4116fabd..ef9e6372 100644 --- a/tests/server/events/test_event_consumer.py +++ b/tests/server/events/test_event_consumer.py @@ -27,8 +27,8 @@ MINIMAL_TASK: dict[str, Any] = { - 'id': '123', - 'context_id': 'session-xyz', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', + 'context_id': '598c0e6f-72c2-48fc-803a-15d693622c6f', 'status': {'state': 'submitted'}, 'kind': 'task', } @@ -36,7 +36,7 @@ MESSAGE_PAYLOAD: dict[str, Any] = { 'role': 'agent', 'parts': [{'text': 'test message'}], - 'message_id': '111', + 'message_id': '2e888b8b-6d81-4505-a8ec-9220dc3c508f', } @@ -128,15 +128,16 @@ async def test_consume_all_multiple_events( events: list[Any] = [ Task(**MINIMAL_TASK), TaskArtifactUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', artifact=Artifact( - artifact_id='11', parts=[Part(TextPart(text='text'))] + artifact_id='d2323590-71c6-4a4b-8d53-b3f92fe8d1c7', + parts=[Part(TextPart(text='text'))], ), ), TaskStatusUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', status=TaskStatus(state=TaskState.working), final=True, ), @@ -170,16 +171,17 @@ async def test_consume_until_message( events: list[Any] = [ Task(**MINIMAL_TASK), TaskArtifactUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', artifact=Artifact( - artifact_id='11', parts=[Part(TextPart(text='text'))] + artifact_id='d2323590-71c6-4a4b-8d53-b3f92fe8d1c7', + parts=[Part(TextPart(text='text'))], ), ), Message(**MESSAGE_PAYLOAD), TaskStatusUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', status=TaskStatus(state=TaskState.working), final=True, ), @@ -276,7 +278,7 @@ async def test_consume_all_continues_on_queue_empty_if_not_really_closed( ): """Test that QueueClosed with is_closed=False allows loop to continue via timeout.""" payload = MESSAGE_PAYLOAD.copy() - payload['message_id'] = 'final_event_id' + payload['message_id'] = 'cce10a17-1f2f-48c5-9afe-43f97389a476' final_event = Message(**payload) # Setup dequeue_event behavior: diff --git a/tests/server/events/test_event_queue.py b/tests/server/events/test_event_queue.py index ecb7d814..6680d9bc 100644 --- a/tests/server/events/test_event_queue.py +++ b/tests/server/events/test_event_queue.py @@ -28,15 +28,15 @@ MINIMAL_TASK: dict[str, Any] = { - 'id': '123', - 'context_id': 'session-xyz', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', + 'context_id': '598c0e6f-72c2-48fc-803a-15d693622c6f', 'status': {'state': 'submitted'}, 'kind': 'task', } MESSAGE_PAYLOAD: dict[str, Any] = { 'role': 'agent', 'parts': [{'text': 'test message'}], - 'message_id': '111', + 'message_id': '2e888b8b-6d81-4505-a8ec-9220dc3c508f', } @@ -101,8 +101,8 @@ async def test_dequeue_event_empty_queue_no_wait( async def test_dequeue_event_wait(event_queue: EventQueue) -> None: """Test dequeue_event with the default wait behavior.""" event = TaskStatusUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', status=TaskStatus(state=TaskState.working), final=True, ) @@ -115,10 +115,11 @@ async def test_dequeue_event_wait(event_queue: EventQueue) -> None: async def test_task_done(event_queue: EventQueue) -> None: """Test the task_done method.""" event = TaskArtifactUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', artifact=Artifact( - artifact_id='11', parts=[Part(TextPart(text='text'))] + artifact_id='d2323590-71c6-4a4b-8d53-b3f92fe8d1c7', + parts=[Part(TextPart(text='text'))], ), ) await event_queue.enqueue_event(event) diff --git a/tests/server/events/test_inmemory_queue_manager.py b/tests/server/events/test_inmemory_queue_manager.py index 3fb8f4c7..dc4b5bd0 100644 --- a/tests/server/events/test_inmemory_queue_manager.py +++ b/tests/server/events/test_inmemory_queue_manager.py @@ -35,14 +35,14 @@ async def test_init(self, queue_manager): @pytest.mark.asyncio async def test_add_new_queue(self, queue_manager, event_queue): """Test adding a new queue to the manager.""" - task_id = 'test_task_id' + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' await queue_manager.add(task_id, event_queue) assert queue_manager._task_queue[task_id] == event_queue @pytest.mark.asyncio async def test_add_existing_queue(self, queue_manager, event_queue): """Test adding a queue with an existing task_id raises TaskQueueExists.""" - task_id = 'test_task_id' + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' await queue_manager.add(task_id, event_queue) with pytest.raises(TaskQueueExists): @@ -51,7 +51,7 @@ async def test_add_existing_queue(self, queue_manager, event_queue): @pytest.mark.asyncio async def test_get_existing_queue(self, queue_manager, event_queue): """Test getting an existing queue returns the queue.""" - task_id = 'test_task_id' + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' await queue_manager.add(task_id, event_queue) result = await queue_manager.get(task_id) @@ -66,7 +66,7 @@ async def test_get_nonexistent_queue(self, queue_manager): @pytest.mark.asyncio async def test_tap_existing_queue(self, queue_manager, event_queue): """Test tapping an existing queue returns the tapped queue.""" - task_id = 'test_task_id' + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' await queue_manager.add(task_id, event_queue) result = await queue_manager.tap(task_id) @@ -82,7 +82,7 @@ async def test_tap_nonexistent_queue(self, queue_manager): @pytest.mark.asyncio async def test_close_existing_queue(self, queue_manager, event_queue): """Test closing an existing queue removes it from the manager.""" - task_id = 'test_task_id' + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' await queue_manager.add(task_id, event_queue) await queue_manager.close(task_id) @@ -97,7 +97,7 @@ async def test_close_nonexistent_queue(self, queue_manager): @pytest.mark.asyncio async def test_create_or_tap_new_queue(self, queue_manager): """Test create_or_tap with a new task_id creates and returns a new queue.""" - task_id = 'test_task_id' + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' result = await queue_manager.create_or_tap(task_id) assert isinstance(result, EventQueue) @@ -108,7 +108,7 @@ async def test_create_or_tap_existing_queue( self, queue_manager, event_queue ): """Test create_or_tap with an existing task_id taps and returns the existing queue.""" - task_id = 'test_task_id' + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' await queue_manager.add(task_id, event_queue) result = await queue_manager.create_or_tap(task_id) diff --git a/tests/server/request_handlers/test_default_request_handler.py b/tests/server/request_handlers/test_default_request_handler.py index 6cb21662..a09caf91 100644 --- a/tests/server/request_handlers/test_default_request_handler.py +++ b/tests/server/request_handlers/test_default_request_handler.py @@ -82,7 +82,9 @@ async def cancel(self, context: RequestContext, event_queue: EventQueue): # Helper to create a simple task for tests def create_sample_task( - task_id='task1', status_state=TaskState.submitted, context_id='ctx1' + task_id='13d5b8a8-62d7-4490-98c8-d3951b42702a', + status_state=TaskState.submitted, + context_id='06cc947f-8946-4bde-b776-165462407e57', ) -> Task: return Task( id=task_id, @@ -131,7 +133,7 @@ async def test_on_get_task_not_found(): agent_executor=DummyAgentExecutor(), task_store=mock_task_store ) - params = TaskQueryParams(id='non_existent_task') + params = TaskQueryParams(id='b87b95a6-cf02-4d0a-8355-eb9cf307d323') from a2a.utils.errors import ServerError # Local import for ServerError @@ -139,7 +141,9 @@ async def test_on_get_task_not_found(): await request_handler.on_get_task(params, create_server_call_context()) assert isinstance(exc_info.value.error, TaskNotFoundError) - mock_task_store.get.assert_awaited_once_with('non_existent_task') + mock_task_store.get.assert_awaited_once_with( + 'b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) @pytest.mark.asyncio @@ -151,7 +155,7 @@ async def test_on_cancel_task_task_not_found(): request_handler = DefaultRequestHandler( agent_executor=DummyAgentExecutor(), task_store=mock_task_store ) - params = TaskIdParams(id='task_not_found_for_cancel') + params = TaskIdParams(id='d1acbc3d-f320-4c99-aee9-3c9c9627c3f6') from a2a.utils.errors import ServerError # Local import @@ -161,14 +165,18 @@ async def test_on_cancel_task_task_not_found(): ) assert isinstance(exc_info.value.error, TaskNotFoundError) - mock_task_store.get.assert_awaited_once_with('task_not_found_for_cancel') + mock_task_store.get.assert_awaited_once_with( + 'd1acbc3d-f320-4c99-aee9-3c9c9627c3f6' + ) @pytest.mark.asyncio async def test_on_cancel_task_queue_tap_returns_none(): """Test on_cancel_task when queue_manager.tap returns None.""" mock_task_store = AsyncMock(spec=TaskStore) - sample_task = create_sample_task(task_id='tap_none_task') + sample_task = create_sample_task( + task_id='82680a9b-d9cf-40f6-bf17-ff03f32accb5' + ) mock_task_store.get.return_value = sample_task mock_queue_manager = AsyncMock(spec=QueueManager) @@ -184,7 +192,7 @@ async def test_on_cancel_task_queue_tap_returns_none(): mock_result_aggregator_instance = AsyncMock(spec=ResultAggregator) mock_result_aggregator_instance.consume_all.return_value = ( create_sample_task( - task_id='tap_none_task', + task_id='82680a9b-d9cf-40f6-bf17-ff03f32accb5', status_state=TaskState.canceled, # Expected final state ) ) @@ -199,13 +207,17 @@ async def test_on_cancel_task_queue_tap_returns_none(): 'a2a.server.request_handlers.default_request_handler.ResultAggregator', return_value=mock_result_aggregator_instance, ): - params = TaskIdParams(id='tap_none_task') + params = TaskIdParams(id='82680a9b-d9cf-40f6-bf17-ff03f32accb5') result_task = await request_handler.on_cancel_task( params, create_server_call_context() ) - mock_task_store.get.assert_awaited_once_with('tap_none_task') - mock_queue_manager.tap.assert_awaited_once_with('tap_none_task') + mock_task_store.get.assert_awaited_once_with( + '82680a9b-d9cf-40f6-bf17-ff03f32accb5' + ) + mock_queue_manager.tap.assert_awaited_once_with( + '82680a9b-d9cf-40f6-bf17-ff03f32accb5' + ) # agent_executor.cancel should be called with a new EventQueue if tap returned None mock_agent_executor.cancel.assert_awaited_once() # Verify the EventQueue passed to cancel was a new one @@ -223,7 +235,7 @@ async def test_on_cancel_task_queue_tap_returns_none(): @pytest.mark.asyncio async def test_on_cancel_task_cancels_running_agent(): """Test on_cancel_task cancels a running agent task.""" - task_id = 'running_agent_task_to_cancel' + task_id = 'e5681ebe-445c-49e1-b956-ee7c155c92f2' sample_task = create_sample_task(task_id=task_id) mock_task_store = AsyncMock(spec=TaskStore) mock_task_store.get.return_value = sample_task @@ -266,7 +278,7 @@ async def test_on_cancel_task_cancels_running_agent(): @pytest.mark.asyncio async def test_on_cancel_task_invalid_result_type(): """Test on_cancel_task when result_aggregator returns a Message instead of a Task.""" - task_id = 'cancel_invalid_result_task' + task_id = 'e2b71d7b-f826-4768-9b02-f1ec851aac19' sample_task = create_sample_task(task_id=task_id) mock_task_store = AsyncMock(spec=TaskStore) mock_task_store.get.return_value = sample_task @@ -280,7 +292,9 @@ async def test_on_cancel_task_invalid_result_type(): # Mock ResultAggregator to return a Message mock_result_aggregator_instance = AsyncMock(spec=ResultAggregator) mock_result_aggregator_instance.consume_all.return_value = Message( - message_id='unexpected_msg', role=Role.agent, parts=[] + message_id='6e7579fb-eeeb-439d-8b94-0008c6a2c626', + role=Role.agent, + parts=[], ) request_handler = DefaultRequestHandler( @@ -316,8 +330,8 @@ async def test_on_message_send_with_push_notification(): mock_agent_executor = AsyncMock(spec=AgentExecutor) mock_request_context_builder = AsyncMock(spec=RequestContextBuilder) - task_id = 'push_task_1' - context_id = 'push_ctx_1' + task_id = '757b7ee2-0cfa-4234-b436-d65fc65acb22' + context_id = 'f0b24c69-a41b-4a56-8c5a-0f8d54b6c09b' sample_initial_task = create_sample_task( task_id=task_id, context_id=context_id, status_state=TaskState.submitted ) @@ -353,7 +367,7 @@ async def test_on_message_send_with_push_notification(): params = MessageSendParams( message=Message( role=Role.user, - message_id='msg_push', + message_id='5b7d1d17-173b-4b55-ab83-3e5b566fc104', parts=[], task_id=task_id, context_id=context_id, @@ -413,8 +427,8 @@ async def test_on_message_send_with_push_notification_no_existing_Task(): mock_agent_executor = AsyncMock(spec=AgentExecutor) mock_request_context_builder = AsyncMock(spec=RequestContextBuilder) - task_id = 'push_task_1' - context_id = 'push_ctx_1' + task_id = '757b7ee2-0cfa-4234-b436-d65fc65acb22' + context_id = 'f0b24c69-a41b-4a56-8c5a-0f8d54b6c09b' mock_task_store.get.return_value = ( None # Simulate new task scenario for TaskManager @@ -439,7 +453,11 @@ async def test_on_message_send_with_push_notification_no_existing_Task(): accepted_output_modes=['text/plain'], # Added required field ) params = MessageSendParams( - message=Message(role=Role.user, message_id='msg_push', parts=[]), + message=Message( + role=Role.user, + message_id='5b7d1d17-173b-4b55-ab83-3e5b566fc104', + parts=[], + ), configuration=message_config, ) @@ -490,7 +508,7 @@ async def test_on_message_send_no_result_from_aggregator(): mock_agent_executor = AsyncMock(spec=AgentExecutor) mock_request_context_builder = AsyncMock(spec=RequestContextBuilder) - task_id = 'no_result_task' + task_id = '43b91701-0e3e-415b-b4bf-2d53eb23db81' # Mock _request_context_builder.build mock_request_context = MagicMock(spec=RequestContext) mock_request_context.task_id = task_id @@ -502,7 +520,11 @@ async def test_on_message_send_no_result_from_aggregator(): request_context_builder=mock_request_context_builder, ) params = MessageSendParams( - message=Message(role=Role.user, message_id='msg_no_res', parts=[]) + message=Message( + role=Role.user, + message_id='0df4ec66-b5d7-4872-ba3a-5f7b231a9022', + parts=[], + ) ) mock_result_aggregator_instance = AsyncMock(spec=ResultAggregator) @@ -538,8 +560,8 @@ async def test_on_message_send_task_id_mismatch(): mock_agent_executor = AsyncMock(spec=AgentExecutor) mock_request_context_builder = AsyncMock(spec=RequestContextBuilder) - context_task_id = 'context_task_id_1' - result_task_id = 'DIFFERENT_task_id_1' # Mismatch + context_task_id = 'c65e1186-487b-4bd2-a7f3-ddc766a02783' + result_task_id = 'b6d8d5df-2da3-4f86-a173-388ed8654584' # Mismatch # Mock _request_context_builder.build mock_request_context = MagicMock(spec=RequestContext) @@ -552,7 +574,11 @@ async def test_on_message_send_task_id_mismatch(): request_context_builder=mock_request_context_builder, ) params = MessageSendParams( - message=Message(role=Role.user, message_id='msg_id_mismatch', parts=[]) + message=Message( + role=Role.user, + message_id='2cf42a1c-b61c-44ed-88f1-58111760e21f', + parts=[], + ) ) mock_result_aggregator_instance = AsyncMock(spec=ResultAggregator) @@ -627,7 +653,7 @@ async def test_on_message_send_non_blocking(): params = MessageSendParams( message=Message( role=Role.user, - message_id='msg_push', + message_id='5b7d1d17-173b-4b55-ab83-3e5b566fc104', parts=[Part(root=TextPart(text='Hi'))], ), configuration=MessageSendConfiguration( @@ -663,7 +689,7 @@ async def test_on_message_send_interrupted_flow(): mock_agent_executor = AsyncMock(spec=AgentExecutor) mock_request_context_builder = AsyncMock(spec=RequestContextBuilder) - task_id = 'interrupted_task_1' + task_id = '6a24e838-b6cb-4ccb-aab1-09b57ec28256' # Mock _request_context_builder.build mock_request_context = MagicMock(spec=RequestContext) mock_request_context.task_id = task_id @@ -675,7 +701,11 @@ async def test_on_message_send_interrupted_flow(): request_context_builder=mock_request_context_builder, ) params = MessageSendParams( - message=Message(role=Role.user, message_id='msg_interrupt', parts=[]) + message=Message( + role=Role.user, + message_id='21b34182-195d-467a-9ed5-3160c8acd8f5', + parts=[], + ) ) mock_result_aggregator_instance = AsyncMock(spec=ResultAggregator) @@ -732,8 +762,8 @@ async def test_on_message_send_stream_with_push_notification(): mock_agent_executor = AsyncMock(spec=AgentExecutor) mock_request_context_builder = AsyncMock(spec=RequestContextBuilder) - task_id = 'stream_push_task_1' - context_id = 'stream_push_ctx_1' + task_id = '13662c2a-8544-4fd0-b052-60797780e15a' + context_id = '3587eea8-d5e6-41c1-9aa9-9d8acb24797f' # Initial task state for TaskManager initial_task_for_tm = create_sample_task( @@ -768,7 +798,7 @@ async def test_on_message_send_stream_with_push_notification(): params = MessageSendParams( message=Message( role=Role.user, - message_id='msg_stream_push', + message_id='cffc8e42-0016-40e1-99ba-3e588923312c', parts=[], task_id=task_id, context_id=context_id, @@ -1010,8 +1040,8 @@ async def test_on_message_send_stream_task_id_mismatch(): ) # Only need a basic mock mock_request_context_builder = AsyncMock(spec=RequestContextBuilder) - context_task_id = 'stream_task_id_ctx' - mismatched_task_id = 'DIFFERENT_stream_task_id' + context_task_id = 'dc1d1c1e-0b5b-45d1-a70e-47faafb2adff' + mismatched_task_id = '677cb217-5841-475c-9f45-06c3f8914f65' mock_request_context = MagicMock(spec=RequestContext) mock_request_context.task_id = context_task_id @@ -1024,7 +1054,9 @@ async def test_on_message_send_stream_task_id_mismatch(): ) params = MessageSendParams( message=Message( - role=Role.user, message_id='msg_stream_mismatch', parts=[] + role=Role.user, + message_id='b990eddf-01d6-414d-90cb-02f8549debe9', + parts=[], ) ) @@ -1073,7 +1105,7 @@ async def test_cleanup_producer_task_id_not_in_running_agents(): queue_manager=mock_queue_manager, ) - task_id = 'task_already_cleaned' + task_id = 'f7075439-b5c9-4286-a09a-a7a2d2756a03' # Create a real, completed asyncio.Task for the test async def dummy_coro_for_task(): @@ -1108,7 +1140,7 @@ async def test_set_task_push_notification_config_no_notifier(): push_config_store=None, # Explicitly None ) params = TaskPushNotificationConfig( - task_id='task1', + task_id='13d5b8a8-62d7-4490-98c8-d3951b42702a', push_notification_config=PushNotificationConfig( url='http://example.com' ), @@ -1137,7 +1169,7 @@ async def test_set_task_push_notification_config_task_not_found(): push_sender=mock_push_sender, ) params = TaskPushNotificationConfig( - task_id='non_existent_task', + task_id='b87b95a6-cf02-4d0a-8355-eb9cf307d323', push_notification_config=PushNotificationConfig( url='http://example.com' ), @@ -1150,7 +1182,9 @@ async def test_set_task_push_notification_config_task_not_found(): ) assert isinstance(exc_info.value.error, TaskNotFoundError) - mock_task_store.get.assert_awaited_once_with('non_existent_task') + mock_task_store.get.assert_awaited_once_with( + 'b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) mock_push_store.set_info.assert_not_awaited() @@ -1162,7 +1196,9 @@ async def test_get_task_push_notification_config_no_store(): task_store=AsyncMock(spec=TaskStore), push_config_store=None, # Explicitly None ) - params = GetTaskPushNotificationConfigParams(id='task1') + params = GetTaskPushNotificationConfigParams( + id='13d5b8a8-62d7-4490-98c8-d3951b42702a' + ) from a2a.utils.errors import ServerError # Local import with pytest.raises(ServerError) as exc_info: @@ -1184,7 +1220,9 @@ async def test_get_task_push_notification_config_task_not_found(): task_store=mock_task_store, push_config_store=mock_push_store, ) - params = GetTaskPushNotificationConfigParams(id='non_existent_task') + params = GetTaskPushNotificationConfigParams( + id='b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) from a2a.utils.errors import ServerError # Local import with pytest.raises(ServerError) as exc_info: @@ -1193,7 +1231,9 @@ async def test_get_task_push_notification_config_task_not_found(): ) assert isinstance(exc_info.value.error, TaskNotFoundError) - mock_task_store.get.assert_awaited_once_with('non_existent_task') + mock_task_store.get.assert_awaited_once_with( + 'b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) mock_push_store.get_info.assert_not_awaited() @@ -1202,7 +1242,9 @@ async def test_get_task_push_notification_config_info_not_found(): """Test on_get_task_push_notification_config when push_config_store.get_info returns None.""" mock_task_store = AsyncMock(spec=TaskStore) - sample_task = create_sample_task(task_id='non_existent_task') + sample_task = create_sample_task( + task_id='b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) mock_task_store.get.return_value = sample_task mock_push_store = AsyncMock(spec=PushNotificationConfigStore) @@ -1213,7 +1255,9 @@ async def test_get_task_push_notification_config_info_not_found(): task_store=mock_task_store, push_config_store=mock_push_store, ) - params = GetTaskPushNotificationConfigParams(id='non_existent_task') + params = GetTaskPushNotificationConfigParams( + id='b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) from a2a.utils.errors import ServerError # Local import with pytest.raises(ServerError) as exc_info: @@ -1224,8 +1268,12 @@ async def test_get_task_push_notification_config_info_not_found(): assert isinstance( exc_info.value.error, InternalError ) # Current code raises InternalError - mock_task_store.get.assert_awaited_once_with('non_existent_task') - mock_push_store.get_info.assert_awaited_once_with('non_existent_task') + mock_task_store.get.assert_awaited_once_with( + 'b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) + mock_push_store.get_info.assert_awaited_once_with( + 'b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) @pytest.mark.asyncio @@ -1242,9 +1290,10 @@ async def test_get_task_push_notification_config_info_with_config(): ) set_config_params = TaskPushNotificationConfig( - task_id='task_1', + task_id='0a9970e3-0cdd-4726-899f-a1dfef92bd64', push_notification_config=PushNotificationConfig( - id='config_id', url='http://1.example.com' + id='81abbba0-e8eb-48e1-828b-75fd20663c34', + url='http://1.example.com', ), ) await request_handler.on_set_task_push_notification_config( @@ -1252,7 +1301,8 @@ async def test_get_task_push_notification_config_info_with_config(): ) params = GetTaskPushNotificationConfigParams( - id='task_1', push_notification_config_id='config_id' + id='0a9970e3-0cdd-4726-899f-a1dfef92bd64', + push_notification_config_id='81abbba0-e8eb-48e1-828b-75fd20663c34', ) result: TaskPushNotificationConfig = ( @@ -1262,12 +1312,15 @@ async def test_get_task_push_notification_config_info_with_config(): ) assert result is not None - assert result.task_id == 'task_1' + assert result.task_id == '0a9970e3-0cdd-4726-899f-a1dfef92bd64' assert ( result.push_notification_config.url == set_config_params.push_notification_config.url ) - assert result.push_notification_config.id == 'config_id' + assert ( + result.push_notification_config.id + == '81abbba0-e8eb-48e1-828b-75fd20663c34' + ) @pytest.mark.asyncio @@ -1284,7 +1337,7 @@ async def test_get_task_push_notification_config_info_with_config_no_id(): ) set_config_params = TaskPushNotificationConfig( - task_id='task_1', + task_id='0a9970e3-0cdd-4726-899f-a1dfef92bd64', push_notification_config=PushNotificationConfig( url='http://1.example.com' ), @@ -1293,7 +1346,7 @@ async def test_get_task_push_notification_config_info_with_config_no_id(): set_config_params, create_server_call_context() ) - params = TaskIdParams(id='task_1') + params = TaskIdParams(id='0a9970e3-0cdd-4726-899f-a1dfef92bd64') result: TaskPushNotificationConfig = ( await request_handler.on_get_task_push_notification_config( @@ -1302,12 +1355,15 @@ async def test_get_task_push_notification_config_info_with_config_no_id(): ) assert result is not None - assert result.task_id == 'task_1' + assert result.task_id == '0a9970e3-0cdd-4726-899f-a1dfef92bd64' assert ( result.push_notification_config.url == set_config_params.push_notification_config.url ) - assert result.push_notification_config.id == 'task_1' + assert ( + result.push_notification_config.id + == '0a9970e3-0cdd-4726-899f-a1dfef92bd64' + ) @pytest.mark.asyncio @@ -1319,7 +1375,7 @@ async def test_on_resubscribe_to_task_task_not_found(): request_handler = DefaultRequestHandler( agent_executor=DummyAgentExecutor(), task_store=mock_task_store ) - params = TaskIdParams(id='resub_task_not_found') + params = TaskIdParams(id='8c897b3f-89a8-4692-aa72-4c33367d27b8') from a2a.utils.errors import ServerError # Local import @@ -1331,14 +1387,18 @@ async def test_on_resubscribe_to_task_task_not_found(): pass assert isinstance(exc_info.value.error, TaskNotFoundError) - mock_task_store.get.assert_awaited_once_with('resub_task_not_found') + mock_task_store.get.assert_awaited_once_with( + '8c897b3f-89a8-4692-aa72-4c33367d27b8' + ) @pytest.mark.asyncio async def test_on_resubscribe_to_task_queue_not_found(): """Test on_resubscribe_to_task when the queue is not found by queue_manager.tap.""" mock_task_store = AsyncMock(spec=TaskStore) - sample_task = create_sample_task(task_id='resub_queue_not_found') + sample_task = create_sample_task( + task_id='306589b7-57f8-48a0-8b8c-d1ab5aa237e0' + ) mock_task_store.get.return_value = sample_task mock_queue_manager = AsyncMock(spec=QueueManager) @@ -1349,7 +1409,7 @@ async def test_on_resubscribe_to_task_queue_not_found(): task_store=mock_task_store, queue_manager=mock_queue_manager, ) - params = TaskIdParams(id='resub_queue_not_found') + params = TaskIdParams(id='306589b7-57f8-48a0-8b8c-d1ab5aa237e0') from a2a.utils.errors import ServerError # Local import @@ -1362,8 +1422,12 @@ async def test_on_resubscribe_to_task_queue_not_found(): assert isinstance( exc_info.value.error, TaskNotFoundError ) # Should be TaskNotFoundError as per spec - mock_task_store.get.assert_awaited_once_with('resub_queue_not_found') - mock_queue_manager.tap.assert_awaited_once_with('resub_queue_not_found') + mock_task_store.get.assert_awaited_once_with( + '306589b7-57f8-48a0-8b8c-d1ab5aa237e0' + ) + mock_queue_manager.tap.assert_awaited_once_with( + '306589b7-57f8-48a0-8b8c-d1ab5aa237e0' + ) @pytest.mark.asyncio @@ -1374,7 +1438,7 @@ async def test_on_message_send_stream(): message_params = MessageSendParams( message=Message( role=Role.user, - message_id='msg-123', + message_id='4a90ce5d-eda0-44be-afae-a709621eb63c', parts=[Part(root=TextPart(text='How are you?'))], ), ) @@ -1411,7 +1475,9 @@ async def test_list_task_push_notification_config_no_store(): task_store=AsyncMock(spec=TaskStore), push_config_store=None, # Explicitly None ) - params = ListTaskPushNotificationConfigParams(id='task1') + params = ListTaskPushNotificationConfigParams( + id='13d5b8a8-62d7-4490-98c8-d3951b42702a' + ) from a2a.utils.errors import ServerError # Local import with pytest.raises(ServerError) as exc_info: @@ -1433,7 +1499,9 @@ async def test_list_task_push_notification_config_task_not_found(): task_store=mock_task_store, push_config_store=mock_push_store, ) - params = ListTaskPushNotificationConfigParams(id='non_existent_task') + params = ListTaskPushNotificationConfigParams( + id='b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) from a2a.utils.errors import ServerError # Local import with pytest.raises(ServerError) as exc_info: @@ -1442,7 +1510,9 @@ async def test_list_task_push_notification_config_task_not_found(): ) assert isinstance(exc_info.value.error, TaskNotFoundError) - mock_task_store.get.assert_awaited_once_with('non_existent_task') + mock_task_store.get.assert_awaited_once_with( + 'b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) mock_push_store.get_info.assert_not_awaited() @@ -1451,7 +1521,9 @@ async def test_list_no_task_push_notification_config_info(): """Test on_get_task_push_notification_config when push_config_store.get_info returns []""" mock_task_store = AsyncMock(spec=TaskStore) - sample_task = create_sample_task(task_id='non_existent_task') + sample_task = create_sample_task( + task_id='b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) mock_task_store.get.return_value = sample_task push_store = InMemoryPushNotificationConfigStore() @@ -1461,7 +1533,9 @@ async def test_list_no_task_push_notification_config_info(): task_store=mock_task_store, push_config_store=push_store, ) - params = ListTaskPushNotificationConfigParams(id='non_existent_task') + params = ListTaskPushNotificationConfigParams( + id='b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) result = await request_handler.on_list_task_push_notification_config( params, create_server_call_context() @@ -1474,26 +1548,34 @@ async def test_list_task_push_notification_config_info_with_config(): """Test on_list_task_push_notification_config with push config+id""" mock_task_store = AsyncMock(spec=TaskStore) - sample_task = create_sample_task(task_id='non_existent_task') + sample_task = create_sample_task( + task_id='b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) mock_task_store.get.return_value = sample_task push_config1 = PushNotificationConfig( - id='config_1', url='http://example.com' + id='37d6af86-231f-40a5-8dba-02d2ccb4e161', url='http://example.com' ) push_config2 = PushNotificationConfig( - id='config_2', url='http://example.com' + id='86d0a728-e0f5-4a5c-af2d-e43bd116780c', url='http://example.com' ) push_store = InMemoryPushNotificationConfigStore() - await push_store.set_info('task_1', push_config1) - await push_store.set_info('task_1', push_config2) + await push_store.set_info( + '0a9970e3-0cdd-4726-899f-a1dfef92bd64', push_config1 + ) + await push_store.set_info( + '0a9970e3-0cdd-4726-899f-a1dfef92bd64', push_config2 + ) request_handler = DefaultRequestHandler( agent_executor=DummyAgentExecutor(), task_store=mock_task_store, push_config_store=push_store, ) - params = ListTaskPushNotificationConfigParams(id='task_1') + params = ListTaskPushNotificationConfigParams( + id='0a9970e3-0cdd-4726-899f-a1dfef92bd64' + ) result: list[ TaskPushNotificationConfig @@ -1502,9 +1584,9 @@ async def test_list_task_push_notification_config_info_with_config(): ) assert len(result) == 2 - assert result[0].task_id == 'task_1' + assert str(result[0].task_id) == '0a9970e3-0cdd-4726-899f-a1dfef92bd64' assert result[0].push_notification_config == push_config1 - assert result[1].task_id == 'task_1' + assert str(result[1].task_id) == '0a9970e3-0cdd-4726-899f-a1dfef92bd64' assert result[1].push_notification_config == push_config2 @@ -1523,7 +1605,7 @@ async def test_list_task_push_notification_config_info_with_config_and_no_id(): # multiple calls without config id should replace the existing set_config_params1 = TaskPushNotificationConfig( - task_id='task_1', + task_id='0a9970e3-0cdd-4726-899f-a1dfef92bd64', push_notification_config=PushNotificationConfig( url='http://1.example.com' ), @@ -1533,7 +1615,7 @@ async def test_list_task_push_notification_config_info_with_config_and_no_id(): ) set_config_params2 = TaskPushNotificationConfig( - task_id='task_1', + task_id='0a9970e3-0cdd-4726-899f-a1dfef92bd64', push_notification_config=PushNotificationConfig( url='http://2.example.com' ), @@ -1542,7 +1624,9 @@ async def test_list_task_push_notification_config_info_with_config_and_no_id(): set_config_params2, create_server_call_context() ) - params = ListTaskPushNotificationConfigParams(id='task_1') + params = ListTaskPushNotificationConfigParams( + id='0a9970e3-0cdd-4726-899f-a1dfef92bd64' + ) result: list[ TaskPushNotificationConfig @@ -1551,12 +1635,15 @@ async def test_list_task_push_notification_config_info_with_config_and_no_id(): ) assert len(result) == 1 - assert result[0].task_id == 'task_1' + assert str(result[0].task_id) == '0a9970e3-0cdd-4726-899f-a1dfef92bd64' assert ( result[0].push_notification_config.url == set_config_params2.push_notification_config.url ) - assert result[0].push_notification_config.id == 'task_1' + assert ( + str(result[0].push_notification_config.id) + == '0a9970e3-0cdd-4726-899f-a1dfef92bd64' + ) @pytest.mark.asyncio @@ -1568,7 +1655,8 @@ async def test_delete_task_push_notification_config_no_store(): push_config_store=None, # Explicitly None ) params = DeleteTaskPushNotificationConfigParams( - id='task1', push_notification_config_id='config1' + id='13d5b8a8-62d7-4490-98c8-d3951b42702a', + push_notification_config_id='2fbdf017-d3d0-498f-9135-ebf8d2ae8492', ) from a2a.utils.errors import ServerError # Local import @@ -1592,7 +1680,8 @@ async def test_delete_task_push_notification_config_task_not_found(): push_config_store=mock_push_store, ) params = DeleteTaskPushNotificationConfigParams( - id='non_existent_task', push_notification_config_id='config1' + id='b87b95a6-cf02-4d0a-8355-eb9cf307d323', + push_notification_config_id='2fbdf017-d3d0-498f-9135-ebf8d2ae8492', ) from a2a.utils.errors import ServerError # Local import @@ -1602,7 +1691,9 @@ async def test_delete_task_push_notification_config_task_not_found(): ) assert isinstance(exc_info.value.error, TaskNotFoundError) - mock_task_store.get.assert_awaited_once_with('non_existent_task') + mock_task_store.get.assert_awaited_once_with( + 'b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) mock_push_store.get_info.assert_not_awaited() @@ -1611,13 +1702,17 @@ async def test_delete_no_task_push_notification_config_info(): """Test on_delete_task_push_notification_config without config info""" mock_task_store = AsyncMock(spec=TaskStore) - sample_task = create_sample_task(task_id='task_1') + sample_task = create_sample_task( + task_id='0a9970e3-0cdd-4726-899f-a1dfef92bd64' + ) mock_task_store.get.return_value = sample_task push_store = InMemoryPushNotificationConfigStore() await push_store.set_info( 'task_2', - PushNotificationConfig(id='config_1', url='http://example.com'), + PushNotificationConfig( + id='37d6af86-231f-40a5-8dba-02d2ccb4e161', url='http://example.com' + ), ) request_handler = DefaultRequestHandler( @@ -1626,7 +1721,8 @@ async def test_delete_no_task_push_notification_config_info(): push_config_store=push_store, ) params = DeleteTaskPushNotificationConfigParams( - id='task1', push_notification_config_id='config_non_existant' + id='13d5b8a8-62d7-4490-98c8-d3951b42702a', + push_notification_config_id='fb0133f8-0cf7-4e3e-adab-d65b8df0ae22', ) result = await request_handler.on_delete_task_push_notification_config( @@ -1635,7 +1731,8 @@ async def test_delete_no_task_push_notification_config_info(): assert result is None params = DeleteTaskPushNotificationConfigParams( - id='task2', push_notification_config_id='config_non_existant' + id='c20360a1-201f-46d0-9e1d-5d5a6cb2601c', + push_notification_config_id='fb0133f8-0cf7-4e3e-adab-d65b8df0ae22', ) result = await request_handler.on_delete_task_push_notification_config( @@ -1649,19 +1746,25 @@ async def test_delete_task_push_notification_config_info_with_config(): """Test on_list_task_push_notification_config with push config+id""" mock_task_store = AsyncMock(spec=TaskStore) - sample_task = create_sample_task(task_id='non_existent_task') + sample_task = create_sample_task( + task_id='b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) mock_task_store.get.return_value = sample_task push_config1 = PushNotificationConfig( - id='config_1', url='http://example.com' + id='37d6af86-231f-40a5-8dba-02d2ccb4e161', url='http://example.com' ) push_config2 = PushNotificationConfig( - id='config_2', url='http://example.com' + id='86d0a728-e0f5-4a5c-af2d-e43bd116780c', url='http://example.com' ) push_store = InMemoryPushNotificationConfigStore() - await push_store.set_info('task_1', push_config1) - await push_store.set_info('task_1', push_config2) + await push_store.set_info( + '0a9970e3-0cdd-4726-899f-a1dfef92bd64', push_config1 + ) + await push_store.set_info( + '0a9970e3-0cdd-4726-899f-a1dfef92bd64', push_config2 + ) await push_store.set_info('task_2', push_config1) request_handler = DefaultRequestHandler( @@ -1670,7 +1773,8 @@ async def test_delete_task_push_notification_config_info_with_config(): push_config_store=push_store, ) params = DeleteTaskPushNotificationConfigParams( - id='task_1', push_notification_config_id='config_1' + id='0a9970e3-0cdd-4726-899f-a1dfef92bd64', + push_notification_config_id='37d6af86-231f-40a5-8dba-02d2ccb4e161', ) result1 = await request_handler.on_delete_task_push_notification_config( @@ -1680,12 +1784,14 @@ async def test_delete_task_push_notification_config_info_with_config(): assert result1 is None result2 = await request_handler.on_list_task_push_notification_config( - ListTaskPushNotificationConfigParams(id='task_1'), + ListTaskPushNotificationConfigParams( + id='0a9970e3-0cdd-4726-899f-a1dfef92bd64' + ), create_server_call_context(), ) assert len(result2) == 1 - assert result2[0].task_id == 'task_1' + assert result2[0].task_id == '0a9970e3-0cdd-4726-899f-a1dfef92bd64' assert result2[0].push_notification_config == push_config2 @@ -1694,15 +1800,21 @@ async def test_delete_task_push_notification_config_info_with_config_and_no_id() """Test on_list_task_push_notification_config with no push config id""" mock_task_store = AsyncMock(spec=TaskStore) - sample_task = create_sample_task(task_id='non_existent_task') + sample_task = create_sample_task( + task_id='b87b95a6-cf02-4d0a-8355-eb9cf307d323' + ) mock_task_store.get.return_value = sample_task push_config = PushNotificationConfig(url='http://example.com') # insertion without id should replace the existing config push_store = InMemoryPushNotificationConfigStore() - await push_store.set_info('task_1', push_config) - await push_store.set_info('task_1', push_config) + await push_store.set_info( + '0a9970e3-0cdd-4726-899f-a1dfef92bd64', push_config + ) + await push_store.set_info( + '0a9970e3-0cdd-4726-899f-a1dfef92bd64', push_config + ) request_handler = DefaultRequestHandler( agent_executor=DummyAgentExecutor(), @@ -1710,7 +1822,8 @@ async def test_delete_task_push_notification_config_info_with_config_and_no_id() push_config_store=push_store, ) params = DeleteTaskPushNotificationConfigParams( - id='task_1', push_notification_config_id='task_1' + id='0a9970e3-0cdd-4726-899f-a1dfef92bd64', + push_notification_config_id='0a9970e3-0cdd-4726-899f-a1dfef92bd64', ) result = await request_handler.on_delete_task_push_notification_config( @@ -1720,7 +1833,9 @@ async def test_delete_task_push_notification_config_info_with_config_and_no_id() assert result is None result2 = await request_handler.on_list_task_push_notification_config( - ListTaskPushNotificationConfigParams(id='task_1'), + ListTaskPushNotificationConfigParams( + id='0a9970e3-0cdd-4726-899f-a1dfef92bd64' + ), create_server_call_context(), ) @@ -1739,7 +1854,7 @@ async def test_delete_task_push_notification_config_info_with_config_and_no_id() @pytest.mark.parametrize('terminal_state', TERMINAL_TASK_STATES) async def test_on_message_send_task_in_terminal_state(terminal_state): """Test on_message_send when task is already in a terminal state.""" - task_id = f'terminal_task_{terminal_state.value}' + task_id = '5520dd18-ad0a-4307-a295-c4c93b543932' terminal_task = create_sample_task( task_id=task_id, status_state=terminal_state ) @@ -1756,7 +1871,7 @@ async def test_on_message_send_task_in_terminal_state(terminal_state): params = MessageSendParams( message=Message( role=Role.user, - message_id='msg_terminal', + message_id='4d1249a9-e290-4b55-8e16-691b060bedb1', parts=[], task_id=task_id, ) @@ -1786,7 +1901,7 @@ async def test_on_message_send_task_in_terminal_state(terminal_state): @pytest.mark.parametrize('terminal_state', TERMINAL_TASK_STATES) async def test_on_message_send_stream_task_in_terminal_state(terminal_state): """Test on_message_send_stream when task is already in a terminal state.""" - task_id = f'terminal_stream_task_{terminal_state.value}' + task_id = 'f7075439-b5c9-4286-a09a-a7a2d2756a03' terminal_task = create_sample_task( task_id=task_id, status_state=terminal_state ) @@ -1800,7 +1915,7 @@ async def test_on_message_send_stream_task_in_terminal_state(terminal_state): params = MessageSendParams( message=Message( role=Role.user, - message_id='msg_terminal_stream', + message_id='4d1249a9-e290-4b55-8e16-691b060bedb1', parts=[], task_id=task_id, ) @@ -1830,7 +1945,7 @@ async def test_on_message_send_stream_task_in_terminal_state(terminal_state): @pytest.mark.parametrize('terminal_state', TERMINAL_TASK_STATES) async def test_on_resubscribe_to_task_in_terminal_state(terminal_state): """Test on_resubscribe_to_task when task is in a terminal state.""" - task_id = f'resub_terminal_task_{terminal_state.value}' + task_id = 'a12bb281-c7ab-491f-8b3f-9913addca78a' terminal_task = create_sample_task( task_id=task_id, status_state=terminal_state ) @@ -1865,7 +1980,7 @@ async def test_on_resubscribe_to_task_in_terminal_state(terminal_state): @pytest.mark.asyncio async def test_on_message_send_task_id_provided_but_task_not_found(): """Test on_message_send when task_id is provided but task doesn't exist.""" - task_id = 'nonexistent_task' + task_id = 'd95515a2-b95b-4706-a4d2-b1d2e8b068d0' mock_task_store = AsyncMock(spec=TaskStore) request_handler = DefaultRequestHandler( @@ -1875,10 +1990,10 @@ async def test_on_message_send_task_id_provided_but_task_not_found(): params = MessageSendParams( message=Message( role=Role.user, - message_id='msg_nonexistent', + message_id='c5e7c368-8f16-4518-bd4a-d61be13858fe', parts=[Part(root=TextPart(text='Hello'))], task_id=task_id, - context_id='ctx1', + context_id='06cc947f-8946-4bde-b776-165462407e57', ) ) @@ -1905,7 +2020,7 @@ async def test_on_message_send_task_id_provided_but_task_not_found(): @pytest.mark.asyncio async def test_on_message_send_stream_task_id_provided_but_task_not_found(): """Test on_message_send_stream when task_id is provided but task doesn't exist.""" - task_id = 'nonexistent_stream_task' + task_id = 'e4cc2ed4-117c-4bc6-90a4-415f0a7dec5a' mock_task_store = AsyncMock(spec=TaskStore) request_handler = DefaultRequestHandler( @@ -1915,10 +2030,10 @@ async def test_on_message_send_stream_task_id_provided_but_task_not_found(): params = MessageSendParams( message=Message( role=Role.user, - message_id='msg_nonexistent_stream', + message_id='e3d82e74-63ac-4603-b54a-fce0bb01c447', parts=[Part(root=TextPart(text='Hello'))], task_id=task_id, - context_id='ctx1', + context_id='06cc947f-8946-4bde-b776-165462407e57', ) ) diff --git a/tests/server/request_handlers/test_grpc_handler.py b/tests/server/request_handlers/test_grpc_handler.py index 05af6cda..e83e797e 100644 --- a/tests/server/request_handlers/test_grpc_handler.py +++ b/tests/server/request_handlers/test_grpc_handler.py @@ -64,11 +64,13 @@ async def test_send_message_success( ): """Test successful SendMessage call.""" request_proto = a2a_pb2.SendMessageRequest( - request=a2a_pb2.Message(message_id='msg-1') + request=a2a_pb2.Message( + message_id='15957e91-63e6-40ac-8205-1d1ffb09a5b2' + ) ) response_model = types.Task( - id='task-1', - context_id='ctx-1', + id='1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7', + context_id='e1bbdfd5-8818-4200-873f-8124135770fe', status=types.TaskStatus(state=types.TaskState.completed), ) mock_request_handler.on_message_send.return_value = response_model @@ -78,7 +80,7 @@ async def test_send_message_success( mock_request_handler.on_message_send.assert_awaited_once() assert isinstance(response, a2a_pb2.SendMessageResponse) assert response.HasField('task') - assert response.task.id == 'task-1' + assert response.task.id == '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' @pytest.mark.asyncio @@ -106,10 +108,12 @@ async def test_get_task_success( mock_grpc_context: AsyncMock, ): """Test successful GetTask call.""" - request_proto = a2a_pb2.GetTaskRequest(name='tasks/task-1') + request_proto = a2a_pb2.GetTaskRequest( + name='tasks/1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' + ) response_model = types.Task( - id='task-1', - context_id='ctx-1', + id='1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7', + context_id='e1bbdfd5-8818-4200-873f-8124135770fe', status=types.TaskStatus(state=types.TaskState.working), ) mock_request_handler.on_get_task.return_value = response_model @@ -118,7 +122,7 @@ async def test_get_task_success( mock_request_handler.on_get_task.assert_awaited_once() assert isinstance(response, a2a_pb2.Task) - assert response.id == 'task-1' + assert response.id == '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' @pytest.mark.asyncio @@ -128,7 +132,9 @@ async def test_get_task_not_found( mock_grpc_context: AsyncMock, ): """Test GetTask call when task is not found.""" - request_proto = a2a_pb2.GetTaskRequest(name='tasks/task-1') + request_proto = a2a_pb2.GetTaskRequest( + name='tasks/293e3a19-4ebb-4c47-b7b9-651a664a9237' + ) mock_request_handler.on_get_task.return_value = None await grpc_handler.GetTask(request_proto, mock_grpc_context) @@ -145,7 +151,9 @@ async def test_cancel_task_server_error( mock_grpc_context: AsyncMock, ): """Test CancelTask call when handler raises ServerError.""" - request_proto = a2a_pb2.CancelTaskRequest(name='tasks/task-1') + request_proto = a2a_pb2.CancelTaskRequest( + name='tasks/7857a35a-e8d7-44e0-9502-a0710e58938a' + ) error = ServerError(error=types.TaskNotCancelableError()) mock_request_handler.on_cancel_task.side_effect = error @@ -167,8 +175,8 @@ async def test_send_streaming_message( async def mock_stream(): yield types.Task( - id='task-1', - context_id='ctx-1', + id='1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7', + context_id='e1bbdfd5-8818-4200-873f-8124135770fe', status=types.TaskStatus(state=types.TaskState.working), ) @@ -184,7 +192,7 @@ async def mock_stream(): assert len(results) == 1 assert results[0].HasField('task') - assert results[0].task.id == 'task-1' + assert results[0].task.id == '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' @pytest.mark.asyncio @@ -330,8 +338,8 @@ def side_effect(request, context: ServerCallContext): context.activated_extensions.add('foo') context.activated_extensions.add('baz') return types.Task( - id='task-1', - context_id='ctx-1', + id='1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7', + context_id='e1bbdfd5-8818-4200-873f-8124135770fe', status=types.TaskStatus(state=types.TaskState.completed), ) @@ -366,7 +374,7 @@ async def test_send_message_with_comma_separated_extensions( (HTTP_EXTENSION_HEADER, 'baz , bar'), ) mock_request_handler.on_message_send.return_value = types.Message( - message_id='1', + message_id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', role=types.Role.agent, parts=[types.Part(root=types.TextPart(text='test'))], ) @@ -395,8 +403,8 @@ async def side_effect(request, context: ServerCallContext): context.activated_extensions.add('foo') context.activated_extensions.add('baz') yield types.Task( - id='task-1', - context_id='ctx-1', + id='1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7', + context_id='e1bbdfd5-8818-4200-873f-8124135770fe', status=types.TaskStatus(state=types.TaskState.working), ) diff --git a/tests/server/request_handlers/test_jsonrpc_handler.py b/tests/server/request_handlers/test_jsonrpc_handler.py index b460b2f3..2a816396 100644 --- a/tests/server/request_handlers/test_jsonrpc_handler.py +++ b/tests/server/request_handlers/test_jsonrpc_handler.py @@ -77,15 +77,15 @@ MINIMAL_TASK: dict[str, Any] = { - 'id': 'task_123', - 'contextId': 'session-xyz', + 'id': '43305029-d2b0-4494-a61b-1c7980bf259d', + 'contextId': '598c0e6f-72c2-48fc-803a-15d693622c6f', 'status': {'state': 'submitted'}, 'kind': 'task', } MESSAGE_PAYLOAD: dict[str, Any] = { 'role': 'agent', 'parts': [{'text': 'test message'}], - 'messageId': '111', + 'messageId': '2e888b8b-6d81-4505-a8ec-9220dc3c508f', } @@ -104,10 +104,13 @@ async def test_on_get_task_success(self) -> None: ) call_context = ServerCallContext(state={'foo': 'bar'}) handler = JSONRPCHandler(self.mock_agent_card, request_handler) - task_id = 'test_task_id' + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' mock_task = Task(**MINIMAL_TASK) mock_task_store.get.return_value = mock_task - request = GetTaskRequest(id='1', params=TaskQueryParams(id=task_id)) + request = GetTaskRequest( + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', + params=TaskQueryParams(id=task_id), + ) response: GetTaskResponse = await handler.on_get_task( request, call_context ) @@ -124,9 +127,9 @@ async def test_on_get_task_not_found(self) -> None: handler = JSONRPCHandler(self.mock_agent_card, request_handler) mock_task_store.get.return_value = None request = GetTaskRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', method='tasks/get', - params=TaskQueryParams(id='nonexistent_id'), + params=TaskQueryParams(id='a87cc6eb-f623-42a5-bd38-2b5cbe9f5553'), ) call_context = ServerCallContext(state={'foo': 'bar'}) response: GetTaskResponse = await handler.on_get_task( @@ -142,7 +145,7 @@ async def test_on_cancel_task_success(self) -> None: mock_agent_executor, mock_task_store ) handler = JSONRPCHandler(self.mock_agent_card, request_handler) - task_id = 'test_task_id' + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' mock_task = Task(**MINIMAL_TASK) mock_task_store.get.return_value = mock_task mock_agent_executor.cancel.return_value = None @@ -155,7 +158,10 @@ async def streaming_coro(): 'a2a.server.request_handlers.default_request_handler.EventConsumer.consume_all', return_value=streaming_coro(), ): - request = CancelTaskRequest(id='1', params=TaskIdParams(id=task_id)) + request = CancelTaskRequest( + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', + params=TaskIdParams(id=task_id), + ) response = await handler.on_cancel_task(request, call_context) assert mock_agent_executor.cancel.call_count == 1 self.assertIsInstance(response.root, CancelTaskSuccessResponse) @@ -169,7 +175,7 @@ async def test_on_cancel_task_not_supported(self) -> None: mock_agent_executor, mock_task_store ) handler = JSONRPCHandler(self.mock_agent_card, request_handler) - task_id = 'test_task_id' + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' mock_task = Task(**MINIMAL_TASK) mock_task_store.get.return_value = mock_task mock_agent_executor.cancel.return_value = None @@ -183,7 +189,10 @@ async def streaming_coro(): 'a2a.server.request_handlers.default_request_handler.EventConsumer.consume_all', return_value=streaming_coro(), ): - request = CancelTaskRequest(id='1', params=TaskIdParams(id=task_id)) + request = CancelTaskRequest( + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', + params=TaskIdParams(id=task_id), + ) response = await handler.on_cancel_task(request, call_context) assert mock_agent_executor.cancel.call_count == 1 self.assertIsInstance(response.root, JSONRPCErrorResponse) @@ -199,14 +208,14 @@ async def test_on_cancel_task_not_found(self) -> None: handler = JSONRPCHandler(self.mock_agent_card, request_handler) mock_task_store.get.return_value = None request = CancelTaskRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', method='tasks/cancel', - params=TaskIdParams(id='nonexistent_id'), + params=TaskIdParams(id='a87cc6eb-f623-42a5-bd38-2b5cbe9f5553'), ) response = await handler.on_cancel_task(request) self.assertIsInstance(response.root, JSONRPCErrorResponse) assert response.root.error == TaskNotFoundError() # type: ignore - mock_task_store.get.assert_called_once_with('nonexistent_id') + mock_task_store.get.assert_called_once_with('a87cc6eb-f623-42a5-bd38-2b5cbe9f5553') mock_agent_executor.cancel.assert_not_called() @patch( @@ -227,8 +236,8 @@ async def test_on_message_new_message_success( _mock_builder_build.return_value = RequestContext( request=MagicMock(), - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', task=None, related_tasks=None, ) @@ -241,7 +250,7 @@ async def streaming_coro(): return_value=streaming_coro(), ): request = SendMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams(message=Message(**MESSAGE_PAYLOAD)), ) response = await handler.on_message_send(request) @@ -271,7 +280,7 @@ async def streaming_coro(): return_value=streaming_coro(), ): request = SendMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams( message=Message( **MESSAGE_PAYLOAD, @@ -305,7 +314,7 @@ async def streaming_coro(): return_value=streaming_coro(), ): request = SendMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams( message=Message( **MESSAGE_PAYLOAD, @@ -334,8 +343,8 @@ async def test_on_message_stream_new_message_success( handler = JSONRPCHandler(self.mock_agent_card, request_handler) _mock_builder_build.return_value = RequestContext( request=MagicMock(), - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', task=None, related_tasks=None, ) @@ -343,15 +352,16 @@ async def test_on_message_stream_new_message_success( events: list[Any] = [ Task(**MINIMAL_TASK), TaskArtifactUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', artifact=Artifact( - artifact_id='11', parts=[Part(TextPart(text='text'))] + artifact_id='d2323590-71c6-4a4b-8d53-b3f92fe8d1c7', + parts=[Part(TextPart(text='text'))], ), ), TaskStatusUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', status=TaskStatus(state=TaskState.completed), final=True, ), @@ -368,7 +378,7 @@ async def streaming_coro(): mock_task_store.get.return_value = None mock_agent_executor.execute.return_value = None request = SendStreamingMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams(message=Message(**MESSAGE_PAYLOAD)), ) response = handler.on_message_send_stream(request) @@ -400,15 +410,16 @@ async def test_on_message_stream_new_message_existing_task_success( events: list[Any] = [ mock_task, TaskArtifactUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', artifact=Artifact( - artifact_id='11', parts=[Part(TextPart(text='text'))] + artifact_id='d2323590-71c6-4a4b-8d53-b3f92fe8d1c7', + parts=[Part(TextPart(text='text'))], ), ), TaskStatusUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', status=TaskStatus(state=TaskState.working), final=True, ), @@ -425,7 +436,7 @@ async def streaming_coro(): mock_task_store.get.return_value = mock_task mock_agent_executor.execute.return_value = None request = SendStreamingMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams( message=Message( **MESSAGE_PAYLOAD, @@ -466,7 +477,7 @@ async def test_set_push_notification_success(self) -> None: ), ) request = SetTaskPushNotificationConfigRequest( - id='1', params=task_push_config + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=task_push_config ) response: SetTaskPushNotificationConfigResponse = ( await handler.set_push_notification_config(request) @@ -501,13 +512,14 @@ async def test_get_push_notification_success(self) -> None: ), ) request = SetTaskPushNotificationConfigRequest( - id='1', params=task_push_config + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=task_push_config ) await handler.set_push_notification_config(request) get_request: GetTaskPushNotificationConfigRequest = ( GetTaskPushNotificationConfigRequest( - id='1', params=TaskIdParams(id=mock_task.id) + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', + params=TaskIdParams(id=mock_task.id), ) ) get_response: GetTaskPushNotificationConfigResponse = ( @@ -542,8 +554,8 @@ async def test_on_message_stream_new_message_send_push_notification_success( ) _mock_builder_build.return_value = RequestContext( request=MagicMock(), - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', task=None, related_tasks=None, ) @@ -552,15 +564,16 @@ async def test_on_message_stream_new_message_send_push_notification_success( events: list[Any] = [ Task(**MINIMAL_TASK), TaskArtifactUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', artifact=Artifact( - artifact_id='11', parts=[Part(TextPart(text='text'))] + artifact_id='d2323590-71c6-4a4b-8d53-b3f92fe8d1c7', + parts=[Part(TextPart(text='text'))], ), ), TaskStatusUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', status=TaskStatus(state=TaskState.completed), final=True, ), @@ -578,7 +591,7 @@ async def streaming_coro(): mock_agent_executor.execute.return_value = None mock_httpx_client.post.return_value = httpx.Response(200) request = SendStreamingMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams(message=Message(**MESSAGE_PAYLOAD)), ) request.params.configuration = MessageSendConfiguration( @@ -597,8 +610,8 @@ async def streaming_coro(): call( 'http://example.com', json={ - 'contextId': 'session-xyz', - 'id': 'task_123', + 'contextId': '598c0e6f-72c2-48fc-803a-15d693622c6f', + 'id': '43305029-d2b0-4494-a61b-1c7980bf259d', 'kind': 'task', 'status': {'state': 'submitted'}, }, @@ -609,7 +622,7 @@ async def streaming_coro(): json={ 'artifacts': [ { - 'artifactId': '11', + 'artifactId': 'd2323590-71c6-4a4b-8d53-b3f92fe8d1c7', 'parts': [ { 'kind': 'text', @@ -618,8 +631,8 @@ async def streaming_coro(): ], } ], - 'contextId': 'session-xyz', - 'id': 'task_123', + 'contextId': '598c0e6f-72c2-48fc-803a-15d693622c6f', + 'id': '43305029-d2b0-4494-a61b-1c7980bf259d', 'kind': 'task', 'status': {'state': 'submitted'}, }, @@ -630,7 +643,7 @@ async def streaming_coro(): json={ 'artifacts': [ { - 'artifactId': '11', + 'artifactId': 'd2323590-71c6-4a4b-8d53-b3f92fe8d1c7', 'parts': [ { 'kind': 'text', @@ -639,8 +652,8 @@ async def streaming_coro(): ], } ], - 'contextId': 'session-xyz', - 'id': 'task_123', + 'contextId': '598c0e6f-72c2-48fc-803a-15d693622c6f', + 'id': '43305029-d2b0-4494-a61b-1c7980bf259d', 'kind': 'task', 'status': {'state': 'completed'}, }, @@ -663,15 +676,16 @@ async def test_on_resubscribe_existing_task_success( mock_task = Task(**MINIMAL_TASK, history=[]) events: list[Any] = [ TaskArtifactUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', artifact=Artifact( - artifact_id='11', parts=[Part(TextPart(text='text'))] + artifact_id='d2323590-71c6-4a4b-8d53-b3f92fe8d1c7', + parts=[Part(TextPart(text='text'))], ), ), TaskStatusUpdateEvent( - task_id='task_123', - context_id='session-xyz', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', status=TaskStatus(state=TaskState.completed), final=True, ), @@ -688,7 +702,8 @@ async def streaming_coro(): mock_task_store.get.return_value = mock_task mock_queue_manager.tap.return_value = EventQueue() request = TaskResubscriptionRequest( - id='1', params=TaskIdParams(id=mock_task.id) + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', + params=TaskIdParams(id=mock_task.id), ) response = handler.on_resubscribe_to_task(request) assert isinstance(response, AsyncGenerator) @@ -707,7 +722,8 @@ async def test_on_resubscribe_no_existing_task_error(self) -> None: handler = JSONRPCHandler(self.mock_agent_card, request_handler) mock_task_store.get.return_value = None request = TaskResubscriptionRequest( - id='1', params=TaskIdParams(id='nonexistent_id') + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', + params=TaskIdParams(id='a87cc6eb-f623-42a5-bd38-2b5cbe9f5553'), ) response = handler.on_resubscribe_to_task(request) assert isinstance(response, AsyncGenerator) @@ -734,7 +750,7 @@ async def test_streaming_not_supported_error( # Act & Assert request = SendStreamingMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams(message=Message(**MESSAGE_PAYLOAD)), ) @@ -764,13 +780,13 @@ async def test_push_notifications_not_supported_error(self) -> None: # Act & Assert task_push_config = TaskPushNotificationConfig( - task_id='task_123', + task_id='43305029-d2b0-4494-a61b-1c7980bf259d', push_notification_config=PushNotificationConfig( url='http://example.com' ), ) request = SetTaskPushNotificationConfigRequest( - id='1', params=task_push_config + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=task_push_config ) # Should raise ServerError about push notifications not supported @@ -801,7 +817,8 @@ async def test_on_get_push_notification_no_push_config_store(self) -> None: # Act get_request = GetTaskPushNotificationConfigRequest( - id='1', params=TaskIdParams(id=mock_task.id) + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', + params=TaskIdParams(id=mock_task.id), ) response = await handler.get_push_notification_config(get_request) @@ -834,7 +851,7 @@ async def test_on_set_push_notification_no_push_config_store(self) -> None: ), ) request = SetTaskPushNotificationConfigRequest( - id='1', params=task_push_config + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=task_push_config ) response = await handler.set_push_notification_config(request) @@ -862,7 +879,7 @@ async def raise_server_error(*args, **kwargs) -> NoReturn: ): # Act request = SendMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams(message=Message(**MESSAGE_PAYLOAD)), ) response = await handler.on_message_send(request) @@ -895,7 +912,7 @@ async def raise_server_error(*args, **kwargs): ): # Act request = SendStreamingMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams(message=Message(**MESSAGE_PAYLOAD)), ) @@ -963,7 +980,7 @@ async def consume_raises_error(*args, **kwargs) -> NoReturn: ): # Act request = SendMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams( message=Message( **MESSAGE_PAYLOAD, @@ -998,7 +1015,7 @@ async def streaming_coro(): return_value=streaming_coro(), ): request = SendMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams(message=Message(**MESSAGE_PAYLOAD)), ) response = await handler.on_message_send(request) @@ -1028,7 +1045,7 @@ async def streaming_coro(): mock_task_store.get.return_value = None mock_agent_executor.execute.return_value = None request = SendStreamingMessageRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=MessageSendParams(message=Message(**MESSAGE_PAYLOAD)), ) response = handler.on_message_send_stream(request) @@ -1054,7 +1071,7 @@ async def test_on_get_push_notification(self) -> None: task_push_config = TaskPushNotificationConfig( task_id=mock_task.id, push_notification_config=PushNotificationConfig( - id='config1', url='http://example.com' + id='2fbdf017-d3d0-498f-9135-ebf8d2ae8492', url='http://example.com' ), ) request_handler.on_get_task_push_notification_config.return_value = ( @@ -1066,9 +1083,9 @@ async def test_on_get_push_notification(self) -> None: ) handler = JSONRPCHandler(self.mock_agent_card, request_handler) list_request = GetTaskPushNotificationConfigRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=GetTaskPushNotificationConfigParams( - id=mock_task.id, push_notification_config_id='config1' + id=mock_task.id, push_notification_config_id='2fbdf017-d3d0-498f-9135-ebf8d2ae8492' ), ) response = await handler.get_push_notification_config(list_request) @@ -1102,7 +1119,8 @@ async def test_on_list_push_notification(self) -> None: ) handler = JSONRPCHandler(self.mock_agent_card, request_handler) list_request = ListTaskPushNotificationConfigRequest( - id='1', params=ListTaskPushNotificationConfigParams(id=mock_task.id) + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', + params=ListTaskPushNotificationConfigParams(id=mock_task.id), ) response = await handler.list_push_notification_config(list_request) # Assert @@ -1136,7 +1154,8 @@ async def test_on_list_push_notification_error(self) -> None: ) handler = JSONRPCHandler(self.mock_agent_card, request_handler) list_request = ListTaskPushNotificationConfigRequest( - id='1', params=ListTaskPushNotificationConfigParams(id=mock_task.id) + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', + params=ListTaskPushNotificationConfigParams(id=mock_task.id), ) response = await handler.list_push_notification_config(list_request) # Assert @@ -1157,9 +1176,10 @@ async def test_on_delete_push_notification(self) -> None: ) handler = JSONRPCHandler(self.mock_agent_card, request_handler) delete_request = DeleteTaskPushNotificationConfigRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=DeleteTaskPushNotificationConfigParams( - id='task1', push_notification_config_id='config1' + id='13d5b8a8-62d7-4490-98c8-d3951b42702a', + push_notification_config_id='2fbdf017-d3d0-498f-9135-ebf8d2ae8492', ), ) response = await handler.delete_push_notification_config(delete_request) @@ -1184,9 +1204,10 @@ async def test_on_delete_push_notification_error(self) -> None: ) handler = JSONRPCHandler(self.mock_agent_card, request_handler) delete_request = DeleteTaskPushNotificationConfigRequest( - id='1', + id='8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', params=DeleteTaskPushNotificationConfigParams( - id='task1', push_notification_config_id='config1' + id='13d5b8a8-62d7-4490-98c8-d3951b42702a', + push_notification_config_id='2fbdf017-d3d0-498f-9135-ebf8d2ae8492', ), ) response = await handler.delete_push_notification_config(delete_request) diff --git a/tests/server/request_handlers/test_response_helpers.py b/tests/server/request_handlers/test_response_helpers.py index 96e79e51..54902a1b 100644 --- a/tests/server/request_handlers/test_response_helpers.py +++ b/tests/server/request_handlers/test_response_helpers.py @@ -93,7 +93,11 @@ def test_build_error_response_with_request_id_none(self): self.assertIsInstance(response_wrapper.root, JSONRPCErrorResponse) self.assertIsNone(response_wrapper.root.id) - def _create_sample_task(self, task_id='task123', context_id='ctx456'): + def _create_sample_task( + self, + task_id='eede470e-ae8f-4910-ba05-085d45dc43c6', + context_id='a2e44180-c4f5-4bdb-9c57-5151b145a0cd', + ): return Task( id=task_id, context_id=context_id, diff --git a/tests/server/tasks/test_database_push_notification_config_store.py b/tests/server/tasks/test_database_push_notification_config_store.py index 0c3bd468..6d94f85e 100644 --- a/tests/server/tasks/test_database_push_notification_config_store.py +++ b/tests/server/tasks/test_database_push_notification_config_store.py @@ -84,8 +84,8 @@ state=TaskState.submitted, timestamp='2023-01-01T00:00:00Z' ) MINIMAL_TASK_OBJ = Task( - id='task-abc', - context_id='session-xyz', + id='ea719c56-e398-425e-b02c-49fd77b7c156', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', status=task_status_submitted, kind='task', metadata={'test_key': 'test_value'}, @@ -170,8 +170,8 @@ async def test_set_and_get_info_single_config( db_store_parameterized: DatabasePushNotificationConfigStore, ): """Test setting and retrieving a single configuration.""" - task_id = 'task-1' - config = PushNotificationConfig(id='config-1', url='http://example.com') + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' + config = PushNotificationConfig(id='36b8b0c3-e284-4cf0-a592-0159f5b8d3bb', url='http://example.com') await db_store_parameterized.set_info(task_id, config) retrieved_configs = await db_store_parameterized.get_info(task_id) @@ -186,9 +186,9 @@ async def test_set_and_get_info_multiple_configs( ): """Test setting and retrieving multiple configurations for a single task.""" - task_id = 'task-1' - config1 = PushNotificationConfig(id='config-1', url='http://example.com/1') - config2 = PushNotificationConfig(id='config-2', url='http://example.com/2') + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' + config1 = PushNotificationConfig(id='36b8b0c3-e284-4cf0-a592-0159f5b8d3bb', url='http://example.com/1') + config2 = PushNotificationConfig(id='b7dfa41e-04b0-4c6a-86ad-f6422487f098', url='http://example.com/2') await db_store_parameterized.set_info(task_id, config1) await db_store_parameterized.set_info(task_id, config2) @@ -204,8 +204,8 @@ async def test_set_info_updates_existing_config( db_store_parameterized: DatabasePushNotificationConfigStore, ): """Test that setting an existing config ID updates the record.""" - task_id = 'task-1' - config_id = 'config-1' + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' + config_id = '36b8b0c3-e284-4cf0-a592-0159f5b8d3bb' initial_config = PushNotificationConfig( id=config_id, url='http://initial.url' ) @@ -226,7 +226,7 @@ async def test_set_info_defaults_config_id_to_task_id( db_store_parameterized: DatabasePushNotificationConfigStore, ): """Test that config.id defaults to task_id if not provided.""" - task_id = 'task-1' + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' config = PushNotificationConfig(url='http://example.com') # id is None await db_store_parameterized.set_info(task_id, config) @@ -252,14 +252,14 @@ async def test_delete_info_specific_config( db_store_parameterized: DatabasePushNotificationConfigStore, ): """Test deleting a single, specific configuration.""" - task_id = 'task-1' - config1 = PushNotificationConfig(id='config-1', url='http://a.com') - config2 = PushNotificationConfig(id='config-2', url='http://b.com') + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' + config1 = PushNotificationConfig(id='36b8b0c3-e284-4cf0-a592-0159f5b8d3bb', url='http://a.com') + config2 = PushNotificationConfig(id='b7dfa41e-04b0-4c6a-86ad-f6422487f098', url='http://b.com') await db_store_parameterized.set_info(task_id, config1) await db_store_parameterized.set_info(task_id, config2) - await db_store_parameterized.delete_info(task_id, 'config-1') + await db_store_parameterized.delete_info(task_id, '36b8b0c3-e284-4cf0-a592-0159f5b8d3bb') retrieved_configs = await db_store_parameterized.get_info(task_id) assert len(retrieved_configs) == 1 @@ -272,9 +272,9 @@ async def test_delete_info_all_for_task( ): """Test deleting all configurations for a task when config_id is None.""" - task_id = 'task-1' - config1 = PushNotificationConfig(id='config-1', url='http://a.com') - config2 = PushNotificationConfig(id='config-2', url='http://b.com') + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' + config1 = PushNotificationConfig(id='36b8b0c3-e284-4cf0-a592-0159f5b8d3bb', url='http://a.com') + config2 = PushNotificationConfig(id='b7dfa41e-04b0-4c6a-86ad-f6422487f098', url='http://b.com') await db_store_parameterized.set_info(task_id, config1) await db_store_parameterized.set_info(task_id, config2) @@ -291,7 +291,9 @@ async def test_delete_info_not_found( ): """Test that deleting a non-existent config does not raise an error.""" # Should not raise - await db_store_parameterized.delete_info('task-1', 'non-existent-config') + await db_store_parameterized.delete_info( + '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7', 'non-existent-config' + ) @pytest.mark.asyncio @@ -301,7 +303,7 @@ async def test_data_is_encrypted_in_db( """Verify that the data stored in the database is actually encrypted.""" task_id = 'encrypted-task' config = PushNotificationConfig( - id='config-1', url='http://secret.url', token='secret-token' + id='36b8b0c3-e284-4cf0-a592-0159f5b8d3bb', url='http://secret.url', token='secret-token' ) plain_json = config.model_dump_json() @@ -334,7 +336,7 @@ async def test_decryption_error_with_wrong_key( # 1. Store with one key task_id = 'wrong-key-task' - config = PushNotificationConfig(id='config-1', url='http://secret.url') + config = PushNotificationConfig(id='36b8b0c3-e284-4cf0-a592-0159f5b8d3bb', url='http://secret.url') await db_store_parameterized.set_info(task_id, config) # 2. Try to read with a different key @@ -353,7 +355,7 @@ async def test_decryption_error_with_wrong_key( ) async with async_session() as session: db_model = await session.get( - PushNotificationConfigModel, (task_id, 'config-1') + PushNotificationConfigModel, (task_id, '36b8b0c3-e284-4cf0-a592-0159f5b8d3bb') ) with pytest.raises(ValueError): @@ -368,7 +370,7 @@ async def test_decryption_error_with_no_key( # 1. Store with one key task_id = 'wrong-key-task' - config = PushNotificationConfig(id='config-1', url='http://secret.url') + config = PushNotificationConfig(id='36b8b0c3-e284-4cf0-a592-0159f5b8d3bb', url='http://secret.url') await db_store_parameterized.set_info(task_id, config) # 2. Try to read with no key set @@ -384,7 +386,7 @@ async def test_decryption_error_with_no_key( ) async with async_session() as session: db_model = await session.get( - PushNotificationConfigModel, (task_id, 'config-1') + PushNotificationConfigModel, (task_id, '36b8b0c3-e284-4cf0-a592-0159f5b8d3bb') ) with pytest.raises(ValueError): @@ -409,7 +411,7 @@ async def test_custom_table_name( ) task_id = 'custom-table-task' - config = PushNotificationConfig(id='config-1', url='http://custom.url') + config = PushNotificationConfig(id='36b8b0c3-e284-4cf0-a592-0159f5b8d3bb', url='http://custom.url') # This will create the table on first use await custom_store.set_info(task_id, config) @@ -453,9 +455,9 @@ async def test_set_and_get_info_multiple_configs_no_key( ) await store.initialize() - task_id = 'task-1' - config1 = PushNotificationConfig(id='config-1', url='http://example.com/1') - config2 = PushNotificationConfig(id='config-2', url='http://example.com/2') + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' + config1 = PushNotificationConfig(id='36b8b0c3-e284-4cf0-a592-0159f5b8d3bb', url='http://example.com/1') + config2 = PushNotificationConfig(id='b7dfa41e-04b0-4c6a-86ad-f6422487f098', url='http://example.com/2') await store.set_info(task_id, config1) await store.set_info(task_id, config2) @@ -479,8 +481,8 @@ async def test_data_is_not_encrypted_in_db_if_no_key_is_set( ) await store.initialize() - task_id = 'task-1' - config = PushNotificationConfig(id='config-1', url='http://example.com/1') + task_id = '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' + config = PushNotificationConfig(id='36b8b0c3-e284-4cf0-a592-0159f5b8d3bb', url='http://example.com/1') plain_json = config.model_dump_json() await store.set_info(task_id, config) @@ -513,7 +515,7 @@ async def test_decryption_fallback_for_unencrypted_data( await unencrypted_store.initialize() task_id = 'mixed-encryption-task' - config = PushNotificationConfig(id='config-1', url='http://plain.url') + config = PushNotificationConfig(id='36b8b0c3-e284-4cf0-a592-0159f5b8d3bb', url='http://plain.url') await unencrypted_store.set_info(task_id, config) # 2. Try to read with the encryption-enabled store from the fixture @@ -531,7 +533,7 @@ async def test_parsing_error_after_successful_decryption( """Test that a parsing error after successful decryption is handled.""" task_id = 'corrupted-data-task' - config_id = 'config-1' + config_id = '36b8b0c3-e284-4cf0-a592-0159f5b8d3bb' # 1. Encrypt data that is NOT valid JSON fernet = Fernet(Fernet.generate_key()) diff --git a/tests/server/tasks/test_database_task_store.py b/tests/server/tasks/test_database_task_store.py index 87069be4..22075ee7 100644 --- a/tests/server/tasks/test_database_task_store.py +++ b/tests/server/tasks/test_database_task_store.py @@ -75,8 +75,8 @@ state=TaskState.submitted, timestamp='2023-01-01T00:00:00Z' ) MINIMAL_TASK_OBJ = Task( - id='task-abc', - context_id='session-xyz', + id='ea719c56-e398-425e-b02c-49fd77b7c156', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', status=task_status_submitted, kind='task', metadata={'test_key': 'test_value'}, @@ -220,13 +220,13 @@ async def test_save_and_get_detailed_task( metadata={'key1': 'value1', 'key2': 123}, artifacts=[ Artifact( - artifact_id='artifact-1', + artifact_id='c88484c8-b8fb-4c97-bd6a-6c0a07276bf0', parts=[Part(root=TextPart(text='hello'))], ) ], history=[ Message( - message_id='msg-1', + message_id='15957e91-63e6-40ac-8205-1d1ffb09a5b2', role=Role.user, parts=[Part(root=TextPart(text='user input'))], ) @@ -263,7 +263,7 @@ async def test_update_task(db_store_parameterized: DatabaseTaskStore) -> None: task_id = f'update-test-task-{db_store_parameterized.engine.url.drivername}' original_task = Task( id=task_id, - context_id='session-update', + context_id='8b499585-e27a-4d74-a368-acffcf802688', status=TaskStatus( state=TaskState.submitted, timestamp='2023-01-02T10:00:00Z' ), @@ -309,15 +309,15 @@ async def test_metadata_field_mapping( """ # Test 1: Task with no metadata (None) task_no_metadata = Task( - id='task-metadata-test-1', - context_id='session-meta-1', + id='24bcbd71-4f67-4863-9aa7-5d9d6c7e9505', + context_id='ef3ce439-ae23-45e3-9c2d-0b01e69fd857', status=TaskStatus(state=TaskState.submitted), kind='task', metadata=None, ) await db_store_parameterized.save(task_no_metadata) retrieved_no_metadata = await db_store_parameterized.get( - 'task-metadata-test-1' + '24bcbd71-4f67-4863-9aa7-5d9d6c7e9505' ) assert retrieved_no_metadata is not None assert retrieved_no_metadata.metadata is None @@ -391,7 +391,7 @@ async def test_metadata_field_mapping( assert retrieved_none.metadata is None # Cleanup - await db_store_parameterized.delete('task-metadata-test-1') + await db_store_parameterized.delete('24bcbd71-4f67-4863-9aa7-5d9d6c7e9505') await db_store_parameterized.delete('task-metadata-test-2') await db_store_parameterized.delete('task-metadata-test-3') await db_store_parameterized.delete('task-metadata-test-4') diff --git a/tests/server/tasks/test_inmemory_push_notifications.py b/tests/server/tasks/test_inmemory_push_notifications.py index aef850c9..e117d2e5 100644 --- a/tests/server/tasks/test_inmemory_push_notifications.py +++ b/tests/server/tasks/test_inmemory_push_notifications.py @@ -17,16 +17,19 @@ # logging.disable(logging.CRITICAL) -def create_sample_task(task_id='task123', status_state=TaskState.completed): +def create_sample_task( + task_id='eede470e-ae8f-4910-ba05-085d45dc43c6', + status_state=TaskState.completed, +): return Task( id=task_id, - context_id='ctx456', + context_id='a2e44180-c4f5-4bdb-9c57-5151b145a0cd', status=TaskStatus(state=status_state), ) def create_sample_push_config( - url='http://example.com/callback', config_id='cfg1', token=None + url='http://example.com/callback', config_id='e40b9db6-fdb2-4712-8d56-2ff86de9038f', token=None ): return PushNotificationConfig(id=config_id, url=url, token=token) @@ -56,7 +59,7 @@ async def test_set_info_adds_new_config(self): async def test_set_info_appends_to_existing_config(self): task_id = 'task_update' initial_config = create_sample_push_config( - url='http://initial.url/callback', config_id='cfg_initial' + url='http://initial.url/callback', config_id='0aeee4de-70ea-4924-8fd6-486e171c49e6' ) await self.config_store.set_info(task_id, initial_config) @@ -76,7 +79,7 @@ async def test_set_info_appends_to_existing_config(self): ) async def test_set_info_without_config_id(self): - task_id = 'task1' + task_id = '13d5b8a8-62d7-4490-98c8-d3951b42702a' initial_config = PushNotificationConfig( url='http://initial.url/callback' ) @@ -134,7 +137,7 @@ async def test_delete_info_non_existent_config(self): ) # Should still not be there async def test_send_notification_success(self): - task_id = 'task_send_success' + task_id = '54a31351-1de9-4dd1-8e57-64a1ff99b2b1' task_data = create_sample_task(task_id=task_id) config = create_sample_push_config(url='http://notify.me/here') await self.config_store.set_info(task_id, config) @@ -159,7 +162,7 @@ async def test_send_notification_success(self): mock_response.raise_for_status.assert_called_once() async def test_send_notification_with_token_success(self): - task_id = 'task_send_success' + task_id = '54a31351-1de9-4dd1-8e57-64a1ff99b2b1' task_data = create_sample_task(task_id=task_id) config = create_sample_push_config( url='http://notify.me/here', token='unique_token' @@ -190,7 +193,7 @@ async def test_send_notification_with_token_success(self): mock_response.raise_for_status.assert_called_once() async def test_send_notification_no_config(self): - task_id = 'task_send_no_config' + task_id = '17bf28b3-2381-472c-9fab-7d1962f630ab' task_data = create_sample_task(task_id=task_id) await self.notifier.send_notification(task_data) # Pass only task_data @@ -201,7 +204,7 @@ async def test_send_notification_no_config(self): async def test_send_notification_http_status_error( self, mock_logger: MagicMock ): - task_id = 'task_send_http_err' + task_id = '65dad88d-500a-4629-a6ff-de7cc8d535ca' task_data = create_sample_task(task_id=task_id) config = create_sample_push_config(url='http://notify.me/http_error') await self.config_store.set_info(task_id, config) @@ -231,7 +234,7 @@ async def test_send_notification_http_status_error( async def test_send_notification_request_error( self, mock_logger: MagicMock ): - task_id = 'task_send_req_err' + task_id = '819edfe4-88ad-4f80-bba7-ec9409d745d6' task_data = create_sample_task(task_id=task_id) config = create_sample_push_config(url='http://notify.me/req_error') await self.config_store.set_info(task_id, config) @@ -250,7 +253,7 @@ async def test_send_notification_request_error( @patch('a2a.server.tasks.base_push_notification_sender.logger') async def test_send_notification_with_auth(self, mock_logger: MagicMock): - task_id = 'task_send_auth' + task_id = '58c25c5a-d8b1-443c-aab7-45b5743166b1' task_data = create_sample_task(task_id=task_id) auth_info = ('user', 'pass') config = create_sample_push_config(url='http://notify.me/auth') diff --git a/tests/server/tasks/test_inmemory_task_store.py b/tests/server/tasks/test_inmemory_task_store.py index c41e3559..1adc82f2 100644 --- a/tests/server/tasks/test_inmemory_task_store.py +++ b/tests/server/tasks/test_inmemory_task_store.py @@ -7,8 +7,8 @@ MINIMAL_TASK: dict[str, Any] = { - 'id': 'task-abc', - 'context_id': 'session-xyz', + 'id': 'ea719c56-e398-425e-b02c-49fd77b7c156', + 'context_id': '598c0e6f-72c2-48fc-803a-15d693622c6f', 'status': {'state': 'submitted'}, 'kind': 'task', } diff --git a/tests/server/tasks/test_push_notification_sender.py b/tests/server/tasks/test_push_notification_sender.py index 6cd4521d..d58bb278 100644 --- a/tests/server/tasks/test_push_notification_sender.py +++ b/tests/server/tasks/test_push_notification_sender.py @@ -15,16 +15,19 @@ ) -def create_sample_task(task_id='task123', status_state=TaskState.completed): +def create_sample_task( + task_id='eede470e-ae8f-4910-ba05-085d45dc43c6', + status_state=TaskState.completed, +): return Task( id=task_id, - context_id='ctx456', + context_id='a2e44180-c4f5-4bdb-9c57-5151b145a0cd', status=TaskStatus(state=status_state), ) def create_sample_push_config( - url='http://example.com/callback', config_id='cfg1', token=None + url='http://example.com/callback', config_id='e40b9db6-fdb2-4712-8d56-2ff86de9038f', token=None ): return PushNotificationConfig(id=config_id, url=url, token=token) @@ -43,7 +46,7 @@ def test_constructor_stores_client_and_config_store(self): self.assertEqual(self.sender._config_store, self.mock_config_store) async def test_send_notification_success(self): - task_id = 'task_send_success' + task_id = '54a31351-1de9-4dd1-8e57-64a1ff99b2b1' task_data = create_sample_task(task_id=task_id) config = create_sample_push_config(url='http://notify.me/here') self.mock_config_store.get_info.return_value = [config] @@ -65,7 +68,7 @@ async def test_send_notification_success(self): mock_response.raise_for_status.assert_called_once() async def test_send_notification_with_token_success(self): - task_id = 'task_send_success' + task_id = '54a31351-1de9-4dd1-8e57-64a1ff99b2b1' task_data = create_sample_task(task_id=task_id) config = create_sample_push_config( url='http://notify.me/here', token='unique_token' @@ -89,7 +92,7 @@ async def test_send_notification_with_token_success(self): mock_response.raise_for_status.assert_called_once() async def test_send_notification_no_config(self): - task_id = 'task_send_no_config' + task_id = '17bf28b3-2381-472c-9fab-7d1962f630ab' task_data = create_sample_task(task_id=task_id) self.mock_config_store.get_info.return_value = [] @@ -102,7 +105,7 @@ async def test_send_notification_no_config(self): async def test_send_notification_http_status_error( self, mock_logger: MagicMock ): - task_id = 'task_send_http_err' + task_id = '65dad88d-500a-4629-a6ff-de7cc8d535ca' task_data = create_sample_task(task_id=task_id) config = create_sample_push_config(url='http://notify.me/http_error') self.mock_config_store.get_info.return_value = [config] @@ -126,10 +129,10 @@ async def test_send_notification_http_status_error( mock_logger.error.assert_called_once() async def test_send_notification_multiple_configs(self): - task_id = 'task_multiple_configs' + task_id = '816b4b79-1b61-4f11-9a29-edfc32bc5a45' task_data = create_sample_task(task_id=task_id) config1 = create_sample_push_config( - url='http://notify.me/cfg1', config_id='cfg1' + url='http://notify.me/cfg1', config_id='e40b9db6-fdb2-4712-8d56-2ff86de9038f' ) config2 = create_sample_push_config( url='http://notify.me/cfg2', config_id='cfg2' diff --git a/tests/server/tasks/test_result_aggregator.py b/tests/server/tasks/test_result_aggregator.py index da77e693..d6e2e1ab 100644 --- a/tests/server/tasks/test_result_aggregator.py +++ b/tests/server/tasks/test_result_aggregator.py @@ -21,7 +21,9 @@ # Helper to create a simple message def create_sample_message( - content='test message', msg_id='msg1', role=Role.user + content='test message', + msg_id='87c8541d-f773-4825-bbb1-f518727231f2', + role=Role.user, ): return Message( message_id=msg_id, @@ -32,7 +34,9 @@ def create_sample_message( # Helper to create a simple task def create_sample_task( - task_id='task1', status_state=TaskState.submitted, context_id='ctx1' + task_id='7cf554b5-747f-409e-bf50-a3c05fd4c92c', + status_state=TaskState.submitted, + context_id='06cc947f-8946-4bde-b776-165462407e57', ): return Task( id=task_id, @@ -43,7 +47,9 @@ def create_sample_task( # Helper to create a TaskStatusUpdateEvent def create_sample_status_update( - task_id='task1', status_state=TaskState.working, context_id='ctx1' + task_id='13d5b8a8-62d7-4490-98c8-d3951b42702a', + status_state=TaskState.working, + context_id='06cc947f-8946-4bde-b776-165462407e57', ): return TaskStatusUpdateEvent( task_id=task_id, @@ -73,7 +79,7 @@ async def test_current_result_property_with_message_set(self): self.mock_task_manager.get_task.assert_not_called() async def test_current_result_property_with_message_none(self): - expected_task = create_sample_task(task_id='task_from_tm') + expected_task = create_sample_task(task_id='66f752c5-683b-4f67-ab1a-5b2ffdac2c6e') self.mock_task_manager.get_task.return_value = expected_task self.aggregator._message = None @@ -83,7 +89,7 @@ async def test_current_result_property_with_message_none(self): self.mock_task_manager.get_task.assert_called_once() async def test_consume_and_emit(self): - event1 = create_sample_message(content='event one', msg_id='e1') + event1 = create_sample_message(content='event one', msg_id='5c3683f9-78b1-4dbf-963e-f49794656399') event2 = create_sample_task( task_id='task_event', status_state=TaskState.working ) @@ -137,12 +143,12 @@ async def mock_consume_generator(): self.mock_task_manager.get_task.assert_not_called() # Should not be called if message is returned async def test_consume_all_other_event_types(self): - task_event = create_sample_task(task_id='task_other_event') + task_event = create_sample_task(task_id='eb85a5ac-5e75-4d33-ba30-28288e75cbdb') status_update_event = create_sample_status_update( - task_id='task_other_event', status_state=TaskState.completed + task_id='eb85a5ac-5e75-4d33-ba30-28288e75cbdb', status_state=TaskState.completed ) final_task_state = create_sample_task( - task_id='task_other_event', status_state=TaskState.completed + task_id='eb85a5ac-5e75-4d33-ba30-28288e75cbdb', status_state=TaskState.completed ) async def mock_consume_generator(): @@ -163,7 +169,9 @@ async def mock_consume_generator(): self.mock_task_manager.get_task.assert_called_once() async def test_consume_all_empty_stream(self): - empty_task_state = create_sample_task(task_id='empty_stream_task') + empty_task_state = create_sample_task( + task_id='a4237428-57bc-4efb-903f-ed30003e7195' + ) async def mock_consume_generator(): if False: # Will not yield anything @@ -190,7 +198,7 @@ class TestException(Exception): async def raiser_gen(): # Yield a non-Message event first to ensure process is called - yield create_sample_task('task_before_error_consume_all') + yield create_sample_task('06cc947f-8946-4bde-b776-165462407e57') raise TestException('Consumer error') self.mock_event_consumer.consume_all = MagicMock( @@ -208,7 +216,7 @@ async def raiser_gen(): async def test_consume_and_break_on_message(self): sample_message = create_sample_message(content='interrupt message') - event_after = create_sample_task('task_after_msg') + event_after = create_sample_task('f99ba8e7-6f06-400c-b25e-8bc190c078f3') async def mock_consume_generator(): yield sample_message @@ -236,7 +244,7 @@ async def test_consume_and_break_on_auth_required_task_event( self, mock_create_task: MagicMock ): auth_task = create_sample_task( - task_id='auth_task', status_state=TaskState.auth_required + task_id='f3c47dc7-1d37-43bb-8798-81af1a9da143', status_state=TaskState.auth_required ) event_after_auth = create_sample_message('after auth') @@ -288,10 +296,10 @@ async def test_consume_and_break_on_auth_required_status_update_event( self, mock_create_task: MagicMock ): auth_status_update = create_sample_status_update( - task_id='auth_status_task', status_state=TaskState.auth_required + task_id='77ec9032-6220-49f1-b7b4-3cfb135feaad', status_state=TaskState.auth_required ) current_task_state_after_update = create_sample_task( - task_id='auth_status_task', status_state=TaskState.auth_required + task_id='77ec9032-6220-49f1-b7b4-3cfb135feaad', status_state=TaskState.auth_required ) async def mock_consume_generator(): @@ -326,7 +334,7 @@ async def mock_consume_generator(): ) async def test_consume_and_break_completes_normally(self): - event1 = create_sample_message('event one normal', msg_id='n1') + event1 = create_sample_message('event one normal', msg_id='f10a9e68-59c8-4c23-8a2d-3da0a6015f2b') event2 = create_sample_task('normal_task') final_task_state = create_sample_task( 'normal_task', status_state=TaskState.completed @@ -365,7 +373,7 @@ class TestInterruptException(Exception): async def raiser_gen_interrupt(): # Yield a non-Message event first - yield create_sample_task('task_before_error_interrupt') + yield create_sample_task('49b1275c-6cf2-4712-8476-4de12729f7a7') raise TestInterruptException( 'Consumer error during interrupt check' ) @@ -389,7 +397,7 @@ async def test_consume_and_break_non_blocking( self, mock_create_task: MagicMock ): """Test that with blocking=False, the method returns after the first event.""" - first_event = create_sample_task('non_blocking_task') + first_event = create_sample_task('b0e4a702-8618-4bd5-aaec-3355f4ec0e91') event_after = create_sample_message('should be consumed later') async def mock_consume_generator(): @@ -430,7 +438,7 @@ async def test_continue_consuming_processes_remaining_events( # the events *after* the interrupting one are processed by _continue_consuming. auth_event = create_sample_task( - 'task_auth_for_continue', status_state=TaskState.auth_required + '135e2ae0-6fef-48cf-bb4b-9158f59b2910', status_state=TaskState.auth_required ) event_after_auth1 = create_sample_message( 'after auth 1', msg_id='cont1' diff --git a/tests/server/tasks/test_task_manager.py b/tests/server/tasks/test_task_manager.py index 4f243157..07e64e39 100644 --- a/tests/server/tasks/test_task_manager.py +++ b/tests/server/tasks/test_task_manager.py @@ -21,8 +21,8 @@ MINIMAL_TASK: dict[str, Any] = { - 'id': 'task-abc', - 'context_id': 'session-xyz', + 'id': 'ea719c56-e398-425e-b02c-49fd77b7c156', + 'context_id': '598c0e6f-72c2-48fc-803a-15d693622c6f', 'status': {'state': 'submitted'}, 'kind': 'task', } @@ -104,7 +104,7 @@ async def test_save_task_event_status_update( message=Message( role=Role.agent, parts=[Part(TextPart(text='content'))], - message_id='message-id', + message_id='c222a603-645e-4c37-8f7b-e49f3ea80e9e', ), ) event = TaskStatusUpdateEvent( @@ -127,7 +127,7 @@ async def test_save_task_event_artifact_update( initial_task = Task(**MINIMAL_TASK) mock_task_store.get.return_value = initial_task new_artifact = Artifact( - artifact_id='artifact-id', + artifact_id='a5d46edb-3e5e-4fab-80e8-48ebccf8831d', name='artifact1', parts=[Part(TextPart(text='content'))], ) @@ -195,25 +195,25 @@ async def test_ensure_task_nonexistent( initial_message=None, ) event = TaskStatusUpdateEvent( - task_id='new-task', - context_id='some-context', + task_id='41559ca6-d043-4d39-9bd1-74e4917d3357', + context_id='06a9d439-f7f3-44ba-be8b-0dcf3df61095', status=TaskStatus(state=TaskState.submitted), final=False, ) new_task = await task_manager_without_id.ensure_task(event) - assert new_task.id == 'new-task' - assert new_task.context_id == 'some-context' + assert new_task.id == '41559ca6-d043-4d39-9bd1-74e4917d3357' + assert new_task.context_id == '06a9d439-f7f3-44ba-be8b-0dcf3df61095' assert new_task.status.state == TaskState.submitted mock_task_store.save.assert_called_once_with(new_task) - assert task_manager_without_id.task_id == 'new-task' - assert task_manager_without_id.context_id == 'some-context' + assert task_manager_without_id.task_id == '41559ca6-d043-4d39-9bd1-74e4917d3357' + assert task_manager_without_id.context_id == '06a9d439-f7f3-44ba-be8b-0dcf3df61095' def test_init_task_obj(task_manager: TaskManager) -> None: """Test initializing a new task object.""" - new_task = task_manager._init_task_obj('new-task', 'new-context') # type: ignore - assert new_task.id == 'new-task' - assert new_task.context_id == 'new-context' + new_task = task_manager._init_task_obj('41559ca6-d043-4d39-9bd1-74e4917d3357', '7a5cf082-168d-4d92-be5a-a1d9783b9596') # type: ignore + assert new_task.id == '41559ca6-d043-4d39-9bd1-74e4917d3357' + assert new_task.context_id == '7a5cf082-168d-4d92-be5a-a1d9783b9596' assert new_task.status.state == TaskState.submitted assert new_task.history == [] @@ -233,10 +233,10 @@ async def test_save_task_event_mismatched_id_raises_error( task_manager: TaskManager, ) -> None: """Test that save_task_event raises ServerError on task ID mismatch.""" - # The task_manager is initialized with 'task-abc' + # The task_manager is initialized with 'ea719c56-e398-425e-b02c-49fd77b7c156' mismatched_task = Task( - id='wrong-id', - context_id='session-xyz', + id='7e89931a-dd88-4829-9465-b0c165d535b8', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', status=TaskStatus(state=TaskState.submitted), ) @@ -257,16 +257,16 @@ async def test_save_task_event_new_task_no_task_id( initial_message=None, ) task_data: dict[str, Any] = { - 'id': 'new-task-id', - 'context_id': 'some-context', + 'id': '6673d15e-0a70-404f-8d8d-9904ffbae0a4', + 'context_id': '06a9d439-f7f3-44ba-be8b-0dcf3df61095', 'status': {'state': 'working'}, 'kind': 'task', } task = Task(**task_data) await task_manager_without_id.save_task_event(task) mock_task_store.save.assert_called_once_with(task) - assert task_manager_without_id.task_id == 'new-task-id' - assert task_manager_without_id.context_id == 'some-context' + assert task_manager_without_id.task_id == '6673d15e-0a70-404f-8d8d-9904ffbae0a4' + assert task_manager_without_id.context_id == '06a9d439-f7f3-44ba-be8b-0dcf3df61095' # initial submit should be updated to working assert task.status.state == TaskState.working @@ -278,7 +278,7 @@ async def test_get_task_no_task_id( """Test getting a task when task_id is not set in TaskManager.""" task_manager_without_id = TaskManager( task_id=None, - context_id='some-context', + context_id='06a9d439-f7f3-44ba-be8b-0dcf3df61095', task_store=mock_task_store, initial_message=None, ) @@ -300,8 +300,8 @@ async def test_save_task_event_no_task_existing( ) mock_task_store.get.return_value = None event = TaskStatusUpdateEvent( - task_id='event-task-id', - context_id='some-context', + task_id='880d81ba-289c-49ca-88af-e63ff99f3f21', + context_id='06a9d439-f7f3-44ba-be8b-0dcf3df61095', status=TaskStatus(state=TaskState.completed), final=True, ) @@ -310,8 +310,8 @@ async def test_save_task_event_no_task_existing( call_args = mock_task_store.save.call_args assert call_args is not None saved_task = call_args[0][0] - assert saved_task.id == 'event-task-id' - assert saved_task.context_id == 'some-context' + assert str(saved_task.id) == '880d81ba-289c-49ca-88af-e63ff99f3f21' + assert str(saved_task.context_id) == '06a9d439-f7f3-44ba-be8b-0dcf3df61095' assert saved_task.status.state == TaskState.completed - assert task_manager_without_id.task_id == 'event-task-id' - assert task_manager_without_id.context_id == 'some-context' + assert str(task_manager_without_id.task_id) == '880d81ba-289c-49ca-88af-e63ff99f3f21' + assert str(task_manager_without_id.context_id) == '06a9d439-f7f3-44ba-be8b-0dcf3df61095' diff --git a/tests/server/tasks/test_task_updater.py b/tests/server/tasks/test_task_updater.py index 844470cb..8e4ad705 100644 --- a/tests/server/tasks/test_task_updater.py +++ b/tests/server/tasks/test_task_updater.py @@ -29,8 +29,8 @@ def task_updater(event_queue): """Create a TaskUpdater instance for testing.""" return TaskUpdater( event_queue=event_queue, - task_id='test-task-id', - context_id='test-context-id', + task_id='f05970c0-6215-4742-94f7-94cb27d962b2', + context_id='821a03d5-786b-47b0-bc2e-a248b73bfe9e', ) @@ -39,9 +39,9 @@ def sample_message(): """Create a sample message for testing.""" return Message( role=Role.agent, - task_id='test-task-id', - context_id='test-context-id', - message_id='test-message-id', + task_id='f05970c0-6215-4742-94f7-94cb27d962b2', + context_id='821a03d5-786b-47b0-bc2e-a248b73bfe9e', + message_id='243fd82e-36c6-4e09-8835-56665053bfd4', parts=[Part(root=TextPart(text='Test message'))], ) @@ -56,13 +56,13 @@ def test_init(event_queue): """Test that TaskUpdater initializes correctly.""" task_updater = TaskUpdater( event_queue=event_queue, - task_id='test-task-id', - context_id='test-context-id', + task_id='f05970c0-6215-4742-94f7-94cb27d962b2', + context_id='821a03d5-786b-47b0-bc2e-a248b73bfe9e', ) assert task_updater.event_queue == event_queue - assert task_updater.task_id == 'test-task-id' - assert task_updater.context_id == 'test-context-id' + assert task_updater.task_id == 'f05970c0-6215-4742-94f7-94cb27d962b2' + assert task_updater.context_id == '821a03d5-786b-47b0-bc2e-a248b73bfe9e' @pytest.mark.asyncio @@ -74,8 +74,8 @@ async def test_update_status_without_message(task_updater, event_queue): event = event_queue.enqueue_event.call_args[0][0] assert isinstance(event, TaskStatusUpdateEvent) - assert event.task_id == 'test-task-id' - assert event.context_id == 'test-context-id' + assert event.task_id == 'f05970c0-6215-4742-94f7-94cb27d962b2' + assert event.context_id == '821a03d5-786b-47b0-bc2e-a248b73bfe9e' assert event.final is False assert event.status.state == TaskState.working assert event.status.message is None @@ -92,8 +92,8 @@ async def test_update_status_with_message( event = event_queue.enqueue_event.call_args[0][0] assert isinstance(event, TaskStatusUpdateEvent) - assert event.task_id == 'test-task-id' - assert event.context_id == 'test-context-id' + assert event.task_id == 'f05970c0-6215-4742-94f7-94cb27d962b2' + assert event.context_id == '821a03d5-786b-47b0-bc2e-a248b73bfe9e' assert event.final is False assert event.status.state == TaskState.working assert event.status.message == sample_message @@ -119,7 +119,7 @@ async def test_add_artifact_with_custom_id_and_name( """Test adding an artifact with a custom ID and name.""" await task_updater.add_artifact( parts=sample_parts, - artifact_id='custom-artifact-id', + artifact_id='8a8e26f2-bf65-469a-9b91-e6501ca6d5ae', name='Custom Artifact', ) @@ -127,7 +127,7 @@ async def test_add_artifact_with_custom_id_and_name( event = event_queue.enqueue_event.call_args[0][0] assert isinstance(event, TaskArtifactUpdateEvent) - assert event.artifact.artifact_id == 'custom-artifact-id' + assert str(event.artifact.artifact_id) == '8a8e26f2-bf65-469a-9b91-e6501ca6d5ae' assert event.artifact.name == 'Custom Artifact' assert event.artifact.parts == sample_parts @@ -137,7 +137,7 @@ async def test_add_artifact_generates_id( task_updater, event_queue, sample_parts ): """Test add_artifact generates an ID if artifact_id is None.""" - known_uuid = uuid.UUID('12345678-1234-5678-1234-567812345678') + known_uuid = uuid.UUID('26a78b4e-58de-44b7-bea4-082241ff3447') with patch('uuid.uuid4', return_value=known_uuid): await task_updater.add_artifact(parts=sample_parts, artifact_id=None) @@ -167,7 +167,7 @@ async def test_add_artifact_with_append_last_chunk( """Test add_artifact with append and last_chunk flags.""" await task_updater.add_artifact( parts=sample_parts, - artifact_id='id1', + artifact_id='11aec17b-882d-4c14-a1c3-629e04041bb5', append=append_val, last_chunk=last_chunk_val, ) @@ -176,7 +176,7 @@ async def test_add_artifact_with_append_last_chunk( event = event_queue.enqueue_event.call_args[0][0] assert isinstance(event, TaskArtifactUpdateEvent) - assert event.artifact.artifact_id == 'id1' + assert event.artifact.artifact_id == '11aec17b-882d-4c14-a1c3-629e04041bb5' assert event.artifact.parts == sample_parts assert event.append == append_val assert event.last_chunk == last_chunk_val @@ -272,14 +272,14 @@ def test_new_agent_message(task_updater, sample_parts): """Test creating a new agent message.""" with patch( 'uuid.uuid4', - return_value=uuid.UUID('12345678-1234-5678-1234-567812345678'), + return_value=uuid.UUID('26a78b4e-58de-44b7-bea4-082241ff3447'), ): message = task_updater.new_agent_message(parts=sample_parts) assert message.role == Role.agent - assert message.task_id == 'test-task-id' - assert message.context_id == 'test-context-id' - assert message.message_id == '12345678-1234-5678-1234-567812345678' + assert message.task_id == 'f05970c0-6215-4742-94f7-94cb27d962b2' + assert message.context_id == '821a03d5-786b-47b0-bc2e-a248b73bfe9e' + assert message.message_id == '26a78b4e-58de-44b7-bea4-082241ff3447' assert message.parts == sample_parts assert message.metadata is None @@ -290,16 +290,16 @@ def test_new_agent_message_with_metadata(task_updater, sample_parts): with patch( 'uuid.uuid4', - return_value=uuid.UUID('12345678-1234-5678-1234-567812345678'), + return_value=uuid.UUID('26a78b4e-58de-44b7-bea4-082241ff3447'), ): message = task_updater.new_agent_message( parts=sample_parts, metadata=metadata ) assert message.role == Role.agent - assert message.task_id == 'test-task-id' - assert message.context_id == 'test-context-id' - assert message.message_id == '12345678-1234-5678-1234-567812345678' + assert message.task_id == 'f05970c0-6215-4742-94f7-94cb27d962b2' + assert message.context_id == '821a03d5-786b-47b0-bc2e-a248b73bfe9e' + assert message.message_id == '26a78b4e-58de-44b7-bea4-082241ff3447' assert message.parts == sample_parts assert message.metadata == metadata @@ -523,8 +523,8 @@ async def test_update_status_raises_error_if_terminal_state_reached( async def test_concurrent_updates_race_condition(event_queue): task_updater = TaskUpdater( event_queue=event_queue, - task_id='test-task-id', - context_id='test-context-id', + task_id='f05970c0-6215-4742-94f7-94cb27d962b2', + context_id='821a03d5-786b-47b0-bc2e-a248b73bfe9e', ) tasks = [ task_updater.complete(), diff --git a/tests/server/test_integration.py b/tests/server/test_integration.py index f135349b..09217c66 100644 --- a/tests/server/test_integration.py +++ b/tests/server/test_integration.py @@ -101,7 +101,7 @@ MINIMAL_MESSAGE_USER: dict[str, Any] = { 'role': 'user', 'parts': [TEXT_PART_DATA], - 'message_id': 'msg-123', + 'message_id': '4a90ce5d-eda0-44be-afae-a709621eb63c', 'kind': 'message', } @@ -289,21 +289,25 @@ def test_starlette_rpc_endpoint_custom_url( """Test the RPC endpoint with a custom URL.""" # Provide a valid Task object as the return value task_status = TaskStatus(**MINIMAL_TASK_STATUS) - task = Task(id='task1', context_id='ctx1', status=task_status) + task = Task( + id='13d5b8a8-62d7-4490-98c8-d3951b42702a', + context_id='06cc947f-8946-4bde-b776-165462407e57', + status=task_status, + ) handler.on_get_task.return_value = task client = TestClient(app.build(rpc_url='/api/rpc')) response = client.post( '/api/rpc', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'tasks/get', - 'params': {'id': 'task1'}, + 'params': {'id': '13d5b8a8-62d7-4490-98c8-d3951b42702a'}, }, ) assert response.status_code == 200 data = response.json() - assert data['result']['id'] == 'task1' + assert data['result']['id'] == '13d5b8a8-62d7-4490-98c8-d3951b42702a' def test_fastapi_rpc_endpoint_custom_url( @@ -312,21 +316,25 @@ def test_fastapi_rpc_endpoint_custom_url( """Test the RPC endpoint with a custom URL.""" # Provide a valid Task object as the return value task_status = TaskStatus(**MINIMAL_TASK_STATUS) - task = Task(id='task1', context_id='ctx1', status=task_status) + task = Task( + id='13d5b8a8-62d7-4490-98c8-d3951b42702a', + context_id='06cc947f-8946-4bde-b776-165462407e57', + status=task_status, + ) handler.on_get_task.return_value = task client = TestClient(app.build(rpc_url='/api/rpc')) response = client.post( '/api/rpc', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'tasks/get', - 'params': {'id': 'task1'}, + 'params': {'id': '13d5b8a8-62d7-4490-98c8-d3951b42702a'}, }, ) assert response.status_code == 200 data = response.json() - assert data['result']['id'] == 'task1' + assert data['result']['id'] == '13d5b8a8-62d7-4490-98c8-d3951b42702a' def test_starlette_build_with_extra_routes( @@ -414,8 +422,8 @@ def test_send_message(client: TestClient, handler: mock.AsyncMock): # Prepare mock response task_status = TaskStatus(**MINIMAL_TASK_STATUS) mock_task = Task( - id='task1', - context_id='session-xyz', + id='13d5b8a8-62d7-4490-98c8-d3951b42702a', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', status=task_status, ) handler.on_message_send.return_value = mock_task @@ -425,16 +433,16 @@ def test_send_message(client: TestClient, handler: mock.AsyncMock): '/', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'message/send', 'params': { 'message': { 'role': 'agent', 'parts': [{'kind': 'text', 'text': 'Hello'}], - 'message_id': '111', + 'message_id': '2e888b8b-6d81-4505-a8ec-9220dc3c508f', 'kind': 'message', - 'task_id': 'task1', - 'context_id': 'session-xyz', + 'task_id': '13d5b8a8-62d7-4490-98c8-d3951b42702a', + 'context_id': '598c0e6f-72c2-48fc-803a-15d693622c6f', } }, }, @@ -444,7 +452,7 @@ def test_send_message(client: TestClient, handler: mock.AsyncMock): assert response.status_code == 200 data = response.json() assert 'result' in data - assert data['result']['id'] == 'task1' + assert data['result']['id'] == '13d5b8a8-62d7-4490-98c8-d3951b42702a' assert data['result']['status']['state'] == 'submitted' # Verify handler was called @@ -456,7 +464,11 @@ def test_cancel_task(client: TestClient, handler: mock.AsyncMock): # Setup mock response task_status = TaskStatus(**MINIMAL_TASK_STATUS) task_status.state = TaskState.canceled # 'cancelled' # - task = Task(id='task1', context_id='ctx1', status=task_status) + task = Task( + id='13d5b8a8-62d7-4490-98c8-d3951b42702a', + context_id='06cc947f-8946-4bde-b776-165462407e57', + status=task_status, + ) handler.on_cancel_task.return_value = task # Send request @@ -464,16 +476,16 @@ def test_cancel_task(client: TestClient, handler: mock.AsyncMock): '/', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'tasks/cancel', - 'params': {'id': 'task1'}, + 'params': {'id': '13d5b8a8-62d7-4490-98c8-d3951b42702a'}, }, ) # Verify response assert response.status_code == 200 data = response.json() - assert data['result']['id'] == 'task1' + assert data['result']['id'] == '13d5b8a8-62d7-4490-98c8-d3951b42702a' assert data['result']['status']['state'] == 'canceled' # Verify handler was called @@ -484,7 +496,11 @@ def test_get_task(client: TestClient, handler: mock.AsyncMock): """Test getting a task.""" # Setup mock response task_status = TaskStatus(**MINIMAL_TASK_STATUS) - task = Task(id='task1', context_id='ctx1', status=task_status) + task = Task( + id='13d5b8a8-62d7-4490-98c8-d3951b42702a', + context_id='06cc947f-8946-4bde-b776-165462407e57', + status=task_status, + ) handler.on_get_task.return_value = task # JSONRPCResponse(root=task) # Send request @@ -492,16 +508,16 @@ def test_get_task(client: TestClient, handler: mock.AsyncMock): '/', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'tasks/get', - 'params': {'id': 'task1'}, + 'params': {'id': '13d5b8a8-62d7-4490-98c8-d3951b42702a'}, }, ) # Verify response assert response.status_code == 200 data = response.json() - assert data['result']['id'] == 'task1' + assert data['result']['id'] == '13d5b8a8-62d7-4490-98c8-d3951b42702a' # Verify handler was called handler.on_get_task.assert_awaited_once() @@ -513,7 +529,7 @@ def test_set_push_notification_config( """Test setting push notification configuration.""" # Setup mock response task_push_config = TaskPushNotificationConfig( - task_id='t2', + task_id='10b55431-5f90-4c69-b1b8-a43e9b6510af', push_notification_config=PushNotificationConfig( url='https://example.com', token='secret-token' ), @@ -525,10 +541,10 @@ def test_set_push_notification_config( '/', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'tasks/pushNotificationConfig/set', 'params': { - 'task_id': 't2', + 'task_id': '10b55431-5f90-4c69-b1b8-a43e9b6510af', 'pushNotificationConfig': { 'url': 'https://example.com', 'token': 'secret-token', @@ -552,7 +568,7 @@ def test_get_push_notification_config( """Test getting push notification configuration.""" # Setup mock response task_push_config = TaskPushNotificationConfig( - task_id='task1', + task_id='13d5b8a8-62d7-4490-98c8-d3951b42702a', push_notification_config=PushNotificationConfig( url='https://example.com', token='secret-token' ), @@ -565,9 +581,9 @@ def test_get_push_notification_config( '/', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'tasks/pushNotificationConfig/get', - 'params': {'id': 'task1'}, + 'params': {'id': '13d5b8a8-62d7-4490-98c8-d3951b42702a'}, }, ) @@ -600,8 +616,8 @@ async def authenticate( # Set the output message to be the authenticated user name handler.on_message_send.side_effect = lambda params, context: Message( - context_id='session-xyz', - message_id='112', + context_id='598c0e6f-72c2-48fc-803a-15d693622c6f', + message_id='8b87e456-c3db-4c20-aa49-698ab1fcb2a6', role=Role.agent, parts=[ Part(TextPart(text=context.user.user_name)), @@ -613,16 +629,16 @@ async def authenticate( '/', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'message/send', 'params': { 'message': { 'role': 'agent', 'parts': [{'kind': 'text', 'text': 'Hello'}], - 'message_id': '111', + 'message_id': '2e888b8b-6d81-4505-a8ec-9220dc3c508f', 'kind': 'message', - 'task_id': 'task1', - 'context_id': 'session-xyz', + 'task_id': '13d5b8a8-62d7-4490-98c8-d3951b42702a', + 'context_id': '598c0e6f-72c2-48fc-803a-15d693622c6f', } }, }, @@ -663,8 +679,8 @@ async def stream_generator(): last = [False, False, True] task_artifact_update_event_data: dict[str, Any] = { 'artifact': artifact, - 'task_id': 'task_id', - 'context_id': 'session-xyz', + 'task_id': '85c7b187-4215-49a3-91e5-a62896a50b46', + 'context_id': '598c0e6f-72c2-48fc-803a-15d693622c6f', 'append': False, 'lastChunk': last[i], 'kind': 'artifact-update', @@ -686,16 +702,16 @@ async def stream_generator(): '/', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'message/stream', 'params': { 'message': { 'role': 'agent', 'parts': [{'kind': 'text', 'text': 'Hello'}], - 'message_id': '111', + 'message_id': '2e888b8b-6d81-4505-a8ec-9220dc3c508f', 'kind': 'message', - 'task_id': 'task_id', - 'context_id': 'session-xyz', + 'task_id': '85c7b187-4215-49a3-91e5-a62896a50b46', + 'context_id': '598c0e6f-72c2-48fc-803a-15d693622c6f', } }, }, @@ -753,8 +769,8 @@ async def stream_generator(): last = [False, False, True] task_artifact_update_event_data: dict[str, Any] = { 'artifact': artifact, - 'task_id': 'task_id', - 'context_id': 'session-xyz', + 'task_id': '85c7b187-4215-49a3-91e5-a62896a50b46', + 'context_id': '598c0e6f-72c2-48fc-803a-15d693622c6f', 'append': False, 'lastChunk': last[i], 'kind': 'artifact-update', @@ -771,16 +787,18 @@ async def stream_generator(): try: # Send request using client.stream() context manager # Send request - with client.stream( - 'POST', - '/', - json={ - 'jsonrpc': '2.0', - 'id': '123', # This ID is used in the success_event above - 'method': 'tasks/resubscribe', - 'params': {'id': 'task1'}, - }, - ) as response: + with ( + client.stream( + 'POST', + '/', + json={ + 'jsonrpc': '2.0', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', # This ID is used in the success_event above + 'method': 'tasks/resubscribe', + 'params': {'id': '13d5b8a8-62d7-4490-98c8-d3951b42702a'}, + }, + ) as response + ): # Verify response is a stream assert response.status_code == 200 assert ( @@ -838,7 +856,7 @@ def test_invalid_request_structure(client: TestClient): '/', json={ # Missing required fields - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'foo/bar', }, ) @@ -950,9 +968,9 @@ def test_method_not_implemented(client: TestClient, handler: mock.AsyncMock): '/', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'tasks/get', - 'params': {'id': 'task1'}, + 'params': {'id': '13d5b8a8-62d7-4490-98c8-d3951b42702a'}, }, ) assert response.status_code == 200 @@ -967,7 +985,7 @@ def test_unknown_method(client: TestClient): '/', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'unknown/method', 'params': {}, }, @@ -986,7 +1004,7 @@ def test_validation_error(client: TestClient): '/', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'messages/send', 'params': { 'message': { @@ -1010,9 +1028,9 @@ def test_unhandled_exception(client: TestClient, handler: mock.AsyncMock): '/', json={ 'jsonrpc': '2.0', - 'id': '123', + 'id': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', 'method': 'tasks/get', - 'params': {'id': 'task1'}, + 'params': {'id': '13d5b8a8-62d7-4490-98c8-d3951b42702a'}, }, ) assert response.status_code == 200 diff --git a/tests/test_types.py b/tests/test_types.py index 73e6af7b..579bd5e5 100644 --- a/tests/test_types.py +++ b/tests/test_types.py @@ -127,7 +127,7 @@ MINIMAL_MESSAGE_USER: dict[str, Any] = { 'role': 'user', 'parts': [TEXT_PART_DATA], - 'message_id': 'msg-123', + 'message_id': '4a90ce5d-eda0-44be-afae-a709621eb63c', 'kind': 'message', } @@ -135,7 +135,7 @@ 'role': 'agent', 'parts': [TEXT_PART_DATA, FILE_URI_PART_DATA], 'metadata': {'timestamp': 'now'}, - 'message_id': 'msg-456', + 'message_id': '63124154-4edd-426a-ba99-dce87f3d659b', } MINIMAL_TASK_STATUS: dict[str, Any] = {'state': 'submitted'} @@ -146,19 +146,19 @@ } MINIMAL_TASK: dict[str, Any] = { - 'id': 'task-abc', - 'context_id': 'session-xyz', + 'id': 'ea719c56-e398-425e-b02c-49fd77b7c156', + 'context_id': '598c0e6f-72c2-48fc-803a-15d693622c6f', 'status': MINIMAL_TASK_STATUS, 'kind': 'task', } FULL_TASK: dict[str, Any] = { - 'id': 'task-abc', - 'context_id': 'session-xyz', + 'id': 'ea719c56-e398-425e-b02c-49fd77b7c156', + 'context_id': '598c0e6f-72c2-48fc-803a-15d693622c6f', 'status': FULL_TASK_STATUS, 'history': [MINIMAL_MESSAGE_USER, AGENT_MESSAGE_WITH_FILE], 'artifacts': [ { - 'artifactId': 'artifact-123', + 'artifactId': '9ecc2482-f6bd-4ecc-a46c-771c5f49f5de', 'parts': [DATA_PART_DATA], 'name': 'result_data', } @@ -167,9 +167,11 @@ 'kind': 'task', } -MINIMAL_TASK_ID_PARAMS: dict[str, Any] = {'id': 'task-123'} +MINIMAL_TASK_ID_PARAMS: dict[str, Any] = { + 'id': '536ab032-6915-47d1-9909-4172dbee4aa0' +} FULL_TASK_ID_PARAMS: dict[str, Any] = { - 'id': 'task-456', + 'id': '9368e3b5-c796-46cf-9318-6c73e1a37e58', 'metadata': {'source': 'test'}, } @@ -394,15 +396,15 @@ def test_task_status(): def test_task(): task = Task(**MINIMAL_TASK) - assert task.id == 'task-abc' - assert task.context_id == 'session-xyz' + assert task.id == 'ea719c56-e398-425e-b02c-49fd77b7c156' + assert task.context_id == '598c0e6f-72c2-48fc-803a-15d693622c6f' assert task.status.state == TaskState.submitted assert task.history is None assert task.artifacts is None assert task.metadata is None task_full = Task(**FULL_TASK) - assert task_full.id == 'task-abc' + assert task_full.id == 'ea719c56-e398-425e-b02c-49fd77b7c156' assert task_full.status.state == TaskState.working assert task_full.history is not None and len(task_full.history) == 2 assert isinstance(task_full.history[0], Message) @@ -425,10 +427,12 @@ def test_jsonrpc_error(): assert err.data is None err_data = JSONRPCError( - code=-32001, message='Task not found', data={'taskId': '123'} + code=-32001, + message='Task not found', + data={'taskId': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863'}, ) assert err_data.code == -32001 - assert err_data.data == {'taskId': '123'} + assert err_data.data == {'taskId': '5bb3c918-28c9-4d1f-8ca6-8ddc85c91863'} def test_jsonrpc_request(): @@ -538,7 +542,9 @@ def test_send_subscribe_request() -> None: def test_get_task_request() -> None: - params = TaskQueryParams(id='task-1', history_length=2) + params = TaskQueryParams( + id='1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7', history_length=2 + ) req_data: dict[str, Any] = { 'jsonrpc': '2.0', 'method': 'tasks/get', @@ -548,7 +554,8 @@ def test_get_task_request() -> None: req = GetTaskRequest.model_validate(req_data) assert req.method == 'tasks/get' assert isinstance(req.params, TaskQueryParams) - assert req.params.id == 'task-1' + assert req.params.id == '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' + assert req.params.history_length == 2 with pytest.raises(ValidationError): # Wrong method literal @@ -556,7 +563,7 @@ def test_get_task_request() -> None: def test_cancel_task_request() -> None: - params = TaskIdParams(id='task-1') + params = TaskIdParams(id='1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7') req_data: dict[str, Any] = { 'jsonrpc': '2.0', 'method': 'tasks/cancel', @@ -566,7 +573,7 @@ def test_cancel_task_request() -> None: req = CancelTaskRequest.model_validate(req_data) assert req.method == 'tasks/cancel' assert isinstance(req.params, TaskIdParams) - assert req.params.id == 'task-1' + assert req.params.id == '1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7' with pytest.raises(ValidationError): # Wrong method literal CancelTaskRequest.model_validate({**req_data, 'method': 'wrong/method'}) @@ -582,7 +589,7 @@ def test_get_task_response() -> None: assert resp.root.id == 'resp-1' assert isinstance(resp.root, GetTaskSuccessResponse) assert isinstance(resp.root.result, Task) - assert resp.root.result.id == 'task-abc' + assert resp.root.result.id == 'ea719c56-e398-425e-b02c-49fd77b7c156' with pytest.raises(ValidationError): # Result is not a Task GetTaskResponse.model_validate( @@ -611,7 +618,7 @@ def test_send_message_response() -> None: assert resp.root.id == 'resp-1' assert isinstance(resp.root, SendMessageSuccessResponse) assert isinstance(resp.root.result, Task) - assert resp.root.result.id == 'task-abc' + assert resp.root.result.id == 'ea719c56-e398-425e-b02c-49fd77b7c156' with pytest.raises(ValidationError): # Result is not a Task SendMessageResponse.model_validate( @@ -640,7 +647,7 @@ def test_cancel_task_response() -> None: assert resp.root.id == 1 assert isinstance(resp.root, CancelTaskSuccessResponse) assert isinstance(resp.root.result, Task) - assert resp.root.result.id == 'task-abc' + assert resp.root.result.id == 'ea719c56-e398-425e-b02c-49fd77b7c156' resp_data_err: dict[str, Any] = { 'jsonrpc': '2.0', @@ -657,8 +664,8 @@ def test_cancel_task_response() -> None: def test_send_message_streaming_status_update_response() -> None: task_status_update_event_data: dict[str, Any] = { 'status': MINIMAL_TASK_STATUS, - 'taskId': '1', - 'context_id': '2', + 'taskId': '8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32', + 'context_id': '2964160a-4f18-40a5-91e1-498eafb206f6', 'final': False, 'kind': 'status-update', } @@ -673,7 +680,9 @@ def test_send_message_streaming_status_update_response() -> None: assert isinstance(response.root, SendStreamingMessageSuccessResponse) assert isinstance(response.root.result, TaskStatusUpdateEvent) assert response.root.result.status.state == TaskState.submitted - assert response.root.result.task_id == '1' + assert ( + response.root.result.task_id == '8a9ca3aa-1f78-4e4d-8e8f-b8228f02ed32' + ) assert not response.root.result.final with pytest.raises( @@ -710,14 +719,14 @@ def test_send_message_streaming_artifact_update_response() -> None: text_part = TextPart(**TEXT_PART_DATA) data_part = DataPart(**DATA_PART_DATA) artifact = Artifact( - artifact_id='artifact-123', + artifact_id='9ecc2482-f6bd-4ecc-a46c-771c5f49f5de', name='result_data', parts=[Part(root=text_part), Part(root=data_part)], ) task_artifact_update_event_data: dict[str, Any] = { 'artifact': artifact, - 'taskId': 'task_id', - 'context_id': '2', + 'taskId': '85c7b187-4215-49a3-91e5-a62896a50b46', + 'context_id': '2964160a-4f18-40a5-91e1-498eafb206f6', 'append': False, 'lastChunk': True, 'kind': 'artifact-update', @@ -731,9 +740,14 @@ def test_send_message_streaming_artifact_update_response() -> None: assert response.root.id == 1 assert isinstance(response.root, SendStreamingMessageSuccessResponse) assert isinstance(response.root.result, TaskArtifactUpdateEvent) - assert response.root.result.artifact.artifact_id == 'artifact-123' + assert ( + response.root.result.artifact.artifact_id + == '9ecc2482-f6bd-4ecc-a46c-771c5f49f5de' + ) assert response.root.result.artifact.name == 'result_data' - assert response.root.result.task_id == 'task_id' + assert ( + response.root.result.task_id == '85c7b187-4215-49a3-91e5-a62896a50b46' + ) assert not response.root.result.append assert response.root.result.last_chunk assert len(response.root.result.artifact.parts) == 2 @@ -743,7 +757,7 @@ def test_send_message_streaming_artifact_update_response() -> None: def test_set_task_push_notification_response() -> None: task_push_config = TaskPushNotificationConfig( - task_id='t2', + task_id='10b55431-5f90-4c69-b1b8-a43e9b6510af', push_notification_config=PushNotificationConfig( url='https://example.com', token='token' ), @@ -757,7 +771,9 @@ def test_set_task_push_notification_response() -> None: assert resp.root.id == 1 assert isinstance(resp.root, SetTaskPushNotificationConfigSuccessResponse) assert isinstance(resp.root.result, TaskPushNotificationConfig) - assert resp.root.result.task_id == 't2' + assert ( + str(resp.root.result.task_id) == '10b55431-5f90-4c69-b1b8-a43e9b6510af' + ) assert ( resp.root.result.push_notification_config.url == 'https://example.com' ) @@ -804,7 +820,7 @@ def test_set_task_push_notification_response() -> None: def test_get_task_push_notification_response() -> None: task_push_config = TaskPushNotificationConfig( - task_id='t2', + task_id='10b55431-5f90-4c69-b1b8-a43e9b6510af', push_notification_config=PushNotificationConfig( url='https://example.com', token='token' ), @@ -818,7 +834,9 @@ def test_get_task_push_notification_response() -> None: assert resp.root.id == 1 assert isinstance(resp.root, GetTaskPushNotificationConfigSuccessResponse) assert isinstance(resp.root.result, TaskPushNotificationConfig) - assert resp.root.result.task_id == 't2' + assert ( + str(resp.root.result.task_id) == '10b55431-5f90-4c69-b1b8-a43e9b6510af' + ) assert ( resp.root.result.push_notification_config.url == 'https://example.com' ) @@ -891,24 +909,24 @@ def test_a2a_request_root_model() -> None: assert a2a_req_send_subs.root.method == 'message/stream' # GetTaskRequest case - get_params = TaskQueryParams(id='t2') + get_params = TaskQueryParams(id='10b55431-5f90-4c69-b1b8-a43e9b6510af') get_req_data: dict[str, Any] = { 'jsonrpc': '2.0', 'method': 'tasks/get', 'params': get_params.model_dump(), - 'id': 2, + 'id': '02f69d7b-041c-416f-ba8c-b280f2b2c018', } a2a_req_get = A2ARequest.model_validate(get_req_data) assert isinstance(a2a_req_get.root, GetTaskRequest) assert a2a_req_get.root.method == 'tasks/get' # CancelTaskRequest case - id_params = TaskIdParams(id='t2') + id_params = TaskIdParams(id='10b55431-5f90-4c69-b1b8-a43e9b6510af') cancel_req_data: dict[str, Any] = { 'jsonrpc': '2.0', 'method': 'tasks/cancel', 'params': id_params.model_dump(), - 'id': 2, + 'id': '02f69d7b-041c-416f-ba8c-b280f2b2c018', } a2a_req_cancel = A2ARequest.model_validate(cancel_req_data) assert isinstance(a2a_req_cancel.root, CancelTaskRequest) @@ -916,7 +934,7 @@ def test_a2a_request_root_model() -> None: # SetTaskPushNotificationConfigRequest task_push_config = TaskPushNotificationConfig( - task_id='t2', + task_id='10b55431-5f90-4c69-b1b8-a43e9b6510af', push_notification_config=PushNotificationConfig( url='https://example.com', token='token' ), @@ -939,7 +957,7 @@ def test_a2a_request_root_model() -> None: ) # GetTaskPushNotificationConfigRequest - id_params = TaskIdParams(id='t2') + id_params = TaskIdParams(id='10b55431-5f90-4c69-b1b8-a43e9b6510af') get_push_notif_req_data: dict[str, Any] = { 'id': 1, 'jsonrpc': '2.0', @@ -960,7 +978,7 @@ def test_a2a_request_root_model() -> None: 'jsonrpc': '2.0', 'method': 'tasks/resubscribe', 'params': id_params.model_dump(), - 'id': 2, + 'id': '02f69d7b-041c-416f-ba8c-b280f2b2c018', } a2a_req_task_resubscribe_req = A2ARequest.model_validate( task_resubscribe_req_data @@ -975,7 +993,7 @@ def test_a2a_request_root_model() -> None: get_auth_card_req_data: dict[str, Any] = { 'jsonrpc': '2.0', 'method': 'agent/getAuthenticatedExtendedCard', - 'id': 2, + 'id': '02f69d7b-041c-416f-ba8c-b280f2b2c018', } a2a_req_get_auth_card = A2ARequest.model_validate(get_auth_card_req_data) assert isinstance( @@ -1018,7 +1036,7 @@ def test_a2a_request_root_model_id_validation() -> None: A2ARequest.model_validate(send_subs_req_data) # missing id # GetTaskRequest case - get_params = TaskQueryParams(id='t2') + get_params = TaskQueryParams(id='10b55431-5f90-4c69-b1b8-a43e9b6510af') get_req_data: dict[str, Any] = { 'jsonrpc': '2.0', 'method': 'tasks/get', @@ -1028,7 +1046,7 @@ def test_a2a_request_root_model_id_validation() -> None: A2ARequest.model_validate(get_req_data) # missing id # CancelTaskRequest case - id_params = TaskIdParams(id='t2') + id_params = TaskIdParams(id='10b55431-5f90-4c69-b1b8-a43e9b6510af') cancel_req_data: dict[str, Any] = { 'jsonrpc': '2.0', 'method': 'tasks/cancel', @@ -1039,7 +1057,7 @@ def test_a2a_request_root_model_id_validation() -> None: # SetTaskPushNotificationConfigRequest task_push_config = TaskPushNotificationConfig( - task_id='t2', + task_id='10b55431-5f90-4c69-b1b8-a43e9b6510af', push_notification_config=PushNotificationConfig( url='https://example.com', token='token' ), @@ -1048,18 +1066,18 @@ def test_a2a_request_root_model_id_validation() -> None: 'jsonrpc': '2.0', 'method': 'tasks/pushNotificationConfig/set', 'params': task_push_config.model_dump(), - 'task_id': 2, + 'task_id': '02f69d7b-041c-416f-ba8c-b280f2b2c018', } with pytest.raises(ValidationError): A2ARequest.model_validate(set_push_notif_req_data) # missing id # GetTaskPushNotificationConfigRequest - id_params = TaskIdParams(id='t2') + id_params = TaskIdParams(id='10b55431-5f90-4c69-b1b8-a43e9b6510af') get_push_notif_req_data: dict[str, Any] = { 'jsonrpc': '2.0', 'method': 'tasks/pushNotificationConfig/get', 'params': id_params.model_dump(), - 'task_id': 2, + 'task_id': '02f69d7b-041c-416f-ba8c-b280f2b2c018', } with pytest.raises(ValidationError): A2ARequest.model_validate(get_push_notif_req_data) @@ -1283,12 +1301,12 @@ def test_task_id_params_valid(): """Tests successful validation of TaskIdParams.""" # Minimal valid data params_min = TaskIdParams(**MINIMAL_TASK_ID_PARAMS) - assert params_min.id == 'task-123' + assert params_min.id == '536ab032-6915-47d1-9909-4172dbee4aa0' assert params_min.metadata is None # Full valid data params_full = TaskIdParams(**FULL_TASK_ID_PARAMS) - assert params_full.id == 'task-456' + assert params_full.id == '9368e3b5-c796-46cf-9318-6c73e1a37e58' assert params_full.metadata == {'source': 'test'} @@ -1306,7 +1324,10 @@ def test_task_id_params_invalid(): TaskIdParams(**invalid_data) # type: ignore # Incorrect type for metadata (should be dict) - invalid_metadata_type = {'id': 'task-789', 'metadata': 'not_a_dict'} + invalid_metadata_type = { + 'id': 'd7541723-0796-4231-8849-f6f137ea3bf8', + 'metadata': 'not_a_dict', + } with pytest.raises(ValidationError) as excinfo_type: TaskIdParams(**invalid_metadata_type) # type: ignore assert 'metadata' in str( @@ -1330,15 +1351,19 @@ def test_task_push_notification_config() -> None: assert push_notification_config.authentication == auth_info task_push_notification_config = TaskPushNotificationConfig( - task_id='task-123', push_notification_config=push_notification_config + task_id='536ab032-6915-47d1-9909-4172dbee4aa0', + push_notification_config=push_notification_config, + ) + assert ( + task_push_notification_config.task_id + == '536ab032-6915-47d1-9909-4172dbee4aa0' ) - assert task_push_notification_config.task_id == 'task-123' assert ( task_push_notification_config.push_notification_config == push_notification_config ) assert task_push_notification_config.model_dump(exclude_none=True) == { - 'taskId': 'task-123', + 'taskId': '536ab032-6915-47d1-9909-4172dbee4aa0', 'pushNotificationConfig': { 'url': 'https://example.com', 'token': 'token', @@ -1531,7 +1556,7 @@ def test_subclass_enums() -> None: def test_get_task_push_config_params() -> None: """Tests successful validation of GetTaskPushNotificationConfigParams.""" # Minimal valid data - params = {'id': 'task-1234'} + params = {'id': 'cf810732-24e2-4f81-a235-f318de16d6f7'} TaskIdParams.model_validate(params) GetTaskPushNotificationConfigParams.model_validate(params) @@ -1542,7 +1567,10 @@ def test_use_get_task_push_notification_params_for_request() -> None: 'id': 1, 'jsonrpc': '2.0', 'method': 'tasks/pushNotificationConfig/get', - 'params': {'id': 'task-1234', 'pushNotificationConfigId': 'c1'}, + 'params': { + 'id': 'cf810732-24e2-4f81-a235-f318de16d6f7', + 'pushNotificationConfigId': 'c1', + }, } a2a_req_get_push_req = A2ARequest.model_validate(get_push_notif_req_data) assert isinstance( diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py index 28acd27c..b63c28d3 100644 --- a/tests/utils/test_helpers.py +++ b/tests/utils/test_helpers.py @@ -32,15 +32,15 @@ MINIMAL_MESSAGE_USER: dict[str, Any] = { 'role': 'user', 'parts': [TEXT_PART_DATA], - 'message_id': 'msg-123', + 'message_id': '4a90ce5d-eda0-44be-afae-a709621eb63c', 'type': 'message', } MINIMAL_TASK_STATUS: dict[str, Any] = {'state': 'submitted'} MINIMAL_TASK: dict[str, Any] = { - 'id': 'task-abc', - 'context_id': 'session-xyz', + 'id': 'ea719c56-e398-425e-b02c-49fd77b7c156', + 'context_id': '598c0e6f-72c2-48fc-803a-15d693622c6f', 'status': MINIMAL_TASK_STATUS, 'type': 'task', } @@ -65,8 +65,8 @@ def test_create_task_obj_generates_context_id(): message_no_context_id = Message( role=Role.user, parts=[Part(root=TextPart(text='test'))], - message_id='msg-no-ctx', - task_id='task-from-msg', # Provide a task_id to differentiate from generated task.id + message_id='e4c28e7f-10f8-476a-a971-4c1e64bb2156', + task_id='c3dcd50f-a590-4e2a-9615-7bde3614e846', # Provide a task_id to differentiate from generated task.id ) send_params = MessageSendParams(message=message_no_context_id) @@ -105,8 +105,8 @@ def test_create_task_obj_generates_context_id(): def test_append_artifact_to_task(): # Prepare base task task = Task(**MINIMAL_TASK) - assert task.id == 'task-abc' - assert task.context_id == 'session-xyz' + assert str(task.id) == 'ea719c56-e398-425e-b02c-49fd77b7c156' + assert str(task.context_id) == '598c0e6f-72c2-48fc-803a-15d693622c6f' assert task.status.state == TaskState.submitted assert task.history is None assert task.artifacts is None @@ -114,45 +114,57 @@ def test_append_artifact_to_task(): # Prepare appending artifact and event artifact_1 = Artifact( - artifact_id='artifact-123', parts=[Part(root=TextPart(text='Hello'))] + artifact_id='9ecc2482-f6bd-4ecc-a46c-771c5f49f5de', + parts=[Part(root=TextPart(text='Hello'))], ) append_event_1 = TaskArtifactUpdateEvent( - artifact=artifact_1, append=False, task_id='123', context_id='123' + artifact=artifact_1, + append=False, + task_id='5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', + context_id='5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', ) # Test adding a new artifact (not appending) append_artifact_to_task(task, append_event_1) assert len(task.artifacts) == 1 - assert task.artifacts[0].artifact_id == 'artifact-123' + assert ( + task.artifacts[0].artifact_id == '9ecc2482-f6bd-4ecc-a46c-771c5f49f5de' + ) assert task.artifacts[0].name is None assert len(task.artifacts[0].parts) == 1 assert task.artifacts[0].parts[0].root.text == 'Hello' # Test replacing the artifact artifact_2 = Artifact( - artifact_id='artifact-123', + artifact_id='9ecc2482-f6bd-4ecc-a46c-771c5f49f5de', name='updated name', parts=[Part(root=TextPart(text='Updated'))], ) append_event_2 = TaskArtifactUpdateEvent( - artifact=artifact_2, append=False, task_id='123', context_id='123' + artifact=artifact_2, + append=False, + task_id='5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', + context_id='5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', ) append_artifact_to_task(task, append_event_2) assert len(task.artifacts) == 1 # Should still have one artifact - assert task.artifacts[0].artifact_id == 'artifact-123' + assert ( + task.artifacts[0].artifact_id == '9ecc2482-f6bd-4ecc-a46c-771c5f49f5de' + ) assert task.artifacts[0].name == 'updated name' assert len(task.artifacts[0].parts) == 1 assert task.artifacts[0].parts[0].root.text == 'Updated' # Test appending parts to an existing artifact artifact_with_parts = Artifact( - artifact_id='artifact-123', parts=[Part(root=TextPart(text='Part 2'))] + artifact_id='9ecc2482-f6bd-4ecc-a46c-771c5f49f5de', + parts=[Part(root=TextPart(text='Part 2'))], ) append_event_3 = TaskArtifactUpdateEvent( artifact=artifact_with_parts, append=True, - task_id='123', - context_id='123', + task_id='5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', + context_id='5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', ) append_artifact_to_task(task, append_event_3) assert len(task.artifacts[0].parts) == 2 @@ -167,12 +179,14 @@ def test_append_artifact_to_task(): append_event_4 = TaskArtifactUpdateEvent( artifact=another_artifact_with_parts, append=False, - task_id='123', - context_id='123', + task_id='5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', + context_id='5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', ) append_artifact_to_task(task, append_event_4) assert len(task.artifacts) == 2 - assert task.artifacts[0].artifact_id == 'artifact-123' + assert ( + task.artifacts[0].artifact_id == '9ecc2482-f6bd-4ecc-a46c-771c5f49f5de' + ) assert task.artifacts[1].artifact_id == 'new_artifact' assert len(task.artifacts[0].parts) == 2 assert len(task.artifacts[1].parts) == 1 @@ -184,8 +198,8 @@ def test_append_artifact_to_task(): append_event_5 = TaskArtifactUpdateEvent( artifact=non_existing_artifact_with_parts, append=True, - task_id='123', - context_id='123', + task_id='5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', + context_id='5bb3c918-28c9-4d1f-8ca6-8ddc85c91863', ) append_artifact_to_task(task, append_event_5) assert len(task.artifacts) == 2 @@ -195,7 +209,7 @@ def test_append_artifact_to_task(): # Test build_text_artifact def test_build_text_artifact(): - artifact_id = 'text_artifact' + artifact_id = 'cad02293-b072-4f04-b20f-51f160455f93' text = 'This is a sample text' artifact = build_text_artifact(text, artifact_id) diff --git a/tests/utils/test_message.py b/tests/utils/test_message.py index 3270eab7..5943fc4f 100644 --- a/tests/utils/test_message.py +++ b/tests/utils/test_message.py @@ -30,7 +30,7 @@ def test_new_agent_text_message_basic(self): # Exercise - with a fixed uuid for testing with patch( 'uuid.uuid4', - return_value=uuid.UUID('12345678-1234-5678-1234-567812345678'), + return_value=uuid.UUID('26a78b4e-58de-44b7-bea4-082241ff3447'), ): message = new_agent_text_message(text) @@ -38,58 +38,58 @@ def test_new_agent_text_message_basic(self): assert message.role == Role.agent assert len(message.parts) == 1 assert message.parts[0].root.text == text - assert message.message_id == '12345678-1234-5678-1234-567812345678' + assert message.message_id == '26a78b4e-58de-44b7-bea4-082241ff3447' assert message.task_id is None assert message.context_id is None def test_new_agent_text_message_with_context_id(self): # Setup text = 'Message with context' - context_id = 'test-context-id' + context_id = '821a03d5-786b-47b0-bc2e-a248b73bfe9e' # Exercise with patch( 'uuid.uuid4', - return_value=uuid.UUID('12345678-1234-5678-1234-567812345678'), + return_value=uuid.UUID('26a78b4e-58de-44b7-bea4-082241ff3447'), ): message = new_agent_text_message(text, context_id=context_id) # Verify assert message.role == Role.agent assert message.parts[0].root.text == text - assert message.message_id == '12345678-1234-5678-1234-567812345678' + assert message.message_id == '26a78b4e-58de-44b7-bea4-082241ff3447' assert message.context_id == context_id assert message.task_id is None def test_new_agent_text_message_with_task_id(self): # Setup text = 'Message with task id' - task_id = 'test-task-id' + task_id = 'f05970c0-6215-4742-94f7-94cb27d962b2' # Exercise with patch( 'uuid.uuid4', - return_value=uuid.UUID('12345678-1234-5678-1234-567812345678'), + return_value=uuid.UUID('26a78b4e-58de-44b7-bea4-082241ff3447'), ): message = new_agent_text_message(text, task_id=task_id) # Verify assert message.role == Role.agent assert message.parts[0].root.text == text - assert message.message_id == '12345678-1234-5678-1234-567812345678' + assert message.message_id == '26a78b4e-58de-44b7-bea4-082241ff3447' assert message.task_id == task_id assert message.context_id is None def test_new_agent_text_message_with_both_ids(self): # Setup text = 'Message with both ids' - context_id = 'test-context-id' - task_id = 'test-task-id' + context_id = '821a03d5-786b-47b0-bc2e-a248b73bfe9e' + task_id = 'f05970c0-6215-4742-94f7-94cb27d962b2' # Exercise with patch( 'uuid.uuid4', - return_value=uuid.UUID('12345678-1234-5678-1234-567812345678'), + return_value=uuid.UUID('26a78b4e-58de-44b7-bea4-082241ff3447'), ): message = new_agent_text_message( text, context_id=context_id, task_id=task_id @@ -98,7 +98,7 @@ def test_new_agent_text_message_with_both_ids(self): # Verify assert message.role == Role.agent assert message.parts[0].root.text == text - assert message.message_id == '12345678-1234-5678-1234-567812345678' + assert message.message_id == '26a78b4e-58de-44b7-bea4-082241ff3447' assert message.context_id == context_id assert message.task_id == task_id @@ -109,14 +109,14 @@ def test_new_agent_text_message_empty_text(self): # Exercise with patch( 'uuid.uuid4', - return_value=uuid.UUID('12345678-1234-5678-1234-567812345678'), + return_value=uuid.UUID('26a78b4e-58de-44b7-bea4-082241ff3447'), ): message = new_agent_text_message(text) # Verify assert message.role == Role.agent assert message.parts[0].root.text == '' - assert message.message_id == '12345678-1234-5678-1234-567812345678' + assert message.message_id == '26a78b4e-58de-44b7-bea4-082241ff3447' class TestNewAgentPartsMessage: @@ -127,8 +127,8 @@ def test_new_agent_parts_message(self): Part(root=TextPart(text='Here is some text.')), Part(root=DataPart(data={'product_id': 123, 'quantity': 2})), ] - context_id = 'ctx-multi-part' - task_id = 'task-multi-part' + context_id = '48e75ad3-7d13-4f9b-8a53-5a6434e3b50d' + task_id = '8af2cad9-322a-483a-bbbd-ecc8635fe471' # Exercise with patch( @@ -324,7 +324,7 @@ def test_get_message_text_single_part(self): message = Message( role=Role.agent, parts=[Part(root=TextPart(text='Hello world'))], - message_id='test-message-id', + message_id='243fd82e-36c6-4e09-8835-56665053bfd4', ) # Exercise @@ -342,7 +342,7 @@ def test_get_message_text_multiple_parts(self): Part(root=TextPart(text='Second line')), Part(root=TextPart(text='Third line')), ], - message_id='test-message-id', + message_id='243fd82e-36c6-4e09-8835-56665053bfd4', ) # Exercise @@ -360,7 +360,7 @@ def test_get_message_text_custom_delimiter(self): Part(root=TextPart(text='Second part')), Part(root=TextPart(text='Third part')), ], - message_id='test-message-id', + message_id='243fd82e-36c6-4e09-8835-56665053bfd4', ) # Exercise @@ -374,7 +374,7 @@ def test_get_message_text_empty_parts(self): message = Message( role=Role.agent, parts=[], - message_id='test-message-id', + message_id='243fd82e-36c6-4e09-8835-56665053bfd4', ) # Exercise diff --git a/tests/utils/test_proto_utils.py b/tests/utils/test_proto_utils.py index 83848c24..202bf17f 100644 --- a/tests/utils/test_proto_utils.py +++ b/tests/utils/test_proto_utils.py @@ -14,9 +14,9 @@ @pytest.fixture def sample_message() -> types.Message: return types.Message( - message_id='msg-1', - context_id='ctx-1', - task_id='task-1', + message_id='15957e91-63e6-40ac-8205-1d1ffb09a5b2', + context_id='e1bbdfd5-8818-4200-873f-8124135770fe', + task_id='1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7', role=types.Role.user, parts=[ types.Part(root=types.TextPart(text='Hello')), @@ -34,8 +34,8 @@ def sample_message() -> types.Message: @pytest.fixture def sample_task(sample_message: types.Message) -> types.Task: return types.Task( - id='task-1', - context_id='ctx-1', + id='1c3a35ab-e35c-49d8-a37b-7988f5a2ecb7', + context_id='e1bbdfd5-8818-4200-873f-8124135770fe', status=types.TaskStatus( state=types.TaskState.working, message=sample_message ), diff --git a/tests/utils/test_task.py b/tests/utils/test_task.py index 77441316..e2b529e3 100644 --- a/tests/utils/test_task.py +++ b/tests/utils/test_task.py @@ -7,6 +7,7 @@ from a2a.types import Artifact, Message, Part, Role, TextPart from a2a.utils.task import completed_task, new_task +from pydantic import ValidationError class TestTask(unittest.TestCase): @@ -21,24 +22,24 @@ def test_new_task_status(self): @patch('uuid.uuid4') def test_new_task_generates_ids(self, mock_uuid4): - mock_uuid = uuid.UUID('12345678-1234-5678-1234-567812345678') + mock_uuid = uuid.UUID('26a78b4e-58de-44b7-bea4-082241ff3447') mock_uuid4.return_value = mock_uuid message = Message( role=Role.user, parts=[Part(root=TextPart(text='test message'))], - message_id=str(uuid.uuid4()), + message_id=uuid.uuid4(), ) task = new_task(message) - self.assertEqual(task.id, str(mock_uuid)) - self.assertEqual(task.context_id, str(mock_uuid)) + self.assertEqual(task.id, mock_uuid) + self.assertEqual(task.context_id, mock_uuid) def test_new_task_uses_provided_ids(self): - task_id = str(uuid.uuid4()) - context_id = str(uuid.uuid4()) + task_id = uuid.uuid4() + context_id = uuid.uuid4() message = Message( role=Role.user, parts=[Part(root=TextPart(text='test message'))], - message_id=str(uuid.uuid4()), + message_id=uuid.uuid4(), task_id=task_id, context_id=context_id, ) @@ -61,7 +62,7 @@ def test_completed_task_status(self): context_id = str(uuid.uuid4()) artifacts = [ Artifact( - artifact_id='artifact_1', + artifact_id='78ae376b-6b1e-4b65-8bf8-7e3eae7d7e41', parts=[Part(root=TextPart(text='some content'))], ) ] @@ -78,7 +79,7 @@ def test_completed_task_assigns_ids_and_artifacts(self): context_id = str(uuid.uuid4()) artifacts = [ Artifact( - artifact_id='artifact_1', + artifact_id='78ae376b-6b1e-4b65-8bf8-7e3eae7d7e41', parts=[Part(root=TextPart(text='some content'))], ) ] @@ -97,7 +98,7 @@ def test_completed_task_empty_history_if_not_provided(self): context_id = str(uuid.uuid4()) artifacts = [ Artifact( - artifact_id='artifact_1', + artifact_id='78ae376b-6b1e-4b65-8bf8-7e3eae7d7e41', parts=[Part(root=TextPart(text='some content'))], ) ] @@ -111,7 +112,7 @@ def test_completed_task_uses_provided_history(self): context_id = str(uuid.uuid4()) artifacts = [ Artifact( - artifact_id='artifact_1', + artifact_id='78ae376b-6b1e-4b65-8bf8-7e3eae7d7e41', parts=[Part(root=TextPart(text='some content'))], ) ] @@ -170,8 +171,8 @@ def test_completed_task_empty_artifacts(self): match='artifacts must be a non-empty list of Artifact objects', ): completed_task( - task_id='task-123', - context_id='ctx-456', + task_id='536ab032-6915-47d1-9909-4172dbee4aa0', + context_id='9f18b6e9-63c4-4d44-a8b8-f4648003b6b8', artifacts=[], history=[], ) @@ -182,8 +183,8 @@ def test_completed_task_invalid_artifact_type(self): match='artifacts must be a non-empty list of Artifact objects', ): completed_task( - task_id='task-123', - context_id='ctx-456', + task_id='536ab032-6915-47d1-9909-4172dbee4aa0', + context_id='9f18b6e9-63c4-4d44-a8b8-f4648003b6b8', artifacts=['not an artifact'], history=[], ) @@ -194,8 +195,8 @@ def test_new_task_with_invalid_context_id(self): for invalid_id in invalid_ids: with self.subTest(invalid_id=invalid_id): with pytest.raises( - ValueError, - match=f"Invalid context_id: '{invalid_id}' is not a valid UUID.", + ValidationError, + match='Input should be a valid UUID', ): new_task( Message(