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
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/14949-merge-queue-gate-logs-and-verdicts-answe → main 7 commits fork
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`): | ||
| 35 | 35 | `passed` sums each `bun test` process's ` N pass`; `failed` counts distinct |
| 36 | 36 | `(fail)` names, so the shards' tally — which repeats every failure as |
| 37 | 37 | `(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 @@ | ||
| 11 | 11 | "src/web/pages/board_style.ts", |
| 12 | 12 | "src/web/pages/boards-doctor.ts", |
| 13 | 13 | "src/web/pages/boards-edit.ts", |
| 14 | "src/web/pages/boards-gates.ts", | |
| 15 | 14 | "src/web/pages/boards-held.ts", |
| 16 | 15 | "src/web/pages/boards-holds.ts", |
| 17 | 16 | "src/web/pages/boards-view.ts", |
src/actions/runs.ts +33 −1
| @@ -9,6 +9,7 @@ | ||
| 9 | 9 | |
| 10 | 10 | import { commitVerdicts, isCommitId, releaseCheck, type CommitCheck } from "../checks/commit_check.ts"; |
| 11 | 11 | import { readLooks } from "../checks/looks.ts"; |
| 12 | import type { KeptResult } from "../checks/gate_result.ts"; | |
| 12 | 13 | import { vitalsRows, type PageSize } from "../checks/summary.ts"; |
| 13 | 14 | import { hasCommit, isAncestor } from "../git/builds.ts"; |
| 14 | 15 | import { repoDir } from "../git/repos.ts"; |
| @@ -20,7 +21,7 @@ import { steerRun } from "../crew/runner.ts"; | ||
| 20 | 21 | import { getIssueById, getIssuesByIds } from "../core/issues.ts"; |
| 21 | 22 | import { addComment } from "./issues.ts"; |
| 22 | 23 | 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"; | |
| 24 | 25 | import { |
| 25 | 26 | cancelRun as markCancelled, |
| 26 | 27 | getRun, |
| @@ -134,6 +135,37 @@ export function mayReadRunLog( | ||
| 134 | 135 | ); |
| 135 | 136 | } |
| 136 | 137 | |
| 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 | ||
| 137 | 169 | /** |
| 138 | 170 | * Whether `actor` may read this run's log: the run is theirs to see (app |
| 139 | 171 | * 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 { | ||
| 254 | 254 | } from "../actions/crew.ts"; |
| 255 | 255 | import { assignIssue, editIssue, TAKEN_UP } from "../actions/issues.ts"; |
| 256 | 256 | 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"; | |
| 258 | 258 | import { openPlan, parsePlan, proposePlan } from "../actions/plan.ts"; |
| 259 | 259 | import { |
| 260 | 260 | DECISIONS_LIMIT_MAX, |
| @@ -4291,7 +4291,9 @@ export function apiRoutes(router: Router<Handler>, isPage: (path: string) => boo | ||
| 4291 | 4291 | const parsed = parseCursor(q.get("cursor"), /^[0-9A-Za-z]{1,40}$/); |
| 4292 | 4292 | if (parsed === undefined) return cursorRefusal("cursor is a gate id from next_cursor"); |
| 4293 | 4293 | 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 | ); | |
| 4295 | 4297 | return timePhase(ctx.request, "render", () => json(paged(items, limit, (g) => g.id), 200, { "cache-control": "no-store" })); |
| 4296 | 4298 | }); |
| 4297 | 4299 | |
| @@ -4310,10 +4312,11 @@ export function apiRoutes(router: Router<Handler>, isPage: (path: string) => boo | ||
| 4310 | 4312 | return json({ ...g, planner: { paused: paused !== null, until: paused } }, 200, { "cache-control": "no-store" }); |
| 4311 | 4313 | }); |
| 4312 | 4314 | |
| 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. | |
| 4314 | 4317 | router.add("GET", "/api/v1/repos/:owner/:name/gates/:id/log", (ctx) => { |
| 4315 | 4318 | const repo = loadRepo(ctx); |
| 4316 | if (!repo) return notFound(); | |
| 4319 | if (!repo || !mayReadRunLog(ctx.app, ctx.auth.user, repo)) return notFound(); | |
| 4317 | 4320 | const kept = readGateLog(ctx.app.config.dataDir, repo.ownerName, repo.name, ctx.params.id ?? ""); |
| 4318 | 4321 | if (!kept) return notFound(); |
| 4319 | 4322 | 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 @@ | ||
| 1 | 1 | import { doctorRuns } from "../../../checks/doctor.ts"; |
| 2 | 2 | import { recentGates } from "../../../checks/gate_result.ts"; |
| 3 | import { gatesForReader } from "../../../actions/runs.ts"; | |
| 3 | 4 | import { good, limitArg, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts"; |
| 4 | 5 | |
| 5 | 6 | export const tool: Tool = { |
| @@ -20,7 +21,7 @@ export const tool: Tool = { | ||
| 20 | 21 | if (isAnswer(repo)) return repo; |
| 21 | 22 | const limit = limitArg(args, 100, 20); |
| 22 | 23 | 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)); | |
| 24 | 25 | const red = gates.filter((g) => g.state === "red").length; |
| 25 | 26 | return good({ says: `${gates.length} gate(s), ${red} red.`, gates, doctor: doctorRuns(ctx.app.db, repo.id, limit) }); |
| 26 | 27 | }, |
src/tui/forge.ts +7 −1
| @@ -102,6 +102,7 @@ import { readVerified } from "../flow/verified.ts"; | ||
| 102 | 102 | import { memoryScreen } from "./screens/system.ts"; |
| 103 | 103 | import { noteRead, telemetryReader } from "../actions/telemetry.ts"; |
| 104 | 104 | import { queuesFor, systemFor } from "../system/telemetry.ts"; |
| 105 | import { flowGatesFor } from "../actions/runs.ts"; | |
| 105 | 106 | import { apiScreen } from "./screens/api.ts"; |
| 106 | 107 | import { changelogScreen } from "./screens/changelog.ts"; |
| 107 | 108 | import { docScreen, docsScreen } from "./screens/docs.ts"; |
| @@ -553,7 +554,12 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 553 | 554 | session.db, |
| 554 | 555 | new Date(), |
| 555 | 556 | 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, | |
| 557 | 563 | readHeld(session.app, flowReader.kind === "owner"), |
| 558 | 564 | forgeCeiling(session.app.config), |
| 559 | 565 | readVerified(session.app, flowReader.kind === "owner"), |
src/tui/screens/flow.ts +18 −2
| @@ -94,7 +94,16 @@ export function flowLines( | ||
| 94 | 94 | * What an agent reader may see: its queue lines, conflicted pulls and changes-requested waits |
| 95 | 95 | * come already cut to public. |
| 96 | 96 | */ |
| 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, | |
| 98 | 107 | /** |
| 99 | 108 | * Why ready issues wait, per autonomous repository (`readHeld`, already cut to what the reader |
| 100 | 109 | * may see). |
| @@ -180,7 +189,11 @@ export function flowLines( | ||
| 180 | 189 | const id = ids.get(q.repo); |
| 181 | 190 | return [ |
| 182 | 191 | `${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 | ), | |
| 184 | 197 | ...doctorLines(id === undefined ? [] : doctorRuns(db, id, DOCTOR_SHOWN), now.getTime(), inner), |
| 185 | 198 | ]; |
| 186 | 199 | })), |
| @@ -257,6 +270,9 @@ function repoIds(db: Database, names: readonly string[]): Map<string, string> { | ||
| 257 | 270 | return new Map(rows.map((r) => [r.full, r.id])); |
| 258 | 271 | } |
| 259 | 272 | |
| 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 | ||
| 260 | 276 | const STATE_WORD: Record<KeptResult["state"], string> = { green: "green", red: "red", cut_off: "cut off" }; |
| 261 | 277 | |
| 262 | 278 | /** |
src/web/pages/boards-gates.ts +26 −4
| @@ -3,10 +3,17 @@ | ||
| 3 | 3 | * across the repositories the reader may see, one row each with when, the |
| 4 | 4 | * pulls, the verdict, and on red the first failing test and its first error |
| 5 | 5 | * 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. | |
| 7 | 10 | */ |
| 8 | 11 | |
| 9 | 12 | 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"; | |
| 10 | 17 | import { recentGates, type KeptResult } from "../../checks/gate_result.ts"; |
| 11 | 18 | import { span } from "../../flow/pipeline.ts"; |
| 12 | 19 | import { html, type Html } from "../html.ts"; |
| @@ -69,11 +76,26 @@ function gateRow(l: Listed, now: number): Html { | ||
| 69 | 76 | }); |
| 70 | 77 | } |
| 71 | 78 | |
| 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; | |
| 74 | 96 | const all: Listed[] = []; |
| 75 | 97 | 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)) { | |
| 77 | 99 | all.push({ repo: r.name, gate, sealed: sealedPulls(db, r.id, gate.pulls) }); |
| 78 | 100 | } |
| 79 | 101 | } |
src/web/pages/flow-panel.ts +1 −1
| @@ -255,7 +255,7 @@ export function flowPanel(app: App, reader: Reader, url: URL, base: string, slot | ||
| 255 | 255 | ${owner ? html`<p id="keeper-heartbeat-row">Release tick: <span id="keeper-heartbeat">${beatFact(lastBeat(app.db), new Date(now))}</span></p>` : ""}`, { id: "day" })} |
| 256 | 256 | ${heldCard(pic.held)} |
| 257 | 257 | ${queueCard(queuesFor(app, reader, new Date(now), { batches: true }))} |
| 258 | ${gatesSection(app.db, owner, now)} | |
| 258 | ${gatesSection(app, owner, now)} | |
| 259 | 259 | ${doctorCard(app.db, owner, now)} |
| 260 | 260 | ${hotFilesCard(app, reader)} |
| 261 | 261 | ${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", () => { | ||
| 29 | 29 | * Lower this when the list shrinks; raising it is adding a page without a door, which review |
| 30 | 30 | * refuses. |
| 31 | 31 | */ |
| 32 | const CEILING = 99; | |
| 32 | const CEILING = 98; | |
| 33 | 33 | |
| 34 | 34 | test("the allow list cannot gain a page", () => { |
| 35 | 35 | 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 | ||
| 35 | 35 | app.db, "g2", |
| 36 | 36 | gate({ pulls: [15], state: "red", failed: 1, failing: [{ name: "a <b> works", errors: ["boom <script>", "second"] }], finishedAt: ago(5) }), |
| 37 | 37 | ); |
| 38 | const out = draw("agent"); | |
| 38 | const out = draw("owner"); | |
| 39 | 39 | expect(out).toContain('id="gates"'); |
| 40 | 40 | expect(out).toContain('href="/alice/svc/pulls/12"'); |
| 41 | 41 | 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 | ||
| 47 | 47 | expect(out).not.toContain("second"); |
| 48 | 48 | }); |
| 49 | 49 | |
| 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 <b> works"); | |
| 58 | expect(agent).not.toContain("boom"); | |
| 59 | const owner = draw("owner"); | |
| 60 | expect(owner).toContain("a <b> works"); | |
| 61 | expect(owner).toContain("boom <script>"); | |
| 62 | }); | |
| 63 | ||
| 50 | 64 | test("a sealed pull is never named or linked; a private repository's gates are the owner's alone", () => { |
| 51 | 65 | keepGateResult(app.db, "g3", gate({ pulls: [14], finishedAt: ago(3) })); |
| 52 | 66 | 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"; | ||
| 11 | 11 | import { forgeHttp, type ForgeHttp } from "../src/http/server.ts"; |
| 12 | 12 | import { quietLogs } from "./helpers/globals.ts"; |
| 13 | 13 | import { landVerdict } from "../src/checks/tiers.ts"; |
| 14 | import { keepGateResult } from "../src/checks/gate_result.ts"; | |
| 14 | 15 | |
| 15 | 16 | quietLogs(); |
| 16 | 17 | |
| @@ -65,6 +66,7 @@ describe("GET /api/v1/repos/:owner/:name/gates/:id/log", () => { | ||
| 65 | 66 | let app: App; |
| 66 | 67 | let http: ForgeHttp; |
| 67 | 68 | let id: string; |
| 69 | let openId: string; | |
| 68 | 70 | const token: Record<string, string> = {}; |
| 69 | 71 | |
| 70 | 72 | 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", () => { | ||
| 107 | 109 | token.alice = createToken(app.db, alice.id, "t", "rw").token; |
| 108 | 110 | token.mallory = createToken(app.db, mallory.id, "t", "rw").token; |
| 109 | 111 | 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 | }); | |
| 110 | 134 | }, 60_000); |
| 111 | 135 | |
| 112 | 136 | afterAll(() => { |
| @@ -130,6 +154,28 @@ describe("GET /api/v1/repos/:owner/:name/gates/:id/log", () => { | ||
| 130 | 154 | expect(text.trimEnd().split("\n").at(-1)).toBe("(fail) two"); |
| 131 | 155 | }); |
| 132 | 156 | |
| 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 | ||
| 133 | 179 | test("an unknown id is 404 for the owner", async () => { |
| 134 | 180 | expect((await get(path("0000000005000-123456abcdef"), "alice")).res.status).toBe(404); |
| 135 | 181 | 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"; | ||
| 7 | 7 | import { keepGateResult, recentGates, type GateResult } from "../src/checks/gate_result.ts"; |
| 8 | 8 | import { createUser } from "../src/core/users.ts"; |
| 9 | 9 | 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"; | |
| 10 | 12 | |
| 11 | 13 | const NOW = new Date("2026-10-27T12:00:00Z"); |
| 12 | 14 | 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 | ||
| 47 | 49 | { repo: "alice/svc", queued: 1, gating: 0, gates: 0, landedHour: 0, approvedToLanded: null }, |
| 48 | 50 | { repo: "alice/quiet", queued: 0, gating: 0, gates: 0, landedHour: 1, approvedToLanded: null }, |
| 49 | 51 | ]; |
| 50 | const lines = flowLines(app.db, NOW, [], { queues }, []); | |
| 52 | const lines = flowLines(app.db, NOW, [], { queues, gates: flowGatesFor(app, getUserByName(app.db, "alice")) }, []); | |
| 51 | 53 | const svc = lines.findIndex((l) => l.startsWith("alice/svc")); |
| 52 | 54 | expect(lines[svc + 1]).toBe(" #14 red · 5 minutes ago · a > b (test/a.test.ts)"); |
| 53 | 55 | 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", () => { | ||
| 100 | 102 | expect(lines).toContain("Nothing queued, gating or landed in the last hour."); |
| 101 | 103 | expect(lines).not.toContain(" no gates yet"); |
| 102 | 104 | }); |
| 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 | }); |
new above
offline