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

Defect on the v1.0.0 path: the probe's "stranger journey green on a release" line is UNKNOWN from a public read, so v1.0.0 cannot be proven without a person #15517

Merged opened this

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

Merged

mason/forge:mason/15514-defect-on-the-v1-0-0-path-the-probe-s-st → main 0 commits fork

  • Merged. mason/15514-defect-on-the-v1-0-0-path-the-probe-s-st was merged into main as bdaf26b.

Review

Sign in to review this change.
7 files changed +206 −7
AGENTS.md +2
@@ -40,6 +40,8 @@ The check queue hands work to a runner through `src/checks/runner.ts` (#13652, R
4040
4141 `src/apps/relay_wait.ts`: each app's slowest production wait relayed in the last 10 minutes, with the forge's loop lag beside it, noted by the proxy (`relayUpstream`) and read by `appVitals`; `forgeWaited` decides whose wait it was, and the speed card and terminal line say "the forge was busy" when it was the forge's (#10858). At most 2,000 apps, gone on restart.
4242
43 `src/release/running_check.ts`: `settled`, per forge, the full check's settled verdict (`ok` or `failed`) on the running commit, the one the public changelog answer states (#15514); one entry, replaced when the commit changes, gone on restart.
44
4345 `src/core/transfer.ts`: the old owner/name pairs a transfer left behind (`repo_redirect`), held per database after the first request reads them and dropped by `transferRepo`, so a request under a path nothing moved from costs no statement (#569).
4446
4547 `src/http/mcp/load.ts`: `loading`, the one import of the MCP server and its tool index (#12521), started by the first request that needs the tools; when it settles it hands the list to /llms.txt (`setMcpTools`) and the cards (`setCardTools`), so a reader of those lists awaits `loadMcp()` first. A failed import is dropped and tried again; gone on restart.
scripts/v1-probe.ts +41 −5
@@ -15,6 +15,10 @@
1515 * scheduled app prints, and wins (#15388): its newest `<time datetime>` or `<updated>` is when the
1616 * schedule last ran, the schedules API answers 404 to an anonymous read.
1717 *
18 * The stranger-journey line reads the full check's verdict that the same `releases` answer states
19 * beside its running commit (`check`, #15514); only when it names no verdict on the newest
20 * release's commit is the check API asked, which answers 404 to an anonymous read.
21 *
1822 * It prints one line per item, `PASS`, `FAIL` or `UNKNOWN`, with the URL and
1923 * the evidence, and exits 0 only when every line is PASS. UNKNOWN is what an
2024 * anonymous read cannot prove; the line says what a person must check.
@@ -154,6 +158,34 @@ export function newestRelease(answer: unknown, repo: string): { release: Release
154158 return { release: { name: `running ${version ? `v${version}` : top.commit.slice(0, 7)}`, version, commit: top.commit, running: true } };
155159 }
156160
161 /**
162 * The full check's verdict on the running commit, as the public `releases` answer states it
163 * (#15514).
164 */
165 export interface RunningCheck {
166 readonly commit: string;
167 readonly state: string;
168 readonly runId: string | null;
169 }
170
171 /**
172 * The `check` the `releases` tool's answer names beside its running commit, or undefined when the
173 * answer says nothing of it (an older forge, or no check known).
174 */
175 export function runningCheckOf(answer: unknown): RunningCheck | undefined {
176 const text = (answer as { result?: { content?: { text?: unknown }[] } } | undefined)?.result?.content?.[0]?.text;
177 if (typeof text !== "string") return undefined;
178 let value: unknown;
179 try {
180 value = JSON.parse(text);
181 } catch {
182 return undefined;
183 }
184 const c = (value as { check?: { commit?: unknown; state?: unknown; runId?: unknown } | null } | null)?.check;
185 if (typeof c?.commit !== "string" || !/^[0-9a-f]{40}$/.test(c.commit) || typeof c.state !== "string") return undefined;
186 return { commit: c.commit, state: c.state, runId: typeof c.runId === "string" ? c.runId : null };
187 }
188
157189 /**
158190 * A POST the probe may send: MCP `initialize`, or `tools/call` of the read-only `releases` tool.
159191 */
@@ -228,15 +260,19 @@ export async function probe(base: string, repo: string, fetcher: Fetcher = fetch
228260 const tagCommit = read?.release?.commit;
229261 const unread = typeof shipped === "string" ? shipped : `${shipped.status}, the releases tool did not answer its JSON`;
230262
231 // 3. The stranger journey's last green release, from the check API.
232 const checkPath = tagCommit ? `${api}/commits/${tagCommit}/check` : releasePath;
263 // 3. The stranger journey's last green release: the public answer states the running commit's
264 // check (#15514); when it names another commit or none, the check API (which a stranger may not
265 // read) is asked.
266 const stated = typeof shipped === "string" ? undefined : runningCheckOf(json(shipped));
267 const own = stated !== undefined && stated.commit === tagCommit && stated.state !== "none" ? stated : undefined;
268 const checkPath = own ? releasePath : tagCommit ? `${api}/commits/${tagCommit}/check` : releasePath;
233269 if (!read) say("stranger journey green on a release", "UNKNOWN", checkPath, `${unread}; a person must open the latest release's check`);
234270 else if (!tagName || !tagCommit) say("stranger journey green on a release", "FAIL", checkPath, `the releases tool lists no release of ${repo} and names no running commit`);
235271 else {
236 const check = await get(checkPath);
237 const c = typeof check === "string" ? undefined : (json(check) as { state?: unknown; runId?: unknown; finishedAt?: unknown } | undefined);
272 const check = own === undefined ? await get(checkPath) : undefined;
273 const c = own ?? (check === undefined || typeof check === "string" ? undefined : (json(check) as { state?: unknown; runId?: unknown; finishedAt?: unknown } | undefined));
238274 if (!c || typeof c.state !== "string") {
239 const why = typeof check === "string" ? check : `${check.status}, not the check's JSON`;
275 const why = check === undefined ? "no check named" : typeof check === "string" ? check : `${check.status}, not the check's JSON`;
240276 say("stranger journey green on a release", "UNKNOWN", checkPath, `${why}; a person must open ${tagName}'s check and see the stranger tests green`);
241277 } 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`);
242278 else if (c.state === "failed") say("stranger journey green on a release", "FAIL", checkPath, `${tagName} check failed, run ${String(c.runId)}`);
src/release/answer.ts +3
@@ -17,6 +17,7 @@ import { chosenRepo, readLandings, type Landing, type Landings } from "./landing
1717 import { keeperReleaseOfSha, type Stage } from "../keeper/record.ts";
1818 import { listReleases, releaseName } from "./record.ts";
1919 import { mergeReleases, publicTagReleases } from "./repo_tags.ts";
20 import { runningCheck } from "./running_check.ts";
2021
2122 /**
2223 * What the forge can say of a kept release's soundness: the keeper's verdict, else the preflight's.
@@ -77,6 +78,8 @@ export async function shippedAnswer(app: App, asked: string | null = null) {
7778 commit: read.commit,
7879 short: read.commit === null ? null : shortOf(read.commit),
7980 liveSince: BOOTED,
81 // The full check's verdict on `commit`, the running one only (#15514): null when it is unknown.
82 check: await runningCheck(app, read.commit),
8083 live,
8184 waves,
8285 onItsWay: read.onItsWay.filter(keep),
src/release/running_check.ts added +50
@@ -0,0 +1,50 @@
1 /**
2 * The full check's verdict on the commit this forge runs, for anyone (#15514): what the public
3 * changelog answer (`GET /api/v1/changelog`, MCP `releases`) says beside the running commit, so a
4 * stranger can see the release's tests ran green without reading the runs. Only the running
5 * commit of the forge's own public repository is ever asked, and only its state and run id leave:
6 * no summary, no log, no other commit's check.
7 */
8
9 import type { App } from "../app.ts";
10 import { releaseCheck, type CommitCheck } from "../checks/commit_check.ts";
11 import { publicForgeRepo } from "../core/forge_repo.ts";
12 import { hasCommit, isAncestor } from "../git/builds.ts";
13 import { repoDir } from "../git/repos.ts";
14
15 /** `running` is queued or running; `none` is never checked, or every check of it was cancelled. */
16 export type RunningCheckState = "ok" | "failed" | "running" | "none";
17
18 export interface RunningCheck {
19 readonly commit: string;
20 readonly state: RunningCheckState;
21 readonly runId: string | null;
22 }
23
24 /** The words a stranger reads for the check's own state. */
25 export function runningState(state: CommitCheck["state"]): RunningCheckState {
26 return state === "ok" || state === "failed" ? state : state === "pending" ? "running" : "none";
27 }
28
29 /**
30 * The settled verdict (`ok` or `failed`) on the running commit, per forge: one entry, replaced when
31 * the commit changes, so a settled answer costs no query or git process again.
32 */
33 const settled = new WeakMap<App["db"], RunningCheck>();
34
35 /** The running commit's check, or null when the forge has no public repository or no commit. */
36 export async function runningCheck(app: App, commit: string | null): Promise<RunningCheck | null> {
37 if (commit === null || !/^[0-9a-f]{40}$/.test(commit)) return null;
38 const repo = publicForgeRepo(app);
39 if (repo === undefined) return null;
40 const kept = settled.get(app.db);
41 if (kept !== undefined && kept.commit === commit) return kept;
42 const dir = repoDir(app.reposRoot, repo.ownerName, repo.name);
43 const found = await releaseCheck(app.db, repo.id, repo.defaultBranch, commit, {
44 has: () => hasCommit(dir, commit),
45 contains: (descendant) => isAncestor(dir, commit, descendant),
46 });
47 const answer: RunningCheck = { commit, state: runningState(found.state), runId: found.runId };
48 if (answer.state === "ok" || answer.state === "failed") settled.set(app.db, answer);
49 return answer;
50 }
src/web/pages/changelog.ts +1 −1
@@ -462,7 +462,7 @@ export async function changelogJson(ctx: Ctx): Promise<Response> {
462462 // The answer is the same for every viewer (public repositories only), so a shared cache may keep
463463 // it.
464464 const { releases } = answer;
465 const etag = changelogTag(answer.version ?? "dev", [...answer.live, ...answer.onItsWay], [asked ?? "", answer.live.length, releases.length, releases[0]?.servedAt ?? "", releases.map((r) => r.tests[0]).join("")]);
465 const etag = changelogTag(answer.version ?? "dev", [...answer.live, ...answer.onItsWay], [asked ?? "", answer.live.length, releases.length, releases[0]?.servedAt ?? "", releases.map((r) => r.tests[0]).join(""), answer.check?.state ?? ""]);
466466 const headers = { etag, "cache-control": "public, max-age=5" };
467467 if (holds(ctx.request.headers.get("if-none-match"), etag)) return new Response(null, { status: 304, headers });
468468 return json(answer, 200, headers);
test/running-check.test.ts added +86
@@ -0,0 +1,86 @@
1 /**
2 * The public changelog answer states the full check's verdict on the running commit, and only that
3 * commit's, only for the forge's own public repository (#15514): a stranger reads ok, failed or
4 * running and the run id, never a summary.
5 */
6 import { afterAll, beforeAll, expect, test } from "bun:test";
7 import { mkdtemp, rm } from "node:fs/promises";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { createApp, type App } from "../src/app.ts";
11 import { createRepo } from "../src/actions/repos.ts";
12 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
13 import { createUser } from "../src/core/users.ts";
14 import type { Repo } from "../src/core/repos.ts";
15 import { shippedAnswer } from "../src/release/answer.ts";
16 import { runningCheck } from "../src/release/running_check.ts";
17 import { quietLogs } from "./helpers/globals.ts";
18
19 quietLogs();
20
21 const OID = (c: string) => c.repeat(40);
22 let dirs: string[] = [];
23 let app: App;
24 let repo: Repo;
25 let hidden: App;
26
27 async function forge(visibility: "public" | "private"): Promise<{ app: App; repo: Repo }> {
28 const dataDir = await mkdtemp(join(tmpdir(), "forge-running-check-"));
29 dirs.push(dataDir);
30 const made = createApp({ dataDir, port: 0, forgeRepo: "alice/forge" });
31 const u = await createUser(made.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
32 if (!u.ok) throw new Error(u.error);
33 const r = await createRepo(made, u.value, { name: "forge", visibility });
34 if (!r.ok) throw new Error(String(r.error));
35 return { app: made, repo: r.value };
36 }
37
38 function check(on: App, r: Repo, commit: string, state: "ok" | "failed" | "running"): string {
39 const id = createRun(on.db, { repoId: r.id, kind: "check", env: r.defaultBranch, commitOid: commit, reason: "push" }).id;
40 if (state === "running") return id;
41 claimRun(on.db, id);
42 finishRun(on.db, id, { state, summary: "a private summary" });
43 return id;
44 }
45
46 beforeAll(async () => {
47 ({ app, repo } = await forge("public"));
48 const other = await forge("private");
49 hidden = other.app;
50 check(hidden, other.repo, OID("a"), "ok");
51 }, 30_000);
52
53 afterAll(async () => {
54 app.close();
55 hidden.close();
56 for (const d of dirs) await rm(d, { recursive: true, force: true });
57 });
58
59 test("ok, failed and running are each stated with the run id", async () => {
60 const ok = check(app, repo, OID("1"), "ok");
61 expect(await runningCheck(app, OID("1"))).toEqual({ commit: OID("1"), state: "ok", runId: ok });
62 const failed = check(app, repo, OID("2"), "failed");
63 expect(await runningCheck(app, OID("2"))).toEqual({ commit: OID("2"), state: "failed", runId: failed });
64 const running = check(app, repo, OID("3"), "running");
65 expect(await runningCheck(app, OID("3"))).toEqual({ commit: OID("3"), state: "running", runId: running });
66 });
67
68 test("nothing is stated without a running commit, and a private forge repository states nothing", async () => {
69 expect(await runningCheck(app, null)).toBeNull();
70 expect(await runningCheck(app, "not-a-commit")).toBeNull();
71 expect(await runningCheck(hidden, OID("a"))).toBeNull();
72 });
73
74 test("the public answer carries the running commit's check, and nothing of its summary", async () => {
75 const id = check(app, repo, OID("4"), "ok");
76 const before = process.env["FORGE_COMMIT"];
77 process.env["FORGE_COMMIT"] = OID("4");
78 try {
79 const answer = await shippedAnswer(app);
80 expect(answer.check).toEqual({ commit: OID("4"), state: "ok", runId: id });
81 expect(JSON.stringify(answer)).not.toContain("a private summary");
82 } finally {
83 if (before === undefined) delete process.env["FORGE_COMMIT"];
84 else process.env["FORGE_COMMIT"] = before;
85 }
86 });
test/v1-probe.test.ts +23 −1
@@ -20,6 +20,8 @@ interface World {
2020 releases: { repo: string; version: string; commit: string }[] | null;
2121 /** The running build the answer names beside its list (#15473). */
2222 running?: { version: string | null; commit: string | null };
23 /** The full check's verdict the answer states beside its running commit (#15514). */
24 stated?: { commit: string; state: string; runId: string | null };
2325 /** The keeper's heartbeat, served only to `Bearer t` (#15449). */
2426 beat?: { at: string; outcome: string; reason: string; silent: boolean } | null;
2527 }
@@ -59,7 +61,7 @@ const server = Bun.serve({
5961 case "/mcp":
6062 if (call?.method === "tools/call") {
6163 if (world.releases === null) return html("Just a moment...", 403);
62 const text = JSON.stringify({ ...(world.running ?? { version: null, commit: COMMIT }), live: [], releases: world.releases });
64 const text = JSON.stringify({ ...(world.running ?? { version: null, commit: COMMIT }), live: [], releases: world.releases, ...(world.stated ? { check: world.stated } : {}) });
6365 return json({ jsonrpc: "2.0", id: 2, result: { content: [{ type: "text", text }] } });
6466 }
6567 return json({ jsonrpc: "2.0", id: 1, result: { serverInfo: { name: "forge", version: world.version } } });
@@ -193,6 +195,26 @@ describe("v1 probe", () => {
193195 expect(silent["version agrees"]!.evidence).toContain("production says 687c4ae; 403");
194196 });
195197
198 test("the stranger line reads the check the public answer states for the running commit, with the check API closed (#15514)", async () => {
199 const line = async (state: string) => (await run({ checkState: null, stated: { commit: COMMIT, state, runId: "run7" } }))["stranger journey green on a release"]!;
200 const ok = await line("ok");
201 expect(ok.verdict).toBe("PASS");
202 expect(ok.evidence).toBe("v1.0.0 (ccccccccc) full check ok, run run7, which runs the stranger tests");
203 expect(ok.url).toBe(`${base}/mcp`);
204 const failed = await line("failed");
205 expect(failed.verdict).toBe("FAIL");
206 expect(failed.evidence).toBe("v1.0.0 check failed, run run7");
207 const running = await line("running");
208 expect(running.verdict).toBe("UNKNOWN");
209 expect(running.evidence).toBe("v1.0.0 check is running");
210 // Nothing stated, or a verdict on another commit: the closed check API is all there is.
211 for (const stated of [undefined, { commit: "e".repeat(40), state: "ok", runId: "run7" }, { commit: COMMIT, state: "none", runId: null }]) {
212 const silent = (await run({ checkState: null, ...(stated ? { stated } : {}) }))["stranger journey green on a release"]!;
213 expect(silent.verdict).toBe("UNKNOWN");
214 expect(silent.evidence).toContain("a person must open v1.0.0's check");
215 }
216 });
217
196218 test("no release listed but a running version and commit named: that build is the release, read from its check (#15473)", async () => {
197219 const r = await run({ releases: [], running: { version: "1.0.0", commit: COMMIT } });
198220 expect(r["stranger journey green on a release"]!.verdict).toBe("PASS");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs