@@ -438,6 +438,97 @@ async def test_e2e_generate_cold_storage_object_key_successful():
438
438
assert isinstance (result , str )
439
439
440
440
441
+ @pytest .mark .asyncio
442
+ async def test_e2e_generate_cold_storage_object_key_with_custom_logger_s3_path ():
443
+ """
444
+ Test that _generate_cold_storage_object_key uses s3_path from custom logger instance.
445
+ """
446
+ from datetime import datetime , timezone
447
+ from unittest .mock import MagicMock , patch
448
+
449
+ from litellm .litellm_core_utils .litellm_logging import StandardLoggingPayloadSetup
450
+
451
+ # Create test data
452
+ start_time = datetime (2025 , 1 , 15 , 10 , 30 , 45 , 123456 , timezone .utc )
453
+ response_id = "chatcmpl-test-12345"
454
+
455
+ # Create mock custom logger with s3_path
456
+ mock_custom_logger = MagicMock ()
457
+ mock_custom_logger .s3_path = "storage"
458
+
459
+ with patch ("litellm.configured_cold_storage_logger" , "s3_v2" ), \
460
+ patch ("litellm.logging_callback_manager.get_active_custom_logger_for_callback_name" ) as mock_get_logger , \
461
+ patch ("litellm.integrations.s3.get_s3_object_key" ) as mock_get_s3_key :
462
+
463
+ # Setup mocks
464
+ mock_get_logger .return_value = mock_custom_logger
465
+ mock_get_s3_key .return_value = "storage/2025-01-15/time-10-30-45-123456_chatcmpl-test-12345.json"
466
+
467
+ # Call the function
468
+ result = StandardLoggingPayloadSetup ._generate_cold_storage_object_key (
469
+ start_time = start_time ,
470
+ response_id = response_id
471
+ )
472
+
473
+ # Verify logger was queried correctly
474
+ mock_get_logger .assert_called_once_with ("s3_v2" )
475
+
476
+ # Verify the S3 function was called with the custom logger's s3_path
477
+ mock_get_s3_key .assert_called_once_with (
478
+ s3_path = "storage" , # Should use custom logger's s3_path
479
+ team_alias_prefix = "" ,
480
+ start_time = start_time ,
481
+ s3_file_name = "time-10-30-45-123456_chatcmpl-test-12345"
482
+ )
483
+
484
+ # Verify the result
485
+ assert result == "storage/2025-01-15/time-10-30-45-123456_chatcmpl-test-12345.json"
486
+
487
+
488
+ @pytest .mark .asyncio
489
+ async def test_e2e_generate_cold_storage_object_key_with_logger_no_s3_path ():
490
+ """
491
+ Test that _generate_cold_storage_object_key falls back to empty s3_path when logger has no s3_path.
492
+ """
493
+ from datetime import datetime , timezone
494
+ from unittest .mock import MagicMock , patch
495
+
496
+ from litellm .litellm_core_utils .litellm_logging import StandardLoggingPayloadSetup
497
+
498
+ # Create test data
499
+ start_time = datetime (2025 , 1 , 15 , 10 , 30 , 45 , 123456 , timezone .utc )
500
+ response_id = "chatcmpl-test-12345"
501
+
502
+ # Create mock custom logger without s3_path
503
+ mock_custom_logger = MagicMock ()
504
+ mock_custom_logger .s3_path = None # or could be missing attribute
505
+
506
+ with patch ("litellm.configured_cold_storage_logger" , "s3_v2" ), \
507
+ patch ("litellm.logging_callback_manager.get_active_custom_logger_for_callback_name" ) as mock_get_logger , \
508
+ patch ("litellm.integrations.s3.get_s3_object_key" ) as mock_get_s3_key :
509
+
510
+ # Setup mocks
511
+ mock_get_logger .return_value = mock_custom_logger
512
+ mock_get_s3_key .return_value = "2025-01-15/time-10-30-45-123456_chatcmpl-test-12345.json"
513
+
514
+ # Call the function
515
+ result = StandardLoggingPayloadSetup ._generate_cold_storage_object_key (
516
+ start_time = start_time ,
517
+ response_id = response_id
518
+ )
519
+
520
+ # Verify the S3 function was called with empty s3_path (fallback)
521
+ mock_get_s3_key .assert_called_once_with (
522
+ s3_path = "" , # Should fall back to empty string
523
+ team_alias_prefix = "" ,
524
+ start_time = start_time ,
525
+ s3_file_name = "time-10-30-45-123456_chatcmpl-test-12345"
526
+ )
527
+
528
+ # Verify the result
529
+ assert result == "2025-01-15/time-10-30-45-123456_chatcmpl-test-12345.json"
530
+
531
+
441
532
@pytest .mark .asyncio
442
533
async def test_e2e_generate_cold_storage_object_key_not_configured ():
443
534
"""
0 commit comments