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

Production's changelog carries the running commit's check verdict even when the forge's repository is private #15529

Merged opened this

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

Merged

scout/forge:scout/15528-production-s-changelog-carries-the-runni → main 0 commits fork 2 threads · 2 unresolved

  • Merged. scout/15528-production-s-changelog-carries-the-runni was merged into main as f50404a.

Review

Sign in to review this change.
3 files changed +38 −12
src/core/forge_repo.ts +9 −2
@@ -8,11 +8,18 @@ import { forgeSource } from "../settings/forge_source.ts";
88 import { getRepo, type Repo } from "./repos.ts";
99
1010 export function publicForgeRepo(app: App): Repo | undefined {
11 const [owner = "", name = ""] = (app.config.forgeRepo ?? "").split("/");
12 const repo = owner === "" || name === "" ? undefined : getRepo(app.db, owner, name);
11 const repo = forgeRepo(app);
1312 return repo !== undefined && repo.visibility === "public" ? repo : undefined;
1413 }
1514
15 /**
16 * The repository `FORGE_REPO` names, whatever its visibility: callers decide what of it may leave.
17 */
18 export function forgeRepo(app: App): Repo | undefined {
19 const [owner = "", name = ""] = (app.config.forgeRepo ?? "").split("/");
20 return owner === "" || name === "" ? undefined : getRepo(app.db, owner, name);
21 }
22
1623 /**
1724 * Whether `repo` is the forge's own source (`settings/forge_source.ts`): an
1825 * admin's setting, else `FORGE_REPO`. Names compare without case, as the
src/release/running_check.ts +8 −5
@@ -2,13 +2,13 @@
22 * The full check's verdict on the commit this forge runs, for anyone (#15514): what the public
33 * changelog answer (`GET /api/v1/changelog`, MCP `releases`) says beside the running commit, so a
44 * 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.
5 * commit of the forge's own repository (`FORGE_REPO`) is ever asked, and only its state and run id
6 * leave: no summary, no log, no other commit's check.
77 */
88
99 import type { App } from "../app.ts";
1010 import { releaseCheck, type CommitCheck } from "../checks/commit_check.ts";
11 import { publicForgeRepo } from "../core/forge_repo.ts";
11 import { forgeRepo } from "../core/forge_repo.ts";
1212 import { hasCommit, isAncestor } from "../git/builds.ts";
1313 import { repoDir } from "../git/repos.ts";
1414
@@ -32,10 +32,13 @@ export function runningState(state: CommitCheck["state"]): RunningCheckState {
3232 */
3333 const settled = new WeakMap<App["db"], RunningCheck>();
3434
35 /** The running commit's check, or null when the forge has no public repository or no commit. */
35 /**
36 * The running commit's check, or null when the forge names no repository of its own or no commit.
37 */
3638 export async function runningCheck(app: App, commit: string | null): Promise<RunningCheck | null> {
3739 if (commit === null || !/^[0-9a-f]{40}$/.test(commit)) return null;
38 const repo = publicForgeRepo(app);
40 // Private too (#15528): a release's verdict on its own public commit is the release's claim.
41 const repo = forgeRepo(app);
outdated

Duplicates the FORGE_REPO parse in core/forge_repo.ts. Extract a shared forgeRepo(app) there (any visibility) and call it here and from publicForgeRepo.

3942 if (repo === undefined) return null;
outdated

Box 1 wants the reason as one line. Condense these three lines to a single sentence.

4043 const kept = settled.get(app.db);
4144 if (kept !== undefined && kept.commit === commit) return kept;
test/running-check.test.ts +21 −5
@@ -1,7 +1,7 @@
11 /**
22 * 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.
3 * commit's, of the forge's own repository, public or private (#15514, #15528): a stranger reads ok,
4 * failed or running and the run id, never a summary.
55 */
66 import { afterAll, beforeAll, expect, test } from "bun:test";
77 import { mkdtemp, rm } from "node:fs/promises";
@@ -23,6 +23,7 @@ let dirs: string[] = [];
2323 let app: App;
2424 let repo: Repo;
2525 let hidden: App;
26 let hiddenRun: string;
2627
2728 async function forge(visibility: "public" | "private"): Promise<{ app: App; repo: Repo }> {
2829 const dataDir = await mkdtemp(join(tmpdir(), "forge-running-check-"));
@@ -47,7 +48,7 @@ beforeAll(async () => {
4748 ({ app, repo } = await forge("public"));
4849 const other = await forge("private");
4950 hidden = other.app;
50 check(hidden, other.repo, OID("a"), "ok");
51 hiddenRun = check(hidden, other.repo, OID("a"), "ok");
5152 }, 30_000);
5253
5354 afterAll(async () => {
@@ -65,10 +66,25 @@ test("ok, failed and running are each stated with the run id", async () => {
6566 expect(await runningCheck(app, OID("3"))).toEqual({ commit: OID("3"), state: "running", runId: running });
6667 });
6768
68 test("nothing is stated without a running commit, and a private forge repository states nothing", async () => {
69 test("nothing is stated without a running commit", async () => {
6970 expect(await runningCheck(app, null)).toBeNull();
7071 expect(await runningCheck(app, "not-a-commit")).toBeNull();
71 expect(await runningCheck(hidden, OID("a"))).toBeNull();
72 });
73
74 test("a private forge repository still answers its running commit's verdict, in three fields only", async () => {
75 const found = await runningCheck(hidden, OID("a"));
76 expect(found).toEqual({ commit: OID("a"), state: "ok", runId: hiddenRun });
77 expect(Object.keys(found ?? {}).sort()).toEqual(["commit", "runId", "state"]);
78 const before = process.env["FORGE_COMMIT"];
79 process.env["FORGE_COMMIT"] = OID("a");
80 try {
81 const answer = await shippedAnswer(hidden);
82 expect(answer.check).toEqual({ commit: OID("a"), state: "ok", runId: hiddenRun });
83 expect(JSON.stringify(answer)).not.toContain("a private summary");
84 } finally {
85 if (before === undefined) delete process.env["FORGE_COMMIT"];
86 else process.env["FORGE_COMMIT"] = before;
87 }
7288 });
7389
7490 test("the public answer carries the running commit's check, and nothing of its summary", async () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs