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

The v1 probe reads releases where a stranger can: anonymous /tags answers 404, so two checklist lines stay UNKNOWN #15389

Merged opened this

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

Merged

scout/forge:scout/15387-the-v1-probe-reads-releases-where-a-stra → main 0 commits fork

  • Merged. scout/15387-the-v1-probe-reads-releases-where-a-stra was merged into main as 731f7a6.

Review

Sign in to review this change.
2 files changed +133 −32
scripts/v1-probe.ts +88 −25
@@ -1,7 +1,8 @@
11 /**
22 * `bun scripts/v1-probe.ts <base-url> [--repo owner/name]`: the v1.0.0
33 * 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
4 * is a GET, apart from one MCP `initialize` and one `tools/call` of the token-free
5 * `releases` tool (POSTs that change nothing), and
56 * every request goes to `<base-url>`, never to another host, and reads only
67 * `--repo` (default `trevato/forge`). It never signs in, pays or writes.
78 *
@@ -56,6 +57,56 @@ export function parseArgs(argv: readonly string[]): { base: string; repo: string
5657 return { base: url.origin, repo };
5758 }
5859
60 /** What production announced: a release number, or the short commit of an unstamped build. */
61 export function announcedOf(served: string): { kind: "version" | "commit"; text: string } | undefined {
62 if (/^v?\d+\.\d+\.\d+$/.test(served)) return { kind: "version", text: served.replace(/^v/, "") };
63 if (/^[0-9a-f]{7,40}$/.test(served)) return { kind: "commit", text: served };
64 return undefined;
65 }
66
67 /** The newest release of `repo` in the `releases` tool's answer. */
68 export interface Release {
69 readonly name: string;
70 readonly version: string | undefined;
71 readonly commit: string;
72 }
73
74 /**
75 * The newest release of `repo` from a `tools/call releases` JSON-RPC answer: undefined when the
76 * answer is not the tool's JSON (no source answered), `{ release: undefined }` when it lists none.
77 */
78 export function newestRelease(answer: unknown, repo: string): { release: Release | undefined } | undefined {
79 const text = (answer as { result?: { content?: { text?: unknown }[] } } | undefined)?.result?.content?.[0]?.text;
80 if (typeof text !== "string") return undefined;
81 let value: unknown;
82 try {
83 value = JSON.parse(text);
84 } catch {
85 return undefined;
86 }
87 const list = (value as { releases?: unknown } | null)?.releases;
88 if (!Array.isArray(list)) return undefined;
89 for (const item of list as { repo?: unknown; version?: unknown; commit?: unknown }[]) {
90 if (item?.repo !== repo || typeof item.commit !== "string" || !/^[0-9a-f]{40}$/.test(item.commit)) continue;
91 const version = typeof item.version === "string" && item.version !== "" ? item.version.replace(/^v/, "") : undefined;
92 return { release: { name: version ? `v${version}` : item.commit.slice(0, 7), version, commit: item.commit } };
93 }
94 return { release: undefined };
95 }
96
97 /**
98 * A POST the probe may send: MCP `initialize`, or `tools/call` of the read-only `releases` tool.
99 */
100 function readOnlyCall(body: unknown): boolean {
101 if (typeof body !== "string") return false;
102 try {
103 const m = JSON.parse(body) as { method?: unknown; params?: { name?: unknown } };
104 return m.method === "initialize" || (m.method === "tools/call" && m.params?.name === "releases");
105 } catch {
106 return false;
107 }
108 }
109
59110 /** Runs every item against `base` and returns the lines in checklist order. */
60111 export async function probe(base: string, repo: string, fetcher: Fetcher = fetch, now = Date.now()): Promise<Line[]> {
61112 const origin = new URL(base).origin;
@@ -63,7 +114,7 @@ export async function probe(base: string, repo: string, fetcher: Fetcher = fetch
63114 const url = new URL(path, origin);
64115 if (url.origin !== origin) return `${url.href} is not on ${origin}`;
65116 const method = init?.method ?? "GET";
66 if (method !== "GET" && !(method === "POST" && url.pathname === "/mcp")) return `${method} is not a read`;
117 if (method !== "GET" && !(method === "POST" && url.pathname === "/mcp" && readOnlyCall(init?.body))) return `${method} is not a read`;
67118 const started = performance.now();
68119 try {
69120 const r = await fetcher(url.href, { ...init, method, redirect: "manual", signal: AbortSignal.timeout(15_000) });
@@ -99,22 +150,28 @@ export async function probe(base: string, repo: string, fetcher: Fetcher = fetch
99150 else if (pricing.status === 200 && price) say("pricing names a price", "PASS", "/pricing", `200, names ${price}`);
100151 else say("pricing names a price", "FAIL", "/pricing", `${pricing.status}, names no price`);
101152
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 });
153 // 2. Production's version, from MCP initialize, and the newest release, from the token-free
154 // `releases` tool (what /changelog shows anyone): `/tags` answers 404 to an anonymous read.
155 const mcp = (id: number, method: string, params: unknown) =>
156 get("/mcp", {
157 method: "POST",
158 headers: { "content-type": "application/json", accept: "application/json, text/event-stream" },
159 body: JSON.stringify({ jsonrpc: "2.0", id, method, params }),
160 });
161 const init = await mcp(1, "initialize", { protocolVersion: "2025-06-18", capabilities: {}, clientInfo: { name: "v1-probe", version: "1" } });
108162 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;
163 const announced = typeof served === "string" ? announcedOf(served) : undefined;
164 const shipped = await mcp(2, "tools/call", { name: "releases", arguments: { repo } });
165 const read = typeof shipped === "string" ? undefined : newestRelease(json(shipped), repo);
166 const releasePath = "/mcp";
167 const tagName = read?.release?.name;
168 const tagCommit = read?.release?.commit;
169 const unread = typeof shipped === "string" ? shipped : `${shipped.status}, the releases tool did not answer its JSON`;
114170
115171 // 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");
172 const checkPath = tagCommit ? `${api}/commits/${tagCommit}/check` : releasePath;
173 if (!read) say("stranger journey green on a release", "UNKNOWN", checkPath, `${unread}; a person must open the latest release's check`);
174 else if (!tagName || !tagCommit) say("stranger journey green on a release", "FAIL", checkPath, `the releases tool lists no release of ${repo}`);
118175 else {
119176 const check = await get(checkPath);
120177 const c = typeof check === "string" ? undefined : (json(check) as { state?: unknown; runId?: unknown; finishedAt?: unknown } | undefined);
@@ -126,17 +183,23 @@ export async function probe(base: string, repo: string, fetcher: Fetcher = fetch
126183 else say("stranger journey green on a release", "UNKNOWN", checkPath, `${tagName} check is ${c.state}`);
127184 }
128185
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}`);
186 // 4. /changelog, /changelog.atom and production's version agree with the newest release.
187 if (!announced) say("version agrees", "UNKNOWN", "/mcp", typeof init === "string" ? init : `initialize named no version or commit (${init.status})`);
188 else if (!read) say("version agrees", "UNKNOWN", releasePath, `production says ${announced.text}; ${unread}`);
189 else if (!read.release) say("version agrees", "FAIL", releasePath, `production says ${announced.text}; the releases tool lists no release of ${repo}`);
133190 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`);
191 const r = read.release;
192 const agrees = announced.kind === "version" ? r.version === announced.text : r.commit.startsWith(announced.text);
193 const theirs = announced.kind === "version" ? (r.version ?? `no version (${r.commit.slice(0, 7)})`) : r.commit.slice(0, announced.text.length);
194 if (!agrees) say("version agrees", "FAIL", releasePath, `production says ${announced.text}, the newest release ${r.name} is ${theirs}`);
195 else {
196 const page = await get("/changelog");
197 const atom = await get("/changelog.atom");
198 const named = (s: Seen | string): boolean => typeof s !== "string" && s.status === 200 && ((r.version !== undefined && s.body.includes(r.version)) || s.body.includes(r.commit.slice(0, 7)));
199 const misses = [named(page) ? "" : "/changelog", named(atom) ? "" : "/changelog.atom"].filter(Boolean);
200 if (misses.length === 0) say("version agrees", "PASS", "/changelog", `production ${announced.text} = release ${r.name}, named by /changelog and /changelog.atom`);
201 else say("version agrees", "FAIL", misses[0] ?? "/changelog", `production ${announced.text} = release ${r.name}, but ${misses.join(" and ")} ${misses.length === 1 ? "does" : "do"} not name it`);
202 }
140203 }
141204
142205 // 5. /healthz fast.
test/v1-probe.test.ts +45 −7
@@ -16,8 +16,17 @@ interface World {
1616 runs: { startedAt: number }[] | null;
1717 atomNames: boolean;
1818 headers: boolean;
19 /** What the token-free `releases` tool lists; null when it does not answer. */
20 releases: { repo: string; version: string; commit: string }[] | null;
1921 }
20 const green = (): World => ({ version: "1.0.0", checkState: "ok", runs: [{ startedAt: NOW - 60_000 }], atomNames: true, headers: true });
22 const green = (): World => ({
23 version: "1.0.0",
24 checkState: "ok",
25 runs: [{ startedAt: NOW - 60_000 }],
26 atomNames: true,
27 headers: true,
28 releases: [{ repo: "x/y", version: "9.9.9", commit: "d".repeat(40) }, { repo: "o/r", version: "1.0.0", commit: COMMIT }],
29 });
2130 let world = green();
2231 const seen: { method: string; path: string; mcp?: string }[] = [];
2332
@@ -26,7 +35,8 @@ const server = Bun.serve({
2635 async fetch(req) {
2736 const url = new URL(req.url);
2837 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 } : {}) });
38 const call = body ? (JSON.parse(body) as { method: string; params?: { name?: string; arguments?: unknown } }) : undefined;
39 seen.push({ method: req.method, path: url.pathname, ...(call ? { mcp: call.params?.name ? `${call.method} ${call.params.name}` : call.method } : {}) });
3040 const html = (b: string, status = 200) => new Response(b, { status, headers: { "content-type": "text/html", ...(world.headers ? HEADERS : {}) } });
3141 const json = (v: unknown, status = 200) => Response.json(v, { status });
3242 switch (url.pathname) {
@@ -43,9 +53,12 @@ const server = Bun.serve({
4353 case "/changelog.atom":
4454 return new Response(world.atomNames ? `<feed>${world.version}</feed>` : "<feed></feed>");
4555 case "/mcp":
56 if (call?.method === "tools/call") {
57 if (world.releases === null) return html("Just a moment...", 403);
58 const text = JSON.stringify({ version: null, commit: COMMIT, releases: world.releases });
59 return json({ jsonrpc: "2.0", id: 2, result: { content: [{ type: "text", text }] } });
60 }
4661 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 }] });
4962 case `/api/v1/repos/o/r/commits/${COMMIT}/check`:
5063 return world.checkState === null ? html("Just a moment...", 403) : json({ state: world.checkState, runId: "run1" });
5164 case "/api/v1/repos/o/r/schedules":
@@ -75,7 +88,7 @@ describe("v1 probe", () => {
7588 test("FAIL when the check failed, the feed is silent, the version trails the tag, a schedule is stale or headers are gone", async () => {
7689 expect((await run({ checkState: "failed" }))["stranger journey green on a release"]!.verdict).toBe("FAIL");
7790 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");
91 expect((await run({ version: "0.9.0" }))["version agrees"]!.evidence).toBe("production says 0.9.0, the newest release v1.0.0 is 1.0.0");
7992 expect((await run({ runs: [{ startedAt: NOW - 25 * 3600_000 }] }))["schedules ran in 24 h"]!.verdict).toBe("FAIL");
8093 const bare = await run({ headers: false });
8194 expect(bare["security headers on /"]!.evidence).toBe("missing content-security-policy, x-content-type-options, referrer-policy");
@@ -89,11 +102,36 @@ describe("v1 probe", () => {
89102 expect((await run({ runs: null }))["schedules ran in 24 h"]!.verdict).toBe("UNKNOWN");
90103 });
91104
92 test("sends only GETs and one MCP initialize, all to the base host", async () => {
105 test("a short commit announced is compared to the newest release's commit, naming both (#15387)", async () => {
106 const pass = (await run({ version: COMMIT.slice(0, 7) }))["version agrees"]!;
107 expect(pass.verdict).toBe("PASS");
108 expect(pass.evidence).toBe("production ccccccc = release v1.0.0, named by /changelog and /changelog.atom");
109 const fail = (await run({ version: "687c4ae" }))["version agrees"]!;
110 expect(fail.verdict).toBe("FAIL");
111 expect(fail.evidence).toBe("production says 687c4ae, the newest release v1.0.0 is ccccccc");
112 });
113
114 test("the release is read from the token-free releases tool; none listed is FAIL, no answer is UNKNOWN (#15387)", async () => {
115 const r = await run({});
116 expect(r["stranger journey green on a release"]!.evidence).toContain("v1.0.0 (ccccccccc) full check ok");
117 const none = await run({ releases: [{ repo: "x/y", version: "9.9.9", commit: "d".repeat(40) }] });
118 expect(none["stranger journey green on a release"]!.verdict).toBe("FAIL");
119 expect(none["version agrees"]!.verdict).toBe("FAIL");
120 expect(none["version agrees"]!.evidence).toBe("production says 1.0.0; the releases tool lists no release of o/r");
121 const silent = await run({ releases: null, version: "687c4ae" });
122 expect(silent["stranger journey green on a release"]!.verdict).toBe("UNKNOWN");
123 expect(silent["version agrees"]!.verdict).toBe("UNKNOWN");
124 expect(silent["version agrees"]!.evidence).toContain("production says 687c4ae; 403");
125 });
126
127 test("sends only GETs, one MCP initialize and one releases call, all to the base host", async () => {
93128 seen.length = 0;
94129 const urls: string[] = [];
95130 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" }]);
131 expect(seen.filter((s) => s.method !== "GET")).toEqual([
132 { method: "POST", path: "/mcp", mcp: "initialize" },
133 { method: "POST", path: "/mcp", mcp: "tools/call releases" },
134 ]);
97135 expect(urls.every((u) => u.startsWith(`${base}/`))).toBe(true);
98136 });
99137

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs