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

Merge-queue gate logs and verdicts answer only those who may read the run's log #14973

Merged opened this

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

Merged

torque/forge:torque/14949-merge-queue-gate-logs-and-verdicts-answe → main 7 commits fork

  • Merged. torque/14949-merge-queue-gate-logs-and-verdicts-answe was merged into main as 15342fb.

Review

Sign in to review this change.
13 files changed +197 −18
docs/features/queue-gates.md +20
@@ -35,3 +35,23 @@ The counts come from the gate's own output (`src/checks/gate_tests.ts`):
3535 `passed` sums each `bun test` process's ` N pass`; `failed` counts distinct
3636 `(fail)` names, so the shards' tally — which repeats every failure as
3737 `(fail) name [1ms] [shard 3]` — no longer counts a test twice.
38
39 ## Who sees the failing tests
40
41 A gate's failing tests — their names and first error lines — are the gate's
42 log, so they answer only to someone who may read the repository's run logs
43 (`gatesForReader` in `src/actions/runs.ts`). Everyone else who may read the
44 repository's runs gets the same gates with the verdict, reason and counts,
45 and `failing: []`; `GET …/gates/<id>/log` answers them `404`. Someone who
46 may not read the runs at all sees no gates.
47
48 Both doors cut the same way:
49
50 - on the web, the flow panel's **Last gates** on /boards
51 (`src/web/pages/boards-gates.ts`) shows a red row's first failing test to
52 such a reader, and the gate's reason (`tests`, `typecheck`, …) to anyone
53 else;
54 - in the terminal, the **Flow** command's dialog (`src/tui/screens/flow.ts`)
55 lists each repository's gates under its queue line the same way: the
56 failing test where you may read the log, the verdict and reason where you
57 may not.
scripts/doorless-allow.json −1
@@ -11,7 +11,6 @@
1111 "src/web/pages/board_style.ts",
1212 "src/web/pages/boards-doctor.ts",
1313 "src/web/pages/boards-edit.ts",
14 "src/web/pages/boards-gates.ts",
1514 "src/web/pages/boards-held.ts",
1615 "src/web/pages/boards-holds.ts",
1716 "src/web/pages/boards-view.ts",
src/actions/runs.ts +33 −1
@@ -9,6 +9,7 @@
99
1010 import { commitVerdicts, isCommitId, releaseCheck, type CommitCheck } from "../checks/commit_check.ts";
1111 import { readLooks } from "../checks/looks.ts";
12 import type { KeptResult } from "../checks/gate_result.ts";
1213 import { vitalsRows, type PageSize } from "../checks/summary.ts";
1314 import { hasCommit, isAncestor } from "../git/builds.ts";
1415 import { repoDir } from "../git/repos.ts";
@@ -20,7 +21,7 @@ import { steerRun } from "../crew/runner.ts";
2021 import { getIssueById, getIssuesByIds } from "../core/issues.ts";
2122 import { addComment } from "./issues.ts";
2223 import { getAppByRepo } from "../core/apps.ts";
23 import { canEnterApp, canSeeOwnerFacts, onCrew, type Repo } from "../core/repos.ts";
24 import { canEnterApp, canSeeOwnerFacts, getRepoById, onCrew, type Repo } from "../core/repos.ts";
2425 import {
2526 cancelRun as markCancelled,
2627 getRun,
@@ -134,6 +135,37 @@ export function mayReadRunLog(
134135 );
135136 }
136137
138 /**
139 * The merge queue's kept gates as `actor` may see them (#14949): none to
140 * someone who may not read the repository's runs; to someone who may not
141 * read a run's log, the verdicts and counts without the failing tests, whose
142 * names and first error lines are the gate's log.
143 */
144 export function gatesForReader(
145 app: App,
146 actor: User | undefined,
147 repo: Repo,
148 gates: readonly KeptResult[],
149 ): KeptResult[] {
150 if (!mayReadRuns(app, actor, repo)) return [];
151 if (mayReadRunLog(app, actor, repo)) return [...gates];
152 return gates.map((g) => ({ ...g, failing: [] }));
153 }
154
155 /**
156 * The same cut keyed by repository id, for a screen that reads gates across
157 * repositories (the terminal's Flow dialog): an unknown id shows none.
158 */
159 export function flowGatesFor(
160 app: App,
161 actor: User | undefined,
162 ): (repoId: string, gates: readonly KeptResult[]) => KeptResult[] {
163 return (repoId, gates) => {
164 const repo = getRepoById(app.db, repoId);
165 return repo === undefined ? [] : gatesForReader(app, actor, repo, gates);
166 };
167 }
168
137169 /**
138170 * Whether `actor` may read this run's log: the run is theirs to see (app
139171 * gate, sealed report) and the log is theirs to read. The one question both
src/http/api.ts +7 −4
@@ -254,7 +254,7 @@ import {
254254 } from "../actions/crew.ts";
255255 import { assignIssue, editIssue, TAKEN_UP } from "../actions/issues.ts";
256256 import { requireReader } from "../actions/access.ts";
257 import { looksOfCheck, mayReadRuns, runsViewKey, steerRepoRun } from "../actions/runs.ts";
257 import { gatesForReader, looksOfCheck, mayReadRunLog, mayReadRuns, runsViewKey, steerRepoRun } from "../actions/runs.ts";
258258 import { openPlan, parsePlan, proposePlan } from "../actions/plan.ts";
259259 import {
260260 DECISIONS_LIMIT_MAX,
@@ -4291,7 +4291,9 @@ export function apiRoutes(router: Router<Handler>, isPage: (path: string) => boo
42914291 const parsed = parseCursor(q.get("cursor"), /^[0-9A-Za-z]{1,40}$/);
42924292 if (parsed === undefined) return cursorRefusal("cursor is a gate id from next_cursor");
42934293 const cursor = parsed ?? undefined;
4294 const items = timePhase(ctx.request, "gates", () => recentGates(ctx.app.db, repo.id, limit, cursor));
4294 const items = timePhase(ctx.request, "gates", () =>
4295 gatesForReader(ctx.app, ctx.auth.user, repo, recentGates(ctx.app.db, repo.id, limit, cursor)),
4296 );
42954297 return timePhase(ctx.request, "render", () => json(paged(items, limit, (g) => g.id), 200, { "cache-control": "no-store" }));
42964298 });
42974299
@@ -4310,10 +4312,11 @@ export function apiRoutes(router: Router<Handler>, isPage: (path: string) => boo
43104312 return json({ ...g, planner: { paused: paused !== null, until: paused } }, 200, { "cache-control": "no-store" });
43114313 });
43124314
4313 // A kept gate's log (`checks/gate_log.ts`): the last 200 lines, as text.
4315 // A kept gate's log (`checks/gate_log.ts`): the last 200 lines, as text,
4316 // to those who may read a run's log (#14949); anyone else gets the 404.
43144317 router.add("GET", "/api/v1/repos/:owner/:name/gates/:id/log", (ctx) => {
43154318 const repo = loadRepo(ctx);
4316 if (!repo) return notFound();
4319 if (!repo || !mayReadRunLog(ctx.app, ctx.auth.user, repo)) return notFound();
43174320 const kept = readGateLog(ctx.app.config.dataDir, repo.ownerName, repo.name, ctx.params.id ?? "");
43184321 if (!kept) return notFound();
43194322 const head = `# gate ${kept.ok ? "green" : "red"} at ${new Date(kept.at).toISOString()}, commit ${kept.commit}\n`;
src/http/mcp/tools/queue_gates.ts +2 −1
@@ -1,5 +1,6 @@
11 import { doctorRuns } from "../../../checks/doctor.ts";
22 import { recentGates } from "../../../checks/gate_result.ts";
3 import { gatesForReader } from "../../../actions/runs.ts";
34 import { good, limitArg, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts";
45
56 export const tool: Tool = {
@@ -20,7 +21,7 @@ export const tool: Tool = {
2021 if (isAnswer(repo)) return repo;
2122 const limit = limitArg(args, 100, 20);
2223 if (typeof limit !== "number") return limit;
23 const gates = recentGates(ctx.app.db, repo.id, limit);
24 const gates = gatesForReader(ctx.app, user, repo, recentGates(ctx.app.db, repo.id, limit));
2425 const red = gates.filter((g) => g.state === "red").length;
2526 return good({ says: `${gates.length} gate(s), ${red} red.`, gates, doctor: doctorRuns(ctx.app.db, repo.id, limit) });
2627 },
src/tui/forge.ts +7 −1
@@ -102,6 +102,7 @@ import { readVerified } from "../flow/verified.ts";
102102 import { memoryScreen } from "./screens/system.ts";
103103 import { noteRead, telemetryReader } from "../actions/telemetry.ts";
104104 import { queuesFor, systemFor } from "../system/telemetry.ts";
105 import { flowGatesFor } from "../actions/runs.ts";
105106 import { apiScreen } from "./screens/api.ts";
106107 import { changelogScreen } from "./screens/changelog.ts";
107108 import { docScreen, docsScreen } from "./screens/docs.ts";
@@ -553,7 +554,12 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] {
553554 session.db,
554555 new Date(),
555556 systemFor(session.app, flowReader).duplicates,
556 flowReader.kind === "agent" ? { queues: queuesFor(session.app, flowReader, new Date(), { batches: true }) } : undefined,
557 flowReader.kind === "agent"
558 ? {
559 queues: queuesFor(session.app, flowReader, new Date(), { batches: true }),
560 gates: flowGatesFor(session.app, user),
561 }
562 : undefined,
557563 readHeld(session.app, flowReader.kind === "owner"),
558564 forgeCeiling(session.app.config),
559565 readVerified(session.app, flowReader.kind === "owner"),
src/tui/screens/flow.ts +18 −2
@@ -94,7 +94,16 @@ export function flowLines(
9494 * What an agent reader may see: its queue lines, conflicted pulls and changes-requested waits
9595 * come already cut to public.
9696 */
97 agent?: { queues: ReturnType<typeof readQueues> } | undefined,
97 agent?:
98 | {
99 queues: ReturnType<typeof readQueues>;
100 /**
101 * A repository's kept gates as this reader may see them (#14949, `gatesForReader`): its
102 * failing tests are the gate's log, a stranger's to read only where they may read runs'.
103 */
104 gates?: (repoId: string, gates: readonly KeptResult[]) => readonly KeptResult[];
105 }
106 | undefined,
98107 /**
99108 * Why ready issues wait, per autonomous repository (`readHeld`, already cut to what the reader
100109 * may see).
@@ -180,7 +189,11 @@ export function flowLines(
180189 const id = ids.get(q.repo);
181190 return [
182191 `${pad(truncate(q.repo, 15), 15)} ${pad(String(q.queued), 6, "right")} ${pad(String(q.gating), 6, "right")} ${pad(String(q.gates), 5, "right")} ${pad(String(q.landedHour), 9, "right")} ${pad(q.approvedToLanded === null ? "—" : String(q.approvedToLanded), 12, "right")}`,
183 ...gateLines(id === undefined ? [] : recentGates(db, id, GATES_SHOWN), now.getTime(), inner),
192 ...gateLines(
193 id === undefined ? [] : (agent === undefined ? (_: string, g: readonly KeptResult[]) => g : (agent.gates ?? strangerGates))(id, recentGates(db, id, GATES_SHOWN)),
194 now.getTime(),
195 inner,
196 ),
184197 ...doctorLines(id === undefined ? [] : doctorRuns(db, id, DOCTOR_SHOWN), now.getTime(), inner),
185198 ];
186199 })),
@@ -257,6 +270,9 @@ function repoIds(db: Database, names: readonly string[]): Map<string, string> {
257270 return new Map(rows.map((r) => [r.full, r.id]));
258271 }
259272
273 /** An agent view handed no `gates` cut sees the verdicts without the failing tests (#14949). */
274 const strangerGates = (_: string, gates: readonly KeptResult[]): KeptResult[] => gates.map((g) => ({ ...g, failing: [] }));
275
260276 const STATE_WORD: Record<KeptResult["state"], string> = { green: "green", red: "red", cut_off: "cut off" };
261277
262278 /**
src/web/pages/boards-gates.ts +26 −4
@@ -3,10 +3,17 @@
33 * across the repositories the reader may see, one row each with when, the
44 * pulls, the verdict, and on red the first failing test and its first error
55 * line. Reads `recentGates` once per repository; a sealed pull is never
6 * named by title, only as `a sealed pull`.
6 * named by title, only as `a sealed pull`. A reader who is not the owner
7 * gets each repository's gates through `gatesForReader` (#14949): the
8 * failing tests are the gate's log, so a stranger sees the verdict and
9 * counts, and a red row falls back to the gate's reason.
710 */
811
912 import type { Database } from "bun:sqlite";
13 import type { App } from "../../app.ts";
14 import { gatesForReader } from "../../actions/runs.ts";
15 import { getRepoById } from "../../core/repos.ts";
16 import type { User } from "../../core/users.ts";
1017 import { recentGates, type KeptResult } from "../../checks/gate_result.ts";
1118 import { span } from "../../flow/pipeline.ts";
1219 import { html, type Html } from "../html.ts";
@@ -69,11 +76,26 @@ function gateRow(l: Listed, now: number): Html {
6976 });
7077 }
7178
72 /** The "Last gates" section: a heading and rows, no card. */
73 export function gatesSection(db: Database, owner: boolean, now: number): Html {
79 /**
80 * The gates `reader` may see of one repository: all of them to the owner,
81 * otherwise as `gatesForReader` cuts them (an unknown repository shows none).
82 */
83 function readable(app: App, owner: boolean, reader: User | undefined, repoId: string): KeptResult[] {
84 const gates = recentGates(app.db, repoId, GATES_LISTED);
85 if (owner) return gates;
86 const repo = getRepoById(app.db, repoId);
87 return repo === undefined ? [] : gatesForReader(app, reader, repo, gates);
88 }
89
90 /**
91 * The "Last gates" section: a heading and rows, no card. `reader` is the
92 * account behind a non-owner view (none: read as a stranger).
93 */
94 export function gatesSection(app: App, owner: boolean, now: number, reader?: User): Html {
95 const db = app.db;
7496 const all: Listed[] = [];
7597 for (const r of repos(db, owner)) {
76 for (const gate of recentGates(db, r.id, GATES_LISTED)) {
98 for (const gate of readable(app, owner, reader, r.id)) {
7799 all.push({ repo: r.name, gate, sealed: sealedPulls(db, r.id, gate.pulls) });
78100 }
79101 }
src/web/pages/flow-panel.ts +1 −1
@@ -255,7 +255,7 @@ export function flowPanel(app: App, reader: Reader, url: URL, base: string, slot
255255 ${owner ? html`<p id="keeper-heartbeat-row">Release tick: <span id="keeper-heartbeat">${beatFact(lastBeat(app.db), new Date(now))}</span></p>` : ""}`, { id: "day" })}
256256 ${heldCard(pic.held)}
257257 ${queueCard(queuesFor(app, reader, new Date(now), { batches: true }))}
258 ${gatesSection(app.db, owner, now)}
258 ${gatesSection(app, owner, now)}
259259 ${doctorCard(app.db, owner, now)}
260260 ${hotFilesCard(app, reader)}
261261 ${verifiedCard(readVerified(app, owner), now)}
test/doorless.test.ts +1 −1
@@ -29,7 +29,7 @@ test("a listed page that gained a door fails: prune the list", () => {
2929 * Lower this when the list shrinks; raising it is adding a page without a door, which review
3030 * refuses.
3131 */
32 const CEILING = 99;
32 const CEILING = 98;
3333
3434 test("the allow list cannot gain a page", () => {
3535 expect(allowed.length, "the list only shrinks: give the page a terminal door instead of listing it").toBeLessThanOrEqual(CEILING);
test/flow-panel-gates.test.ts +15 −1
@@ -35,7 +35,7 @@ test("a green and a red gate: rows, pull links, the failing test and its first e
3535 app.db, "g2",
3636 gate({ pulls: [15], state: "red", failed: 1, failing: [{ name: "a <b> works", errors: ["boom <script>", "second"] }], finishedAt: ago(5) }),
3737 );
38 const out = draw("agent");
38 const out = draw("owner");
3939 expect(out).toContain('id="gates"');
4040 expect(out).toContain('href="/alice/svc/pulls/12"');
4141 expect(out).toContain('href="/alice/svc/pulls/13"');
@@ -47,6 +47,20 @@ test("a green and a red gate: rows, pull links, the failing test and its first e
4747 expect(out).not.toContain("second");
4848 });
4949
50 // #14949: a red gate's failing tests are its log. A reader who is not the
51 // owner (here a stranger, no account) gets the verdict and the pull links, and
52 // neither the test's name nor its error line.
53 test("a reader who may not read the run's log sees the red verdict without the failing test", () => {
54 const agent = draw("agent");
55 expect(agent).toContain('data-gate="red"');
56 expect(agent).toContain('href="/alice/svc/pulls/15"');
57 expect(agent).not.toContain("a &lt;b&gt; works");
58 expect(agent).not.toContain("boom");
59 const owner = draw("owner");
60 expect(owner).toContain("a &lt;b&gt; works");
61 expect(owner).toContain("boom &lt;script&gt;");
62 });
63
5064 test("a sealed pull is never named or linked; a private repository's gates are the owner's alone", () => {
5165 keepGateResult(app.db, "g3", gate({ pulls: [14], finishedAt: ago(3) }));
5266 keepGateResult(app.db, "g4", gate({ repoId: "r2", pulls: [77], finishedAt: ago(1) }));
test/gate-log.test.ts +46
@@ -11,6 +11,7 @@ import { createUser } from "../src/core/users.ts";
1111 import { forgeHttp, type ForgeHttp } from "../src/http/server.ts";
1212 import { quietLogs } from "./helpers/globals.ts";
1313 import { landVerdict } from "../src/checks/tiers.ts";
14 import { keepGateResult } from "../src/checks/gate_result.ts";
1415
1516 quietLogs();
1617
@@ -65,6 +66,7 @@ describe("GET /api/v1/repos/:owner/:name/gates/:id/log", () => {
6566 let app: App;
6667 let http: ForgeHttp;
6768 let id: string;
69 let openId: string;
6870 const token: Record<string, string> = {};
6971
7072 const ok = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => {
@@ -107,6 +109,28 @@ describe("GET /api/v1/repos/:owner/:name/gates/:id/log", () => {
107109 token.alice = createToken(app.db, alice.id, "t", "rw").token;
108110 token.mallory = createToken(app.db, mallory.id, "t", "rw").token;
109111 id = keepGateLog(dataDir, "alice/vault", "abcdef1234567890", false, red, 5_000)!;
112 const open = ok(await createRepo(app, alice, { name: "open", visibility: "public" }));
113 ok(
114 await commitToBranch(app, alice, open, {
115 message: "Start",
116 files: [{ path: "README.md", content: "# open\n" }],
117 }),
118 );
119 openId = keepGateLog(dataDir, "alice/open", "abcdef1234567890", false, red, 6_000)!;
120 const at = new Date().toISOString();
121 keepGateResult(app.db, openId, {
122 repoId: open.id,
123 runId: "gate-abcdef123456",
124 tipOid: "abcdef1234567890",
125 pulls: [7],
126 state: "red",
127 reason: "tests",
128 passed: 1,
129 failed: 1,
130 failing: [{ name: "secret > two", file: "test/a.test.ts", errors: ["TOKEN=hunter2"] }],
131 startedAt: at,
132 finishedAt: at,
133 });
110134 }, 60_000);
111135
112136 afterAll(() => {
@@ -130,6 +154,28 @@ describe("GET /api/v1/repos/:owner/:name/gates/:id/log", () => {
130154 expect(text.trimEnd().split("\n").at(-1)).toBe("(fail) two");
131155 });
132156
157 // #14949: a public repository's gate log is the run log's kind, for its
158 // writers and crew; its verdicts are public, its failing tests are not.
159 test("a stranger on a public repository is refused the gate log and the failing tests", async () => {
160 const log = `/api/v1/repos/alice/open/gates/${openId}/log`;
161 const list = "/api/v1/repos/alice/open/queue/gates";
162 for (const who of [undefined, "mallory"]) {
163 expect((await get(log, who)).res.status).toBe(404);
164 const { res, text } = await get(list, who);
165 expect(res.status).toBe(200);
166 const items = JSON.parse(text).items as { state: string; failed: number; failing: unknown[] }[];
167 expect(items).toHaveLength(1);
168 expect(items[0]!.state).toBe("red");
169 expect(items[0]!.failed).toBe(1);
170 expect(items[0]!.failing).toEqual([]);
171 expect(text).not.toContain("secret > two");
172 expect(text).not.toContain("hunter2");
173 }
174 expect((await get(log, "alice")).res.status).toBe(200);
175 const own = JSON.parse((await get(list, "alice")).text).items as { failing: { name: string }[] }[];
176 expect(own[0]!.failing.map((t) => t.name)).toEqual(["secret > two"]);
177 });
178
133179 test("an unknown id is 404 for the owner", async () => {
134180 expect((await get(path("0000000005000-123456abcdef"), "alice")).res.status).toBe(404);
135181 expect((await get(path("nope"), "alice")).res.status).toBe(404);
test/tui-flow-gates.test.ts +21 −1
@@ -7,6 +7,8 @@ import { createApp, type App } from "../src/app.ts";
77 import { keepGateResult, recentGates, type GateResult } from "../src/checks/gate_result.ts";
88 import { createUser } from "../src/core/users.ts";
99 import { flowLines, gateLines } from "../src/tui/screens/flow.ts";
10 import { flowGatesFor } from "../src/actions/runs.ts";
11 import { getUserByName } from "../src/core/users.ts";
1012
1113 const NOW = new Date("2026-10-27T12:00:00Z");
1214 const at = (min: number) => new Date(NOW.getTime() - min * 60_000).toISOString();
@@ -47,7 +49,7 @@ test("one green and one red gate: both lines, the red one names its failing test
4749 { repo: "alice/svc", queued: 1, gating: 0, gates: 0, landedHour: 0, approvedToLanded: null },
4850 { repo: "alice/quiet", queued: 0, gating: 0, gates: 0, landedHour: 1, approvedToLanded: null },
4951 ];
50 const lines = flowLines(app.db, NOW, [], { queues }, []);
52 const lines = flowLines(app.db, NOW, [], { queues, gates: flowGatesFor(app, getUserByName(app.db, "alice")) }, []);
5153 const svc = lines.findIndex((l) => l.startsWith("alice/svc"));
5254 expect(lines[svc + 1]).toBe(" #14 red · 5 minutes ago · a > b (test/a.test.ts)");
5355 expect(lines[svc + 2]).toBe(" #12 #13 green · 10 minutes ago");
@@ -100,3 +102,21 @@ test("nothing queued: the dialog says so and lists no gates", () => {
100102 expect(lines).toContain("Nothing queued, gating or landed in the last hour.");
101103 expect(lines).not.toContain(" no gates yet");
102104 });
105
106 // #14949: the terminal reaches the gates as the API does. A reader who may not
107 // read a run's log sees the verdicts without the failing tests' names.
108 test("an agent reader off the crew sees the red gate but not its failing test; the owner sees it", async () => {
109 const m = await createUser(app.db, { origin: "seed", trusted: true, username: "mallory", email: "[email protected]", password: "a-good-passphrase" });
110 if (!m.ok) throw new Error(m.error);
111 keepGateResult(app.db, "gz1", gate({ pulls: [901], state: "red", failed: 1, failing: [{ name: "leaky > test", file: "test/leaky.test.ts", errors: ["TOKEN=x"] }], finishedAt: at(0) }), NOW);
112 const stranger = flowLines(app.db, NOW, [], { queues: [svcRow], gates: flowGatesFor(app, m.value) }, []).join("\n");
113 expect(stranger).toContain("#901 red");
114 expect(stranger).not.toContain("leaky");
115 const owner = flowLines(app.db, NOW, [], { queues: [svcRow], gates: flowGatesFor(app, getUserByName(app.db, "alice")) }, []).join("\n");
116 expect(owner).toContain("#901 red · just now · leaky > test (test/leaky.test.ts)");
117 expect(flowGatesFor(app, m.value)("no-such-repo", recentGates(app.db, "r1", 5))).toEqual([]);
118 // An agent view handed no cut is read as a stranger's, never as the owner's.
119 const bare = flowLines(app.db, NOW, [], { queues: [svcRow] }, []).join("\n");
120 expect(bare).toContain("#901 red");
121 expect(bare).not.toContain("leaky");
122 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs