@@ -182,3 +182,42 @@ async def fake_run(_cmd: str, **kwargs):
182182 assert 0 < captured_timeouts [0 ] <= 0.3 + 1e-9
183183 assert captured_timeouts [0 ] < 1.0
184184
185+
186+ @pytest .mark .asyncio
187+ async def test_health_unhealthy_when_agent_browser_missing (monkeypatch : pytest .MonkeyPatch ):
188+ monkeypatch .setattr (gull_main .shutil , "which" , lambda _name : None )
189+
190+ response = await gull_main .health ()
191+
192+ assert response .status == "unhealthy"
193+ assert response .browser_active is False
194+
195+
196+ @pytest .mark .asyncio
197+ async def test_health_healthy_when_probe_succeeds (monkeypatch : pytest .MonkeyPatch ):
198+ monkeypatch .setattr (gull_main .shutil , "which" , lambda _name : "/usr/bin/agent-browser" )
199+
200+ async def fake_run (_cmd : str , ** _kwargs ):
201+ return gull_main .SESSION_NAME , "" , 0
202+
203+ monkeypatch .setattr (gull_main , "_run_agent_browser" , fake_run )
204+
205+ response = await gull_main .health ()
206+
207+ assert response .status == "healthy"
208+ assert response .browser_active is True
209+
210+
211+ @pytest .mark .asyncio
212+ async def test_health_degraded_when_probe_fails (monkeypatch : pytest .MonkeyPatch ):
213+ monkeypatch .setattr (gull_main .shutil , "which" , lambda _name : "/usr/bin/agent-browser" )
214+
215+ async def fake_run (_cmd : str , ** _kwargs ):
216+ return "" , "probe failed" , 2
217+
218+ monkeypatch .setattr (gull_main , "_run_agent_browser" , fake_run )
219+
220+ response = await gull_main .health ()
221+
222+ assert response .status == "degraded"
223+ assert response .browser_active is False
0 commit comments