@@ -659,27 +659,29 @@ class TestContextUsagePercentage:
659
659
"""Tests for context usage percentage functionality."""
660
660
661
661
@pytest .mark .asyncio
662
- async def test_working_memory_response_with_context_percentage (
662
+ async def test_working_memory_response_with_context_percentages (
663
663
self , enhanced_test_client
664
664
):
665
- """Test that WorkingMemoryResponse properly handles context_usage_percentage field ."""
665
+ """Test that WorkingMemoryResponse properly handles both context percentage fields ."""
666
666
session_id = "test-session"
667
667
668
- # Test with context percentage set
668
+ # Test with both context percentages set
669
669
working_memory_response = WorkingMemoryResponse (
670
670
session_id = session_id ,
671
671
messages = [],
672
672
memories = [],
673
673
data = {},
674
674
context = None ,
675
675
user_id = None ,
676
- context_usage_percentage = 45.5 ,
676
+ context_percentage_total_used = 45.5 ,
677
+ context_percentage_until_summarization = 65.0 ,
677
678
)
678
679
679
- assert working_memory_response .context_usage_percentage == 45.5
680
+ assert working_memory_response .context_percentage_total_used == 45.5
681
+ assert working_memory_response .context_percentage_until_summarization == 65.0
680
682
assert working_memory_response .session_id == session_id
681
683
682
- # Test with None context percentage (default)
684
+ # Test with None context percentages (default)
683
685
working_memory_response_none = WorkingMemoryResponse (
684
686
session_id = session_id ,
685
687
messages = [],
@@ -689,37 +691,45 @@ async def test_working_memory_response_with_context_percentage(
689
691
user_id = None ,
690
692
)
691
693
692
- assert working_memory_response_none .context_usage_percentage is None
694
+ assert working_memory_response_none .context_percentage_total_used is None
695
+ assert (
696
+ working_memory_response_none .context_percentage_until_summarization is None
697
+ )
693
698
694
699
@pytest .mark .asyncio
695
- async def test_context_percentage_serialization (self , enhanced_test_client ):
696
- """Test that context_usage_percentage is properly serialized."""
700
+ async def test_context_percentages_serialization (self , enhanced_test_client ):
701
+ """Test that both context percentage fields are properly serialized."""
697
702
session_id = "test-session"
698
703
699
- # Create response with context percentage
704
+ # Create response with both context percentages
700
705
working_memory_response = WorkingMemoryResponse (
701
706
session_id = session_id ,
702
707
messages = [],
703
708
memories = [],
704
709
data = {},
705
710
context = None ,
706
711
user_id = None ,
707
- context_usage_percentage = 75.0 ,
712
+ context_percentage_total_used = 75.0 ,
713
+ context_percentage_until_summarization = 85.5 ,
708
714
)
709
715
710
- # Test model_dump includes the field
716
+ # Test model_dump includes both fields
711
717
dumped = working_memory_response .model_dump ()
712
- assert "context_usage_percentage" in dumped
713
- assert dumped ["context_usage_percentage" ] == 75.0
718
+ assert "context_percentage_total_used" in dumped
719
+ assert "context_percentage_until_summarization" in dumped
720
+ assert dumped ["context_percentage_total_used" ] == 75.0
721
+ assert dumped ["context_percentage_until_summarization" ] == 85.5
714
722
715
723
# Test JSON serialization
716
724
json_data = working_memory_response .model_dump_json ()
717
- assert "context_usage_percentage" in json_data
725
+ assert "context_percentage_total_used" in json_data
726
+ assert "context_percentage_until_summarization" in json_data
718
727
assert "75.0" in json_data
728
+ assert "85.5" in json_data
719
729
720
730
@pytest .mark .asyncio
721
- async def test_context_percentage_validation (self , enhanced_test_client ):
722
- """Test that context_usage_percentage accepts valid values."""
731
+ async def test_context_percentages_validation (self , enhanced_test_client ):
732
+ """Test that both context percentage fields accept valid values."""
723
733
session_id = "test-session"
724
734
725
735
# Test valid percentages
@@ -733,12 +743,17 @@ async def test_context_percentage_validation(self, enhanced_test_client):
733
743
data = {},
734
744
context = None ,
735
745
user_id = None ,
736
- context_usage_percentage = percentage ,
746
+ context_percentage_total_used = percentage ,
747
+ context_percentage_until_summarization = percentage ,
748
+ )
749
+ assert working_memory_response .context_percentage_total_used == percentage
750
+ assert (
751
+ working_memory_response .context_percentage_until_summarization
752
+ == percentage
737
753
)
738
- assert working_memory_response .context_usage_percentage == percentage
739
754
740
- def test_working_memory_response_from_dict_with_context_percentage (self ):
741
- """Test that WorkingMemoryResponse can be created from dict with context_usage_percentage ."""
755
+ def test_working_memory_response_from_dict_with_context_percentages (self ):
756
+ """Test that WorkingMemoryResponse can be created from dict with both context percentage fields ."""
742
757
session_id = "test-session"
743
758
744
759
# Test creating WorkingMemoryResponse from dict (simulating API response parsing)
@@ -749,7 +764,8 @@ def test_working_memory_response_from_dict_with_context_percentage(self):
749
764
"data" : {},
750
765
"context" : None ,
751
766
"user_id" : None ,
752
- "context_usage_percentage" : 33.3 ,
767
+ "context_percentage_total_used" : 33.3 ,
768
+ "context_percentage_until_summarization" : 47.5 ,
753
769
"tokens" : 0 ,
754
770
"namespace" : None ,
755
771
"ttl_seconds" : None ,
@@ -759,7 +775,8 @@ def test_working_memory_response_from_dict_with_context_percentage(self):
759
775
# This simulates what happens when the API client parses the JSON response
760
776
result = WorkingMemoryResponse (** response_dict )
761
777
762
- # Verify the context_usage_percentage is included
778
+ # Verify both context percentage fields are included
763
779
assert isinstance (result , WorkingMemoryResponse )
764
- assert result .context_usage_percentage == 33.3
780
+ assert result .context_percentage_total_used == 33.3
781
+ assert result .context_percentage_until_summarization == 47.5
765
782
assert result .session_id == session_id
0 commit comments