mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-08-27 14:17:10 -04:00
Add focused regression coverage for install, runtime, provider, state, health, supervisor, and persistent wrap flows so the new persistent deployment surfaces are exercised more thoroughly in CI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
from __future__ import annotations
|
|
|
|
import urllib.error
|
|
|
|
from headroom.install.health import probe_json, probe_ready
|
|
|
|
|
|
class _Response:
|
|
def __init__(self, payload: bytes) -> None:
|
|
self._payload = payload
|
|
|
|
def __enter__(self) -> _Response:
|
|
return self
|
|
|
|
def __exit__(self, exc_type, exc, tb) -> None:
|
|
return None
|
|
|
|
def read(self) -> bytes:
|
|
return self._payload
|
|
|
|
|
|
def test_probe_json_returns_dict(monkeypatch) -> None:
|
|
monkeypatch.setattr(
|
|
"urllib.request.urlopen",
|
|
lambda url, timeout=2.0: _Response(b'{"ready": true}'),
|
|
)
|
|
|
|
assert probe_json("http://example.test") == {"ready": True}
|
|
|
|
|
|
def test_probe_json_returns_none_for_invalid_payloads(monkeypatch) -> None:
|
|
monkeypatch.setattr("urllib.request.urlopen", lambda url, timeout=2.0: _Response(b"[]"))
|
|
assert probe_json("http://example.test") is None
|
|
|
|
monkeypatch.setattr("urllib.request.urlopen", lambda url, timeout=2.0: _Response(b"{"))
|
|
assert probe_json("http://example.test") is None
|
|
|
|
monkeypatch.setattr(
|
|
"urllib.request.urlopen",
|
|
lambda url, timeout=2.0: (_ for _ in ()).throw(urllib.error.URLError("boom")),
|
|
)
|
|
assert probe_json("http://example.test") is None
|
|
|
|
|
|
def test_probe_ready_accepts_ready_and_healthy(monkeypatch) -> None:
|
|
monkeypatch.setattr(
|
|
"headroom.install.health.probe_json", lambda url, timeout=2.0: {"ready": True}
|
|
)
|
|
assert probe_ready("http://example.test")
|
|
|
|
monkeypatch.setattr(
|
|
"headroom.install.health.probe_json", lambda url, timeout=2.0: {"status": "healthy"}
|
|
)
|
|
assert probe_ready("http://example.test")
|
|
|
|
monkeypatch.setattr("headroom.install.health.probe_json", lambda url, timeout=2.0: None)
|
|
assert not probe_ready("http://example.test")
|