chore(ops): split /api/health (liveness) from /api/ready (readiness)

Previously /api/health did deep dependency probes (postgres + redis +
minio) and 503'd on any failure. That's readiness behavior, not
liveness — a transient Redis/MinIO blip would tell the orchestrator to
restart the pod when it should only be dropped from the load balancer.

Make /api/health a thin liveness check (returns 200 unconditionally if
the process is responding) and move the deep checks to a new
/api/ready endpoint with the canonical Kubernetes-style 200/503
contract. Docker-compose healthchecks keep pointing at /api/health,
which is now more conservative (no false-positive container restarts).

Documenso/SMTP are intentionally not probed in /api/ready: each tenant
configures its own credentials and a tenant misconfiguration shouldn't
deadline the entire shared CRM.

Also tighten the gdpr-bundle-builder casts: replace the scattered
`as unknown as Record<string, unknown>` double-casts with a small
`toJsonRow<T>()` helper that does the widen narrow→wide in one place
with one cast hop instead of two.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt Ciaccio
2026-04-29 02:03:10 +02:00
parent 7f9d90ad05
commit 61e40b5e76
4 changed files with 158 additions and 81 deletions

View File

@@ -0,0 +1,33 @@
import { describe, it, expect } from 'vitest';
import { GET as healthGet } from '@/app/api/health/route';
import { GET as readyGet } from '@/app/api/ready/route';
describe('GET /api/health (liveness)', () => {
it('returns 200 + status=ok regardless of downstream dependency state', async () => {
const res = await healthGet();
expect(res.status).toBe(200);
const body = await res.json();
expect(body.status).toBe('ok');
expect(body.timestamp).toMatch(/^\d{4}-\d{2}-\d{2}T/);
});
});
describe('GET /api/ready (readiness)', () => {
it('returns ready=200 when postgres + redis + minio all answer', async () => {
// The dev/test environment has all three reachable; this covers the
// happy path. The degraded path is not exercised here because
// simulating a down dep without leaking into other tests is awkward;
// the route's logic is intentionally trivial (Promise.allSettled +
// every-ok check) and worth covering at the unit level only.
const res = await readyGet();
expect(res.status).toBe(200);
const body = await res.json();
expect(body.status).toBe('ready');
expect(body.checks).toEqual({
postgres: 'ok',
redis: 'ok',
minio: 'ok',
});
});
});