fix(health): report real per-dependency status instead of hardcoded ok:true
Security Scan (SIAX Cloud) / security (push) Successful in 21s
CI (SIAX Cloud) / security (push) Successful in 21s
CI (SIAX Cloud) / quality (push) Successful in 41s
CI (SIAX Cloud) / security (pull_request) Successful in 22s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 21s
CI (SIAX Cloud) / quality (pull_request) Successful in 41s

BACKLOG P0-3: /api/health only ever checked *presence* of DATABASE_URL/
REDIS_URL and always returned ok:true regardless of whether anything was
reachable -- ARCHITECTURE.md's own words, "an uptime monitor watching HTTP
200 would show green for a dying instance".

lib/health-checks.ts adds real dependency probes:
  - db: a live `select 1` round trip (not just DATABASE_URL presence)
  - engine: a real HTTP call to the FastAPI engine's own GET /health
  - stripe: Stripe's documented lightweight balance.retrieve() liveness call
  - queue: honestly reports "not_integrated" when REDIS_URL is set but
    unused -- no Redis client is wired anywhere in this repo, so reporting
    "ok" would fabricate a check that doesn't exist

/api/health stays a liveness check (always 200 while the process can
respond; the body's `ok` field is the honest signal). New GET /api/ready
fails closed with 503 when the load-bearing dependency (db) isn't both
configured and reachable -- the "no /ready route" gap.

contracts/openapi.yaml, docs/architecture/ARCHITECTURE.md, and docs/slo.md
updated to match. 17 new unit tests (dependency-injected fakes, no real
network/DB) + 5 route-level tests.
This commit is contained in:
2026-08-11 13:49:23 +02:00
parent ebffb7df86
commit a88ad04867
10 changed files with 627 additions and 16 deletions
+75 -5
View File
@@ -22,15 +22,35 @@ paths:
/api/health:
get:
operationId: 0pt.health
summary: Liveness + dependency state
summary: Liveness + real per-dependency state
x-siax-status: live
security: []
responses:
"200":
description: OK — db/queue rapporterar "configured"/"not_configured"
description: Process is alive. Body reports honest per-dependency status (ok/error/not_configured/not_integrated) — see HealthResponse.
content:
application/json:
schema:
$ref: "#/components/schemas/HealthResponse"
/api/ready:
get:
operationId: 0pt.ready
summary: Readiness — fails closed when a load-bearing dependency is down
x-siax-status: live
security: []
responses:
"200":
description: Ready to serve real traffic.
content:
application/json:
schema:
$ref: "#/components/schemas/ReadyResponse"
"503":
description: Not ready — a load-bearing dependency is not configured/reachable.
content:
application/json:
schema:
$ref: "#/components/schemas/ReadyResponse"
/api/estimates:
post:
operationId: 0pt.estimate_order
@@ -401,7 +421,18 @@ components:
type: string
HealthResponse:
type: object
required: [ok, service, db, queue, ts]
description: >
db/engine/stripe report a real dependency probe (BACKLOG P0-3): "ok"
means a live round trip succeeded, "error" means it was configured
but unreachable (see `detail`), "not_configured" means the env var
is unset. `queue` can only ever be "not_configured" or
"not_integrated" -- no Redis client is wired in this repo, so
presence of REDIS_URL is reported honestly rather than faking a
connectivity check. `ok` is true only when no configured dependency
is in "error". This is a LIVENESS check: HTTP status stays 200
whenever the process can respond, regardless of dependency state --
see /api/ready for the readiness gate that fails closed.
required: [ok, service, db, queue, engine, stripe, ts]
properties:
ok:
type: boolean
@@ -409,10 +440,49 @@ components:
type: string
db:
type: string
enum: [configured, not_configured]
enum: [ok, error, not_configured]
queue:
type: string
enum: [configured, not_configured]
enum: [not_configured, not_integrated]
engine:
type: string
enum: [ok, error, not_configured]
stripe:
type: string
enum: [ok, error, not_configured]
detail:
type: object
description: Present only when `ok` is false -- one-line error message per failing dependency.
additionalProperties:
type: string
ts:
type: string
format: date-time
ReadyResponse:
type: object
description: >
Readiness (BACKLOG P0-3: "no /ready route existed"). Fails closed --
503 whenever a load-bearing dependency (today: only `db`) is not
both configured and reachable. Point a load balancer / Coolify
readiness probe here, not at /api/health.
required: [ready, service, db, queue, engine, stripe, ts]
properties:
ready:
type: boolean
service:
type: string
db:
type: string
enum: [ok, error, not_configured]
queue:
type: string
enum: [not_configured, not_integrated]
engine:
type: string
enum: [ok, error, not_configured]
stripe:
type: string
enum: [ok, error, not_configured]
ts:
type: string
format: date-time