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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16381-the-daily-proof-on-a-deployed-forge-chec → main 0 commits fork
6 files
changed +121
−22
src/actions/users.ts +2 −2
| @@ -43,6 +43,7 @@ import { | ||
| 43 | 43 | isStandInEmail, |
| 44 | 44 | } from "../core/users.ts"; |
| 45 | 45 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 46 | import { SIGNUP_CLOSED_MESSAGE } from "../settings/signup.ts"; | |
| 46 | 47 | import { requireUser } from "./access.ts"; |
| 47 | 48 | import type { SignupSlot } from "./signup-window.ts"; |
| 48 | 49 | |
| @@ -65,8 +66,7 @@ export type SignUpError = | ||
| 65 | 66 | | "passkey_required" |
| 66 | 67 | | "signup_closed"; |
| 67 | 68 | |
| 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 }; | |
| 70 | 70 | |
| 71 | 71 | /** What a stranger whose request is in is told, plainly and with no one's name. */ |
| 72 | 72 | export const REQUEST_IN_MESSAGE = |
src/maintain/duties/daily_proof.ts +7 −3
| @@ -16,8 +16,9 @@ import { ownRepoPath } from "../../kernel/own_repo.ts"; | ||
| 16 | 16 | import { publicOrigin } from "../../core/public_origin.ts"; |
| 17 | 17 | import { shortOf } from "../../kernel/version.ts"; |
| 18 | 18 | import { BUDGET_MS, lastRelease, proveDaily, recordRun, releaseDue, releaseId } from "../../release/daily_proof.ts"; |
| 19 | import { getSignup } from "../../settings/signup.ts"; | |
| 19 | 20 | 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"; | |
| 21 | 22 | import type { Duty, Finding } from "../duty.ts"; |
| 22 | 23 | |
| 23 | 24 | export interface ProofClock { |
| @@ -63,12 +64,15 @@ export function dailyProof( | ||
| 63 | 64 | const fresh = release !== null && lastRelease(db) !== release; |
| 64 | 65 | const base = publicOrigin(url, ""); |
| 65 | 66 | 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 }; | |
| 66 | 70 | 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); | |
| 68 | 72 | else { |
| 69 | 73 | const own = await ownFetcher(app, base, fetch); |
| 70 | 74 | 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) => | |
| 72 | 76 | l.item === "healthz fast" && / ms\b/.test(l.evidence) ? { ...l, evidence: `${l.evidence}, ${IN_PROCESS}` } : l, |
| 73 | 77 | ); |
| 74 | 78 | } finally { |
src/release/daily_proof.ts +3 −2
| @@ -24,7 +24,7 @@ | ||
| 24 | 24 | import type { Database } from "bun:sqlite"; |
| 25 | 25 | import { redactSecrets } from "../kernel/log.ts"; |
| 26 | 26 | 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"; | |
| 28 | 28 | |
| 29 | 29 | /** The whole run's budget: every read the checks make, together. */ |
| 30 | 30 | export const BUDGET_MS = 60_000; |
| @@ -79,8 +79,9 @@ export function proveDaily( | ||
| 79 | 79 | fetcher: Fetcher = fetch, |
| 80 | 80 | now = Date.now(), |
| 81 | 81 | budget: AbortSignal = AbortSignal.timeout(BUDGET_MS), |
| 82 | rules: OwnRules = {}, | |
| 82 | 83 | ): Promise<Line[]> { |
| 83 | return probe(base, repo, fetcher, now, undefined, undefined, budget); | |
| 84 | return probe(base, repo, fetcher, now, undefined, undefined, budget, rules); | |
| 84 | 85 | } |
| 85 | 86 | |
| 86 | 87 | /** |
src/release/v1_checks.ts +41 −15
| @@ -29,6 +29,7 @@ | ||
| 29 | 29 | * |
| 30 | 30 | * UNKNOWN is what an anonymous read cannot prove; the line says what a person must check. |
| 31 | 31 | */ |
| 32 | import { SIGNUP_CLOSED_MESSAGE } from "../settings/signup.ts"; | |
| 32 | 33 | |
| 33 | 34 | export type Verdict = "PASS" | "FAIL" | "UNKNOWN"; |
| 34 | 35 | |
| @@ -47,6 +48,20 @@ interface Seen { | ||
| 47 | 48 | readonly ms: number; |
| 48 | 49 | } |
| 49 | 50 | |
| 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 | ||
| 50 | 65 | export type Fetcher = (url: string, init?: RequestInit) => Promise<Response>; |
| 51 | 66 | |
| 52 | 67 | /** Healthz slower than this is a FAIL: the common request answers in milliseconds. */ |
| @@ -194,6 +209,7 @@ export async function probe( | ||
| 194 | 209 | edition?: string, |
| 195 | 210 | token?: string, |
| 196 | 211 | budget?: AbortSignal, |
| 212 | rules: OwnRules = {}, | |
| 197 | 213 | ): Promise<Line[]> { |
| 198 | 214 | const origin = new URL(base).origin; |
| 199 | 215 | const cut = budget === undefined ? undefined : abortedBy(budget); |
| @@ -240,8 +256,14 @@ export async function probe( | ||
| 240 | 256 | |
| 241 | 257 | // 1. Sign-up and pricing. |
| 242 | 258 | const signup = await get("/signup"); |
| 259 | const shut = rules.signup === "invite" || rules.signup === "closed"; | |
| 243 | 260 | 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"); | |
| 245 | 267 | else say("sign-up page", "FAIL", "/signup", `${signup.status}${signup.status === 200 ? " without a form" : ""}`); |
| 246 | 268 | const pricing = await get("/pricing"); |
| 247 | 269 | const price = typeof pricing === "string" ? undefined : PRICE.exec(pricing.body)?.[0]; |
| @@ -296,21 +318,25 @@ export async function probe( | ||
| 296 | 318 | } |
| 297 | 319 | |
| 298 | 320 | // 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`); | |
| 307 | 327 | 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 | } | |
| 314 | 340 | } |
| 315 | 341 | } |
| 316 | 342 |
src/settings/signup.ts +2
| @@ -21,6 +21,8 @@ export const SIGNUP_MEANS: Record<SignupMode, string> = { | ||
| 21 | 21 | closed: "no new accounts", |
| 22 | 22 | }; |
| 23 | 23 | 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."; | |
| 24 | 26 | export const SIGNUP_DEFAULT: SignupMode = "open"; |
| 25 | 27 | |
| 26 | 28 | /** 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"; | ||
| 20 | 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 | 22 | import { HEALTHZ_MS, OUT_OF_BUDGET, type Line } from "../src/release/v1_checks.ts"; |
| 23 | import { getSignup, setSignup } from "../src/settings/signup.ts"; | |
| 23 | 24 | import { Session } from "../src/tui/forge.ts"; |
| 24 | 25 | import { statusLines } from "../src/tui/screens/status.ts"; |
| 25 | 26 | |
| @@ -38,6 +39,12 @@ interface Calls { | ||
| 38 | 39 | /** What the stub forge says today: everything green unless a switch says otherwise. */ |
| 39 | 40 | interface World { |
| 40 | 41 | 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; | |
| 41 | 48 | /** The call (1-based) that never answers and aborts the budget instead. */ |
| 42 | 49 | hangAt?: number; |
| 43 | 50 | } |
| @@ -59,6 +66,8 @@ function stubForge(world: () => World, now: () => number, calls: Calls[], budget | ||
| 59 | 66 | case "/": |
| 60 | 67 | return page("<h1>forge</h1>"); |
| 61 | 68 | 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 } }); | |
| 62 | 71 | return page("<form method=post></form>"); |
| 63 | 72 | case "/pricing": |
| 64 | 73 | return page(w.noPrice ? "<p>free for now</p>" : "<p>$5 a month</p>"); |
| @@ -104,6 +113,9 @@ beforeAll(async () => { | ||
| 104 | 113 | dir = await mkdtemp(join(tmpdir(), "daily-proof-")); |
| 105 | 114 | app = createApp({ dataDir: dir, port: 0 }); |
| 106 | 115 | 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]); | |
| 107 | 119 | }); |
| 108 | 120 | afterAll(async () => { |
| 109 | 121 | await servers.stop(); |
| @@ -389,3 +401,57 @@ describe("recording a run", () => { | ||
| 389 | 401 | expect(e.length).toBeLessThanOrEqual(240); |
| 390 | 402 | }); |
| 391 | 403 | }); |
| 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 | }); |
new above
offline