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
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/15514-defect-on-the-v1-0-0-path-the-probe-s-st → main 0 commits fork
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 | ||
| 40 | 40 | |
| 41 | 41 | `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. |
| 42 | 42 | |
| 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 | ||
| 43 | 45 | `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). |
| 44 | 46 | |
| 45 | 47 | `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 @@ | ||
| 15 | 15 | * scheduled app prints, and wins (#15388): its newest `<time datetime>` or `<updated>` is when the |
| 16 | 16 | * schedule last ran, the schedules API answers 404 to an anonymous read. |
| 17 | 17 | * |
| 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 | * | |
| 18 | 22 | * It prints one line per item, `PASS`, `FAIL` or `UNKNOWN`, with the URL and |
| 19 | 23 | * the evidence, and exits 0 only when every line is PASS. UNKNOWN is what an |
| 20 | 24 | * 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 | ||
| 154 | 158 | return { release: { name: `running ${version ? `v${version}` : top.commit.slice(0, 7)}`, version, commit: top.commit, running: true } }; |
| 155 | 159 | } |
| 156 | 160 | |
| 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 | ||
| 157 | 189 | /** |
| 158 | 190 | * A POST the probe may send: MCP `initialize`, or `tools/call` of the read-only `releases` tool. |
| 159 | 191 | */ |
| @@ -228,15 +260,19 @@ export async function probe(base: string, repo: string, fetcher: Fetcher = fetch | ||
| 228 | 260 | const tagCommit = read?.release?.commit; |
| 229 | 261 | const unread = typeof shipped === "string" ? shipped : `${shipped.status}, the releases tool did not answer its JSON`; |
| 230 | 262 | |
| 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; | |
| 233 | 269 | if (!read) say("stranger journey green on a release", "UNKNOWN", checkPath, `${unread}; a person must open the latest release's check`); |
| 234 | 270 | 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`); |
| 235 | 271 | 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)); | |
| 238 | 274 | 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`; | |
| 240 | 276 | say("stranger journey green on a release", "UNKNOWN", checkPath, `${why}; a person must open ${tagName}'s check and see the stranger tests green`); |
| 241 | 277 | } 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`); |
| 242 | 278 | 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 | ||
| 17 | 17 | import { keeperReleaseOfSha, type Stage } from "../keeper/record.ts"; |
| 18 | 18 | import { listReleases, releaseName } from "./record.ts"; |
| 19 | 19 | import { mergeReleases, publicTagReleases } from "./repo_tags.ts"; |
| 20 | import { runningCheck } from "./running_check.ts"; | |
| 20 | 21 | |
| 21 | 22 | /** |
| 22 | 23 | * 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) { | ||
| 77 | 78 | commit: read.commit, |
| 78 | 79 | short: read.commit === null ? null : shortOf(read.commit), |
| 79 | 80 | 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), | |
| 80 | 83 | live, |
| 81 | 84 | waves, |
| 82 | 85 | 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> { | ||
| 462 | 462 | // The answer is the same for every viewer (public repositories only), so a shared cache may keep |
| 463 | 463 | // it. |
| 464 | 464 | 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 ?? ""]); | |
| 466 | 466 | const headers = { etag, "cache-control": "public, max-age=5" }; |
| 467 | 467 | if (holds(ctx.request.headers.get("if-none-match"), etag)) return new Response(null, { status: 304, headers }); |
| 468 | 468 | 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 { | ||
| 20 | 20 | releases: { repo: string; version: string; commit: string }[] | null; |
| 21 | 21 | /** The running build the answer names beside its list (#15473). */ |
| 22 | 22 | 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 }; | |
| 23 | 25 | /** The keeper's heartbeat, served only to `Bearer t` (#15449). */ |
| 24 | 26 | beat?: { at: string; outcome: string; reason: string; silent: boolean } | null; |
| 25 | 27 | } |
| @@ -59,7 +61,7 @@ const server = Bun.serve({ | ||
| 59 | 61 | case "/mcp": |
| 60 | 62 | if (call?.method === "tools/call") { |
| 61 | 63 | 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 } : {}) }); | |
| 63 | 65 | return json({ jsonrpc: "2.0", id: 2, result: { content: [{ type: "text", text }] } }); |
| 64 | 66 | } |
| 65 | 67 | return json({ jsonrpc: "2.0", id: 1, result: { serverInfo: { name: "forge", version: world.version } } }); |
| @@ -193,6 +195,26 @@ describe("v1 probe", () => { | ||
| 193 | 195 | expect(silent["version agrees"]!.evidence).toContain("production says 687c4ae; 403"); |
| 194 | 196 | }); |
| 195 | 197 | |
| 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 | ||
| 196 | 218 | test("no release listed but a running version and commit named: that build is the release, read from its check (#15473)", async () => { |
| 197 | 219 | const r = await run({ releases: [], running: { version: "1.0.0", commit: COMMIT } }); |
| 198 | 220 | expect(r["stranger journey green on a release"]!.verdict).toBe("PASS"); |
new above
offline