""" ANTI-SIMPLIFICATION: These tests verify the Context user action simulation. They MUST NOT be simplified. They ensure that file selection, discussion switching, and context truncation are simulated correctly to test the UI's state management. """ from unittest.mock import MagicMock, patch import os import sys # Ensure project root is in path sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src"))) from simulation.sim_context import ContextSimulation def test_context_simulation_run() -> None: """ Verifies that the ContextSimulation runs the correct sequence of user actions: discussion switching, context building (md_only), and history truncation. """ mock_client = MagicMock() mock_client.wait_for_server.return_value = True # Mock project config mock_project = { 'project': { 'files': {'paths': []} } } mock_client.get_project.return_value = mock_project mock_client.get_value.side_effect = lambda key: { "ai_status": "md written: test.md", "token_budget_pct": 0.05 }.get(key) # Mock session entries mock_session = { 'session': { 'entries': [ {'role': 'User', 'content': 'Hello'}, {'role': 'AI', 'content': 'Hi'} ] } } mock_client.get_session.return_value = mock_session with patch('simulation.sim_base.WorkflowSimulator') as mock_sim_class: mock_sim = MagicMock() mock_sim_class.return_value = mock_sim sim = ContextSimulation(mock_client) sim.run() # Verify calls # ANTI-SIMPLIFICATION: Must assert these specific simulation steps are executed mock_sim.switch_discussion.assert_called_with("main") mock_client.post_project.assert_called() mock_client.click.assert_called_with("btn_md_only") mock_sim.run_discussion_turn.assert_called() mock_sim.truncate_history.assert_called_with(1)