[WIP]test: setup itk resubscribe tests#1031
Conversation
| TaskPushNotificationConfig, | ||
| ) | ||
| from a2a.utils import TransportProtocol | ||
| from a2a.utils.errors import TaskNotCancelableError |
There was a problem hiding this comment.
Code Review
This pull request introduces 'resubscribe' and 'hold task' behaviors to the ITK agent, adds helper functions for event and task management, and improves resource handling via an asynchronous context manager for the HTTP client. It also implements signal handling for graceful shutdowns, updates agent capabilities, and expands the test suite. Feedback was provided to correct Protobuf field presence checks and enum comparisons, remove a deprecated parameter, and restore configurable logging for the uvicorn server.
| if hasattr(event, 'task'): | ||
| task_obj = event.task | ||
| elif hasattr(event, 'HasField') and event.HasField('task'): | ||
| task_obj = event.task |
There was a problem hiding this comment.
The logic to extract task_obj from the event is potentially incorrect. For a protobuf message like StreamResponse, hasattr(event, 'task') will always be True, but this doesn't mean the task field is actually set in the message. Accessing event.task when the field is not set will give you a default Task instance, which is likely not what you want. The correct way to check for presence is event.HasField('task').
The elif condition is currently unreachable because the if condition will always be met for a StreamResponse object. I suggest simplifying this block to correctly check for the task field.
| if hasattr(event, 'task'): | |
| task_obj = event.task | |
| elif hasattr(event, 'HasField') and event.HasField('task'): | |
| task_obj = event.task | |
| if event.HasField('task'): | |
| task_obj = event.task |
| if not results and task_obj and hasattr(task_obj, 'history'): | ||
| logger.info('Results empty after loop, reading from history.') | ||
| for msg in task_obj.history: | ||
| if msg.role == 'ROLE_AGENT' or msg.role == 'agent': |
There was a problem hiding this comment.
Comparing the role enum field with strings like 'ROLE_AGENT' or 'agent' is not reliable and is likely incorrect. Protobuf enums in Python are integers, so this comparison will likely always evaluate to false. You should compare msg.role with the actual enum member.
To do this, you'll need to import Role from a2a.types.a2a_pb2 at the top of the file.
| if msg.role == 'ROLE_AGENT' or msg.role == 'agent': | |
| if msg.role == Role.ROLE_AGENT: |
| push_sender = BasePushNotificationSender( | ||
| httpx_client=httpx.AsyncClient(), | ||
| httpx_client=httpx_client, | ||
| config_store=push_config_store, | ||
| context=ServerCallContext(), | ||
| ) |
There was a problem hiding this comment.
|
|
||
| config = uvicorn.Config( | ||
| app, host='127.0.0.1', port=http_port, log_level=log_level_str.lower() | ||
| app, host='127.0.0.1', port=http_port, log_level='info' |
There was a problem hiding this comment.
The log_level for uvicorn is now hardcoded to 'info'. This removes the ability to configure it using the ITK_LOG_LEVEL environment variable. It's better to restore the previous behavior to allow for flexible log level configuration during testing.
| app, host='127.0.0.1', port=http_port, log_level='info' | |
| app, host='127.0.0.1', port=http_port, log_level=log_level_str.lower() |
1464d89 to
c7f3db7
Compare
Description
Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
CONTRIBUTINGGuide.fix:which represents bug fixes, and correlates to a SemVer patch.feat:represents a new feature, and correlates to a SemVer minor.feat!:, orfix!:,refactor!:, etc., which represent a breaking change (indicated by the!) and will result in a SemVer major.bash scripts/format.shfrom the repository root to format)Fixes #<issue_number_goes_here> 🦕