diff --git a/tests/conftest.py b/tests/conftest.py index be070f53..56d1d297 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -638,4 +638,12 @@ def live_gui() -> Generator["_LiveGuiHandle", None, None]: except PermissionError: time.sleep(0.5) except: - break \ No newline at end of file + break +@pytest.fixture(autouse=True) +def _check_live_gui_health(request, live_gui) -> Generator[None, None, None]: + """[SDM: tests/conftest.py:_check_live_gui_health] [C: every test using live_gui]""" + if "live_gui" in request.fixturenames: + handle = live_gui + handle.ensure_alive() + yield + diff --git a/tests/test_live_gui_respawn.py b/tests/test_live_gui_respawn.py new file mode 100644 index 00000000..1b9f09fa --- /dev/null +++ b/tests/test_live_gui_respawn.py @@ -0,0 +1,38 @@ +"""Tests for the _check_live_gui_health autouse fixture (Phase 2, Task 2.2).""" +import time +import pytest + + +def test_handle_has_ensure_alive_method(live_gui) -> None: + """The _LiveGuiHandle has an ensure_alive() method that is callable.""" + handle = live_gui + assert hasattr(handle, 'ensure_alive') + assert callable(handle.ensure_alive) + + +def test_handle_respawn_count_is_zero_on_fresh_start(live_gui) -> None: + """A freshly-spawned handle has respawn_count == 0.""" + handle = live_gui + assert handle.respawn_count == 0 + + +def test_ensure_alive_is_fast_on_clean_subprocess(live_gui) -> None: + """ensure_alive() on a running subprocess is < 100ms (per Phase 2 budget).""" + handle = live_gui + t0 = time.perf_counter() + handle.ensure_alive() + elapsed = time.perf_counter() - t0 + assert elapsed < 0.1, f"ensure_alive took {elapsed:.3f}s on a clean subprocess" + + +def test_is_alive_returns_true_for_running_subprocess(live_gui) -> None: + """is_alive() returns True for a running subprocess.""" + handle = live_gui + assert handle.is_alive() + + +def test_autouse_health_fixture_does_not_break_tests(live_gui) -> None: + """The _check_live_gui_health autouse fixture runs before this test and calls ensure_alive(). The test should complete without error.""" + handle = live_gui + assert handle.is_alive() # If the autouse fixture didn't run, the process might be dead + assert handle.respawn_count == 0 # No respawns yet