Public: anyone can read this; the crew can change it.

One read-only production probe proves each v1.0.0 item is live, and its verdict is the checklist for tagging #15372

Merged opened this

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

Merged

scout/forge:scout/15366-one-read-only-production-probe-proves-ea → main 0 commits fork

  • Merged. scout/15366-one-read-only-production-probe-proves-ea was merged into main as d5d0d26.

Review

Sign in to review this change.
3 files changed +302 −0
docs/OPERATING.md +3
@@ -361,6 +361,9 @@ it falls back to a regex read of the served HTML). axe-core is a devDependency
361361 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
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 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
364367 ## Secrets in the terminal
365368
366369 A forge admin opens the palette (`ctrl+k`), picks **Secrets**, and sees the sealed names at a place with when each was set and last read — names only, never a value. `a` sets one (place, name, then the value typed or pasted masked and kept verbatim, newlines included), `d` removes the one under the cursor after a confirm, `s` looks at another place (`forge`, `org NAME`, `repo OWNER/NAME`). Everything is `actions/secrets.ts`, as the page and MCP `secrets` use it; a member has no entry.
scripts/v1-probe.ts added +192
@@ -0,0 +1,192 @@
1 /**
2 * `bun scripts/v1-probe.ts <base-url> [--repo owner/name]`: the v1.0.0
3 * checklist (#15366), proven on the running forge. Read-only: every request
4 * is a GET, apart from one MCP `initialize` (a POST that changes nothing), and
5 * every request goes to `<base-url>`, never to another host, and reads only
6 * `--repo` (default `trevato/forge`). It never signs in, pays or writes.
7 *
8 * It prints one line per item, `PASS`, `FAIL` or `UNKNOWN`, with the URL and
9 * the evidence, and exits 0 only when every line is PASS. UNKNOWN is what an
10 * anonymous read cannot prove; the line says what a person must check.
11 */
12
13 export type Verdict = "PASS" | "FAIL" | "UNKNOWN";
14
15 export interface Line {
16 readonly item: string;
17 readonly verdict: Verdict;
18 readonly url: string;
19 readonly evidence: string;
20 }
21
22 /** What one request saw: status, the headers named, the body, how long it took. */
23 interface Seen {
24 readonly status: number;
25 readonly headers: Headers;
26 readonly body: string;
27 readonly ms: number;
28 }
29
30 type Fetcher = (url: string, init?: RequestInit) => Promise<Response>;
31
32 /** Healthz slower than this is a FAIL: the common request answers in milliseconds. */
33 export const HEALTHZ_MS = 500;
34 const DAY_MS = 24 * 60 * 60 * 1000;
35 const PRICE = /[$€£]\s?\d+(?:[.,]\d+)?/;
36
37 export function parseArgs(argv: readonly string[]): { base: string; repo: string } | { error: string } {
38 const usage = "usage: bun scripts/v1-probe.ts <base-url> [--repo owner/name]";
39 let base: string | undefined;
40 let repo = "trevato/forge";
41 for (let i = 0; i < argv.length; i++) {
42 const a = argv[i] ?? "";
43 if (a === "--repo") repo = argv[++i] ?? "";
44 else if (base === undefined) base = a;
45 else return { error: usage };
46 }
47 if (base === undefined) return { error: usage };
48 let url: URL;
49 try {
50 url = new URL(base);
51 } catch {
52 return { error: `${base} is not a URL; ${usage}` };
53 }
54 if (url.protocol !== "https:" && url.protocol !== "http:") return { error: `${base} is not http(s); ${usage}` };
55 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` };
56 return { base: url.origin, repo };
57 }
58
59 /** Runs every item against `base` and returns the lines in checklist order. */
60 export async function probe(base: string, repo: string, fetcher: Fetcher = fetch, now = Date.now()): Promise<Line[]> {
61 const origin = new URL(base).origin;
62 const get = async (path: string, init?: RequestInit): Promise<Seen | string> => {
63 const url = new URL(path, origin);
64 if (url.origin !== origin) return `${url.href} is not on ${origin}`;
65 const method = init?.method ?? "GET";
66 if (method !== "GET" && !(method === "POST" && url.pathname === "/mcp")) return `${method} is not a read`;
67 const started = performance.now();
68 try {
69 const r = await fetcher(url.href, { ...init, method, redirect: "manual", signal: AbortSignal.timeout(15_000) });
70 const body = await r.text();
71 return { status: r.status, headers: r.headers, body, ms: Math.round(performance.now() - started) };
72 } catch (e) {
73 return `no answer: ${e instanceof Error ? e.message : String(e)}`;
74 }
75 };
76 const at = (path: string): string => new URL(path, origin).href;
77 const json = (s: Seen): unknown => {
78 if (!(s.headers.get("content-type") ?? "").includes("json")) return undefined;
79 try {
80 return JSON.parse(s.body) as unknown;
81 } catch {
82 return undefined;
83 }
84 };
85 const api = `/api/v1/repos/${repo}`;
86 const lines: Line[] = [];
87 const say = (item: string, verdict: Verdict, path: string, evidence: string): void => {
88 lines.push({ item, verdict, url: at(path), evidence });
89 };
90
91 // 1. Sign-up and pricing.
92 const signup = await get("/signup");
93 if (typeof signup === "string") say("sign-up page", "UNKNOWN", "/signup", signup);
94 else if (signup.status === 200 && /<form/i.test(signup.body)) say("sign-up page", "PASS", "/signup", "200 with a form");
95 else say("sign-up page", "FAIL", "/signup", `${signup.status}${signup.status === 200 ? " without a form" : ""}`);
96 const pricing = await get("/pricing");
97 const price = typeof pricing === "string" ? undefined : PRICE.exec(pricing.body)?.[0];
98 if (typeof pricing === "string") say("pricing names a price", "UNKNOWN", "/pricing", pricing);
99 else if (pricing.status === 200 && price) say("pricing names a price", "PASS", "/pricing", `200, names ${price}`);
100 else say("pricing names a price", "FAIL", "/pricing", `${pricing.status}, names no price`);
101
102 // 2. Production's version, from MCP initialize, and the tag main's gate cut.
103 const init = await get("/mcp", {
104 method: "POST",
105 headers: { "content-type": "application/json", accept: "application/json, text/event-stream" },
106 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "v1-probe", version: "1" } } }),
107 });
108 const served = typeof init === "string" ? undefined : (json(init) as { result?: { serverInfo?: { version?: unknown } } } | undefined)?.result?.serverInfo?.version;
109 const version = typeof served === "string" && /^\d+\.\d+\.\d+$/.test(served) ? served : undefined;
110 const tags = await get(`${api}/tags?limit=1`);
111 const tag = typeof tags === "string" ? undefined : (json(tags) as { items?: { name?: unknown; commit?: unknown }[] } | undefined)?.items?.[0];
112 const tagName = typeof tag?.name === "string" ? tag.name : undefined;
113 const tagCommit = typeof tag?.commit === "string" && /^[0-9a-f]{40}$/.test(tag.commit) ? tag.commit : undefined;
114
115 // 3. The stranger journey's last green release, from the check API.
116 const checkPath = tagCommit ? `${api}/commits/${tagCommit}/check` : `${api}/tags`;
117 if (!tagName || !tagCommit) say("stranger journey green on a release", "UNKNOWN", checkPath, "no release tag read; a person must open the latest tag's check");
118 else {
119 const check = await get(checkPath);
120 const c = typeof check === "string" ? undefined : (json(check) as { state?: unknown; runId?: unknown; finishedAt?: unknown } | undefined);
121 if (!c || typeof c.state !== "string") {
122 const why = typeof check === "string" ? check : `${check.status}, not the check's JSON`;
123 say("stranger journey green on a release", "UNKNOWN", checkPath, `${why}; a person must open ${tagName}'s check and see the stranger tests green`);
124 } else if (c.state === "ok") say("stranger journey green on a release", "PASS", checkPath, `${tagName} (${tagCommit.slice(0, 9)}) full check ok, run ${String(c.runId)}, which runs the stranger tests`);
125 else if (c.state === "failed") say("stranger journey green on a release", "FAIL", checkPath, `${tagName} check failed, run ${String(c.runId)}`);
126 else say("stranger journey green on a release", "UNKNOWN", checkPath, `${tagName} check is ${c.state}`);
127 }
128
129 // 4. /changelog, /changelog.atom and production's version agree with main's gate.
130 if (!version) say("version agrees", "UNKNOWN", "/mcp", typeof init === "string" ? init : `initialize named no version (${init.status})`);
131 else if (!tagName) say("version agrees", "UNKNOWN", `${api}/tags`, `production says ${version}; no tag read`);
132 else if (tagName !== `v${version}`) say("version agrees", "FAIL", `${api}/tags`, `production says ${version}, main's last tag is ${tagName}`);
133 else {
134 const page = await get("/changelog");
135 const atom = await get("/changelog.atom");
136 const named = (s: Seen | string): boolean => typeof s !== "string" && s.status === 200 && (s.body.includes(version) || (tagCommit !== undefined && s.body.includes(tagCommit.slice(0, 7))));
137 const misses = [named(page) ? "" : "/changelog", named(atom) ? "" : "/changelog.atom"].filter(Boolean);
138 if (misses.length === 0) say("version agrees", "PASS", "/changelog", `production ${version} = tag ${tagName}, named by /changelog and /changelog.atom`);
139 else say("version agrees", "FAIL", misses[0] ?? "/changelog", `production ${version} = tag ${tagName}, but ${misses.join(" and ")} ${misses.length === 1 ? "does" : "do"} not name it`);
140 }
141
142 // 5. /healthz fast.
143 const health = await get("/healthz");
144 if (typeof health === "string") say("healthz fast", "FAIL", "/healthz", health);
145 else if (health.status === 200 && health.ms <= HEALTHZ_MS) say("healthz fast", "PASS", "/healthz", `200 in ${health.ms} ms`);
146 else say("healthz fast", "FAIL", "/healthz", `${health.status} in ${health.ms} ms (limit ${HEALTHZ_MS} ms)`);
147
148 // 6. Schedules (#11595) ran in the last 24 h.
149 const sched = await get(`${api}/schedules?runs=50`);
150 const runs = typeof sched === "string" ? undefined : (json(sched) as { runs?: { startedAt?: unknown; name?: unknown }[] } | undefined)?.runs;
151 const schedPath = `${api}/schedules?runs=50`;
152 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`);
153 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");
154 else {
155 const newest = Math.max(...runs.map((r) => (typeof r.startedAt === "number" ? r.startedAt : 0)));
156 const ago = Math.round((now - newest) / 60_000);
157 if (now - newest <= DAY_MS) say("schedules ran in 24 h", "PASS", schedPath, `newest run ${ago} min ago`);
158 else say("schedules ran in 24 h", "FAIL", schedPath, newest > 0 ? `newest run ${ago} min ago` : "no run names when it started");
159 }
160
161 // 7. Security headers and CSP on / and /pricing.
162 for (const [path, seen] of [["/", await get("/")], ["/pricing", pricing]] as const) {
163 if (typeof seen === "string") {
164 say(`security headers on ${path}`, "UNKNOWN", path, seen);
165 continue;
166 }
167 const csp = seen.headers.get("content-security-policy") ?? "";
168 const missing = [
169 /default-src 'none'|default-src 'self'/.test(csp) ? "" : "content-security-policy",
170 seen.headers.get("x-content-type-options") === "nosniff" ? "" : "x-content-type-options",
171 seen.headers.get("referrer-policy") ? "" : "referrer-policy",
172 ].filter(Boolean);
173 if (missing.length === 0) say(`security headers on ${path}`, "PASS", path, `CSP, nosniff, referrer-policy ${seen.headers.get("referrer-policy")}`);
174 else say(`security headers on ${path}`, "FAIL", path, `missing ${missing.join(", ")}`);
175 }
176 return lines;
177 }
178
179 export const formatLine = (l: Line): string => `${l.verdict.padEnd(7)} ${l.item}: ${l.url} - ${l.evidence}`;
180
181 if (import.meta.main) {
182 const parsed = parseArgs(process.argv.slice(2));
183 if ("error" in parsed) {
184 console.error(parsed.error);
185 process.exit(2);
186 }
187 const lines = await probe(parsed.base, parsed.repo);
188 for (const l of lines) console.log(formatLine(l));
189 const pass = lines.every((l) => l.verdict === "PASS");
190 console.log(pass ? "every line PASS: v1.0.0 may be tagged" : "not every line is PASS: do not tag v1.0.0");
191 process.exit(pass ? 0 : 1);
192 }
test/v1-probe.test.ts added +107
@@ -0,0 +1,107 @@
1 /**
2 * The v1 probe (#15366) reads a stub forge and says PASS, FAIL or UNKNOWN per item, never sending a
3 * write.
4 */
5
6 import { afterAll, describe, expect, test } from "bun:test";
7 import { formatLine, parseArgs, probe, type Line } from "../scripts/v1-probe.ts";
8
9 const NOW = Date.parse("2026-11-21T12:00:00Z");
10 const COMMIT = "c".repeat(40);
11 const HEADERS = { "content-security-policy": "default-src 'none'", "x-content-type-options": "nosniff", "referrer-policy": "same-origin" };
12
13 interface World {
14 version: string;
15 checkState: string | null;
16 runs: { startedAt: number }[] | null;
17 atomNames: boolean;
18 headers: boolean;
19 }
20 const green = (): World => ({ version: "1.0.0", checkState: "ok", runs: [{ startedAt: NOW - 60_000 }], atomNames: true, headers: true });
21 let world = green();
22 const seen: { method: string; path: string; mcp?: string }[] = [];
23
24 const server = Bun.serve({
25 port: 0,
26 async fetch(req) {
27 const url = new URL(req.url);
28 const body = req.method === "POST" ? await req.text() : undefined;
29 seen.push({ method: req.method, path: url.pathname, ...(body ? { mcp: (JSON.parse(body) as { method: string }).method } : {}) });
30 const html = (b: string, status = 200) => new Response(b, { status, headers: { "content-type": "text/html", ...(world.headers ? HEADERS : {}) } });
31 const json = (v: unknown, status = 200) => Response.json(v, { status });
32 switch (url.pathname) {
33 case "/":
34 return html("<h1>forge</h1>");
35 case "/signup":
36 return html("<form method=post></form>");
37 case "/pricing":
38 return html("<p>$5 a month</p>");
39 case "/healthz":
40 return new Response("ok");
41 case "/changelog":
42 return html(`<p>${world.version}</p>`);
43 case "/changelog.atom":
44 return new Response(world.atomNames ? `<feed>${world.version}</feed>` : "<feed></feed>");
45 case "/mcp":
46 return json({ jsonrpc: "2.0", id: 1, result: { serverInfo: { name: "forge", version: world.version } } });
47 case "/api/v1/repos/o/r/tags":
48 return json({ items: [{ name: "v1.0.0", commit: COMMIT }] });
49 case `/api/v1/repos/o/r/commits/${COMMIT}/check`:
50 return world.checkState === null ? html("Just a moment...", 403) : json({ state: world.checkState, runId: "run1" });
51 case "/api/v1/repos/o/r/schedules":
52 return world.runs === null ? json({ error: "not_found" }, 404) : json({ items: [], runs: world.runs });
53 }
54 return json({ error: "not_found" }, 404);
55 },
56 });
57 afterAll(() => server.stop(true));
58 const base = `http://127.0.0.1:${server.port}`;
59 const run = async (w: Partial<World>): Promise<Record<string, Line>> => {
60 world = { ...green(), ...w };
61 const lines = await probe(base, "o/r", fetch, NOW);
62 return Object.fromEntries(lines.map((l) => [l.item, l]));
63 };
64
65 describe("v1 probe", () => {
66 test("PASS on every line when the stub forge proves each item", async () => {
67 const lines = Object.values(await run({}));
68 expect(lines.map((l) => `${l.item}=${l.verdict}`)).toEqual([
69 "sign-up page=PASS", "pricing names a price=PASS", "stranger journey green on a release=PASS", "version agrees=PASS",
70 "healthz fast=PASS", "schedules ran in 24 h=PASS", "security headers on /=PASS", "security headers on /pricing=PASS",
71 ]);
72 expect(formatLine(lines[1]!)).toBe(`PASS pricing names a price: ${base}/pricing - 200, names $5`);
73 });
74
75 test("FAIL when the check failed, the feed is silent, the version trails the tag, a schedule is stale or headers are gone", async () => {
76 expect((await run({ checkState: "failed" }))["stranger journey green on a release"]!.verdict).toBe("FAIL");
77 expect((await run({ atomNames: false }))["version agrees"]!.evidence).toContain("/changelog.atom does not name it");
78 expect((await run({ version: "0.9.0" }))["version agrees"]!.evidence).toBe("production says 0.9.0, main's last tag is v1.0.0");
79 expect((await run({ runs: [{ startedAt: NOW - 25 * 3600_000 }] }))["schedules ran in 24 h"]!.verdict).toBe("FAIL");
80 const bare = await run({ headers: false });
81 expect(bare["security headers on /"]!.evidence).toBe("missing content-security-policy, x-content-type-options, referrer-policy");
82 });
83
84 test("UNKNOWN, with what a person must check, when an anonymous read cannot see the proof", async () => {
85 const r = await run({ checkState: null, runs: [] });
86 expect(r["stranger journey green on a release"]!.verdict).toBe("UNKNOWN");
87 expect(r["stranger journey green on a release"]!.evidence).toContain("a person must open v1.0.0's check");
88 expect(r["schedules ran in 24 h"]!.verdict).toBe("UNKNOWN");
89 expect((await run({ runs: null }))["schedules ran in 24 h"]!.verdict).toBe("UNKNOWN");
90 });
91
92 test("sends only GETs and one MCP initialize, all to the base host", async () => {
93 seen.length = 0;
94 const urls: string[] = [];
95 await probe(base, "o/r", (u, init) => (urls.push(u), fetch(u, init)), NOW);
96 expect(seen.filter((s) => s.method !== "GET")).toEqual([{ method: "POST", path: "/mcp", mcp: "initialize" }]);
97 expect(urls.every((u) => u.startsWith(`${base}/`))).toBe(true);
98 });
99
100 test("the arguments are a base URL and an owner/name repo", () => {
101 expect(parseArgs(["https://forge.example/x"])).toEqual({ base: "https://forge.example", repo: "trevato/forge" });
102 expect(parseArgs(["https://f.example", "--repo", "a/b"])).toEqual({ base: "https://f.example", repo: "a/b" });
103 expect(parseArgs([])).toHaveProperty("error");
104 expect(parseArgs(["ftp://f.example"])).toHaveProperty("error");
105 expect(parseArgs(["https://f.example", "--repo", "../x"])).toHaveProperty("error");
106 });
107 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs