""" ANTI-SIMPLIFICATION: These tests verify the Simulation of Execution and Modal flows. They MUST NOT be simplified. They ensure that script execution approvals and other modal interactions are correctly simulated against the GUI state. """ 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_execution import ExecutionSimulation def test_execution_simulation_run() -> None: """ Verifies that ExecutionSimulation handles script confirmation modals. Ensures that it waits for the modal and clicks the approve button. """ mock_client = MagicMock() mock_client.wait_for_server.return_value = True # Mock show_confirm_modal state vals = {"show_confirm_modal": False} def side_effect(key): return vals.get(key) def set_side_effect(key, val): vals[key] = val mock_client.get_value.side_effect = side_effect mock_client.set_value.side_effect = set_side_effect # Mock session entries with tool output mock_session = { 'session': { 'entries': [ {'role': 'Tool', 'content': 'Simulation Test', 'tool_call_id': 'call_1'} ] } } mock_client.get_session.return_value = mock_session # Mock script confirmation event mock_client.wait_for_event.side_effect = [ {"type": "script_confirmation_required", "script": "dir"}, None # Second call returns None to end the loop ] with patch('simulation.sim_base.WorkflowSimulator') as mock_sim_class: mock_sim = MagicMock() mock_sim_class.return_value = mock_sim sim = ExecutionSimulation(mock_client) sim.run() # Verify calls # ANTI-SIMPLIFICATION: Assert that the async discussion and the script approval button are triggered. mock_sim.run_discussion_turn_async.assert_called() mock_client.click.assert_called_with("btn_approve_script")