Public: anyone can read this; the crew can change it.
The v1 probe proves schedules ran in the last 24 hours from a public read, not a 404 on an owner-only route #15390
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15388-the-v1-probe-proves-schedules-ran-in-the → main 0 commits fork 1 thread · 1 unresolved
3 files
changed +138
−22
docs/OPERATING.md +1
| @@ -362,6 +362,7 @@ of this check only, never loaded by the server: its rules need a rendered page | ||
| 362 | 362 | and an accessibility tree, which nothing dependency-free gives. |
| 363 | 363 | |
| 364 | 364 | `bun scripts/v1-probe.ts https://forge.open-platform.sh` reads production (GETs and one MCP initialize, never signed in) and prints PASS, FAIL or UNKNOWN per v1.0.0 item with its URL and evidence. |
| 365 | `--edition <url>` names a public page a scheduled app prints (the morning paper's latest edition): its newest `<time datetime>` proves the schedules line, PASS within 24 h, FAIL older, UNKNOWN when the page is not public. Without it that line is UNKNOWN, because the schedules API answers 404 to an anonymous read. No public page prints a dated edition yet: the morning paper posts only in the signed-in Captain thread. #15393 adds one, and that page is the URL to pass. | |
| 365 | 366 | The owner tags v1.0.0 only when every line is PASS; an UNKNOWN line names what a person must check, and is not a pass. |
| 366 | 367 | |
| 367 | 368 | ## Secrets in the terminal |
scripts/v1-probe.ts +82 −20
| @@ -1,11 +1,15 @@ | ||
| 1 | 1 | /** |
| 2 | * `bun scripts/v1-probe.ts <base-url> [--repo owner/name]`: the v1.0.0 | |
| 2 | * `bun scripts/v1-probe.ts <base-url> [--repo owner/name] [--edition <url>]`: the v1.0.0 | |
| 3 | 3 | * checklist (#15366), proven on the running forge. Read-only: every request |
| 4 | 4 | * is a GET, apart from one MCP `initialize` and one `tools/call` of the token-free |
| 5 | 5 | * `releases` tool (POSTs that change nothing), and |
| 6 | * every request goes to `<base-url>`, never to another host, and reads only | |
| 6 | * every request goes to `<base-url>`, apart from one GET of `--edition`, and reads only | |
| 7 | 7 | * `--repo` (default `trevato/forge`). It never signs in, pays or writes. |
| 8 | 8 | * |
| 9 | * `--edition` is a public page a scheduled app prints, such as the morning paper's latest | |
| 10 | * edition (#15388): its newest `<time datetime>` or `<updated>` is when the schedule last ran, | |
| 11 | * because an anonymous read of the schedules API answers 404. | |
| 12 | * | |
| 9 | 13 | * It prints one line per item, `PASS`, `FAIL` or `UNKNOWN`, with the URL and |
| 10 | 14 | * the evidence, and exits 0 only when every line is PASS. UNKNOWN is what an |
| 11 | 15 | * anonymous read cannot prove; the line says what a person must check. |
| @@ -35,14 +39,36 @@ export const HEALTHZ_MS = 500; | ||
| 35 | 39 | const DAY_MS = 24 * 60 * 60 * 1000; |
| 36 | 40 | const PRICE = /[$€£]\s?\d+(?:[.,]\d+)?/; |
| 37 | 41 | |
| 38 | export function parseArgs(argv: readonly string[]): { base: string; repo: string } | { error: string } { | |
| 39 | const usage = "usage: bun scripts/v1-probe.ts <base-url> [--repo owner/name]"; | |
| 42 | export interface Args { | |
| 43 | readonly base: string; | |
| 44 | readonly repo: string; | |
| 45 | /** A public page whose newest date is the schedule's last run (#15388). */ | |
| 46 | readonly edition?: string; | |
| 47 | } | |
| 48 | ||
| 49 | const httpUrl = (text: string): URL | undefined => { | |
| 50 | try { | |
| 51 | const url = new URL(text); | |
| 52 | return url.protocol === "https:" || url.protocol === "http:" ? url : undefined; | |
| 53 | } catch { | |
| 54 | return undefined; | |
| 55 | } | |
| 56 | }; | |
| 57 | ||
| 58 | export function parseArgs(argv: readonly string[]): Args | { error: string } { | |
| 59 | const usage = "usage: bun scripts/v1-probe.ts <base-url> [--repo owner/name] [--edition <url>]"; | |
| 40 | 60 | let base: string | undefined; |
| 41 | 61 | let repo = "trevato/forge"; |
| 62 | let edition: string | undefined; | |
| 42 | 63 | for (let i = 0; i < argv.length; i++) { |
| 43 | 64 | const a = argv[i] ?? ""; |
| 44 | 65 | if (a === "--repo") repo = argv[++i] ?? ""; |
| 45 | else if (base === undefined) base = a; | |
| 66 | else if (a === "--edition") { | |
| 67 | const raw = argv[++i] ?? ""; | |
| 68 | const url = httpUrl(raw); | |
| 69 | if (!url || url.username || url.password) return { error: `--edition ${raw} is not an http(s) URL; ${usage}` }; | |
| 70 | edition = url.href; | |
| 71 | } else if (base === undefined) base = a; | |
| 46 | 72 | else return { error: usage }; |
| 47 | 73 | } |
| 48 | 74 | if (base === undefined) return { error: usage }; |
| @@ -54,7 +80,29 @@ export function parseArgs(argv: readonly string[]): { base: string; repo: string | ||
| 54 | 80 | } |
| 55 | 81 | if (url.protocol !== "https:" && url.protocol !== "http:") return { error: `${base} is not http(s); ${usage}` }; |
| 56 | 82 | if (!/^[A-Za-z0-9_-][A-Za-z0-9._-]*\/[A-Za-z0-9_-][A-Za-z0-9._-]*$/.test(repo)) return { error: `--repo ${repo} is not owner/name` }; |
| 57 | return { base: url.origin, repo }; | |
| 83 | return { base: url.origin, repo, ...(edition ? { edition } : {}) }; | |
| 84 | } | |
| 85 | ||
| 86 | const STAMP = /<time\b[^>]*\bdatetime\s*=\s*["']([^"']{1,40})["']|<updated>\s*([^<]{1,40}?)\s*<\/updated>/gi; | |
| 87 | const DATE_ONLY = /^\d{4}-\d{2}-\d{2}$/; | |
| 88 | ||
| 89 | /** | |
| 90 | * When the newest edition on a printed page was made: the latest `<time datetime>` or Atom | |
| 91 | * `<updated>` not more than an hour ahead of `now`. A date with no time counts as the end of that | |
| 92 | * day (UTC) capped at `now`, kept once its day has begun, so a paper dated today or yesterday is | |
| 93 | * fresh whatever its time zone. | |
| 94 | */ | |
| 95 | export function editionDate(body: string, now: number): { at: number; text: string } | undefined { | |
| 96 | let best: { at: number; text: string } | undefined; | |
| 97 | for (const m of body.matchAll(STAMP)) { | |
| 98 | const text = (m[1] ?? m[2] ?? "").trim(); | |
| 99 | const parsed = Date.parse(text); | |
| 100 | if (!Number.isFinite(parsed)) continue; | |
| 101 | if (parsed - now > 60 * 60 * 1000) continue; | |
| 102 | const at = DATE_ONLY.test(text) ? Math.min(parsed + DAY_MS, now) : parsed; | |
| 103 | if (!best || at > best.at) best = { at, text }; | |
| 104 | } | |
| 105 | return best; | |
| 58 | 106 | } |
| 59 | 107 | |
| 60 | 108 | /** What production announced: a release number, or the short commit of an unstamped build. */ |
| @@ -108,12 +156,12 @@ function readOnlyCall(body: unknown): boolean { | ||
| 108 | 156 | } |
| 109 | 157 | |
| 110 | 158 | /** Runs every item against `base` and returns the lines in checklist order. */ |
| 111 | export async function probe(base: string, repo: string, fetcher: Fetcher = fetch, now = Date.now()): Promise<Line[]> { | |
| 159 | export async function probe(base: string, repo: string, fetcher: Fetcher = fetch, now = Date.now(), edition?: string): Promise<Line[]> { | |
| 112 | 160 | const origin = new URL(base).origin; |
| 113 | 161 | const get = async (path: string, init?: RequestInit): Promise<Seen | string> => { |
| 114 | 162 | const url = new URL(path, origin); |
| 115 | if (url.origin !== origin) return `${url.href} is not on ${origin}`; | |
| 116 | 163 | const method = init?.method ?? "GET"; |
| 164 | if (url.origin !== origin && !(method === "GET" && url.href === edition)) return `${url.href} is not on ${origin}`; | |
| 117 | 165 | if (method !== "GET" && !(method === "POST" && url.pathname === "/mcp" && readOnlyCall(init?.body))) return `${method} is not a read`; |
| 118 | 166 | const started = performance.now(); |
| 119 | 167 | try { |
| @@ -208,17 +256,31 @@ export async function probe(base: string, repo: string, fetcher: Fetcher = fetch | ||
| 208 | 256 | else if (health.status === 200 && health.ms <= HEALTHZ_MS) say("healthz fast", "PASS", "/healthz", `200 in ${health.ms} ms`); |
| 209 | 257 | else say("healthz fast", "FAIL", "/healthz", `${health.status} in ${health.ms} ms (limit ${HEALTHZ_MS} ms)`); |
| 210 | 258 | |
| 211 | // 6. Schedules (#11595) ran in the last 24 h. | |
| 212 | const sched = await get(`${api}/schedules?runs=50`); | |
| 213 | const runs = typeof sched === "string" ? undefined : (json(sched) as { runs?: { startedAt?: unknown; name?: unknown }[] } | undefined)?.runs; | |
| 214 | const schedPath = `${api}/schedules?runs=50`; | |
| 215 | if (!Array.isArray(runs)) say("schedules ran in 24 h", "UNKNOWN", schedPath, `${typeof sched === "string" ? sched : sched.status}; a person must open the schedules page signed in`); | |
| 216 | else if (runs.length === 0) say("schedules ran in 24 h", "UNKNOWN", schedPath, "no runs visible to an anonymous read; a person must open the schedules page signed in"); | |
| 217 | else { | |
| 218 | const newest = Math.max(...runs.map((r) => (typeof r.startedAt === "number" ? r.startedAt : 0))); | |
| 219 | const ago = Math.round((now - newest) / 60_000); | |
| 220 | if (now - newest <= DAY_MS) say("schedules ran in 24 h", "PASS", schedPath, `newest run ${ago} min ago`); | |
| 221 | else say("schedules ran in 24 h", "FAIL", schedPath, newest > 0 ? `newest run ${ago} min ago` : "no run names when it started"); | |
| 259 | // 6. Schedules (#11595) ran in the last 24 h: from the public page a scheduled app prints | |
| 260 | // (#15388), else the schedules API, which answers 404 to an anonymous read. | |
| 261 | const item = "schedules ran in 24 h"; | |
| 262 | const signedIn = `a person must open ${at(`/${repo}`)} signed in and read its Schedules card, or pass --edition <a public page the schedule prints>`; | |
| 263 | if (edition) { | |
| 264 | const page = await get(edition); | |
| 265 | const stamp = typeof page === "string" || page.status !== 200 ? undefined : editionDate(page.body, now); | |
| 266 | if (typeof page === "string" || page.status !== 200) say(item, "UNKNOWN", edition, `${typeof page === "string" ? page : page.status}, the page is not public; a person must open ${edition}`); | |
| 267 | else if (!stamp) say(item, "UNKNOWN", edition, `200 with no <time datetime> or <updated>; a person must open ${edition} and read the edition's date`); | |
| 268 | else { | |
| 269 | const ago = Math.round((now - stamp.at) / 60_000); | |
| 270 | say(item, now - stamp.at <= DAY_MS ? "PASS" : "FAIL", edition, `newest edition dated ${stamp.text}, ${ago} min ago`); | |
| 271 | } | |
| 272 | } else { | |
| 273 | const schedPath = `${api}/schedules?runs=50`; | |
| 274 | const sched = await get(schedPath); | |
| 275 | const runs = typeof sched === "string" ? undefined : (json(sched) as { runs?: { startedAt?: unknown; name?: unknown }[] } | undefined)?.runs; | |
| 276 | if (!Array.isArray(runs)) say(item, "UNKNOWN", schedPath, `${typeof sched === "string" ? sched : sched.status}; ${signedIn}`); | |
| 277 | else if (runs.length === 0) say(item, "UNKNOWN", schedPath, `no runs visible to an anonymous read; ${signedIn}`); | |
| 278 | else { | |
| 279 | const newest = Math.max(...runs.map((r) => (typeof r.startedAt === "number" ? r.startedAt : 0))); | |
| 280 | const ago = Math.round((now - newest) / 60_000); | |
| 281 | if (now - newest <= DAY_MS) say(item, "PASS", schedPath, `newest run ${ago} min ago`); | |
| 282 | else say(item, "FAIL", schedPath, newest > 0 ? `newest run ${ago} min ago` : "no run names when it started"); | |
| 283 | } | |
| 222 | 284 | } |
| 223 | 285 | |
| 224 | 286 | // 7. Security headers and CSP on / and /pricing. |
| @@ -247,7 +309,7 @@ if (import.meta.main) { | ||
| 247 | 309 | console.error(parsed.error); |
| 248 | 310 | process.exit(2); |
| 249 | 311 | } |
| 250 | const lines = await probe(parsed.base, parsed.repo); | |
| 312 | const lines = await probe(parsed.base, parsed.repo, fetch, Date.now(), parsed.edition); | |
| 251 | 313 | for (const l of lines) console.log(formatLine(l)); |
| 252 | 314 | const pass = lines.every((l) => l.verdict === "PASS"); |
| 253 | 315 | console.log(pass ? "every line PASS: v1.0.0 may be tagged" : "not every line is PASS: do not tag v1.0.0"); |
test/v1-probe.test.ts +55 −2
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | import { afterAll, describe, expect, test } from "bun:test"; |
| 7 | import { formatLine, parseArgs, probe, type Line } from "../scripts/v1-probe.ts"; | |
| 7 | import { editionDate, formatLine, parseArgs, probe, type Line } from "../scripts/v1-probe.ts"; | |
| 8 | 8 | |
| 9 | 9 | const NOW = Date.parse("2026-11-21T12:00:00Z"); |
| 10 | 10 | const COMMIT = "c".repeat(40); |
| @@ -67,7 +67,26 @@ const server = Bun.serve({ | ||
| 67 | 67 | return json({ error: "not_found" }, 404); |
| 68 | 68 | }, |
| 69 | 69 | }); |
| 70 | afterAll(() => server.stop(true)); | |
| 70 | /** The scheduled app's own host: its latest printed edition, or 404 when it is not public. */ | |
| 71 | let paper: { status: number; body: string } = { status: 200, body: "" }; | |
| 72 | const paperHost = Bun.serve({ | |
| 73 | port: 0, | |
| 74 | fetch(req) { | |
| 75 | seen.push({ method: req.method, path: `paper${new URL(req.url).pathname}` }); | |
| 76 | return new Response(paper.body, { status: paper.status, headers: { "content-type": "text/html" } }); | |
| 77 | }, | |
| 78 | }); | |
| 79 | afterAll(() => { | |
| 80 | server.stop(true); | |
| 81 | paperHost.stop(true); | |
| 82 | }); | |
| 83 | const editionUrl = `http://127.0.0.1:${paperHost.port}/editions/latest`; | |
| 84 | const printed = async (status: number, body: string): Promise<Line> => { | |
| 85 | world = green(); | |
| 86 | paper = { status, body }; | |
| 87 | const lines = await probe(base, "o/r", fetch, NOW, editionUrl); | |
| 88 | return lines.find((l) => l.item === "schedules ran in 24 h")!; | |
| 89 | }; | |
| 71 | 90 | const base = `http://127.0.0.1:${server.port}`; |
| 72 | 91 | const run = async (w: Partial<World>): Promise<Record<string, Line>> => { |
| 73 | 92 | world = { ...green(), ...w }; |
| @@ -102,6 +121,34 @@ describe("v1 probe", () => { | ||
| 102 | 121 | expect((await run({ runs: null }))["schedules ran in 24 h"]!.verdict).toBe("UNKNOWN"); |
| 103 | 122 | }); |
| 104 | 123 | |
| 124 | test("the schedule is proven by the public edition it printed: PASS within 24 h, FAIL older, UNKNOWN not public (#15388)", async () => { | |
| 125 | const fresh = await printed(200, `<h1>Morning paper</h1><time datetime="2026-11-20T13:15:00Z">Friday</time><a><time datetime="2026-11-21T11:15:00Z"></time></a>`); | |
| 126 | expect(fresh.verdict).toBe("PASS"); | |
| 127 | expect(fresh.url).toBe(editionUrl); | |
| 128 | expect(fresh.evidence).toBe("newest edition dated 2026-11-21T11:15:00Z, 45 min ago"); | |
| 129 | const stale = await printed(200, `<time datetime="2026-11-20T07:00:00Z">Friday</time>`); | |
| 130 | expect(stale.verdict).toBe("FAIL"); | |
| 131 | expect(stale.evidence).toBe("newest edition dated 2026-11-20T07:00:00Z, 1740 min ago"); | |
| 132 | const shut = await printed(404, "not found"); | |
| 133 | expect(shut.verdict).toBe("UNKNOWN"); | |
| 134 | expect(shut.evidence).toBe(`404, the page is not public; a person must open ${editionUrl}`); | |
| 135 | expect((await printed(200, "<p>no date</p>")).evidence).toContain(`a person must open ${editionUrl} and read the edition's date`); | |
| 136 | }); | |
| 137 | ||
| 138 | test("without --edition the line names the page a person must open", async () => { | |
| 139 | const r = await run({ runs: null }); | |
| 140 | expect(r["schedules ran in 24 h"]!.evidence).toContain(`a person must open ${base}/o/r signed in and read its Schedules card`); | |
| 141 | }); | |
| 142 | ||
| 143 | test("an edition's date: the newest stamp, a bare date as its day's end capped at now, none from the future", () => { | |
| 144 | expect(editionDate(`<feed><updated>2026-11-21T05:15:00-06:00</updated></feed>`, NOW)?.at).toBe(Date.parse("2026-11-21T11:15:00Z")); | |
| 145 | expect(editionDate(`<time datetime="2026-11-20">`, NOW)?.at).toBe(Date.parse("2026-11-21T00:00:00Z")); | |
| 146 | expect(editionDate(`<time datetime="2026-11-20">yesterday</time><time datetime="2026-11-21">today</time>`, NOW)).toEqual({ at: NOW, text: "2026-11-21" }); | |
| 147 | expect(editionDate(`<time datetime="2026-11-22">`, NOW)).toBeUndefined(); | |
| 148 | expect(editionDate(`<time datetime="2026-11-25T00:00:00Z">next</time><time datetime="2026-11-19">`, NOW)?.text).toBe("2026-11-19"); | |
| 149 | expect(editionDate(`<time datetime="soon">`, NOW)).toBeUndefined(); | |
| 150 | }); | |
| 151 | ||
| 105 | 152 | test("a short commit announced is compared to the newest release's commit, naming both (#15387)", async () => { |
| 106 | 153 | const pass = (await run({ version: COMMIT.slice(0, 7) }))["version agrees"]!; |
| 107 | 154 | expect(pass.verdict).toBe("PASS"); |
| @@ -133,6 +180,9 @@ describe("v1 probe", () => { | ||
| 133 | 180 | { method: "POST", path: "/mcp", mcp: "tools/call releases" }, |
| 134 | 181 | ]); |
| 135 | 182 | expect(urls.every((u) => u.startsWith(`${base}/`))).toBe(true); |
| 183 | seen.length = 0; | |
| 184 | await printed(200, "<p></p>"); | |
| 185 | expect(seen.filter((s) => s.path.startsWith("paper"))).toEqual([{ method: "GET", path: "paper/editions/latest" }]); | |
| 136 | 186 | }); |
| 137 | 187 | |
| 138 | 188 | test("the arguments are a base URL and an owner/name repo", () => { |
| @@ -141,5 +191,8 @@ describe("v1 probe", () => { | ||
| 141 | 191 | expect(parseArgs([])).toHaveProperty("error"); |
| 142 | 192 | expect(parseArgs(["ftp://f.example"])).toHaveProperty("error"); |
| 143 | 193 | expect(parseArgs(["https://f.example", "--repo", "../x"])).toHaveProperty("error"); |
| 194 | expect(parseArgs(["https://f.example", "--edition", "https://paper.example/today"])).toEqual({ base: "https://f.example", repo: "trevato/forge", edition: "https://paper.example/today" }); | |
| 195 | expect(parseArgs(["https://f.example", "--edition", "file:///etc/passwd"])).toHaveProperty("error"); | |
| 196 | expect(parseArgs(["https://f.example", "--edition"])).toHaveProperty("error"); | |
| 144 | 197 | }); |
| 145 | 198 | }); |
new above
offline
A bare date at end-of-day is usually more than 1 h ahead of now, so today's date is dropped here. Cap the date-only case at
now(or accept when parsed <= now) and test with today's date.