@@ -495,60 +495,34 @@ async def test_files_api_upload_failure(self):
495495 assert "huge_file.pdf" in result .parts [0 ].text
496496 assert "API quota exceeded" in result .parts [0 ].text
497497
498+
498499 @pytest .mark .asyncio
499500 async def test_file_exceeds_files_api_limit (self ):
500501 """Test that files exceeding 2GB limit are rejected with clear error."""
501- # Create a file larger than 2GB (simulated with a descriptor that reports large size)
502- # Create a mock object that behaves like bytes but reports 2GB+ size
503- large_data = b"x" * 1000 # Small actual data for testing
504-
505- # Create inline_data with the small data
502+ # Use a small file for the test
503+ large_data = b"x" * 1000
506504 inline_data = types .Blob (
507505 display_name = "huge_video.mp4" ,
508506 data = large_data ,
509507 mime_type = "video/mp4" ,
510508 )
511-
512509 user_message = types .Content (parts = [types .Part (inline_data = inline_data )])
513510
514- # Patch the file size check to simulate a 2GB+ file
515- original_callback = self .plugin .on_user_message_callback
516-
517- async def patched_callback (* , invocation_context , user_message ):
518- # Temporarily replace the data length check
519- for part in user_message .parts :
520- if part .inline_data :
521- # Simulate 2GB + 1 byte size
522- file_size_over_limit = (2 * 1024 * 1024 * 1024 ) + 1
523- # Manually inject the check that would happen in the real code
524- if file_size_over_limit > (2 * 1024 * 1024 * 1024 ):
525- file_size_gb = file_size_over_limit / (1024 * 1024 * 1024 )
526- display_name = part .inline_data .display_name or "unknown"
527- error_message = (
528- f"File { display_name } ({ file_size_gb :.2f} GB) exceeds the"
529- " maximum supported size of 2GB. Please upload a smaller file."
530- )
531- return types .Content (
532- role = "user" ,
533- parts = [types .Part (text = f"[Upload Error: { error_message } ]" )],
534- )
535- return await original_callback (
536- invocation_context = invocation_context , user_message = user_message
537- )
538-
539- self .plugin .on_user_message_callback = patched_callback
540-
541- result = await self .plugin .on_user_message_callback (
542- invocation_context = self .mock_context , user_message = user_message
543- )
511+ # Patch the size limit to be smaller than the file data
512+ with patch (
513+ "google.adk.plugins.save_files_as_artifacts_plugin._MAX_FILES_API_SIZE_BYTES" , 500
514+ ):
515+ result = await self .plugin .on_user_message_callback (
516+ invocation_context = self .mock_context , user_message = user_message
517+ )
544518
545519 # Should not attempt any upload
546520 self .mock_context .artifact_service .save_artifact .assert_not_called ()
547521
548- # Should return error message about 2GB limit
522+ # Should return error message about the limit
549523 assert result is not None
550524 assert len (result .parts ) == 1
551525 assert "[Upload Error:" in result .parts [0 ].text
552526 assert "huge_video.mp4" in result .parts [0 ].text
553- assert "2.00 GB" in result . parts [ 0 ]. text
554- assert "exceeds the maximum supported size" in result .parts [0 ].text
527+ # Note: This assertion will depend on fixing the hardcoded "2GB" in the error message.
528+ assert "exceeds the maximum supported size" in result .parts [0 ].text
0 commit comments