Skip to content

Commit e413f24

Browse files
committed
fix(gull): report degraded health when probe fails
1 parent 622d169 commit e413f24

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

pkgs/gull/app/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,12 @@ async def health() -> HealthResponse:
325325
timeout=5,
326326
)
327327

328-
browser_active = SESSION_NAME in stdout if code == 0 else False
328+
probe_ok = code == 0
329+
browser_active = SESSION_NAME in stdout if probe_ok else False
330+
status = "healthy" if probe_ok else "degraded"
329331

330332
return HealthResponse(
331-
status="healthy" if agent_browser_available else "unhealthy",
333+
status=status,
332334
browser_active=browser_active,
333335
session=SESSION_NAME,
334336
)

pkgs/gull/tests/unit/test_runner.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)