Public: anyone can read this; the crew can change it.
A daily-proof line that got no answer reads UNKNOWN, never FAIL #15949
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/15947-a-daily-proof-line-that-got-no-answer-re → main 0 commits fork
3 files
changed +52
−11
src/release/v1_checks.ts +4 −5
| @@ -174,9 +174,6 @@ export const GATE_WORDS = "refused by this forge"; | ||
| 174 | 174 | export const gateRefused = (host: string): string => |
| 175 | 175 | `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`; |
| 176 | 176 | |
| 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 | ||
| 180 | 177 | /** A promise that rejects when `signal` aborts, for a fetcher that does not listen to it. */ |
| 181 | 178 | const abortedBy = (signal: AbortSignal): Promise<never> => |
| 182 | 179 | new Promise((_, reject) => { |
| @@ -317,9 +314,11 @@ export async function probe( | ||
| 317 | 314 | } |
| 318 | 315 | } |
| 319 | 316 | |
| 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. | |
| 321 | 320 | 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); | |
| 323 | 322 | else if (health.status === 200 && health.ms <= HEALTHZ_MS) say("healthz fast", "PASS", "/healthz", `200 in ${health.ms} ms`); |
| 324 | 323 | else say("healthz fast", "FAIL", "/healthz", `${health.status} in ${health.ms} ms (limit ${HEALTHZ_MS} ms)`); |
| 325 | 324 |
test/daily-proof.test.ts +45 −4
| @@ -7,7 +7,7 @@ | ||
| 7 | 7 | * and `GET /api/v1/proof/daily` without a token, naming the release it proved. A release no run |
| 8 | 8 | * has recorded runs the proof once, a few minutes after boot, besides the daily tick (#15937). |
| 9 | 9 | */ |
| 10 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 10 | import { afterAll, beforeAll, describe, expect, spyOn, test } from "bun:test"; | |
| 11 | 11 | import { mkdtemp, rm } from "node:fs/promises"; |
| 12 | 12 | import { tmpdir } from "node:os"; |
| 13 | 13 | import { join } from "node:path"; |
| @@ -17,9 +17,9 @@ import { serve, type Servers } from "../src/http/server.ts"; | ||
| 17 | 17 | import { dailyProof } from "../src/maintain/duties/daily_proof.ts"; |
| 18 | 18 | import { startMaintain } from "../src/maintain/runner.ts"; |
| 19 | 19 | 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"; | |
| 21 | 21 | 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"; | |
| 23 | 23 | import { Session } from "../src/tui/forge.ts"; |
| 24 | 24 | import { statusLines } from "../src/tui/screens/status.ts"; |
| 25 | 25 | |
| @@ -175,7 +175,7 @@ describe("the daily proof", () => { | ||
| 175 | 175 | expect(calls.length).toBe(3); |
| 176 | 176 | const lines = lastRun(app.db)!.lines; |
| 177 | 177 | 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 }); | |
| 179 | 179 | expect(r.findings.length).toBeGreaterThan(0); |
| 180 | 180 | await runDay(5); // all pass again, for the reads below |
| 181 | 181 | expect(openAsks(app.db)).toEqual([]); |
| @@ -266,6 +266,47 @@ describe("once after each release goes live (#15937)", () => { | ||
| 266 | 266 | }); |
| 267 | 267 | }); |
| 268 | 268 | |
| 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 | ||
| 269 | 310 | describe("the forge's own origin, read in process (#15936)", () => { |
| 270 | 311 | const GATE = "refused by this forge: forge.example:443 is not in this app's forge.json egress"; |
| 271 | 312 |
test/v1-probe.test.ts +3 −2
| @@ -343,7 +343,7 @@ describe("v1 probe", () => { | ||
| 343 | 343 | } |
| 344 | 344 | }); |
| 345 | 345 | |
| 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 () => { | |
| 347 | 347 | const down: typeof fetch = Object.assign(async (u: string | URL | Request, init?: RequestInit) => |
| 348 | 348 | String(u).endsWith("/healthz") ? new Response("down", { status: 503 }) : fetch(u, init), { preconnect: fetch.preconnect }); |
| 349 | 349 | const line = (await probe(base, "o/r", down, NOW)).find((l) => l.item === "healthz fast")!; |
| @@ -352,6 +352,7 @@ describe("v1 probe", () => { | ||
| 352 | 352 | if (String(u).endsWith("/healthz")) throw new Error("Unable to connect"); |
| 353 | 353 | return fetch(u, init); |
| 354 | 354 | }, { 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"]); | |
| 356 | 357 | }); |
| 357 | 358 | }); |
new above
offline