mirror of
https://github.com/pewdiepie-archdaemon/odysseus.git
synced 2026-06-16 01:35:36 -04:00
feat: add /api/ready readiness probe (DB, data dir, local-first) (#1200)
/api/health is a liveness ping. This adds /api/ready as a readiness /
integrity self-check that returns 503 unless every critical subsystem is
whole, so an orchestrator (Docker/Compose/k8s) can gate traffic on real
readiness rather than mere process liveness:
- database: opens a connection and runs SELECT 1
- data_dir: confirms the data directory exists and is writable
- local_first: reports whether storage stays on the host (informational;
a remote database is a valid deployment, so it never fails readiness)
The check logic lives in src/readiness.py so it is unit-testable in
isolation; the route is a thin wrapper. Covered by tests/test_readiness.py.
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
"""Tests for the readiness / integrity self-check (src/readiness.py)."""
|
||||
|
||||
from src.readiness import check_readiness
|
||||
|
||||
|
||||
def test_readiness_reports_core_subsystems():
|
||||
result = check_readiness()
|
||||
|
||||
assert {"ready", "version", "checks", "timestamp"}.issubset(result.keys())
|
||||
checks = result["checks"]
|
||||
for name in ("database", "data_dir", "local_first"):
|
||||
assert name in checks, f"missing check: {name}"
|
||||
|
||||
# In the dev/test environment the local SQLite DB and data dir are present,
|
||||
# so the critical checks must pass and overall readiness must be True.
|
||||
assert checks["database"]["ok"] is True, checks["database"]
|
||||
assert checks["data_dir"]["ok"] is True, checks["data_dir"]
|
||||
assert result["ready"] is True, result
|
||||
|
||||
|
||||
def test_local_first_check_is_informational_never_fatal():
|
||||
result = check_readiness()
|
||||
lf = result["checks"]["local_first"]
|
||||
# local_first reports whether storage stays on-host but must never gate
|
||||
# readiness — a remote database is a valid deployment.
|
||||
assert lf["ok"] is True
|
||||
assert "local" in lf
|
||||
Reference in New Issue
Block a user