MCPcopy Create free account
hub / github.com/IBM/mcp-cli / test_window_limits_messages

Method test_window_limits_messages

tests/chat/test_chat_context.py:868–902  ·  view source on GitHub ↗

Sliding window keeps only last N event messages.

(self, dummy_tool_manager, monkeypatch)

Source from the content-addressed store, hash-verified

866
867 @pytest.mark.asyncio
868 async def test_window_limits_messages(self, dummy_tool_manager, monkeypatch):
869 """Sliding window keeps only last N event messages."""
870 monkeypatch.setattr(
871 "mcp_cli.chat.chat_context.generate_system_prompt",
872 lambda tools=None, **kw: "SYS_PROMPT",
873 )
874 from unittest.mock import Mock
875 from mcp_cli.model_management import ModelManager
876
877 mock_manager = Mock(spec=ModelManager)
878 mock_manager.get_client.return_value = None
879 mock_manager.get_active_provider.return_value = "mock"
880 mock_manager.get_active_model.return_value = "mock-model"
881
882 ctx = ChatContext(
883 tool_manager=dummy_tool_manager,
884 model_manager=mock_manager,
885 max_history_messages=3,
886 )
887 ctx._system_prompt = "SYS"
888 await ctx._initialize_session()
889
890 # Add 10 messages
891 for i in range(10):
892 await ctx.add_user_message(f"msg-{i}")
893
894 history = ctx.conversation_history
895 # 1 system + 3 windowed = 4
896 assert len(history) == 4
897 # System prompt always first
898 assert history[0].role.value == "system"
899 # Last 3 messages are the most recent
900 assert history[-1].content == "msg-9"
901 assert history[-2].content == "msg-8"
902 assert history[-3].content == "msg-7"
903
904 @pytest.mark.asyncio
905 async def test_system_prompt_not_evicted(self, dummy_tool_manager, monkeypatch):

Callers

nothing calls this directly

Calls 3

_initialize_sessionMethod · 0.95
add_user_messageMethod · 0.95
ChatContextClass · 0.90

Tested by

no test coverage detected