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

Merged opened this

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

Merged

scout/forge:scout/15388-the-v1-probe-proves-schedules-ran-in-the → main 0 commits fork 1 thread · 1 unresolved

  • Merged. scout/15388-the-v1-probe-proves-schedules-ran-in-the was merged into main as 27acc1a.

Review

Sign in to review this change.
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
362362 and an accessibility tree, which nothing dependency-free gives.
363363
364364 `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.
365366 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.
366367
367368 ## Secrets in the terminal
scripts/v1-probe.ts +82 −20
@@ -1,11 +1,15 @@
11 /**
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
33 * checklist (#15366), proven on the running forge. Read-only: every request
44 * is a GET, apart from one MCP `initialize` and one `tools/call` of the token-free
55 * `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
77 * `--repo` (default `trevato/forge`). It never signs in, pays or writes.
88 *
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 *
913 * It prints one line per item, `PASS`, `FAIL` or `UNKNOWN`, with the URL and
1014 * the evidence, and exits 0 only when every line is PASS. UNKNOWN is what an
1115 * anonymous read cannot prove; the line says what a person must check.
@@ -35,14 +39,36 @@ export const HEALTHZ_MS = 500;
3539 const DAY_MS = 24 * 60 * 60 * 1000;
3640 const PRICE = /[$€£]\s?\d+(?:[.,]\d+)?/;
3741
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>]";
4060 let base: string | undefined;
4161 let repo = "trevato/forge";
62 let edition: string | undefined;
4263 for (let i = 0; i < argv.length; i++) {
4364 const a = argv[i] ?? "";
4465 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;
4672 else return { error: usage };
4773 }
4874 if (base === undefined) return { error: usage };
@@ -54,7 +80,29 @@ export function parseArgs(argv: readonly string[]): { base: string; repo: string
5480 }
5581 if (url.protocol !== "https:" && url.protocol !== "http:") return { error: `${base} is not http(s); ${usage}` };
5682 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);
outdated

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.

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;
58106 }
59107
60108 /** What production announced: a release number, or the short commit of an unstamped build. */
@@ -108,12 +156,12 @@ function readOnlyCall(body: unknown): boolean {
108156 }
109157
110158 /** 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[]> {
112160 const origin = new URL(base).origin;
113161 const get = async (path: string, init?: RequestInit): Promise<Seen | string> => {
114162 const url = new URL(path, origin);
115 if (url.origin !== origin) return `${url.href} is not on ${origin}`;
116163 const method = init?.method ?? "GET";
164 if (url.origin !== origin && !(method === "GET" && url.href === edition)) return `${url.href} is not on ${origin}`;
117165 if (method !== "GET" && !(method === "POST" && url.pathname === "/mcp" && readOnlyCall(init?.body))) return `${method} is not a read`;
118166 const started = performance.now();
119167 try {
@@ -208,17 +256,31 @@ export async function probe(base: string, repo: string, fetcher: Fetcher = fetch
208256 else if (health.status === 200 && health.ms <= HEALTHZ_MS) say("healthz fast", "PASS", "/healthz", `200 in ${health.ms} ms`);
209257 else say("healthz fast", "FAIL", "/healthz", `${health.status} in ${health.ms} ms (limit ${HEALTHZ_MS} ms)`);
210258
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 }
222284 }
223285
224286 // 7. Security headers and CSP on / and /pricing.
@@ -247,7 +309,7 @@ if (import.meta.main) {
247309 console.error(parsed.error);
248310 process.exit(2);
249311 }
250 const lines = await probe(parsed.base, parsed.repo);
312 const lines = await probe(parsed.base, parsed.repo, fetch, Date.now(), parsed.edition);
251313 for (const l of lines) console.log(formatLine(l));
252314 const pass = lines.every((l) => l.verdict === "PASS");
253315 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 @@
44 */
55
66 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";
88
99 const NOW = Date.parse("2026-11-21T12:00:00Z");
1010 const COMMIT = "c".repeat(40);
@@ -67,7 +67,26 @@ const server = Bun.serve({
6767 return json({ error: "not_found" }, 404);
6868 },
6969 });
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 };
7190 const base = `http://127.0.0.1:${server.port}`;
7291 const run = async (w: Partial<World>): Promise<Record<string, Line>> => {
7392 world = { ...green(), ...w };
@@ -102,6 +121,34 @@ describe("v1 probe", () => {
102121 expect((await run({ runs: null }))["schedules ran in 24 h"]!.verdict).toBe("UNKNOWN");
103122 });
104123
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
105152 test("a short commit announced is compared to the newest release's commit, naming both (#15387)", async () => {
106153 const pass = (await run({ version: COMMIT.slice(0, 7) }))["version agrees"]!;
107154 expect(pass.verdict).toBe("PASS");
@@ -133,6 +180,9 @@ describe("v1 probe", () => {
133180 { method: "POST", path: "/mcp", mcp: "tools/call releases" },
134181 ]);
135182 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" }]);
136186 });
137187
138188 test("the arguments are a base URL and an owner/name repo", () => {
@@ -141,5 +191,8 @@ describe("v1 probe", () => {
141191 expect(parseArgs([])).toHaveProperty("error");
142192 expect(parseArgs(["ftp://f.example"])).toHaveProperty("error");
143193 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");
144197 });
145198 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs