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

The daily proof on a deployed forge checks that forge, by that forge's own rules #16523

Merged opened this in answer to

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

Merged

scout/forge:scout/16381-the-daily-proof-on-a-deployed-forge-chec → main 0 commits fork

  • Merged. scout/16381-the-daily-proof-on-a-deployed-forge-chec was merged into main as 7106cfb.

Review

Sign in to review this change.
6 files changed +121 −22
src/actions/users.ts +2 −2
@@ -43,6 +43,7 @@ import {
4343 isStandInEmail,
4444 } from "../core/users.ts";
4545 import { err, ok, type Result } from "../kernel/result.ts";
46 import { SIGNUP_CLOSED_MESSAGE } from "../settings/signup.ts";
4647 import { requireUser } from "./access.ts";
4748 import type { SignupSlot } from "./signup-window.ts";
4849
@@ -65,8 +66,7 @@ export type SignUpError =
6566 | "passkey_required"
6667 | "signup_closed";
6768
68 /** What anyone is told when the forge makes no new accounts. */
69 export const SIGNUP_CLOSED_MESSAGE = "Signup is closed on this forge.";
69 export { SIGNUP_CLOSED_MESSAGE };
7070
7171 /** What a stranger whose request is in is told, plainly and with no one's name. */
7272 export const REQUEST_IN_MESSAGE =
src/maintain/duties/daily_proof.ts +7 −3
@@ -16,8 +16,9 @@ import { ownRepoPath } from "../../kernel/own_repo.ts";
1616 import { publicOrigin } from "../../core/public_origin.ts";
1717 import { shortOf } from "../../kernel/version.ts";
1818 import { BUDGET_MS, lastRelease, proveDaily, recordRun, releaseDue, releaseId } from "../../release/daily_proof.ts";
19 import { getSignup } from "../../settings/signup.ts";
1920 import { IN_PROCESS, ownFetcher } from "../../release/own_fetch.ts";
20 import type { Fetcher, Line } from "../../release/v1_checks.ts";
21 import type { Fetcher, Line, OwnRules } from "../../release/v1_checks.ts";
2122 import type { Duty, Finding } from "../duty.ts";
2223
2324 export interface ProofClock {
@@ -63,12 +64,15 @@ export function dailyProof(
6364 const fresh = release !== null && lastRelease(db) !== release;
6465 const base = publicOrigin(url, "");
6566 const repo = app?.config.forgeRepo || ownRepoPath();
67 // What an anonymous read cannot see: this forge's own sign-up setting, and whether its keeper
68 // has cut a release (#16381). A deployed forge is judged by its own rules.
69 const rules: OwnRules = { signup: getSignup(db), keeperCut: db.query("SELECT 1 FROM keeper_release LIMIT 1").get() !== null };
6670 let lines: Line[];
67 if (fetcher !== undefined || app === undefined) lines = await proveDaily(base, repo, fetcher ?? fetch, now.getTime(), budget());
71 if (fetcher !== undefined || app === undefined) lines = await proveDaily(base, repo, fetcher ?? fetch, now.getTime(), budget(), rules);
6872 else {
6973 const own = await ownFetcher(app, base, fetch);
7074 try {
71 lines = (await proveDaily(base, repo, own.fetch, now.getTime(), budget())).map((l) =>
75 lines = (await proveDaily(base, repo, own.fetch, now.getTime(), budget(), rules)).map((l) =>
7276 l.item === "healthz fast" && / ms\b/.test(l.evidence) ? { ...l, evidence: `${l.evidence}, ${IN_PROCESS}` } : l,
7377 );
7478 } finally {
src/release/daily_proof.ts +3 −2
@@ -24,7 +24,7 @@
2424 import type { Database } from "bun:sqlite";
2525 import { redactSecrets } from "../kernel/log.ts";
2626 import { running, UNSTAMPED, type Running } from "../kernel/version.ts";
27 import { probe, type Fetcher, type Line, type Verdict } from "./v1_checks.ts";
27 import { probe, type Fetcher, type Line, type OwnRules, type Verdict } from "./v1_checks.ts";
2828
2929 /** The whole run's budget: every read the checks make, together. */
3030 export const BUDGET_MS = 60_000;
@@ -79,8 +79,9 @@ export function proveDaily(
7979 fetcher: Fetcher = fetch,
8080 now = Date.now(),
8181 budget: AbortSignal = AbortSignal.timeout(BUDGET_MS),
82 rules: OwnRules = {},
8283 ): Promise<Line[]> {
83 return probe(base, repo, fetcher, now, undefined, undefined, budget);
84 return probe(base, repo, fetcher, now, undefined, undefined, budget, rules);
8485 }
8586
8687 /**
src/release/v1_checks.ts +41 −15
@@ -29,6 +29,7 @@
2929 *
3030 * UNKNOWN is what an anonymous read cannot prove; the line says what a person must check.
3131 */
32 import { SIGNUP_CLOSED_MESSAGE } from "../settings/signup.ts";
3233
3334 export type Verdict = "PASS" | "FAIL" | "UNKNOWN";
3435
@@ -47,6 +48,20 @@ interface Seen {
4748 readonly ms: number;
4849 }
4950
51 /**
52 * What the forge under test knows of itself, which an anonymous read cannot see: the daily proof
53 * runs in process and passes it (#16381). Absent, the probe holds the forge to the selling forge's
54 * rules: open sign-up, and a newest release to agree with.
55 */
56 export interface OwnRules {
57 /** The forge's sign-up setting. `invite` and `closed` make `/signup` a 403 that says so. */
58 readonly signup?: "open" | "request" | "invite" | "closed";
59 /**
60 * False while this forge's keeper has cut no release: its repository's tags are its upstream's.
61 */
62 readonly keeperCut?: boolean;
63 }
64
5065 export type Fetcher = (url: string, init?: RequestInit) => Promise<Response>;
5166
5267 /** Healthz slower than this is a FAIL: the common request answers in milliseconds. */
@@ -194,6 +209,7 @@ export async function probe(
194209 edition?: string,
195210 token?: string,
196211 budget?: AbortSignal,
212 rules: OwnRules = {},
197213 ): Promise<Line[]> {
198214 const origin = new URL(base).origin;
199215 const cut = budget === undefined ? undefined : abortedBy(budget);
@@ -240,8 +256,14 @@ export async function probe(
240256
241257 // 1. Sign-up and pricing.
242258 const signup = await get("/signup");
259 const shut = rules.signup === "invite" || rules.signup === "closed";
243260 if (typeof signup === "string") say("sign-up page", "UNKNOWN", "/signup", signup);
244 else if (signup.status === 200 && /<form/i.test(signup.body)) say("sign-up page", "PASS", "/signup", "200 with a form");
261 else if (shut) {
262 // The page explains itself: a 403 that says sign-up is closed is the setting working. An
263 // error, or a form offered where the setting forbids one, contradicts it.
264 if (signup.status === 403 && signup.body.includes(SIGNUP_CLOSED_MESSAGE) && !/<form/i.test(signup.body)) say("sign-up page", "PASS", "/signup", `403 saying sign-up is closed, as this forge's setting (${rules.signup}) says`);
265 else say("sign-up page", "FAIL", "/signup", `${signup.status}${signup.status === 200 ? " with a page" : ""}, but this forge's setting is ${rules.signup}: expected 403 saying sign-up is closed`);
266 } else if (signup.status === 200 && /<form/i.test(signup.body)) say("sign-up page", "PASS", "/signup", "200 with a form");
245267 else say("sign-up page", "FAIL", "/signup", `${signup.status}${signup.status === 200 ? " without a form" : ""}`);
246268 const pricing = await get("/pricing");
247269 const price = typeof pricing === "string" ? undefined : PRICE.exec(pricing.body)?.[0];
@@ -296,21 +318,25 @@ export async function probe(
296318 }
297319
298320 // 4. /changelog, /changelog.atom and production's version agree with the newest release.
299 if (!announced) say("version agrees", "UNKNOWN", "/mcp", typeof init === "string" ? init : `initialize named no version or commit (${init.status})`);
300 else if (!read) say("version agrees", "UNKNOWN", releasePath, `production says ${announced.text}; ${unread}`);
301 else if (!read.release) say("version agrees", "FAIL", releasePath, `production says ${announced.text}; the releases tool lists no release of ${repo} and names no running commit`);
302 else {
303 const r = read.release;
304 const agrees = announced.kind === "version" ? r.version === announced.text : r.commit.startsWith(announced.text);
305 const theirs = announced.kind === "version" ? (r.version ?? `no version (${r.commit.slice(0, 7)})`) : r.commit.slice(0, announced.text.length);
306 if (!agrees) say("version agrees", "FAIL", releasePath, `production says ${announced.text}, the newest release ${r.name} is ${theirs}`);
321 // A forge whose keeper has cut no release has nothing of its own to agree with (its repository's
322 // tags are its upstream's): the line is left out, and the run is quiet about it.
323 if (rules.keeperCut !== false) {
324 if (!announced) say("version agrees", "UNKNOWN", "/mcp", typeof init === "string" ? init : `initialize named no version or commit (${init.status})`);
325 else if (!read) say("version agrees", "UNKNOWN", releasePath, `production says ${announced.text}; ${unread}`);
326 else if (!read.release) say("version agrees", "FAIL", releasePath, `production says ${announced.text}; the releases tool lists no release of ${repo} and names no running commit`);
307327 else {
308 const page = await get("/changelog");
309 const atom = await get("/changelog.atom");
310 const named = (s: Seen | string): boolean => typeof s !== "string" && s.status === 200 && ((r.version !== undefined && s.body.includes(r.version)) || s.body.includes(r.commit.slice(0, 7)));
311 const misses = [named(page) ? "" : "/changelog", named(atom) ? "" : "/changelog.atom"].filter(Boolean);
312 if (misses.length === 0) say("version agrees", "PASS", "/changelog", `production ${announced.text} = release ${r.name}, named by /changelog and /changelog.atom`);
313 else say("version agrees", "FAIL", misses[0] ?? "/changelog", `production ${announced.text} = release ${r.name}, but ${misses.join(" and ")} ${misses.length === 1 ? "does" : "do"} not name it`);
328 const r = read.release;
329 const agrees = announced.kind === "version" ? r.version === announced.text : r.commit.startsWith(announced.text);
330 const theirs = announced.kind === "version" ? (r.version ?? `no version (${r.commit.slice(0, 7)})`) : r.commit.slice(0, announced.text.length);
331 if (!agrees) say("version agrees", "FAIL", releasePath, `production says ${announced.text}, the newest release ${r.name} is ${theirs}`);
332 else {
333 const page = await get("/changelog");
334 const atom = await get("/changelog.atom");
335 const named = (s: Seen | string): boolean => typeof s !== "string" && s.status === 200 && ((r.version !== undefined && s.body.includes(r.version)) || s.body.includes(r.commit.slice(0, 7)));
336 const misses = [named(page) ? "" : "/changelog", named(atom) ? "" : "/changelog.atom"].filter(Boolean);
337 if (misses.length === 0) say("version agrees", "PASS", "/changelog", `production ${announced.text} = release ${r.name}, named by /changelog and /changelog.atom`);
338 else say("version agrees", "FAIL", misses[0] ?? "/changelog", `production ${announced.text} = release ${r.name}, but ${misses.join(" and ")} ${misses.length === 1 ? "does" : "do"} not name it`);
339 }
314340 }
315341 }
316342
src/settings/signup.ts +2
@@ -21,6 +21,8 @@ export const SIGNUP_MEANS: Record<SignupMode, string> = {
2121 closed: "no new accounts",
2222 };
2323 export type SignupMode = (typeof SIGNUP_MODES)[number];
24 /** What anyone is told when the forge makes no new accounts. */
25 export const SIGNUP_CLOSED_MESSAGE = "Signup is closed on this forge.";
2426 export const SIGNUP_DEFAULT: SignupMode = "open";
2527
2628 /** The actor kept for a change made by `FORGE_SIGNUP` at boot. */
test/daily-proof.test.ts +66
@@ -20,6 +20,7 @@ import type { DutyResult } from "../src/maintain/duty.ts";
2020 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";
2222 import { HEALTHZ_MS, OUT_OF_BUDGET, type Line } from "../src/release/v1_checks.ts";
23 import { getSignup, setSignup } from "../src/settings/signup.ts";
2324 import { Session } from "../src/tui/forge.ts";
2425 import { statusLines } from "../src/tui/screens/status.ts";
2526
@@ -38,6 +39,12 @@ interface Calls {
3839 /** What the stub forge says today: everything green unless a switch says otherwise. */
3940 interface World {
4041 noPrice?: boolean;
42 /**
43 * `/signup` answers as the forge's own setting says (403 saying it is closed) rather than a form.
44 */
45 shut?: "invite" | "closed";
46 /** `/signup` is broken: a 500. */
47 signupBroken?: boolean;
4148 /** The call (1-based) that never answers and aborts the budget instead. */
4249 hangAt?: number;
4350 }
@@ -59,6 +66,8 @@ function stubForge(world: () => World, now: () => number, calls: Calls[], budget
5966 case "/":
6067 return page("<h1>forge</h1>");
6168 case "/signup":
69 if (w.signupBroken) return new Response("boom", { status: 500, headers: { "content-type": "text/html", ...SEC } });
70 if (w.shut) return new Response("<p>Signup is closed on this forge.</p>", { status: 403, headers: { "content-type": "text/html", ...SEC } });
6271 return page("<form method=post></form>");
6372 case "/pricing":
6473 return page(w.noPrice ? "<p>free for now</p>" : "<p>$5 a month</p>");
@@ -104,6 +113,9 @@ beforeAll(async () => {
104113 dir = await mkdtemp(join(tmpdir(), "daily-proof-"));
105114 app = createApp({ dataDir: dir, port: 0 });
106115 servers = await serve(app);
116 // The selling forge: open sign-up, and a release its keeper cut. A deployed forge is below.
117 setSignup(app.db, "open", "test");
118 app.db.run("INSERT INTO keeper_release (version, sha, known_good_version, known_good_image, stage, cut_at) VALUES ('1.0.0', ?1, '', '', 'verified', '2026-11-01T00:00:00Z')", [COMMIT]);
107119 });
108120 afterAll(async () => {
109121 await servers.stop();
@@ -389,3 +401,57 @@ describe("recording a run", () => {
389401 expect(e.length).toBeLessThanOrEqual(240);
390402 });
391403 });
404
405 describe("a deployed forge is checked by its own rules (#16381)", () => {
406 const items = (lines: Line[]) => Object.fromEntries(lines.map((l) => [l.item, l.verdict]));
407 const forge = (w: World) => stubForge(() => w, () => T0, []);
408
409 test("invite-only sign-up passes when /signup says it is closed, and fails when it errors or offers a form", async () => {
410 for (const mode of ["invite", "closed"] as const) {
411 const ok = items(await proveDaily(BASE, "o/forge", forge({ shut: mode }), T0, undefined, { signup: mode }));
412 expect(ok["sign-up page"]).toBe("PASS");
413 const broke = items(await proveDaily(BASE, "o/forge", forge({ signupBroken: true }), T0, undefined, { signup: mode }));
414 expect(broke["sign-up page"]).toBe("FAIL");
415 const form = items(await proveDaily(BASE, "o/forge", forge({}), T0, undefined, { signup: mode }));
416 expect(form["sign-up page"]).toBe("FAIL");
417 }
418 });
419
420 test("open sign-up still fails on a 403 and the selling forge still needs a form", async () => {
421 const lines = items(await proveDaily(BASE, "o/forge", forge({ shut: "invite" }), T0, undefined, { signup: "open" }));
422 expect(lines["sign-up page"]).toBe("FAIL");
423 expect(items(await proveDaily(BASE, "o/forge", forge({}), T0))["sign-up page"]).toBe("PASS");
424 });
425
426 test("version agrees says nothing until the keeper has cut a release, and fails for the selling forge on a disagreement", async () => {
427 const quiet = await proveDaily(BASE, "o/forge", forge({}), T0, undefined, { keeperCut: false });
428 expect(quiet.some((l) => l.item === "version agrees")).toBe(false);
429 // Production says 2.0.0 while its newest release is 1.0.0: a real disagreement once a release
430 // is cut.
431 const lying = async (url: string, init?: RequestInit) => {
432 if (new URL(url).pathname === "/mcp" && JSON.parse(String(init?.body)).method === "initialize")
433 return Response.json({ jsonrpc: "2.0", id: 1, result: { serverInfo: { name: "forge", version: "2.0.0" } } });
434 return forge({})(url, init);
435 };
436 const cut = items(await proveDaily(BASE, "o/forge", lying, T0, undefined, { keeperCut: true }));
437 expect(cut["version agrees"]).toBe("FAIL");
438 });
439
440 test("the duty reads the setting and the keeper's rows: a freshly deployed forge is all PASS", async () => {
441 const dir2 = await mkdtemp(join(tmpdir(), "daily-proof-deployed-"));
442 const fresh = createApp({ dataDir: dir2, port: 0 });
443 try {
444 setSignup(fresh.db, "invite", "owner"); // what a new forge stores (seedSignup)
445 expect(getSignup(fresh.db)).toBe("invite");
446 const budget = new AbortController();
447 const duty = dailyProof(stubForge(() => ({ shut: "invite" }), () => T0, [], budget), () => budget.signal, { release: null });
448 await duty.run({ db: fresh.db, bus: fresh.bus, now: new Date(T0), app: fakeApp() });
449 const run = lastRun(fresh.db)!;
450 expect(run.lines.every((l) => l.verdict === "PASS")).toBe(true);
451 expect(run.lines.some((l) => l.item === "version agrees")).toBe(false);
452 } finally {
453 fresh.close();
454 await rm(dir2, { recursive: true, force: true });
455 }
456 });
457 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs