Public: anyone can read this; the crew can change it.
A read the forge's own egress gate refused is UNKNOWN with its cause, never FAIL: the healthz line stops failing the daily proof #15939
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15935-a-read-the-forge-s-own-egress-gate-refus → main 0 commits fork 1 thread · 1 unresolved
2 files
changed +45
−2
src/release/v1_checks.ts +18 −2
| @@ -164,6 +164,19 @@ function readOnlyCall(body: unknown): boolean { | ||
| 164 | 164 | /** What a line says of a read the budget cut short, or never let start. */ |
| 165 | 165 | export const OUT_OF_BUDGET = "no answer: the probe's budget ran out"; |
| 166 | 166 | |
| 167 | /** The words the forge's egress gate says its own no in (src/apps/egress.ts `REFUSED_PREFIX`). */ | |
| 168 | export const GATE_WORDS = "refused by this forge"; | |
| 169 | ||
| 170 | /** | |
| 171 | * What a line says of a read the forge's own egress gate refused (#15935): the probe never | |
| 172 | * reached production, so the line proves nothing about it and is UNKNOWN, healthz included. | |
| 173 | */ | |
| 174 | export const gateRefused = (host: string): string => | |
| 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 | ||
| 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 | ||
| 167 | 180 | /** A promise that rejects when `signal` aborts, for a fetcher that does not listen to it. */ |
| 168 | 181 | const abortedBy = (signal: AbortSignal): Promise<never> => |
| 169 | 182 | new Promise((_, reject) => { |
| @@ -200,13 +213,16 @@ export async function probe( | ||
| 200 | 213 | try { |
| 201 | 214 | const read = (async () => { |
| 202 | 215 | const r = await fetcher(url.href, { ...init, method, redirect: "manual", signal }); |
| 216 | if (r.status === 403 && r.headers.get("x-forge-egress") === "refused") return gateRefused(url.host); | |
| 203 | 217 | return { status: r.status, headers: r.headers, body: await r.text() }; |
| 204 | 218 | })(); |
| 205 | 219 | read.catch(() => {}); // a read the budget outran settles unheard |
| 206 | 220 | const r = cut === undefined ? await read : await Promise.race([read, cut]); |
| 221 | if (typeof r === "string") return r; | |
| 207 | 222 | return { ...r, ms: Math.round(performance.now() - started) }; |
| 208 | 223 | } catch (e) { |
| 209 | 224 | if (budget?.aborted) return OUT_OF_BUDGET; |
| 225 | if (String(e instanceof Error ? e.message : e).includes(GATE_WORDS)) return gateRefused(url.host); | |
| 210 | 226 | return `no answer: ${e instanceof Error ? e.message : String(e)}`; |
| 211 | 227 | } |
| 212 | 228 | }; |
| @@ -301,9 +317,9 @@ export async function probe( | ||
| 301 | 317 | } |
| 302 | 318 | } |
| 303 | 319 | |
| 304 | // 5. /healthz fast. | |
| 320 | // 5. /healthz fast. A read the forge's own gate refused never reached production: UNKNOWN. | |
| 305 | 321 | const health = await get("/healthz"); |
| 306 | if (typeof health === "string") say("healthz fast", "FAIL", "/healthz", health); | |
| 322 | if (typeof health === "string") say("healthz fast", isGateRefusal(health) ? "UNKNOWN" : "FAIL", "/healthz", health); | |
| 307 | 323 | else if (health.status === 200 && health.ms <= HEALTHZ_MS) say("healthz fast", "PASS", "/healthz", `200 in ${health.ms} ms`); |
| 308 | 324 | else say("healthz fast", "FAIL", "/healthz", `${health.status} in ${health.ms} ms (limit ${HEALTHZ_MS} ms)`); |
| 309 | 325 |
test/v1-probe.test.ts +27
| @@ -327,4 +327,31 @@ describe("v1 probe", () => { | ||
| 327 | 327 | expect(stripped.evidence).toBe(`403, the token did not reach ${origin}: a proxy in front strips the authorization header, so this forge saw no one`); |
| 328 | 328 | expect(seen.filter((s) => s.path.startsWith("/api/v1/here")).length).toBeGreaterThan(0); |
| 329 | 329 | }); |
| 330 | test("a read the forge's own egress gate refused is UNKNOWN on every line, healthz included, naming the host (#15935)", async () => { | |
| 331 | const host = new URL(base).host; | |
| 332 | const thrown: typeof fetch = Object.assign(async () => { | |
| 333 | throw new Error(`Proxy refused to open a tunnel: 403 refused by this forge: ${host}:443 is not in this app's forge.json egress`); | |
| 334 | }, { preconnect: fetch.preconnect }); | |
| 335 | const answered: typeof fetch = Object.assign(async () => new Response("refused by this forge", { status: 403, headers: { "x-forge-egress": "refused" } }), { preconnect: fetch.preconnect }); | |
| 336 | for (const fetcher of [thrown, answered]) { | |
| 337 | const lines = await probe(base, "o/r", fetcher, NOW); | |
| 338 | expect(lines).toHaveLength(8); | |
| 339 | for (const l of lines) { | |
| 340 | expect(`${l.item}=${l.verdict}`).toBe(`${l.item}=UNKNOWN`); | |
| 341 | expect(l.evidence).toContain(`refused by this forge: ${host}`); | |
| 342 | } | |
| 343 | } | |
| 344 | }); | |
| 345 | ||
| 346 | test("a healthz production answers 503, or not at all, is still FAIL (#15935)", async () => { | |
| 347 | const down: typeof fetch = Object.assign(async (u: string | URL | Request, init?: RequestInit) => | |
| 348 | String(u).endsWith("/healthz") ? new Response("down", { status: 503 }) : fetch(u, init), { preconnect: fetch.preconnect }); | |
| 349 | const line = (await probe(base, "o/r", down, NOW)).find((l) => l.item === "healthz fast")!; | |
| 350 | expect([line.verdict, line.evidence.startsWith("503 in ")]).toEqual(["FAIL", true]); | |
| 351 | const gone: typeof fetch = Object.assign(async (u: string | URL | Request, init?: RequestInit) => { | |
| 352 | if (String(u).endsWith("/healthz")) throw new Error("Unable to connect"); | |
| 353 | return fetch(u, init); | |
| 354 | }, { preconnect: fetch.preconnect }); | |
| 355 | expect((await probe(base, "o/r", gone, NOW)).find((l) => l.item === "healthz fast")!.verdict).toBe("FAIL"); | |
| 356 | }); | |
| 330 | 357 | }); |
new above
offline
GATE_WORDS duplicates REFUSED_PREFIX. Add a one-line test asserting they are equal so a wording change in the gate fails loudly here.