Skip to content

Commit f3667dc

Browse files
authored
Merge branch 'main' into add-get_data_parts
2 parents e341394 + a38d438 commit f3667dc

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/a2a/server/tasks/task_manager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def __init__(
4141
initial_message: The `Message` that initiated the task, if any.
4242
Used when creating a new task object.
4343
"""
44+
if task_id is not None and not (isinstance(task_id, str) and task_id):
45+
raise ValueError('Task ID must be a non-empty string')
46+
4447
self.task_id = task_id
4548
self.context_id = context_id
4649
self.task_store = task_store

tests/server/tasks/test_task_manager.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,20 @@ def task_manager(mock_task_store: AsyncMock) -> TaskManager:
4545
)
4646

4747

48+
@pytest.mark.parametrize('invalid_task_id', ['', 123])
49+
def test_task_manager_invalid_task_id(
50+
mock_task_store: AsyncMock, invalid_task_id: Any
51+
):
52+
"""Test that TaskManager raises ValueError for an invalid task_id."""
53+
with pytest.raises(ValueError, match='Task ID must be a non-empty string'):
54+
TaskManager(
55+
task_id=invalid_task_id,
56+
context_id='test_context',
57+
task_store=mock_task_store,
58+
initial_message=None,
59+
)
60+
61+
4862
@pytest.mark.asyncio
4963
async def test_get_task_existing(
5064
task_manager: TaskManager, mock_task_store: AsyncMock

0 commit comments

Comments
 (0)