Public: anyone can read this; the crew can change it.

Health tells a stranger only ok and draining #16604

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

torque/forge:torque/16262-health-tells-a-stranger-only-ok-and-drai → main 0 commits fork

  • Merged. torque/16262-health-tells-a-stranger-only-ok-and-drai was merged into main as 5bede01.

Review

Sign in to review this change.
10 files changed +54 −25
scripts/forge-compat-lab/driver.ts +4 −3
@@ -225,11 +225,12 @@ const results = async (): Promise<void> => {
225225 /** Direct answers of a source forge's own endpoints, no receiver in between. */
226226 const probeSource = async (name: string, s: string, seed: Seed): Promise<void> => {
227227 const tag = name;
228 await cell(tag, "1 discovery", "health names version and commit", async () => {
228 // A forge tells a stranger only ok and draining on health (#16262); the API version is public.
229 await cell(tag, "1 discovery", "health says ok; version names the API", async () => {
229230 const h = await api(s, "/api/v1/health", "");
230 must(h.status === 200 && typeof h.data.version === "string", `health ${h.status}`);
231 must(h.status === 200 && typeof h.data.ok === "boolean", `health ${h.status}`);
231232 const v = await api(s, "/api/v1/version", "");
232 return `version ${h.data.version}; /api/v1/version ${v.status}; /user/repos ${(await api(s, "/api/v1/user/repos", `Bearer ${seed.ann.ro}`)).status}`;
233 return `version ${h.data.version ?? v.data?.version ?? "unsaid"}; /api/v1/version ${v.status}; /user/repos ${(await api(s, "/api/v1/user/repos", `Bearer ${seed.ann.ro}`)).status}`;
233234 });
234235 for (const [scheme, header] of [
235236 ["Bearer", `Bearer ${seed.ann.ro}`],
src/actions/health.ts +9 −11
@@ -4,11 +4,10 @@
44 *
55 * - a stranger learns whether the forge is well and whether it is draining,
66 * how many schedules are overdue and by how long the worst one is (counts
7 * only, no app or repository: #12512), and nothing of the platform's
8 * incidents or rollout. It is also told the
9 * version and commit for one release more — a running forge's swap reads
10 * its successor's commit without a probe (`release/swap.ts` before #2917);
11 * once that forge is gone the stranger's answer is `ok` alone.
7 * only, no app or repository: #12512), the release number (#13263), and
8 * nothing of the commit, the platform's incidents or rollout (#16262):
9 * every swap, boot, launch, rollback and proof that reads the commit sends
10 * the probe.
1211 * - anyone signed in, and the forge's own release machinery carrying the
1312 * probe (`kernel/probe.ts`), get the whole answer: version, commit,
1413 * rollout and the platform's incidents.
@@ -111,11 +110,10 @@ export function withHeavyAskers(v: Vitals, app: App, now: number = Date.now()):
111110 }
112111
113112 /**
114 * What a stranger is told: no incident, no rollout, no platform words.
115 * Version and commit stay for one release, while a running forge's swap
116 * reads its successor's commit without the probe; #2962 removes them.
113 * What a stranger is told: whether the forge is well and whether it is draining. No version,
114 * commit, incident, rollout or platform words (#16262); the release machinery carries the probe.
117115 */
118 export type StrangerHealth = Pick<ForgeHealth, "ok" | "version" | "commit" | "draining">;
116 export type StrangerHealth = Pick<ForgeHealth, "ok" | "draining">;
119117
120118 /** The optional parts beside the health of anyone signed in (`system/footprint.ts`). */
121119 export interface Parts {
@@ -164,8 +162,8 @@ export function readHealth(
164162 ): StrangerHealth | ForgeHealth | (ForgeHealth & Parts) | (Vitals & ForgeHealth & Parts) {
165163 const health = forgeHealth();
166164 if (actor === undefined && !probe) {
167 const { ok, version, commit, draining } = health;
168 return { ok, version, commit, draining };
165 const { ok, draining } = health;
166 return { ok, draining };
169167 }
170168 // A probe without an actor keeps the forge's own shape: no parts, no memory class.
171169 if (actor === undefined) return health;
src/tui/screens/system.ts +3 −1
@@ -124,7 +124,9 @@ const capOf = (g: SystemView["groups"][number]): string =>
124124 * incidents, so it never has a second line.
125125 */
126126 export function forgeLines(h: ReturnType<typeof readHealth>, inner = WIDTH - 6): string[] {
127 const head = `forge ${h.version} · ${h.commit === null ? "no commit" : h.commit.slice(0, 7)} · ${h.draining ? "draining" : "serving"}`;
127 const serving = h.draining ? "draining" : "serving";
128 // A stranger is told no version or commit (#16262).
129 const head = "version" in h ? `forge ${h.version} · ${h.commit === null ? "no commit" : h.commit.slice(0, 7)} · ${serving}` : `forge · ${serving}`;
128130 if (!("incidents" in h)) return [head];
129131 const full = h as ForgeHealth;
130132 const rollout = rolloutLine(full);
test/app-release-15497.test.ts +6 −1
@@ -16,6 +16,7 @@ import { serve, type Servers } from "../src/http/server.ts";
1616 import { appEnv } from "../src/apps/process.ts";
1717 import { newestRelease, releaseAt } from "../src/apps/release_at.ts";
1818 import { releaseOf, running } from "../src/kernel/version.ts";
19 import { ownProbeHeaders } from "../src/kernel/probe.ts";
1920
2021 const git = (cwd: string, ...args: string[]): string => {
2122 const r = Bun.spawnSync(["git", "-c", "user.name=t", "-c", "[email protected]", "-c", "tag.gpgSign=false", "-c", "commit.gpgSign=false", ...args], { cwd });
@@ -125,7 +126,11 @@ describe("/api/v1/health on an unstamped production app", () => {
125126 });
126127
127128 test("names the release its commit is at, not null", async () => {
128 const health = (await (await fetch(`${servers.url}/api/v1/health`)).json()) as Record<string, unknown>;
129 // The commit and version go to the probe alone (#16262); the release number to anyone.
130 const told = (await (await fetch(`${servers.url}/api/v1/health`)).json()) as Record<string, unknown>;
131 expect(told["release"]).toBe("0.7.629");
132 expect(told["commit"]).toBeUndefined();
133 const health = (await (await fetch(`${servers.url}/api/v1/health`, { headers: ownProbeHeaders(dataDir) })).json()) as Record<string, unknown>;
129134 expect(health["release"]).toBe("0.7.629");
130135 expect(health["commit"]).toBe("1701de1790eb21474f584fed5b02accf0b839434");
131136 expect(health["version"]).toBe("dev");
test/health-schedules.test.ts +7 −2
@@ -14,6 +14,7 @@ import { createUser } from "../src/core/users.ts";
1414 import { OVERDUE_AFTER_MS, overdueSchedules, recordRun, setPaused, scheduleTimer, syncSchedules } from "../src/core/timers.ts";
1515 import { releaseOf, running, UNSTAMPED } from "../src/kernel/version.ts";
1616 import { serve, type Servers } from "../src/http/server.ts";
17 import { ownProbeHeaders } from "../src/kernel/probe.ts";
1718 import { openapi } from "../src/contract/openapi.ts";
1819
1920 let dataDir: string;
@@ -74,7 +75,7 @@ test("a schedule due inside the loop's slack is not overdue; one past it is, wit
7475
7576 const text = await strangerHealth();
7677 const body = JSON.parse(text) as { schedules: { overdue: number; oldestSeconds: number; total: number } };
77 expect(Object.keys(body).sort()).toEqual(["commit", "draining", "ok", "release", "schedules", "version"]);
78 expect(Object.keys(body).sort()).toEqual(["draining", "ok", "release", "schedules"]);
7879 expect(body.schedules.overdue).toBe(1);
7980 expect(body.schedules.total).toBe(read.total);
8081 expect(body.schedules.oldestSeconds).toBeGreaterThanOrEqual(read.oldestSeconds);
@@ -93,7 +94,11 @@ test("a paused schedule is not overdue", async () => {
9394 });
9495
9596 test("a build with no release says release null, and version is unchanged (#13263)", async () => {
96 const body = JSON.parse(await strangerHealth()) as { version: unknown; release: unknown };
97 const told = JSON.parse(await strangerHealth()) as { version: unknown; release: unknown };
98 expect(told.release).toBeNull();
99 // The version goes to the probe alone (#16262), as the swap and the keeper send it.
100 const res = await fetch(servers.url + "/api/v1/health", { headers: ownProbeHeaders(dataDir) });
101 const body = (await res.json()) as { version: unknown; release: unknown };
97102 // The test forge is built from no release: version keeps its word for the swap and the
98103 // keeper, release says there is none rather than passing that word off as a version.
99104 expect(body.version).toBe(running().version);
test/health.test.ts +12
@@ -136,6 +136,18 @@ describe("the served paths", () => {
136136 }
137137 });
138138
139 test("a stranger hears ok and draining; the probe also hears version and commit (#16262)", async () => {
140 for (const path of ["/api/v1/health", "/health"]) {
141 for (const headers of [{}, { "x-forge-probe": "guess" }]) {
142 const told = (await (await fetch(`${servers.url}${path}`, { headers })).json()) as Record<string, unknown>;
143 expect(Object.keys(told).sort()).toEqual(["draining", "ok", "release", "schedules"]);
144 }
145 const probed = (await (await fetch(`${servers.url}${path}`, { headers: ownProbeHeaders(dataDir) })).json()) as Record<string, unknown>;
146 expect(probed["version"]).toBe(running().version);
147 expect(probed["commit"]).toBe(running().commit);
148 }
149 });
150
139151 test("a drain turns /readyz into 503; /healthz and the landing page stay up", async () => {
140152 expect((await fetch(`${servers.url}/readyz`)).status).toBe(200);
141153 startDraining(recordingLog(), "SIGTERM");
test/status-page.test.ts +3 −1
@@ -4,6 +4,7 @@ import { tmpdir } from "node:os";
44 import { join } from "node:path";
55 import { createApp, type App } from "../src/app.ts";
66 import { serve, type Servers } from "../src/http/server.ts";
7 import { ownProbeHeaders } from "../src/kernel/probe.ts";
78 import { asOfWords, rowWords, statusJson, statusOf, statusReuse, statusWords, type StatusInput } from "../src/core/status_words.ts";
89 import { statusBuilds } from "../src/web/pages/status.ts";
910 import { createForgeApp, forgeCommands, Session } from "../src/tui/forge.ts";
@@ -219,7 +220,8 @@ describe("GET /status", () => {
219220 process.env["FORGE_VERSION"] = "v9.8.7";
220221 try {
221222 const s = (await (await fetch(`${base}/status`, { headers: { accept: "application/json" } })).json()) as Record<string, unknown>;
222 const h = (await (await fetch(`${base}/api/v1/health`)).json()) as Record<string, unknown>;
223 // The commit goes to the probe alone on health (#16262); /status says it to anyone.
224 const h = (await (await fetch(`${base}/api/v1/health`, { headers: ownProbeHeaders(dir) })).json()) as Record<string, unknown>;
223225 expect(s["commit"]).toBe(commit);
224226 expect(h["commit"]).toBe(commit);
225227 expect(s["short"]).toBe("0123456");
test/tui-system.test.ts +2 −2
@@ -442,9 +442,9 @@ describe("tui system: the forge's own state (#7296)", () => {
442442 }
443443 });
444444
445 test("a stranger's answer, as MCP gives it, never has a second line", async () => {
445 test("a stranger's answer, as MCP gives it, never has a second line, version or commit (#16262)", async () => {
446446 await seed({ down: "the edge answered 502" });
447 expect(forgeLines(readHealth(app, undefined))).toEqual(["forge 9.8.7 · 0123456 · serving"]);
447 expect(forgeLines(readHealth(app, undefined))).toEqual(["forge · serving"]);
448448 });
449449 });
450450
test/version.test.ts +7 −3
@@ -235,8 +235,12 @@ describe("where the stamp is read", () => {
235235 await rm(dataDir, { recursive: true, force: true });
236236 });
237237
238 test("the health report says the stamp to anyone who asks", async () => {
239 const health = (await (await fetch(`${base}/api/v1/health`)).json()) as any;
238 test("the health report says the stamp to anyone signed in, and not to a stranger (#16262)", async () => {
239 const told = (await (await fetch(`${base}/api/v1/health`)).json()) as any;
240 expect([told.version, told.commit]).toEqual([undefined, undefined]);
241 const health = (await (
242 await fetch(`${base}/api/v1/health`, { headers: { authorization: `Bearer ${memberToken}` } })
243 ).json()) as any;
240244 expect([health.version, health.commit]).toEqual(["9.8.7", COMMIT]);
241245 // A site admin's fuller answer says the same.
242246 const full = (await (
@@ -330,7 +334,7 @@ describe("where the stamp is read", () => {
330334 stamp();
331335 try {
332336 const health = (await (
333 await fetch(`${base}/api/v1/health`)
337 await fetch(`${base}/api/v1/health`, { headers: { authorization: `Bearer ${memberToken}` } })
334338 ).json()) as any;
335339 expect([health.version, health.commit]).toEqual(["dev", null]);
336340 const init = await mcp(memberToken, "initialize", {
test/vitals.test.ts +1 −1
@@ -115,7 +115,7 @@ test("a site admin with a read-only token gets the shape; others get the short o
115115 expect(short["rollout"]).toBeDefined();
116116 // A stranger is told whether it is well, and no more (#2917).
117117 const stranger = (await (await health()).json()) as Record<string, unknown>;
118 expect(Object.keys(stranger).sort()).toEqual(["commit", "draining", "ok", "release", "schedules", "version"]);
118 expect(Object.keys(stranger).sort()).toEqual(["draining", "ok", "release", "schedules"]);
119119 expect((await fetch(servers.url + "/healthz")).status).toBe(200);
120120 });
121121

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs