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

Merged opened this

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

Merged

scout/forge:scout/16256-a-production-that-is-not-serving-is-skip → main 0 commits fork 2 threads · 2 unresolved

  • Merged. scout/16256-a-production-that-is-not-serving-is-skip was merged into main as f5dc773.

Review

Sign in to review this change.
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
149149 // browser only ever visits the forge's own listener, directly.
150150 "--no-proxy-server",
151151 "--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`,

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.

154156 `--window-size=${size.width},${size.height}`,
155157 "--force-device-scale-factor=1",
156158 "--js-flags=--max-old-space-size=256",
src/looks/service.ts +22 −10
@@ -103,7 +103,7 @@ export interface LooksOptions {
103103 * Whether the app answers at its port now: a real request unless a test
104104 * says otherwise. A look waits for this before opening a browser (#11520).
105105 */
106 readonly answers?: ((port: number) => Promise<boolean>) | undefined;
106 readonly answers?: ((port: number) => Promise<boolean | typeof NOT_SERVING>) | undefined;
107107 /** How long a look waits for the app to answer, and how often it asks. */
108108 readonly answerWaitMs?: number | undefined;
109109 readonly answerPollMs?: number | undefined;
@@ -117,15 +117,24 @@ export interface LooksOptions {
117117 readonly maxWaitMs?: number | undefined;
118118 }
119119
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> {
122131 try {
123132 const res = await fetch(`http://127.0.0.1:${port}/`, {
124133 redirect: "manual",
125134 signal: AbortSignal.timeout(2_000),
126135 });
127136 await res.body?.cancel();
128 return res.status < 500;
137 return res.status === 404 || res.status >= 500 ? NOT_SERVING : true;
129138 } catch {
130139 return false;
131140 }
@@ -510,14 +519,16 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle {
510519 }
511520
512521 /** 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> {
514523 const ask = options.answers ?? appAnswers;
515524 const waitMs = options.answerWaitMs ?? ANSWER_WAIT_MS;
516525 const pollMs = options.answerPollMs ?? ANSWER_POLL_MS;
517526 const until = Date.now() + waitMs;
527 let last: boolean | typeof NOT_SERVING = false;
518528 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;
521532 await Bun.sleep(pollMs);
522533 }
523534 }
@@ -559,9 +570,10 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle {
559570 if (wanted.length === 0) return;
560571 // An app still warming up gets no browser: wait, bounded, until it
561572 // 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) {
563575 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 });
565577 for (const { page, kind, theme } of wanted)
566578 recordLook(app.db, {
567579 appId: item.appId,
@@ -571,7 +583,7 @@ export function startLooks(app: App, options: LooksOptions): LooksHandle {
571583 theme,
572584 kind,
573585 path: "",
574 error: NOT_ANSWERING,
586 error: heard,
575587 });
576588 failed(item);
577589 return;
test/look-browser-start.test.ts +3 −1
@@ -47,7 +47,9 @@ describe("the browser's command", () => {
4747 test("a look's browser is in the background class and reaches only the forge's own listener", () => {
4848 const flags = lookFlags("hello--pull-7.apps.test", { width: 390, height: 844 });
4949 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 );
5153 expect(flags).toContain("--remote-debugging-port=0");
5254 expect(flags).toContain("--remote-allow-origins=http://127.0.0.1");
5355 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 {
4444 type Capture,
4545 type LookInput,
4646 } 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";
4848 import type { BackoffClock } from "../src/looks/backoff.ts";
4949 import { logLevel, setLogLevel } from "../src/kernel/log.ts";
5050
@@ -1116,7 +1116,7 @@ describe("the look", () => {
11161116 const head = status.commitOid;
11171117 const forgetPictures = () =>
11181118 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>) => {
11201120 forgetPictures();
11211121 const seen: LookInput[] = [];
11221122 const own = startLooks(app, {
@@ -1163,6 +1163,20 @@ describe("the look", () => {
11631163 forgetPictures();
11641164 });
11651165
1166 test("an app answering 404 is skipped as not serving, with no browser; a serving one is pictured", async () => {

This drives the answers seam, not appAnswers, so the 404 to not serving mapping is untested. Serve a real 404 on a loopback port and let the default probe run, with a 200 server for the pictured case.

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
11661180 test("the boot prune spares an owner-taken thumb, an attached one, and every thumb of a public app", async () => {
11671181 const put = (oid: string, extra: Partial<Parameters<typeof recordLook>[1]>) => {
11681182 const path = `looks/${record.id}/production/${oid}-thumb.png`;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs