Skip to content

Commit 6a7b6a3

Browse files
committed
test: cover both ValueError branches for file_uri MIME type guard
Adds test_content_to_message_param_user_message_file_uri_explicit_octet_stream to confirm that an upstream caller passing mime_type='application/octet-stream' raises a clear ValueError, covering both branches of the combined guard. Fixes: #5022
1 parent 3d12e4e commit 6a7b6a3

1 file changed

Lines changed: 33 additions & 5 deletions

File tree

tests/unittests/models/test_litellm.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1889,7 +1889,7 @@ async def test_content_to_message_param_user_message_file_uri_without_mime_type(
18891889
extension or display_name, ADK raises a clear ValueError rather than
18901890
forwarding an unsupported 'application/octet-stream' to LiteLLM.
18911891
1892-
See: https://github.com/google/adk-python/issues/3787
1892+
See: https://github.com/google/adk-python/issues/5022
18931893
"""
18941894
file_part = types.Part(
18951895
file_data=types.FileData(
@@ -1908,14 +1908,42 @@ async def test_content_to_message_param_user_message_file_uri_without_mime_type(
19081908
await _content_to_message_param(content)
19091909

19101910

1911+
@pytest.mark.asyncio
1912+
async def test_content_to_message_param_user_message_file_uri_explicit_octet_stream():
1913+
"""Test that an explicit application/octet-stream MIME type raises ValueError.
1914+
1915+
Upstream callers may explicitly set mime_type to 'application/octet-stream'
1916+
when the true type is unknown. ADK treats this identically to a missing MIME
1917+
type and raises early rather than forwarding the unsupported type to LiteLLM.
1918+
1919+
See: https://github.com/google/adk-python/issues/5022
1920+
"""
1921+
file_part = types.Part(
1922+
file_data=types.FileData(
1923+
file_uri="gs://agent-artifact-bucket/app/user/session/artifact/0",
1924+
mime_type="application/octet-stream",
1925+
)
1926+
)
1927+
content = types.Content(
1928+
role="user",
1929+
parts=[
1930+
types.Part.from_text(text="Analyze this file."),
1931+
file_part,
1932+
],
1933+
)
1934+
1935+
with pytest.raises(ValueError, match="application/octet-stream"):
1936+
await _content_to_message_param(content)
1937+
1938+
19111939
@pytest.mark.asyncio
19121940
async def test_content_to_message_param_user_message_file_uri_infer_mime_type():
19131941
"""Test MIME type inference from file_uri extension.
19141942
19151943
When file_data has a file_uri with a recognizable extension but no explicit
19161944
mime_type, the MIME type should be inferred from the extension.
19171945
1918-
See: https://github.com/google/adk-python/issues/3787
1946+
See: https://github.com/google/adk-python/issues/5022
19191947
"""
19201948
file_part = types.Part(
19211949
file_data=types.FileData(
@@ -3033,7 +3061,7 @@ async def test_get_content_file_uri_infer_mime_type():
30333061
When file_data has a file_uri with a recognizable extension but no explicit
30343062
mime_type, the MIME type should be inferred from the extension.
30353063
3036-
See: https://github.com/google/adk-python/issues/3787
3064+
See: https://github.com/google/adk-python/issues/5022
30373065
"""
30383066
# Use Part constructor directly to test MIME type inference in _get_content
30393067
# (types.Part.from_uri does its own inference, so we bypass it)
@@ -3089,7 +3117,7 @@ async def test_get_content_file_uri_default_mime_type():
30893117
mime_type, ADK raises a clear ValueError instead of forwarding the unsupported
30903118
'application/octet-stream' MIME type to LiteLLM.
30913119
3092-
See: https://github.com/google/adk-python/issues/3787
3120+
See: https://github.com/google/adk-python/issues/5022
30933121
"""
30943122
parts = [
30953123
types.Part(file_data=types.FileData(file_uri="gs://bucket/artifact/0"))
@@ -3107,7 +3135,7 @@ async def test_get_content_file_uri_explicit_octet_stream_raises():
31073135
default fallback or is set explicitly by the caller. ADK raises early with
31083136
an actionable message in both cases.
31093137
3110-
See: https://github.com/google/adk-python/issues/3787
3138+
See: https://github.com/google/adk-python/issues/5022
31113139
"""
31123140
parts = [
31133141
types.Part(

0 commit comments

Comments
 (0)