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

A daily-proof line that got no answer reads UNKNOWN, never FAIL #15949

Merged opened this

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

Merged

torque/forge:torque/15947-a-daily-proof-line-that-got-no-answer-re → main 0 commits fork

  • Merged. torque/15947-a-daily-proof-line-that-got-no-answer-re was merged into main as e54e00b.

Review

Sign in to review this change.
3 files changed +52 −11
src/release/v1_checks.ts +4 −5
@@ -174,9 +174,6 @@ export const GATE_WORDS = "refused by this forge";
174174 export const gateRefused = (host: string): string =>
175175 `no answer: ${GATE_WORDS}: ${host} is not in this app's forge.json egress; the forge's gate refused the read, so production was not looked at`;
176176
177 /** Whether a read's words are the gate's refusal, not production's answer. */
178 export const isGateRefusal = (seen: string): boolean => seen.startsWith(`no answer: ${GATE_WORDS}:`);
179
180177 /** A promise that rejects when `signal` aborts, for a fetcher that does not listen to it. */
181178 const abortedBy = (signal: AbortSignal): Promise<never> =>
182179 new Promise((_, reject) => {
@@ -317,9 +314,11 @@ export async function probe(
317314 }
318315 }
319316
320 // 5. /healthz fast. A read the forge's own gate refused never reached production: UNKNOWN.
317 // 5. /healthz fast. A read that got no answer (thrown, refused by a gate or proxy, out of budget)
318 // never reached production, so it proves nothing: UNKNOWN, like every other line (#15947). FAIL
319 // is production answering wrongly or slowly.
321320 const health = await get("/healthz");
322 if (typeof health === "string") say("healthz fast", isGateRefusal(health) ? "UNKNOWN" : "FAIL", "/healthz", health);
321 if (typeof health === "string") say("healthz fast", "UNKNOWN", "/healthz", health);
323322 else if (health.status === 200 && health.ms <= HEALTHZ_MS) say("healthz fast", "PASS", "/healthz", `200 in ${health.ms} ms`);
324323 else say("healthz fast", "FAIL", "/healthz", `${health.status} in ${health.ms} ms (limit ${HEALTHZ_MS} ms)`);
325324
test/daily-proof.test.ts +45 −4
@@ -7,7 +7,7 @@
77 * and `GET /api/v1/proof/daily` without a token, naming the release it proved. A release no run
88 * has recorded runs the proof once, a few minutes after boot, besides the daily tick (#15937).
99 */
10 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
10 import { afterAll, beforeAll, describe, expect, spyOn, test } from "bun:test";
1111 import { mkdtemp, rm } from "node:fs/promises";
1212 import { tmpdir } from "node:os";
1313 import { join } from "node:path";
@@ -17,9 +17,9 @@ import { serve, type Servers } from "../src/http/server.ts";
1717 import { dailyProof } from "../src/maintain/duties/daily_proof.ts";
1818 import { startMaintain } from "../src/maintain/runner.ts";
1919 import type { DutyResult } from "../src/maintain/duty.ts";
20 import { lastRun, openAsks, plainEvidence, proofAlarm, proofAnswer, recordRun, SETTLE_MS, tallyWords } from "../src/release/daily_proof.ts";
20 import { lastRun, openAsks, plainEvidence, proofAlarm, proofAnswer, proveDaily, recordRun, SETTLE_MS, tallyWords } from "../src/release/daily_proof.ts";
2121 import { IN_PROCESS, ownFetcher } from "../src/release/own_fetch.ts";
22 import { OUT_OF_BUDGET, type Line } from "../src/release/v1_checks.ts";
22 import { HEALTHZ_MS, OUT_OF_BUDGET, type Line } from "../src/release/v1_checks.ts";
2323 import { Session } from "../src/tui/forge.ts";
2424 import { statusLines } from "../src/tui/screens/status.ts";
2525
@@ -175,7 +175,7 @@ describe("the daily proof", () => {
175175 expect(calls.length).toBe(3);
176176 const lines = lastRun(app.db)!.lines;
177177 expect(lines.filter((l) => l.evidence.includes(OUT_OF_BUDGET)).length).toBeGreaterThan(3);
178 expect(lines.find((l) => l.item === "healthz fast")).toMatchObject({ verdict: "FAIL", evidence: OUT_OF_BUDGET });
178 expect(lines.find((l) => l.item === "healthz fast")).toMatchObject({ verdict: "UNKNOWN", evidence: OUT_OF_BUDGET });
179179 expect(r.findings.length).toBeGreaterThan(0);
180180 await runDay(5); // all pass again, for the reads below
181181 expect(openAsks(app.db)).toEqual([]);
@@ -266,6 +266,47 @@ describe("once after each release goes live (#15937)", () => {
266266 });
267267 });
268268
269 describe("a line that got no answer is UNKNOWN, never FAIL (#15947)", () => {
270 /** The green stub forge, with `/healthz` swapped for `healthz`. */
271 const withHealthz = (healthz: () => Promise<Response>) => {
272 const green = stubForge(() => ({}), () => T0, []);
273 return (url: string, init?: RequestInit) => (new URL(url).pathname === "/healthz" ? healthz() : green(url, init));
274 };
275 const healthzLine = async (healthz: () => Promise<Response>) =>
276 (await proveDaily(BASE, "o/forge", withHealthz(healthz), T0)).find((l) => l.item === "healthz fast")!;
277
278 test("a refused fetch is UNKNOWN with its words, redacted; a slow answer is FAIL", async () => {
279 // Assembled at run time so the source holds no token-shaped literal (no-secrets-tracked).
280 const token = ["ghp", "abcdefghijklmnopqrstuvwxyz0123456789"].join("_");
281 const refused = await healthzLine(async () => {
282 throw new Error(`Proxy refused to open a tunnel: 403 Forbidden (token ${token})`);
283 });
284 expect(refused.verdict).toBe("UNKNOWN");
285 expect(refused.evidence).toStartWith("no answer: Proxy refused to open a tunnel: 403");
286 expect(plainEvidence(refused.evidence)).not.toContain(token);
287 // The probe times a read with performance.now(); the slow answer steps that clock past the
288 // limit.
289 let clock = 0;
290 const timed = spyOn(performance, "now").mockImplementation(() => clock);
291 try {
292 const slow = await healthzLine(async () => {
293 clock += HEALTHZ_MS + 60;
294 return new Response("ok");
295 });
296 expect(slow.verdict).toBe("FAIL");
297 expect(slow.evidence).toBe(`200 in ${HEALTHZ_MS + 60} ms (limit ${HEALTHZ_MS} ms)`);
298 } finally {
299 timed.mockRestore();
300 }
301 });
302
303 test("a wrong status that answered stays FAIL", async () => {
304 const down = await healthzLine(async () => new Response("down", { status: 503 }));
305 expect(down.verdict).toBe("FAIL");
306 expect(down.evidence).toStartWith("503 in ");
307 });
308 });
309
269310 describe("the forge's own origin, read in process (#15936)", () => {
270311 const GATE = "refused by this forge: forge.example:443 is not in this app's forge.json egress";
271312
test/v1-probe.test.ts +3 −2
@@ -343,7 +343,7 @@ describe("v1 probe", () => {
343343 }
344344 });
345345
346 test("a healthz production answers 503, or not at all, is still FAIL (#15935)", async () => {
346 test("a healthz production answers 503 is FAIL; one with no answer at all is UNKNOWN (#15935, #15947)", async () => {
347347 const down: typeof fetch = Object.assign(async (u: string | URL | Request, init?: RequestInit) =>
348348 String(u).endsWith("/healthz") ? new Response("down", { status: 503 }) : fetch(u, init), { preconnect: fetch.preconnect });
349349 const line = (await probe(base, "o/r", down, NOW)).find((l) => l.item === "healthz fast")!;
@@ -352,6 +352,7 @@ describe("v1 probe", () => {
352352 if (String(u).endsWith("/healthz")) throw new Error("Unable to connect");
353353 return fetch(u, init);
354354 }, { preconnect: fetch.preconnect });
355 expect((await probe(base, "o/r", gone, NOW)).find((l) => l.item === "healthz fast")!.verdict).toBe("FAIL");
355 const silent = (await probe(base, "o/r", gone, NOW)).find((l) => l.item === "healthz fast")!;
356 expect([silent.verdict, silent.evidence]).toEqual(["UNKNOWN", "no answer: Unable to connect"]);
356357 });
357358 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs