import pytest import time import sys import os 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 src import api_hook_client @pytest.mark.integration @pytest.mark.timeout(120) def test_patch_modal_appears_on_trigger(live_gui) -> None: """ Test that triggering a patch shows the modal in the GUI. Uses live_gui fixture to start the GUI with test hooks enabled. """ proc, _ = live_gui client = api_hook_client.ApiHookClient() if not client.wait_for_server(timeout=15): pytest.skip("GUI server not available") sample_patch = """--- a/test_file.py +++ b/test_file.py @@ -1,3 +1,4 @@ def hello(): - print("old") + print("new") + print("extra") return True""" result = client.trigger_patch(sample_patch, ["test_file.py"]) print(f"[DEBUG] trigger_patch result: {result}") assert result.get("status") == "ok", f"Failed to trigger patch: {result}" time.sleep(2) status = client.get_patch_status() print(f"[DEBUG] get_patch_status result: {status}") assert status.get("show_modal") == True, f"Patch modal should be visible but got {status}" assert status.get("patch_text") == sample_patch assert "test_file.py" in status.get("file_paths", []) result = client.reject_patch() assert result.get("status") == "done" time.sleep(1) status = client.get_patch_status() assert status.get("show_modal") == False, "Patch modal should be closed after reject" @pytest.mark.integration @pytest.mark.timeout(120) def test_patch_apply_modal_workflow(live_gui) -> None: """ Test the full patch apply workflow: trigger -> apply -> verify modal closes. """ proc, _ = live_gui client = api_hook_client.ApiHookClient() if not client.wait_for_server(timeout=15): pytest.skip("GUI server not available") sample_patch = """--- a/example.py +++ b/example.py @@ -5,3 +5,4 @@ def calculate(): x = 1 - return x + return x + 1 + # added line""" result = client.trigger_patch(sample_patch, ["example.py"]) assert result.get("status") == "ok" time.sleep(2) status = client.get_patch_status() assert status.get("show_modal") == True result = client.apply_patch() time.sleep(1) status = client.get_patch_status() assert status.get("show_modal") == False, "Patch modal should close after apply"