caelum0x c3b7edcf6d feat(console): GET /api/v1/rail/status, one aggregated health check for the rail
Consumer products (Rally, Menivor, Scribase, ...) and operators currently
have no single place to ask "is the rail actually up" -- they'd have to
probe Mint, Rago, Relay and Abacus separately before routing real traffic.

Adds lib/rail-status.ts (pure, injectable fetch per the repo's own transport
invariant) that checks every configured service in parallel with a bounded
per-service timeout, and GET /api/v1/rail/status that wires it to four new
optional env vars (MINT_HEALTH_URL, RAGO_HEALTH_URL, RELAY_HEALTH_URL,
ABACUS_HEALTH_URL -- unset services read "not_configured" and are excluded
from the verdict, so this degrades cleanly on any partial deployment).
Overall reads ok/degraded/down/unconfigured; HTTP status is 200 for
ok/degraded and 503 for down/unconfigured so a caller that only checks the
status code still gets the right answer without parsing the body.

TDD: 7 new tests in lib/rail-status.test.ts (all services healthy, one down
degrades the rest, a thrown network error reads down not an unhandled
rejection, a hung service times out instead of blocking forever, an unset
service skips the network call and is excluded from the verdict, zero
configured services reads unconfigured not a false ok, every service down
reads down). Full console suite: 166 pass (164 + the pre-existing env-only
failure in add-app-component.test.ts, unrelated -- missing root node_modules
in this sandbox, not a code regression).

Not deployed: the console Worker's deploy needs
~/.config/products-keys/railyard-console.env (not present on this machine)
and a working wrangler/pnpm toolchain (corepack's pnpm cache is broken here,
and the workspace root node_modules does not exist), so this could not be
shipped to railyard.ereboslab.com from this session -- noted in NOTES.md.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-21 18:39:35 +03:00

29 lines
1.3 KiB
TypeScript

// GET /api/v1/rail/status: aggregated health of the money rail's own
// services (Mint, Rago, Relay, Abacus) in one call, instead of making a
// consumer product (Rally, Menivor, Scribase, ...) or an operator probe four
// hosts directly before routing real traffic at the rail. Public and
// read-only -- no secrets in the response, only up/down + latency per
// service -- so any consumer can poll it without a Railyard session.
import { deps } from "../../../../../lib/deps.ts";
import { json } from "../../../../../lib/http.ts";
import { checkRailStatus } from "../../../../../lib/rail-status.ts";
export const dynamic = "force-dynamic";
export async function GET() {
const { cfg } = deps();
const result = await checkRailStatus({
services: [
{ name: "mint", url: cfg.railStatus.mint },
{ name: "rago", url: cfg.railStatus.rago },
{ name: "relay", url: cfg.railStatus.relay },
{ name: "abacus", url: cfg.railStatus.abacus },
],
});
// ok/degraded answer 200 (the body carries the detail); down/unconfigured
// answer 503 so a naive caller that only checks the HTTP status still
// reads the rail as unavailable without having to parse the body.
const status = result.overall === "ok" || result.overall === "degraded" ? 200 : 503;
return json(result, status);
}