Public: anyone can read this; the crew can change it.
GET /healthz answers the same as /api/v1/health, so an uptime probe that tries the usual path gets the truth #13198
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/13191-get-healthz-answers-the-same-as-api-v1-h → main 7 commits fork 3 threads · 3 unresolved
11 files
changed +143
−32
src/contract/openapi/routes/getHealth.ts added +11
| @@ -0,0 +1,11 @@ | ||
| 1 | import type { Route } from "../shared.ts"; | |
| 2 | ||
| 3 | export const route: Route = { | |
| 4 | method: "get", | |
| 5 | path: "/health", | |
| 6 | summary: | |
| 7 | "The same answer as GET /api/v1/health, at the path an uptime monitor tries first (#13191); /healthz stays the orchestrator's liveness probe and answers ok whenever the process and its database do", | |
| 8 | auth: false, | |
| 9 | role: "anonymous", | |
| 10 | reply: { ok: "boolean", draining: "boolean", schedules: "object" }, | |
| 11 | }; |
src/contract/openapi/routes/index.ts +1
| @@ -243,6 +243,7 @@ export { route as getApiV1UsersUsernameRepos } from "./getApiV1UsersUsernameRepo | ||
| 243 | 243 | export { route as getApiV1UsersUsernameSignins } from "./getApiV1UsersUsernameSignins.ts"; |
| 244 | 244 | export { route as getApiV1Version } from "./getApiV1Version.ts"; |
| 245 | 245 | export { route as getContractOpenapiJson } from "./getContractOpenapiJson.ts"; |
| 246 | export { route as getHealth } from "./getHealth.ts"; | |
| 246 | 247 | export { route as getMetrics } from "./getMetrics.ts"; |
| 247 | 248 | export { route as getOwnerNamePullsNumberCheckTxt } from "./getOwnerNamePullsNumberCheckTxt.ts"; |
| 248 | 249 | export { route as patchApiV1AdminSettings } from "./patchApiV1AdminSettings.ts"; |
src/core/reserved.ts +5
| @@ -58,6 +58,11 @@ export const SYSTEM_NAMES: readonly string[] = [ | ||
| 58 | 58 | "contact", |
| 59 | 59 | // the forge's own pages |
| 60 | 60 | "api", |
| 61 | // the probes' paths (#13191): answered before the web router, so a profile there could never | |
outdated
Reserving new names is not in the issue and can invalidate an existing owner/repo called health; justify it or drop it. |
||
| 62 | // be reached; an account that already holds one keeps it (see the head of this file) | |
| 63 | "health", | |
| 64 | "healthz", | |
| 65 | "readyz", | |
| 61 | 66 | "apps", |
| 62 | 67 | "asks", |
| 63 | 68 | "assets", |
src/http/api.ts +25 −14
| @@ -810,7 +810,9 @@ function editFailure(error: { kind: string } & Record<string, unknown>) { | ||
| 810 | 810 | const ANCHOR_FORMAT = |
| 811 | 811 | 'An anchor is {"path": a file in the pull\'s diff, "line": its line number, "side": "new" (the head\'s numbering, for added or kept lines) or "old" (the base\'s, for removed lines)}; the line must be inside one of the diff\'s hunks: in `@@ -a,b +c,d @@` the hunk\'s first line is c on the new side and a on the old. GET …/pulls/N returns the diff.'; |
| 812 | 812 | |
| 813 | /** A review's line comments as the API was sent them; undefined when they are not a list of objects. */ | |
| 813 | /** | |
| 814 | * A review's line comments as the API was sent them; undefined when they are not a list of objects. | |
| 815 | */ | |
| 814 | 816 | function reviewLines(raw: unknown): ReviewInput[] | undefined { |
| 815 | 817 | if (raw === undefined || raw === null) return []; |
| 816 | 818 | // The cap is `submitReview`'s to refuse, by name (`too_many_lines`). |
| @@ -1969,7 +1971,8 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 1969 | 1971 | const from = at + 1; |
| 1970 | 1972 | const items = all.slice(from, from + limit); |
| 1971 | 1973 | const more = from + limit < all.length; |
| 1972 | // The tag is of the exact bytes sent: a pushed, moved or deleted tag changes them, and so does the page. | |
| 1974 | // The tag is of the exact bytes sent: a pushed, moved or deleted tag changes them, and so | |
| 1975 | // does the page. | |
| 1973 | 1976 | const text = JSON.stringify({ items, next_cursor: more ? items[items.length - 1]!.name : null }); |
| 1974 | 1977 | const etag = weakEtag(text); |
| 1975 | 1978 | const headers = { etag, "cache-control": "private, no-cache", vary: "authorization, cookie" }; |
| @@ -2419,8 +2422,8 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 2419 | 2422 | }, |
| 2420 | 2423 | ); |
| 2421 | 2424 | // One action on a whole limb (#733): defer, resume, or close as not |
| 2422 | // doing, or raise or lower it among its siblings (#1064). A fleet operation in every respect — a dry run by default with a | |
| 2423 | // read credential, an admin token to apply, the receipt in | |
| 2425 | // doing, or raise or lower it among its siblings (#1064). A fleet operation in every respect — a | |
| 2426 | // dry run by default with a read credential, an admin token to apply, the receipt in | |
| 2424 | 2427 | // /api/v1/fleet/ops/:id and its undo at …/undo. |
| 2425 | 2428 | router.add( |
| 2426 | 2429 | "POST", |
| @@ -2500,7 +2503,8 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 2500 | 2503 | const since = parseSince(ctx.url.searchParams.get("since")); |
| 2501 | 2504 | if (since === undefined) return apiError("invalid_since", 422, "since is day, week or month"); |
| 2502 | 2505 | const scope = sealedScope(ctx.app.db, repo, ctx.auth.user); |
| 2503 | // Built by the map's worker, so the thread serves everything else meanwhile; a snapshot of this write clock answers at once. | |
| 2506 | // Built by the map's worker, so the thread serves everything else meanwhile; a snapshot of this | |
| 2507 | // write clock answers at once. | |
| 2504 | 2508 | const got = await snapshotMap(ctx.app, { repoId: repo.id, scope, now: new Date() }); |
| 2505 | 2509 | if (got === undefined) return notFound(); |
| 2506 | 2510 | // The growth line is read here, not in the snapshot: it moves with the clock, not with writes. |
| @@ -2539,7 +2543,8 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 2539 | 2543 | }); |
| 2540 | 2544 | }); |
| 2541 | 2545 | // What people asked of the crew in the repositories the caller can write — |
| 2542 | // by default what has nothing merged yet, oldest first — and what became of each (core/asked.ts, the /asked page). | |
| 2546 | // by default what has nothing merged yet, oldest first — and what became of each (core/asked.ts, | |
| 2547 | // the /asked page). | |
| 2543 | 2548 | router.add("GET", "/api/v1/asked", (ctx) => { |
| 2544 | 2549 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 2545 | 2550 | const denied = requireScope(ctx, "ro"); |
| @@ -2658,8 +2663,8 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 2658 | 2663 | ...(states[i] ?? {}), |
| 2659 | 2664 | })); |
| 2660 | 2665 | }); |
| 2661 | // The tag is of the exact bytes sent, so a new verdict, head or state is never hidden behind a 304; | |
| 2662 | // the page, state, limit, cursor and fields are in the body or the query that chose it. | |
| 2666 | // The tag is of the exact bytes sent, so a new verdict, head or state is never hidden behind a | |
| 2667 | // 304; the page, state, limit, cursor and fields are in the body or the query that chose it. | |
| 2663 | 2668 | return timePhase(ctx.request, "render", () => { |
| 2664 | 2669 | const text = JSON.stringify(paged(items, query.limit, (p) => p.number)); |
| 2665 | 2670 | const etag = weakEtag(text); |
| @@ -2851,7 +2856,8 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 2851 | 2856 | ...(diff === undefined ? {} : { diff }), |
| 2852 | 2857 | hold: hold === undefined ? null : holdJson(hold), |
| 2853 | 2858 | }); |
| 2854 | // Tagged by the exact bytes sent, after access was checked: a new head, verdict, review or merge is never hidden behind a 304. | |
| 2859 | // Tagged by the exact bytes sent, after access was checked: a new head, verdict, review or | |
| 2860 | // merge is never hidden behind a 304. | |
| 2855 | 2861 | const etag = weakEtag(text); |
| 2856 | 2862 | const headers = { etag, "cache-control": "private, no-cache", vary: "authorization, cookie" }; |
| 2857 | 2863 | if (holds(ctx.request, etag)) return new Response(null, { status: 304, headers }); |
| @@ -3535,8 +3541,11 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 3535 | 3541 | |
| 3536 | 3542 | // How the forge is: anyone may ask (a monitor has no account), a stranger |
| 3537 | 3543 | // is told little, the release machinery's probe and a site admin the |
| 3538 | // whole of it (`actions/health.ts`). | |
| 3539 | router.add("GET", "/api/v1/health", (ctx) => { | |
| 3544 | // whole of it (`actions/health.ts`). `/health` is the same answer at the | |
| 3545 | // path an uptime monitor tries first (#13191); `/healthz` stays the | |
| 3546 | // liveness probe's (`http/health.ts`), which must not turn red on a | |
| 3547 | // drain or a broken cause, or the orchestrator restarts a busy forge. | |
| 3548 | const healthRoute: Handler = (ctx) => { | |
| 3540 | 3549 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); |
| 3541 | 3550 | const body = timePhase(ctx.request, "health", () => |
| 3542 | 3551 | healthAnswer(ctx.app, ctx.auth.user, isProbe(ctx.request, ctx.app.config.dataDir)), |
| @@ -3544,7 +3553,9 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 3544 | 3553 | return timePhase(ctx.request, "render", () => |
| 3545 | 3554 | json(body, 200, { "cache-control": "no-store", vary: "authorization, cookie, x-forge-probe" }), |
| 3546 | 3555 | ); |
| 3547 | }); | |
| 3556 | }; | |
| 3557 | router.add("GET", "/api/v1/health", healthRoute); | |
The issue asks for /healthz, not /health. Add /healthz here (or move the orchestrator probe), or have the issue amended. |
||
| 3558 | router.add("GET", "/health", healthRoute); | |
| 3548 | 3559 | |
| 3549 | 3560 | // Open egress connections per app and destination, as Prometheus text |
| 3550 | 3561 | // (#3719). Repository names are in the labels, so a site admin only. |
| @@ -3712,8 +3723,8 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 3712 | 3723 | return kept ? json(await beatAnswer(ctx.app, raw)) : apiError("not_found", 404, "no such door"); |
| 3713 | 3724 | }); |
| 3714 | 3725 | |
| 3715 | // A child asking its parent to broker an origin sign-in (`spawn/origin_broker.ts`): signed with the | |
| 3716 | // heartbeat key; every refusal is the same 404, so nothing says who is a child. | |
| 3726 | // A child asking its parent to broker an origin sign-in (`spawn/origin_broker.ts`): signed with | |
| 3727 | // the heartbeat key; every refusal is the same 404, so nothing says who is a child. | |
| 3717 | 3728 | router.add("POST", "/api/v1/broker/origins", async (ctx) => { |
| 3718 | 3729 | const bytes = await readBounded(ctx.request, CALL_BODY_MAX); |
| 3719 | 3730 | if (bytes === "too_large") return apiError("not_found", 404, "no such door"); |
src/http/asset_miss.ts +1 −1
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | |
| 7 | 7 | const ASSET_EXTENSION = /\.(?:xml|json|txt|js|css|map|png|ico)$/; |
| 8 | 8 | /** Machine surfaces that keep their own JSON miss; the one list server.ts shares. */ |
| 9 | export const MACHINE_PREFIX = /^\/(?:api|contract|mcp|oauth|\.well-known|metrics|healthz)(?:\/|$)/; | |
| 9 | export const MACHINE_PREFIX = /^\/(?:api|contract|mcp|oauth|\.well-known|metrics|health|healthz|readyz)(?:\/|$)/; | |
| 10 | 10 | |
| 11 | 11 | export function isAssetMiss(request: Request, pathname: string): boolean { |
| 12 | 12 | if (request.method !== "GET" && request.method !== "HEAD") return false; |
src/http/route_marks.ts +13 −3
| @@ -16,7 +16,10 @@ import { Router } from "./router.ts"; | ||
| 16 | 16 | |
| 17 | 17 | export type Mark = "admin" | "open"; |
| 18 | 18 | |
| 19 | /** Every head of a registered route: one mark for all of it, or `mixed` when each route is listed below. */ | |
| 19 | /** | |
| 20 | * Every head of a registered route: one mark for all of it, or `mixed` when each route is listed | |
| 21 | * below. | |
| 22 | */ | |
| 20 | 23 | export const HEADS: Readonly<Record<string, Mark | "mixed">> = { |
| 21 | 24 | "/": "open", |
| 22 | 25 | "/-": "open", |
| @@ -140,6 +143,7 @@ export const HEADS: Readonly<Record<string, Mark | "mixed">> = { | ||
| 140 | 143 | "/maintenance": "admin", |
| 141 | 144 | "/manifest.webmanifest": "open", |
| 142 | 145 | "/map": "open", |
| 146 | "/health": "open", | |
| 143 | 147 | "/mcp": "open", |
| 144 | 148 | "/metrics": "open", |
| 145 | 149 | "/migrate": "open", |
| @@ -422,7 +426,10 @@ export function markOf(pattern: string): Mark | undefined { | ||
| 422 | 426 | } |
| 423 | 427 | |
| 424 | 428 | let listed: Router<Mark> | undefined; |
| 425 | /** ROUTES as a matcher, literal segments before parameters so `/packs/new` is not read as `/packs/:name`. */ | |
| 429 | /** | |
| 430 | * ROUTES as a matcher, literal segments before parameters so `/packs/new` is not read as | |
| 431 | * `/packs/:name`. | |
| 432 | */ | |
| 426 | 433 | function listedRoutes(): Router<Mark> { |
| 427 | 434 | if (listed !== undefined) return listed; |
| 428 | 435 | const params = (p: string) => p.split("/").filter((s) => s.startsWith(":") || s.startsWith("*")).length; |
| @@ -432,7 +439,10 @@ function listedRoutes(): Router<Mark> { | ||
| 432 | 439 | return (listed = matcher); |
| 433 | 440 | } |
| 434 | 441 | |
| 435 | /** Whether a request path falls on a route marked `admin`; unlisted under a `mixed` head counts as `admin`. */ | |
| 442 | /** | |
| 443 | * Whether a request path falls on a route marked `admin`; unlisted under a `mixed` head counts as | |
| 444 | * `admin`. | |
| 445 | */ | |
| 436 | 446 | export function isAdminRoute(path: string): boolean { |
| 437 | 447 | const own = listedRoutes().match("*", path); |
| 438 | 448 | if (own !== undefined) return own.handler === "admin"; |
src/http/server.ts +12 −7
| @@ -912,7 +912,8 @@ export function buildRouter(): Router<Handler> { | ||
| 912 | 912 | router.add("GET", "/", home); |
| 913 | 913 | // The home is `/`; its old address goes there (web/pages/home_flow.ts). Literal, above /:owner. |
| 914 | 914 | router.add("GET", "/home", homeRedirect); |
| 915 | // The new home's action bar: preview or apply one bulk action over the rows picked (web/pages/home_table.ts). | |
| 915 | // The new home's action bar: preview or apply one bulk action over the rows picked | |
| 916 | // (web/pages/home_table.ts). | |
| 916 | 917 | router.add("POST", "/home/act", homeActPost); |
| 917 | 918 | router.add("POST", "/desk", deskLeave); |
| 918 | 919 | router.add("POST", "/desk/clear", deskClear); |
| @@ -1044,7 +1045,8 @@ export function buildRouter(): Router<Handler> { | ||
| 1044 | 1045 | router.add("GET", "/new/issue", newIssueAnywhere); |
| 1045 | 1046 | router.add("GET", "/repos", myReposPage); |
| 1046 | 1047 | router.add("GET", "/displays", displaysPage); |
| 1047 | // A repository's display, read only (`display.ts`): 404 without a display.json or without read access. | |
| 1048 | // A repository's display, read only (`display.ts`): 404 without a display.json or without read | |
| 1049 | // access. | |
| 1048 | 1050 | router.add("GET", "/:owner/:name/display", displayPage); |
| 1049 | 1051 | router.add("POST", "/:owner/:name/display", displayChoose); |
| 1050 | 1052 | router.add("GET", "/now/:stage", nowPage); |
| @@ -1080,8 +1082,9 @@ export function buildRouter(): Router<Handler> { | ||
| 1080 | 1082 | router.add("GET", "/migrate/jobs/:job", migrationJobPage); |
| 1081 | 1083 | // Every app on one canvas; a literal route, so it must sit above /:owner. |
| 1082 | 1084 | router.add("GET", "/map", globalMapPage); |
| 1083 | // The pipeline moved to a panel on /boards (#2774); the old address follows it. Literal, above /:owner. | |
| 1084 | // /flow is the week's valves (#8698); a query string is an old pipeline drill, which went to /boards. | |
| 1085 | // The pipeline moved to a panel on /boards (#2774); the old address follows it. Literal, above | |
| 1086 | // /:owner. /flow is the week's valves (#8698); a query string is an old pipeline drill, which | |
| 1087 | // went to /boards. | |
| 1085 | 1088 | router.add("GET", "/flow", flowPage); |
| 1086 | 1089 | router.add("POST", "/flow/valve", valveSet); |
| 1087 | 1090 | router.add("POST", "/flow/backup/retry", backupRetry); |
| @@ -2733,7 +2736,8 @@ export async function serve(app: App): Promise<Servers> { | ||
| 2733 | 2736 | }); |
| 2734 | 2737 | // The minute ledger's history: one write a minute, never on a request. |
| 2735 | 2738 | const trafficWriter = createTrafficWriter(app.db, liveOf(app).perfRecord.ledger, app.log); |
| 2736 | // Page views are buffered by the beacon doors and written here; GitHub's traffic is pulled daily when a token is set. | |
| 2739 | // Page views are buffered by the beacon doors and written here; GitHub's traffic is pulled daily | |
| 2740 | // when a token is set. | |
| 2737 | 2741 | const viewWriter = createViewWriter(app.db, app.log); |
| 2738 | 2742 | const githubPull = startGithubPull(app.db, app.log); |
| 2739 | 2743 | const featureSchedule = startFeatureSchedule(app); |
| @@ -3188,8 +3192,9 @@ async function answerGet( | ||
| 3188 | 3192 | // generic as `/:owner/:name` can never claim it — a route added there |
| 3189 | 3193 | // next year still can't bring the HTML 404 back for an API caller. |
| 3190 | 3194 | const isApiPath = url.pathname === "/api" || url.pathname.startsWith("/api/"); |
| 3191 | // `/metrics` is the API router's too: a scraper, not a page. | |
| 3192 | const matched = isApiPath || url.pathname === "/metrics" | |
| 3195 | // `/metrics` is the API router's too: a scraper, not a page; and | |
| 3196 | // `/health`, a monitor's (#13191). | |
| 3197 | const matched = isApiPath || url.pathname === "/metrics" || url.pathname === "/health" | |
| 3193 | 3198 | ? apiRouter.match(routeMethod, url.pathname) |
| 3194 | 3199 | : router.match(routeMethod, url.pathname); |
| 3195 | 3200 | if (!matched) { |
src/web/standards.ts +23 −5
| @@ -131,7 +131,10 @@ export function securityTxt(ctx: Ctx): Response { | ||
| 131 | 131 | ); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | /** A discovery document and its ETag, per kind and origin, made again only when its inputs read differently. */ | |
| 134 | /** | |
| 135 | * A discovery document and its ETag, per kind and origin, made again only when its inputs read | |
| 136 | * differently. | |
| 137 | */ | |
| 135 | 138 | const discoveryBodies = new Map<string, { inputs: string; body: string; etag: string }>(); |
| 136 | 139 | |
| 137 | 140 | /** |
| @@ -147,7 +150,8 @@ function discovery(ctx: Ctx, kind: string, inputs: string, make: () => unknown, | ||
| 147 | 150 | const etag = `"${new Bun.CryptoHasher("sha256").update(body).digest("hex").slice(0, 32)}"`; |
| 148 | 151 | kept = { inputs, body, etag }; |
| 149 | 152 | // Origins come from the Host header: keep a handful, not one per guess. |
| 150 | // The oldest goes first (a Map keeps insertion order), so junk hosts never flush the real ones at once. | |
| 153 | // The oldest goes first (a Map keeps insertion order), so junk hosts never flush the real ones | |
| 154 | // at once. | |
| 151 | 155 | discoveryBodies.delete(key); |
| 152 | 156 | if (discoveryBodies.size >= 48) discoveryBodies.delete(discoveryBodies.keys().next().value!); |
| 153 | 157 | discoveryBodies.set(key, kept); |
| @@ -177,12 +181,18 @@ export async function agentCardJson(ctx: Ctx): Promise<Response> { | ||
| 177 | 181 | return discovery(ctx, `agent-card ${signedIn}`, JSON.stringify([now.version, toolsKey()]), () => agentCard(ctx.url.origin, now, signedIn), "application/json", signedIn ? "private, max-age=3600" : "public, max-age=3600", true, "Cookie, Authorization"); |
| 178 | 182 | } |
| 179 | 183 | |
| 180 | /** GET /.well-known/api-catalog — RFC 9727: one linkset naming each API's description and docs. Anonymous. */ | |
| 184 | /** | |
| 185 | * GET /.well-known/api-catalog — RFC 9727: one linkset naming each API's description and docs. | |
| 186 | * Anonymous. | |
| 187 | */ | |
| 181 | 188 | export function apiCatalogJson(ctx: Ctx): Response { |
| 182 | 189 | return discovery(ctx, "api-catalog", "", () => apiCatalog(ctx.url.origin), 'application/linkset+json; profile="https://www.rfc-editor.org/info/rfc9727"', "public, max-age=300"); |
| 183 | 190 | } |
| 184 | 191 | |
| 185 | /** GET /.well-known/forge — the standards this forge implements, by id and version (docs/standards/). */ | |
| 192 | /** | |
| 193 | * GET /.well-known/forge — the standards this forge implements, by id and version | |
| 194 | * (docs/standards/). | |
| 195 | */ | |
| 186 | 196 | export function forgeJson(ctx: Ctx): Response { |
| 187 | 197 | const version = running().version; |
| 188 | 198 | return discovery(ctx, "forge", version, () => forgeDocument(version), "application/json", "public, max-age=3600"); |
| @@ -244,6 +254,11 @@ export function robotsTxt(ctx: Ctx): Response { | ||
| 244 | 254 | "Disallow: /settings", |
| 245 | 255 | "Disallow: /search", |
| 246 | 256 | "Disallow: /api/", |
| 257 | // A probe's answers, never a page (#13191); `$` so a profile named | |
| 258 | // `healthy` stays open. | |
| 259 | "Disallow: /health$", | |
| 260 | "Disallow: /healthz$", | |
| 261 | "Disallow: /readyz$", | |
| 247 | 262 | // The deep paths, at every ref and in every mirror: each is a git walk |
| 248 | 263 | // (#8129). Repository roots, docs and the home page stay open. |
| 249 | 264 | ...DEEP_SEGMENTS.map((segment) => `Disallow: /*/*/${segment}`), |
| @@ -419,7 +434,10 @@ function runningSentence(): string { | ||
| 419 | 434 | : `Running ${r.version} at ${r.commit.slice(0, 7)}`; |
| 420 | 435 | } |
| 421 | 436 | |
| 422 | /** llms.txt and its ETag per origin, valid while the listing read, the build, the tell command and the plugin source being public are the same. */ | |
| 437 | /** | |
| 438 | * llms.txt and its ETag per origin, valid while the listing read, the build, the tell command and | |
| 439 | * the plugin source being public are the same. | |
| 440 | */ | |
| 423 | 441 | const llmsBodies = new Map<string, { repos: LlmsListing; running: string; tell: string | undefined; plugins: string | undefined; plans: string; tools: number; body: string; etag: string }>(); |
| 424 | 442 | |
| 425 | 443 | /** |
test/health.test.ts +47
| @@ -12,6 +12,8 @@ import { | ||
| 12 | 12 | readyResponse, |
| 13 | 13 | startDraining, |
| 14 | 14 | } from "../src/http/health.ts"; |
| 15 | import { openapi } from "../src/contract/openapi.ts"; | |
| 16 | import { reservedName } from "../src/core/reserved.ts"; | |
| 15 | 17 | import { serve, type Servers } from "../src/http/server.ts"; |
| 16 | 18 | import { ownProbeHeaders } from "../src/kernel/probe.ts"; |
| 17 | 19 | import { running } from "../src/kernel/version.ts"; |
| @@ -144,6 +146,51 @@ describe("the served paths", () => { | ||
| 144 | 146 | expect((await fetch(`${servers.url}/`)).status).toBe(200); |
| 145 | 147 | }); |
| 146 | 148 | |
| 149 | // A monitor tries /health first and must hear the report, not a 10 KB page (#13191). | |
| 150 | test("/health answers what /api/v1/health answers, without a cookie, behind the security floor", async () => { | |
| 151 | const strip = (b: Record<string, unknown>) => ({ ...b, at: undefined }); | |
| 152 | for (const draining of [false, true]) { | |
| 153 | if (draining) startDraining(recordingLog(), "SIGTERM"); | |
| 154 | const [short, long] = await Promise.all([ | |
| 155 | fetch(`${servers.url}/health`), | |
| 156 | fetch(`${servers.url}/api/v1/health`), | |
| 157 | ]); | |
| 158 | expect(short.status).toBe(long.status); | |
| 159 | expect(short.headers.get("content-type")).toContain("application/json"); | |
| 160 | const body = (await short.json()) as Record<string, unknown>; | |
| 161 | expect(strip(body)).toEqual(strip((await long.json()) as Record<string, unknown>)); | |
| 162 | expect(body.draining).toBe(draining); | |
| 163 | expect(short.headers.get("set-cookie")).toBeNull(); | |
| 164 | expect(short.headers.get("cache-control")).toBe("no-store"); | |
| 165 | expect(short.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 166 | expect(short.headers.get("referrer-policy")).toBeTruthy(); | |
| 167 | expect(short.headers.get("content-security-policy")).toBeTruthy(); | |
| 168 | } | |
| 169 | // The liveness probe keeps its own answer through the drain. | |
| 170 | expect((await fetch(`${servers.url}/healthz`)).status).toBe(200); | |
| 171 | }); | |
| 172 | ||
| 173 | test("robots.txt keeps crawlers off the probes' paths, and the sitemap names none", async () => { | |
| 174 | const robots = await (await fetch(`${servers.url}/robots.txt`)).text(); | |
| 175 | for (const path of ["/health", "/healthz", "/readyz"]) expect(robots).toContain(`Disallow: ${path}$`); | |
| 176 | const sitemap = await (await fetch(`${servers.url}/sitemap.xml`)).text(); | |
| 177 | expect(sitemap).not.toMatch(/\/(?:health|healthz|readyz)</); | |
| 178 | // Nobody can take a probe's path as a profile. | |
| 179 | for (const name of ["health", "healthz", "readyz"]) expect(reservedName(app.db, name)).toBe("system"); | |
| 180 | }); | |
| 181 | ||
| 182 | // The document's server is the bare origin, so `/health` is the root path, not a second | |
| 183 | // /api/v1/health. | |
| 184 | test("the OpenAPI document lists /health at the root, beside /api/v1/health", () => { | |
| 185 | const doc = openapi("https://forge.example", "1", "anonymous") as { | |
| 186 | servers: { url: string }[]; | |
| 187 | paths: Record<string, Record<string, unknown>>; | |
| 188 | }; | |
| 189 | expect(doc.servers).toEqual([{ url: "https://forge.example" }]); | |
| 190 | expect(doc.paths["/health"]?.["get"]).toBeDefined(); | |
| 191 | expect(doc.paths["/api/v1/health"]?.["get"]).toBeDefined(); | |
| 192 | }); | |
| 193 | ||
| 147 | 194 | test("HEAD /readyz is 200 with an empty body", async () => { |
| 148 | 195 | const head = await fetch(`${servers.url}/readyz`, { method: "HEAD" }); |
| 149 | 196 | expect(head.status).toBe(200); |
test/openapi-drift.test.ts +4 −2
| @@ -10,6 +10,7 @@ const NOT_ROUTED: Readonly<Record<string, string>> = { | ||
| 10 | 10 | "GET /contract/openapi.json": "the document, an alias of /api/v1/openapi.json served outside /api/v1", |
| 11 | 11 | "GET /api/v1/repos/{}/{}/app/production/open": "the described form of the routed /app/:env/open, with env fixed to production", |
| 12 | 12 | "GET /metrics": "routed outside /api/v1 (src/http/api.ts); the scan reads /api/v1 routes only", |
| 13 | "GET /health": "routed outside /api/v1 (src/http/api.ts), the monitor's alias of /api/v1/health (#13191)", | |
| 13 | 14 | "GET /{}/{}/pulls/{}/check.txt": "routed outside /api/v1 (src/http/server.ts, check_text.ts); test/openapi-check-txt.test.ts pins it to server.ts", |
| 14 | 15 | "POST /mcp": "routed outside /api/v1 (src/http/mcp.ts); the MCP has its own card and tool list", |
| 15 | 16 | }; |
| @@ -83,8 +84,9 @@ test("every operation names its role, as the pinned list says", () => { | ||
| 83 | 84 | /** |
| 84 | 85 | * The routes that need a signed-in account but refuse a bearer token: a browser |
| 85 | 86 | * session or the password, never a token (`auth` false, role `member`). Pinned |
| 86 | * from the handlers in src/http/api/tokens.ts, src/http/api.ts and src/http/api/conversation_confirms.ts. | |
| 87 | * `DELETE /api/v1/sessions` is not here: without a session it answers 200 all the same. | |
| 87 | * from the handlers in src/http/api/tokens.ts, src/http/api.ts and | |
| 88 | * src/http/api/conversation_confirms.ts. `DELETE /api/v1/sessions` is not here: without a session | |
| 89 | * it answers 200 all the same. | |
| 88 | 90 | */ |
| 89 | 91 | const SESSION_ONLY: ReadonlySet<string> = new Set([ |
| 90 | 92 | "GET /api/v1/tokens", |
test/security-sweep.test.ts +1
| @@ -73,6 +73,7 @@ const NO_405: Record<string, string> = { | ||
| 73 | 73 | "/api/v1": "the API root is read-only and answers a write as it always did: no route (`answerGet`, src/http/server.ts)", |
| 74 | 74 | "/api/v1/": "the API root with its slash, the same read-only root as /api/v1", |
| 75 | 75 | "/metrics": "a scraper's path outside /api/, so its miss is the machine-path 404, not the API's 405", |
| 76 | "/health": "a monitor's path outside /api/ (#13191), so its miss is the machine-path 404 as /metrics's is", | |
| 76 | 77 | }; |
| 77 | 78 | |
| 78 | 79 | /** Cookies a page's own script must read, so not HttpOnly → why. */ |
new above
offline
Path '/health' is rendered under the /api/v1 base by the generator, so this likely documents /api/v1/health twice rather than the root /health; confirm in the generated document.