Public: anyone can read this; the crew can change it.
The daily proof runs only on the forge that holds the repository it proves #16358
sold/proof-only-at-home → main 1 commit
2 files
changed +39
−0
src/maintain/duties/daily_proof.ts +10
| @@ -13,6 +13,7 @@ | ||
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | import { ownRepoPath } from "../../kernel/own_repo.ts"; |
| 16 | import { getRepo } from "../../core/repos.ts"; | |
| 16 | 17 | import { publicOrigin } from "../../core/public_origin.ts"; |
| 17 | 18 | import { shortOf } from "../../kernel/version.ts"; |
| 18 | 19 | import { BUDGET_MS, lastRelease, proveDaily, recordRun, releaseDue, releaseId } from "../../release/daily_proof.ts"; |
| @@ -63,6 +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 | // The proof is of the forge whose repository this is: a forge deployed from it (a pinned or | |
| 68 | // sold forge) holds no such repository and has no release of it, and its closed sign-up is | |
| 69 | // its owner's choice, so proving production there would only ever fail (test1, 2026-11-24). | |
| 70 | const [owner = "", name = ""] = repo.split("/"); | |
| 71 | if (!owner || !name || getRepo(db, owner, name) === undefined) { | |
| 72 | // An ask raised before this rule (a sold forge's first boots) would otherwise stand for ever. | |
| 73 | db.run("DELETE FROM daily_proof_ask"); | |
| 74 | return { findings: [], actions: [`skipped: this forge does not hold ${repo}, the repository whose production this proves`] }; | |
| 75 | } | |
| 66 | 76 | let lines: Line[]; |
| 67 | 77 | if (fetcher !== undefined || app === undefined) lines = await proveDaily(base, repo, fetcher ?? fetch, now.getTime(), budget()); |
| 68 | 78 | else { |
test/daily-proof.test.ts +29
| @@ -12,6 +12,8 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 12 | 12 | import { tmpdir } from "node:os"; |
| 13 | 13 | import { join } from "node:path"; |
| 14 | 14 | import { createApp, type App } from "../src/app.ts"; |
| 15 | import { createRepo } from "../src/core/repos.ts"; | |
| 16 | import { createUser } from "../src/core/users.ts"; | |
| 15 | 17 | import { firedAlarms, FORGE_BROKEN } from "../src/flow/alarms.ts"; |
| 16 | 18 | import { serve, type Servers } from "../src/http/server.ts"; |
| 17 | 19 | import { dailyProof } from "../src/maintain/duties/daily_proof.ts"; |
| @@ -90,6 +92,12 @@ let servers: Servers; | ||
| 90 | 92 | let world: World = {}; |
| 91 | 93 | let now = T0; |
| 92 | 94 | const calls: Calls[] = []; |
| 95 | /** The proof is of the forge that holds `o/forge`: give a test forge that repository. */ | |
| 96 | async function holdOwn(a: App): Promise<void> { | |
| 97 | const u = await createUser(a.db, { origin: "seed", trusted: true, username: "o", email: "[email protected]", password: "a-good-passphrase", isAdmin: true }); | |
| 98 | const id = (u as any).ok === false ? undefined : ((u as any).value?.id ?? (u as any).id); | |
| 99 | await createRepo(a.db, a.reposRoot, { ownerId: id, name: "forge", visibility: "public" } as any); | |
| 100 | } | |
| 93 | 101 | const fakeApp = () => ({ config: { url: `${BASE}/`, forgeRepo: "o/forge" } }) as unknown as App; |
| 94 | 102 | const runDay = async (day: number, w: World = {}): Promise<DutyResult> => { |
| 95 | 103 | world = w; |
| @@ -103,6 +111,7 @@ const verdicts = () => Object.fromEntries((lastRun(app.db)?.lines ?? []).map((l) | ||
| 103 | 111 | beforeAll(async () => { |
| 104 | 112 | dir = await mkdtemp(join(tmpdir(), "daily-proof-")); |
| 105 | 113 | app = createApp({ dataDir: dir, port: 0 }); |
| 114 | await holdOwn(app); | |
| 106 | 115 | servers = await serve(app); |
| 107 | 116 | }); |
| 108 | 117 | afterAll(async () => { |
| @@ -219,6 +228,7 @@ describe("once after each release goes live (#15937)", () => { | ||
| 219 | 228 | |
| 220 | 229 | test("a new release id runs the proof exactly once after it settles; an unchanged one none", async () => { |
| 221 | 230 | const sub = createApp({ dataDir: join(dir, "release-app"), port: 0, url: `${BASE}/`, forgeRepo: "o/forge" }); |
| 231 | await holdOwn(sub); | |
| 222 | 232 | let clock = T0; |
| 223 | 233 | const runs = () => (sub.db.query("SELECT COUNT(*) AS n FROM daily_proof_run").get() as { n: number }).n; |
| 224 | 234 | const boot = (release: string, bootedAt: number) => { |
| @@ -312,6 +322,7 @@ describe("the forge's own origin, read in process (#15936)", () => { | ||
| 312 | 322 | |
| 313 | 323 | test("with the gate refusing every outside fetch, the duty still reads real lines from its own router", async () => { |
| 314 | 324 | const own = createApp({ dataDir: join(dir, "own"), port: 0, url: `${BASE}/`, forgeRepo: "o/forge" }); |
| 325 | await holdOwn(own); | |
| 315 | 326 | const real = globalThis.fetch; |
| 316 | 327 | const outside: string[] = []; |
| 317 | 328 | globalThis.fetch = (async (input: string | URL | Request) => { |
| @@ -389,3 +400,21 @@ describe("recording a run", () => { | ||
| 389 | 400 | expect(e.length).toBeLessThanOrEqual(240); |
| 390 | 401 | }); |
| 391 | 402 | }); |
| 403 | ||
| 404 | describe("a forge that does not hold the repository (a deployed or sold forge)", () => { | |
| 405 | test("proves nothing and asks nothing: its closed sign-up and missing releases are not production failing", async () => { | |
| 406 | const other = createApp({ dataDir: join(dir, "sold"), port: 0, url: `${BASE}/`, forgeRepo: "o/forge" }); | |
| 407 | try { | |
| 408 | other.db.run("INSERT INTO daily_proof_ask (item, raised_at, verdict, url, evidence) VALUES ('sign-up page', '2026-11-24T00:00:00.000Z', 'FAIL', 'u', '403')"); | |
| 409 | const calls: string[] = []; | |
| 410 | const r = await dailyProof(async (u) => (calls.push(String(u)), new Response("x")), undefined, { release: null }).run({ db: other.db, bus: other.bus, now: new Date(), app: other }); | |
| 411 | expect(calls).toEqual([]); | |
| 412 | expect(r.findings).toEqual([]); | |
| 413 | expect(r.actions.join(" ")).toContain("does not hold o/forge"); | |
| 414 | expect((other.db.query("SELECT COUNT(*) AS n FROM daily_proof_run").get() as { n: number }).n).toBe(0); | |
| 415 | expect((other.db.query("SELECT COUNT(*) AS n FROM daily_proof_ask").get() as { n: number }).n).toBe(0); | |
| 416 | } finally { | |
| 417 | other.close(); | |
| 418 | } | |
| 419 | }); | |
| 420 | }); |
new above
offline