feat(vessels): present AISStream + VesselAPI as two independent providers

- keystore KEY_REGISTRY copy splits the two keys (open/shared US-coast WS vs
  commercial Hormuz 5x/day REST); VesselAPI no longer reads as an AIS backup.
- vesselapi.py docstring drops 'fallback'; states both are first-class.
- /api/vessels docstring: last-known is the union (extra.src aisstream vs
  vesselapi).
- tests: VesselAPI idles/polls independently of the AISStream key.
This commit is contained in:
Sirius DevOps 2026-08-29 00:40:41 -04:00
commit e7429a4161
4 changed files with 65 additions and 9 deletions

View file

@ -296,3 +296,56 @@ def _make_get_client(client):
return client
return _get_client
# ── Independent-provider idle behaviour ───────────────────────────────────
# VesselAPI must never be gated on AISStream (or vice versa): a missing key on
# one provider leaves the other running. ``_StopLoop`` is a BaseException so
# the worker's ``except Exception`` handler can't swallow it — the first
# ``asyncio.sleep`` aborts the loop after exactly one decision.
class _StopLoop(BaseException):
pass
async def _stop_sleep(*_a, **_k):
raise _StopLoop()
async def _resolve(value: str):
return value
def test_worker_idles_without_vesselapi_key_even_if_aisstream_set(monkeypatch):
# AISStream key present, VesselAPI key absent -> no poll, still idles.
monkeypatch.setenv("AISSTREAM_API_KEY", "unused-aisstream-key")
monkeypatch.setenv("VESSELAPI_API_KEY", "")
monkeypatch.setattr(vesselapi, "_resolve_key", lambda: _resolve(""))
monkeypatch.setattr(vesselapi.asyncio, "sleep", _stop_sleep)
poll_calls: list = []
async def _spy_poll(store, boxes, key):
poll_calls.append(key)
return True
monkeypatch.setattr(vesselapi, "poll_once", _spy_poll)
with pytest.raises(_StopLoop):
asyncio.run(vesselapi.run_vesselapi_worker(FakeStore()))
assert poll_calls == []
def test_worker_polls_with_vesselapi_key_even_if_aisstream_unset(monkeypatch):
# AISStream key absent, VesselAPI key present -> still polls exactly once.
monkeypatch.setenv("AISSTREAM_API_KEY", "")
monkeypatch.setattr(vesselapi, "_resolve_key", lambda: _resolve("vesselapi-key"))
monkeypatch.setattr(vesselapi.asyncio, "sleep", _stop_sleep)
poll_calls: list = []
async def _spy_poll(store, boxes, key):
poll_calls.append(key)
return True
monkeypatch.setattr(vesselapi, "poll_once", _spy_poll)
with pytest.raises(_StopLoop):
asyncio.run(vesselapi.run_vesselapi_worker(FakeStore()))
assert poll_calls == ["vesselapi-key"]