@@ -703,3 +703,55 @@ def test_boundary_text_in_tool_result_not_truncated():
703703
704704 assert not changed
705705 assert messages [0 ]["content" ][0 ]["toolResult" ]["content" ][0 ]["text" ] == boundary_text
706+
707+
708+ # ==============================================================================
709+ # window_size=0 and negative window_size validation tests
710+ # ==============================================================================
711+
712+
713+ def test_window_size_negative_raises_value_error ():
714+ with pytest .raises (ValueError , match = "window_size" ):
715+ SlidingWindowConversationManager (window_size = - 1 )
716+
717+
718+ def test_window_size_zero_clears_all_messages_on_apply_management ():
719+ """window_size=0 should remove all messages, matching TypeScript SDK behaviour (issue #2205)."""
720+ manager = SlidingWindowConversationManager (window_size = 0 , should_truncate_results = False )
721+ messages = [
722+ {"role" : "user" , "content" : [{"text" : "Hello" }]},
723+ {"role" : "assistant" , "content" : [{"text" : "Hi there" }]},
724+ ]
725+ test_agent = Agent (messages = messages )
726+ manager .apply_management (test_agent )
727+
728+ assert messages == []
729+ assert manager .removed_message_count == 2
730+
731+
732+ def test_window_size_zero_clears_all_messages_on_reduce_context ():
733+ """reduce_context with window_size=0 should clear all messages even without overflow."""
734+ manager = SlidingWindowConversationManager (window_size = 0 , should_truncate_results = False )
735+ messages = [
736+ {"role" : "user" , "content" : [{"text" : "First" }]},
737+ {"role" : "assistant" , "content" : [{"text" : "Second" }]},
738+ {"role" : "user" , "content" : [{"text" : "Third" }]},
739+ ]
740+ test_agent = Agent (messages = messages )
741+ manager .reduce_context (test_agent )
742+
743+ assert messages == []
744+ assert manager .removed_message_count == 3
745+
746+
747+ def test_window_size_zero_clears_on_overflow ():
748+ """reduce_context with window_size=0 should clear messages even when called with an overflow exception."""
749+ manager = SlidingWindowConversationManager (window_size = 0 , should_truncate_results = False )
750+ messages = [
751+ {"role" : "user" , "content" : [{"text" : "Hello" }]},
752+ {"role" : "assistant" , "content" : [{"text" : "Hi" }]},
753+ ]
754+ test_agent = Agent (messages = messages )
755+ manager .reduce_context (test_agent , e = Exception ("overflow" ))
756+
757+ assert messages == []
0 commit comments