Public: anyone can read this; the crew can change it.
A production that is not serving is skipped by the look sweep with its reason, never pictured through a public name #16687
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16256-a-production-that-is-not-serving-is-skip → main 0 commits fork 2 threads · 2 unresolved
5 files
changed +88
−15
src/looks/capture.ts +4 −2
| @@ -149,8 +149,10 @@ export function lookFlags(host: string, size: { readonly width: number; readonly | ||
| 149 | 149 | // browser only ever visits the forge's own listener, directly. |
| 150 | 150 | "--no-proxy-server", |
| 151 | 151 | "--hide-scrollbars", |
| 152 | // The app's hostname is the forge's own listener: no DNS, no edge. | |
| 153 | `--host-resolver-rules=MAP ${host} 127.0.0.1`, | |
| 152 | // The app's hostname is the forge's own listener: no DNS, no edge. Any | |
| 153 | // other name (a bounce to a public https door) does not resolve at all, | |
| 154 | // so no hop reaches a name the pod resolves differently. | |
| 155 | `--host-resolver-rules=MAP ${host} 127.0.0.1, MAP * ~NOTFOUND, EXCLUDE 127.0.0.1`, | |
| 154 | 156 | `--window-size=${size.width},${size.height}`, |
| 155 | 157 | "--force-device-scale-factor=1", |
| 156 | 158 | "--js-flags=--max-old-space-size=256", |
src/looks/service.ts +22 −10
| @@ -103,7 +103,7 @@ export interface LooksOptions { | ||
| 103 | 103 | * Whether the app answers at its port now: a real request unless a test |
| 104 | 104 | * says otherwise. A look waits for this before opening a browser (#11520). |
| 105 | 105 | */ |
| 106 | readonly answers?: ((port: number) => Promise<boolean>) | undefined; | |
| 106 | readonly answers?: ((port: number) => Promise<boolean | typeof NOT_SERVING>) | undefined; | |
| 107 | 107 | /** How long a look waits for the app to answer, and how often it asks. */ |
| 108 | 108 | readonly answerWaitMs?: number | undefined; |
| 109 | 109 | readonly answerPollMs?: number | undefined; |
| @@ -117,15 +117,24 @@ export interface LooksOptions { | ||
| 117 | 117 | readonly maxWaitMs?: number | undefined; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | /** The app answers when its page comes back with anything but a server error. */ | |
| 121 | async function appAnswers(port: number): Promise<boolean> { | |
| 120 | /** | |
| 121 | * What a look records when the app answers, but with a missing page or a | |
| 122 | * server error: not serving. | |
| 123 | */ | |
| 124 | export const NOT_SERVING = "not serving"; | |
| 125 | ||
| 126 | /** | |
| 127 | * The app serves when its page comes back with anything but a 404 or a | |
| 128 | * server error; `false` is silence, `NOT_SERVING` an answer that is not a page. | |
| 129 | */ | |
| 130 | export async function appAnswers(port: number): Promise<boolean | typeof NOT_SERVING> { | |
| 122 | 131 | try { |
| 123 | 132 | const res = await fetch(`http://127.0.0.1:${port}/`, { |
| 124 | 133 | redirect: "manual", |
| 125 | 134 | signal: AbortSignal.timeout(2_000), |
| 126 | 135 | }); |
| 127 | 136 | await res.body?.cancel(); |
| 128 | return res.status < 500; | |
| 137 | return res.status === 404 || res.status >= 500 ? NOT_SERVING : true; | |
| 129 | 138 | } catch { |
| 130 | 139 | return false; |
| 131 | 140 | } |
| @@ -510,14 +519,16 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle { | ||
| 510 | 519 | } |
| 511 | 520 | |
| 512 | 521 | /** Ask until the app answers or the wait is spent. */ |
| 513 | async function answered(port: number): Promise<boolean> { | |
| 522 | async function answered(port: number): Promise<true | string> { | |
| 514 | 523 | const ask = options.answers ?? appAnswers; |
| 515 | 524 | const waitMs = options.answerWaitMs ?? ANSWER_WAIT_MS; |
| 516 | 525 | const pollMs = options.answerPollMs ?? ANSWER_POLL_MS; |
| 517 | 526 | const until = Date.now() + waitMs; |
| 527 | let last: boolean | typeof NOT_SERVING = false; | |
| 518 | 528 | for (;;) { |
| 519 | if (await ask(port)) return true; | |
| 520 | if (stopped || Date.now() >= until) return false; | |
| 529 | last = await ask(port); | |
| 530 | if (last === true) return true; | |
| 531 | if (stopped || Date.now() >= until) return last === NOT_SERVING ? NOT_SERVING : NOT_ANSWERING; | |
| 521 | 532 | await Bun.sleep(pollMs); |
| 522 | 533 | } |
| 523 | 534 | } |
| @@ -559,9 +570,10 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle { | ||
| 559 | 570 | if (wanted.length === 0) return; |
| 560 | 571 | // An app still warming up gets no browser: wait, bounded, until it |
| 561 | 572 | // answers; one that never does is recorded as not answering (#11520). |
| 562 | if (status.port !== undefined && !(await answered(status.port))) { | |
| 573 | const heard = status.port === undefined ? true : await answered(status.port); | |
| 574 | if (heard !== true) { | |
| 563 | 575 | if (stopped) return; |
| 564 | log.warn("no picture: the app did not answer", { app: record.slug, env: item.env }); | |
| 576 | log.warn("no picture: the app is not serving", { app: record.slug, env: item.env, why: heard }); | |
| 565 | 577 | for (const { page, kind, theme } of wanted) |
| 566 | 578 | recordLook(app.db, { |
| 567 | 579 | appId: item.appId, |
| @@ -571,7 +583,7 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle { | ||
| 571 | 583 | theme, |
| 572 | 584 | kind, |
| 573 | 585 | path: "", |
| 574 | error: NOT_ANSWERING, | |
| 586 | error: heard, | |
| 575 | 587 | }); |
| 576 | 588 | failed(item); |
| 577 | 589 | return; |
test/look-browser-start.test.ts +3 −1
| @@ -47,7 +47,9 @@ describe("the browser's command", () => { | ||
| 47 | 47 | test("a look's browser is in the background class and reaches only the forge's own listener", () => { |
| 48 | 48 | const flags = lookFlags("hello--pull-7.apps.test", { width: 390, height: 844 }); |
| 49 | 49 | expect(flags).toContain("--no-proxy-server"); |
| 50 | expect(flags).toContain("--host-resolver-rules=MAP hello--pull-7.apps.test 127.0.0.1"); | |
| 50 | expect(flags).toContain( | |
| 51 | "--host-resolver-rules=MAP hello--pull-7.apps.test 127.0.0.1, MAP * ~NOTFOUND, EXCLUDE 127.0.0.1", | |
| 52 | ); | |
| 51 | 53 | expect(flags).toContain("--remote-debugging-port=0"); |
| 52 | 54 | expect(flags).toContain("--remote-allow-origins=http://127.0.0.1"); |
| 53 | 55 | const { argv } = browserCommand("/usr/bin/chromium", { profile: "/tmp/p", background: true, flags }, "/tmp"); |
test/look-probe.test.ts added +43
| @@ -0,0 +1,43 @@ | ||
| 1 | import { afterAll, expect, test } from "bun:test"; | |
| 2 | import { appAnswers, NOT_SERVING } from "../src/looks/service.ts"; | |
| 3 | import { lookFlags } from "../src/looks/capture.ts"; | |
| 4 | ||
| 5 | const server = Bun.serve({ | |
| 6 | port: 0, | |
| 7 | hostname: "127.0.0.1", | |
| 8 | fetch(req) { | |
| 9 | const path = new URL(req.url).pathname; | |
| 10 | return new Response("x", { status: path === "/" ? 404 : 200 }); | |
| 11 | }, | |
| 12 | }); | |
| 13 | const ok = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch: () => new Response("hi") }); | |
| 14 | const boom = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch: () => new Response("", { status: 503 }) }); | |
| 15 | const moved = Bun.serve({ | |
| 16 | port: 0, | |
| 17 | hostname: "127.0.0.1", | |
| 18 | fetch: () => new Response("", { status: 302, headers: { location: "/in" } }), | |
| 19 | }); | |
| 20 | afterAll(() => { | |
| 21 | for (const s of [server, ok, boom, moved]) s.stop(true); | |
| 22 | }); | |
| 23 | ||
| 24 | test("the real probe: 404 and 5xx are not serving, 200 and a redirect are", async () => { | |
| 25 | expect(await appAnswers(server.port!)).toBe(NOT_SERVING); | |
| 26 | expect(await appAnswers(boom.port!)).toBe(NOT_SERVING); | |
| 27 | expect(await appAnswers(ok.port!)).toBe(true); | |
| 28 | expect(await appAnswers(moved.port!)).toBe(true); | |
| 29 | }); | |
| 30 | ||
| 31 | test("the probe says silence is false, not not-serving", async () => { | |
| 32 | const port = ok.port!; | |
| 33 | ok.stop(true); | |
| 34 | expect(await appAnswers(port)).toBe(false); | |
| 35 | }); | |
| 36 | ||
| 37 | test("a look's browser resolves only the app's name, keeping loopback (DevTools) reachable", () => { | |
| 38 | const rules = lookFlags("a.test", { width: 1, height: 1 }).find((f) => | |
| 39 | f.startsWith("--host-resolver-rules="), | |
| 40 | )!; | |
| 41 | expect(rules.endsWith("EXCLUDE 127.0.0.1")).toBe(true); | |
| 42 | expect(rules).toContain("MAP * ~NOTFOUND"); | |
| 43 | }); |
test/looks.test.ts +16 −2
| @@ -44,7 +44,7 @@ import { | ||
| 44 | 44 | type Capture, |
| 45 | 45 | type LookInput, |
| 46 | 46 | } from "../src/looks/capture.ts"; |
| 47 | import { NOT_ANSWERING, startLooks, type LooksHandle } from "../src/looks/service.ts"; | |
| 47 | import { NOT_ANSWERING, NOT_SERVING, startLooks, type LooksHandle } from "../src/looks/service.ts"; | |
| 48 | 48 | import type { BackoffClock } from "../src/looks/backoff.ts"; |
| 49 | 49 | import { logLevel, setLogLevel } from "../src/kernel/log.ts"; |
| 50 | 50 | |
| @@ -1116,7 +1116,7 @@ describe("the look", () => { | ||
| 1116 | 1116 | const head = status.commitOid; |
| 1117 | 1117 | const forgetPictures = () => |
| 1118 | 1118 | app.db.query("DELETE FROM look WHERE app_id = ? AND env = 'production'").run(record.id); |
| 1119 | const trial = async (answers: (port: number) => Promise<boolean>) => { | |
| 1119 | const trial = async (answers: (port: number) => Promise<boolean | typeof NOT_SERVING>) => { | |
| 1120 | 1120 | forgetPictures(); |
| 1121 | 1121 | const seen: LookInput[] = []; |
| 1122 | 1122 | const own = startLooks(app, { |
| @@ -1163,6 +1163,20 @@ describe("the look", () => { | ||
| 1163 | 1163 | forgetPictures(); |
| 1164 | 1164 | }); |
| 1165 | 1165 | |
| 1166 | test("an app answering 404 is skipped as not serving, with no browser; a serving one is pictured", async () => { | |
| 1167 | const { forgetPictures, trial } = answeringTrial(40); | |
| 1168 | const gone = await trial(async () => NOT_SERVING); | |
| 1169 | expect(gone.seen).toEqual([]); | |
| 1170 | expect(gone.rows.length).toBeGreaterThan(0); | |
| 1171 | for (const look of gone.rows) { | |
| 1172 | expect(look.error).toBe("not serving"); | |
| 1173 | expect(look.path).toBe(""); | |
| 1174 | } | |
| 1175 | const up = await trial(async () => true); | |
| 1176 | expect(up.seen.length).toBeGreaterThan(0); | |
| 1177 | forgetPictures(); | |
| 1178 | }); | |
| 1179 | ||
| 1166 | 1180 | test("the boot prune spares an owner-taken thumb, an attached one, and every thumb of a public app", async () => { |
| 1167 | 1181 | const put = (oid: string, extra: Partial<Parameters<typeof recordLook>[1]>) => { |
| 1168 | 1182 | const path = `looks/${record.id}/production/${oid}-thumb.png`; |
new above
offline
Non-blocking: the rule is right and the loopback exclusion is pinned by a test. A real bounce through Chromium would be the first proof it holds, so run one when a runner can.