Public: anyone can read this; the crew can change it.
The v1 proof's "production reports a release version" probe cannot fail: it reads the API's version constant, and the planner acted on the result #13085
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/13042-the-v1-proof-s-production-reports-a-rele → main 3 commits fork
4 files
changed +46
−16
docs/features/v1-proven.md +7
| @@ -14,6 +14,13 @@ One read-only probe (GET only) for each item on the v1 list, one line each: | ||
| 14 | 14 | is seen), and #11595 only against a forge whose health answer predates |
| 15 | 15 | #12512. |
| 16 | 16 | |
| 17 | Two probes read the release the forge runs, from `version` on | |
| 18 | `GET /api/v1/health` (never `/api/v1/version`, which is the API's own constant | |
| 19 | and says 1.0.0 on every release). #10304 says it: `release 0.7.604`. #13042 | |
| 20 | fails until that release is 1.0.0 or later: `the release is 0.7.604, not 1.0.0`. | |
| 21 | Only the `v1.0.0` tag running on production passes it; the proof alone is not | |
| 22 | the owner's word that v1 is done. | |
| 23 | ||
| 17 | 24 | Exit 0 only when every probe passes; 1 when any fails; 3 when none fails but |
| 18 | 25 | some are unproven; 2 on bad usage. Owner-only pages are probed as "there and |
| 19 | 26 | gated". The schedule probe reads `schedules` on the public `GET /api/v1/health`: |
src/core/v1_proof.ts +20 −5
| @@ -39,6 +39,14 @@ async function bodyOk(get: Get, path: string, status = 200): Promise<Got> { | ||
| 39 | 39 | return got; |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | /** The release the forge runs, as `/api/v1/health` says it: `x.y.z`, or the probe fails. */ | |
| 43 | async function release(get: Get): Promise<string> { | |
| 44 | const got = await bodyOk(get, "/api/v1/health"); | |
| 45 | const v = (JSON.parse(got.text) as { version?: unknown }).version; | |
| 46 | expect(typeof v === "string" && /^\d+\.\d+\.\d+$/.test(v), "/api/v1/health names no x.y.z release"); | |
| 47 | return String(v); | |
| 48 | } | |
| 49 | ||
| 42 | 50 | /** The page exists and is gated: a redirect to sign-in, never a 404 or a 5xx. */ |
| 43 | 51 | async function gated(get: Get, path: string): Promise<string> { |
| 44 | 52 | const got = await get(path); |
| @@ -96,12 +104,19 @@ export const probes: readonly Probe[] = [ | ||
| 96 | 104 | }, |
| 97 | 105 | { |
| 98 | 106 | issue: 10304, |
| 99 | item: "production reports a release version", | |
| 107 | item: "production reports the release it runs", | |
| 108 | // The release the forge runs (`/api/v1/health`), not `/api/v1/version`: | |
| 109 | // that is the API's own constant. | |
| 110 | run: async (get) => `release ${await release(get)}`, | |
| 111 | }, | |
| 112 | { | |
| 113 | issue: 13042, | |
| 114 | item: "the release production runs is 1.0.0 or later", | |
| 100 | 115 | run: async (get) => { |
| 101 | const got = await bodyOk(get, "/api/v1/version"); | |
| 102 | const v = (JSON.parse(got.text) as { version?: unknown }).version; | |
| 103 | expect(typeof v === "string" && /^\d+\.\d+\.\d+$/.test(v), "/api/v1/version has no x.y.z version"); | |
| 104 | return `version ${String(v)}`; | |
| 116 | const v = await release(get); | |
| 117 | const [maj = 0, min = 0, pat = 0] = v.split(".").map(Number); | |
| 118 | expect(maj >= 1, `the release is ${v}, not 1.0.0`); | |
| 119 | return `release ${v} (${maj}.${min}.${pat}) is 1.0.0 or later`; | |
| 105 | 120 | }, |
| 106 | 121 | }, |
| 107 | 122 | { |
test/security-floor-paths.test.ts +3 −1
| @@ -212,6 +212,8 @@ test("`bun scripts/v1-proven.ts`'s proof passes 20 times in a row against a boot | ||
| 212 | 212 | const failed: string[] = []; |
| 213 | 213 | for (let run = 0; run < 20; run++) |
| 214 | 214 | for (const r of await prove(forge.servers.url, fetch)) |
| 215 | if (r.status !== "pass") failed.push(`run ${run}: ${line(r)}`); | |
| 215 | // A test forge is built from no release, so the two probes that read the release | |
| 216 | // (#10304, #13042) have nothing to read; every other probe must pass. | |
| 217 | if (r.status !== "pass" && r.issue !== 10304 && r.issue !== 13042) failed.push(`run ${run}: ${line(r)}`); | |
| 216 | 218 | expect(failed).toEqual([]); |
| 217 | 219 | }, 60_000); |
test/v1-proven.test.ts +16 −10
| @@ -24,8 +24,8 @@ const ldWith = (additionalProperty: unknown[]) => JSON.stringify({ offers: [{ na | ||
| 24 | 24 | const pricing = (json: string) => () => new Response(`<form method="post" action="/pricing/order"></form><script type="application/ld+json">${json}</script>${rule(7)}`); |
| 25 | 25 | const rule = (days: number, words = days) => |
| 26 | 26 | `<p data-lapse="sleep" data-grace-days="${days}">If a payment lapses, you have ${words} days of grace. After that your forge sleeps and keeps its data.</p>`; |
| 27 | const health = (schedules?: unknown) => | |
| 28 | Response.json({ ok: true, version: "1.0.0", commit: "058b6cf", draining: false, ...(schedules === undefined ? {} : { schedules }) }); | |
| 27 | const health = (schedules?: unknown, ver = "1.0.0") => | |
| 28 | Response.json({ ok: true, version: ver, commit: "058b6cf", draining: false, ...(schedules === undefined ? {} : { schedules }) }); | |
| 29 | 29 | |
| 30 | 30 | type Over = Record<string, () => Response>; |
| 31 | 31 | function stub(over: Over = {}, seen: string[] = []): Fetch { |
| @@ -34,7 +34,6 @@ function stub(over: Over = {}, seen: string[] = []): Fetch { | ||
| 34 | 34 | "/healthz": () => new Response("ok", { headers: HEADERS }), |
| 35 | 35 | "/readyz": () => new Response("ok"), |
| 36 | 36 | "/llms.txt": () => new Response("Running dev at 058b6cf\nPress Start my forge."), |
| 37 | "/api/v1/version": () => Response.json({ version: "1.0.0" }), | |
| 38 | 37 | "/pricing": () => |
| 39 | 38 | new Response(`<form method="post" action="/pricing/order"></form><script type="application/ld+json">${ld}</script>${rule(7)}`), |
| 40 | 39 | "/api/v1/plans": () => Response.json({ items: [], graceDays: 7, lapse: "sleep" }), |
| @@ -54,9 +53,9 @@ describe("v1-proven", () => { | ||
| 54 | 53 | test("every list item has a probe, and all pass on a healthy forge", async () => { |
| 55 | 54 | const results = await prove("https://f.test/", stub()); |
| 56 | 55 | expect(results.map((r) => r.issue).sort()).toEqual( |
| 57 | [11541, 11539, 11158, 11573, 10304, 11507, 11138, 11140, 11141, 11515, 11595, 10441].sort(), | |
| 56 | [11541, 11539, 11158, 11573, 10304, 13042, 11507, 11138, 11140, 11141, 11515, 11595, 10441].sort(), | |
| 58 | 57 | ); |
| 59 | expect(probes.length).toBe(12); | |
| 58 | expect(probes.length).toBe(13); | |
| 60 | 59 | const status = (n: number) => results.find((r) => r.issue === n)?.status; |
| 61 | 60 | // What no public read can show is unproven, never a pass. |
| 62 | 61 | expect(results.filter((r) => r.status === "unproven").map((r) => r.issue).sort()).toEqual([]); |
| @@ -65,6 +64,12 @@ describe("v1-proven", () => { | ||
| 65 | 64 | expect(line(results[0]!)).toStartWith("pass #11541"); |
| 66 | 65 | }); |
| 67 | 66 | |
| 67 | test("production at 0.7.604 reports its release and is not proven; the API's own constant does not pass it", async () => { | |
| 68 | const results = await prove("https://f.test", stub({ "/api/v1/health": () => health({ overdue: 0, oldestSeconds: 0 }, "0.7.604") })); | |
| 69 | expect(line(results.find((r) => r.issue === 10304)!)).toBe("pass #10304 production reports the release it runs: release 0.7.604"); | |
| 70 | expect(line(results.find((r) => r.issue === 13042)!)).toBe("fail #13042 the release production runs is 1.0.0 or later: the release is 0.7.604, not 1.0.0"); | |
| 71 | }); | |
| 72 | ||
| 68 | 73 | test("only reads: every request is a GET", async () => { |
| 69 | 74 | const seen: string[] = []; |
| 70 | 75 | await prove("https://f.test", stub({}, seen)); |
| @@ -78,7 +83,8 @@ describe("v1-proven", () => { | ||
| 78 | 83 | [11539, { "/healthz": () => new Response("down", { status: 503 }) }, [10441, 11539]], |
| 79 | 84 | [11158, { "/llms.txt": () => new Response("Running dev at 058b6cf") }, [11158]], |
| 80 | 85 | [11573, { "/readyz": () => new Response("draining", { status: 503 }) }, [11573]], |
| 81 | [10304, { "/api/v1/version": () => Response.json({ version: "dev" }) }, [10304]], | |
| 86 | [10304, { "/api/v1/health": () => health({ overdue: 0, oldestSeconds: 0 }, "dev") }, [10304, 13042]], | |
| 87 | [13042, { "/api/v1/health": () => health({ overdue: 0, oldestSeconds: 0 }, "0.7.604") }, [13042]], | |
| 82 | 88 | [11507, { "/llms.txt": () => new Response("Start my forge") }, [11507]], |
| 83 | 89 | [11138, { "/pricing": () => new Response("<p>none</p>") }, [11138, 11140, 11141]], |
| 84 | 90 | [11140, { "/pricing": () => new Response('<form method="post" action="/pricing/order"></form><script type="application/ld+json">{"offers":[]}</script>') }, [11140, 11141]], |
| @@ -106,8 +112,8 @@ describe("v1-proven", () => { | ||
| 106 | 112 | test("the schedule probe fails naming the oldest age, is unproven without the field, and a network error is a fail", async () => { |
| 107 | 113 | const late = (await prove("https://f.test", stub({ "/api/v1/health": () => health({ overdue: 2, oldestSeconds: 3 * 3600 + 720 }) }))).find((x) => x.issue === 11595)!; |
| 108 | 114 | expect(line(late)).toBe("fail #11595 no schedule is past its period: 2 schedule(s) overdue, the oldest by 3 h 12 min"); |
| 109 | for (const old of [health(), health({ overdue: "none" })]) { | |
| 110 | const r = (await prove("https://f.test", stub({ "/api/v1/health": () => old }))).find((x) => x.issue === 11595)!; | |
| 115 | for (const old of [() => health(), () => health({ overdue: "none" })]) { | |
| 116 | const r = (await prove("https://f.test", stub({ "/api/v1/health": old }))).find((x) => x.issue === 11595)!; | |
| 111 | 117 | expect(r.status).toBe("unproven"); |
| 112 | 118 | expect(line(r)).toStartWith("unproven #11595"); |
| 113 | 119 | } |
| @@ -137,7 +143,7 @@ describe("v1-proven", () => { | ||
| 137 | 143 | const { code, out } = await run(async () => new Response("down", { status: 503 })); |
| 138 | 144 | expect(code).toBe(1); |
| 139 | 145 | expect(out).toContain("fail #11539"); |
| 140 | expect(out).toContain("v1.0.0 is not proven: 12 of 12 fail, 0 unproven"); | |
| 146 | expect(out).toContain("v1.0.0 is not proven: 13 of 13 fail, 0 unproven"); | |
| 141 | 147 | }); |
| 142 | 148 | |
| 143 | 149 | test("the script exits 3, not 0, when nothing fails but some items are unproven", async () => { |
| @@ -145,7 +151,7 @@ describe("v1-proven", () => { | ||
| 145 | 151 | expect(out).not.toContain("fail #"); |
| 146 | 152 | expect(code).toBe(3); |
| 147 | 153 | expect(out).toContain("unproven #11595"); |
| 148 | expect(out).toContain("v1.0.0 is not proven: none fail, 1 of 12 unproven"); | |
| 154 | expect(out).toContain("v1.0.0 is not proven: none fail, 1 of 13 unproven"); | |
| 149 | 155 | }); |
| 150 | 156 | |
| 151 | 157 | test("the script exits 2 on bad usage", () => { |
new above
offline