diff --git a/src/api_hook_client.py b/src/api_hook_client.py index dd47a72..aaca8e2 100644 --- a/src/api_hook_client.py +++ b/src/api_hook_client.py @@ -72,6 +72,17 @@ class ApiHookClient: def clear_events(self) -> list[dict[str, Any]]: return self.get_events() + + def wait_for_event(self, event_type: str, timeout: int = 5) -> dict[str, Any] | None: + start = time.time() + while time.time() - start < timeout: + events = self.get_events() + for ev in events: + if ev.get("type") == event_type or ev.get("event_type") == event_type: + return ev + time.sleep(0.2) + return None + def post_gui(self, payload: dict) -> dict[str, Any]: """Pushes an event to the GUI's SyncEventQueue via the /api/gui endpoint.""" return self._make_request('POST', '/api/gui', data=payload) or {} diff --git a/src/app_controller.py b/src/app_controller.py index d8dfb42..c3490f4 100644 --- a/src/app_controller.py +++ b/src/app_controller.py @@ -573,7 +573,9 @@ class AppController: def _test_callback_func_write_to_file(self, data: str) -> None: """A dummy function that a custom_callback would execute for testing.""" - with open("test_callback_output.txt", "w") as f: + callback_path = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "tests", "artifacts", "temp_callback_output.txt") + os.makedirs(os.path.dirname(callback_path), exist_ok=True) + with open(callback_path, "w") as f: f.write(data) def _handle_approve_script(self, user_data=None) -> None: diff --git a/tests/mock_gemini_cli.py b/tests/mock_gemini_cli.py index a4979a0..93a4676 100644 --- a/tests/mock_gemini_cli.py +++ b/tests/mock_gemini_cli.py @@ -135,7 +135,7 @@ def main() -> None: "role": "assistant", "content": "I will read the first 10 lines of the file." }), flush=True) - file_path = "aggregate.py" + file_path = "src/aggregate.py" print(json.dumps({ "type": "tool_use", "name": "read_file", diff --git a/tests/test_gui2_parity.py b/tests/test_gui2_parity.py index cfd1858..bcb3545 100644 --- a/tests/test_gui2_parity.py +++ b/tests/test_gui2_parity.py @@ -71,7 +71,7 @@ def test_gui2_custom_callback_hook_works(live_gui: Any) -> None: assert response == {'status': 'queued'} time.sleep(1.5) # Give gui_2.py time to process its task queue # Assert that the file WAS created and contains the correct data - temp_workspace_file = Path('tests/artifacts/live_gui_workspace/tests/artifacts/temp_callback_output.txt') + temp_workspace_file = Path('tests/artifacts/temp_callback_output.txt') assert temp_workspace_file.exists(), f"Custom callback was NOT executed, or file path is wrong! Expected: {temp_workspace_file}" with open(temp_workspace_file, "r") as f: content = f.read()