Skip to content

Commit a88fd8a

Browse files
committed
fix(tests): disallow empty parts Artifact
1 parent 451a039 commit a88fd8a

2 files changed

Lines changed: 26 additions & 14 deletions

File tree

tests/test_types.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,19 @@ def test_send_message_streaming_status_update_response() -> None:
706706
assert isinstance(resp_err.root.error, JSONRPCError)
707707

708708

709+
def test_artifact_requires_non_empty_parts() -> None:
710+
"""Tests that Artifact rejects an empty parts list (min_length=1)."""
711+
with pytest.raises(ValidationError, match='too_short'):
712+
Artifact(artifact_id='a-1', parts=[])
713+
714+
# Valid: single part
715+
artifact = Artifact(
716+
artifact_id='a-2',
717+
parts=[Part(root=TextPart(text='hello'))],
718+
)
719+
assert len(artifact.parts) == 1
720+
721+
709722
def test_send_message_streaming_artifact_update_response() -> None:
710723
text_part = TextPart(**TEXT_PART_DATA)
711724
data_part = DataPart(**DATA_PART_DATA)

tests/utils/test_artifact.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
from unittest.mock import patch
55

6+
import pytest
7+
8+
from pydantic import ValidationError
9+
610
from a2a.types import (
711
Artifact,
812
DataPart,
@@ -22,7 +26,8 @@ class TestArtifact(unittest.TestCase):
2226
def test_new_artifact_generates_id(self, mock_uuid4):
2327
mock_uuid = uuid.UUID('abcdef12-1234-5678-1234-567812345678')
2428
mock_uuid4.return_value = mock_uuid
25-
artifact = new_artifact(parts=[], name='test_artifact')
29+
parts = [Part(root=TextPart(text='test'))]
30+
artifact = new_artifact(parts=parts, name='test_artifact')
2631
self.assertEqual(artifact.artifact_id, str(mock_uuid))
2732

2833
def test_new_artifact_assigns_parts_name_description(self):
@@ -140,19 +145,13 @@ def test_get_artifact_text_custom_delimiter(self):
140145
# Verify
141146
assert result == 'First part | Second part | Third part'
142147

143-
def test_get_artifact_text_empty_parts(self):
144-
# Setup
145-
artifact = Artifact(
146-
name='test-artifact',
147-
parts=[],
148-
artifact_id='test-artifact-id',
149-
)
150-
151-
# Exercise
152-
result = get_artifact_text(artifact)
153-
154-
# Verify
155-
assert result == ''
148+
def test_artifact_rejects_empty_parts(self):
149+
with pytest.raises(ValidationError, match='too_short'):
150+
Artifact(
151+
name='test-artifact',
152+
parts=[],
153+
artifact_id='test-artifact-id',
154+
)
156155

157156

158157
if __name__ == '__main__':

0 commit comments

Comments
 (0)