@@ -127,3 +127,45 @@ async def request(self, *args, **kwargs):
127127 adapter = GullAdapter ("http://gull" )
128128 with pytest .raises (RequestTimeoutError ):
129129 await adapter .get_meta ()
130+
131+
132+ @pytest .mark .asyncio
133+ @pytest .mark .parametrize (
134+ ("status_value" , "expected" ),
135+ [
136+ ("healthy" , True ),
137+ ("degraded" , True ),
138+ ("unhealthy" , False ),
139+ ("unknown" , False ),
140+ ],
141+ )
142+ async def test_health_maps_payload_status (
143+ monkeypatch : pytest .MonkeyPatch , status_value : str , expected : bool
144+ ):
145+ async def handler (_request : httpx .Request ) -> httpx .Response :
146+ return httpx .Response (
147+ 200 ,
148+ json = {"status" : status_value , "browser_active" : False , "session" : "s" },
149+ )
150+
151+ client = httpx .AsyncClient (transport = httpx .MockTransport (handler ), base_url = "http://gull" )
152+ monkeypatch .setattr (gull_mod , "_get_shared_client" , lambda : client )
153+
154+ adapter = GullAdapter ("http://gull" )
155+ assert await adapter .health () is expected
156+
157+ await client .aclose ()
158+
159+
160+ @pytest .mark .asyncio
161+ async def test_health_returns_false_on_malformed_payload (monkeypatch : pytest .MonkeyPatch ):
162+ async def handler (_request : httpx .Request ) -> httpx .Response :
163+ return httpx .Response (200 , content = b"not-json" )
164+
165+ client = httpx .AsyncClient (transport = httpx .MockTransport (handler ), base_url = "http://gull" )
166+ monkeypatch .setattr (gull_mod , "_get_shared_client" , lambda : client )
167+
168+ adapter = GullAdapter ("http://gull" )
169+ assert await adapter .health () is False
170+
171+ await client .aclose ()
0 commit comments