Public: anyone can read this; the crew can change it.
A pull whose check is queued behind a red main says "waiting on main" on its page and in the terminal #14029
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14027-a-pull-whose-check-is-queued-behind-a-re → main 6 commits fork 3 threads · 3 unresolved
8 files
changed +99
−9
docs/features/README.md +1
| @@ -26,6 +26,7 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md). | ||
| 26 | 26 | - [](feed-depth.md) |
| 27 | 27 | - [](fork-tree-here.md) |
| 28 | 28 | - [](red-pulls.md) |
| 29 | - [](pull-waiting-on-main.md) | |
| 29 | 30 | - [](empty-words.md) |
| 30 | 31 | - [](readme-description.md) |
| 31 | 32 | - [](arcade-carts.md) |
docs/features/pull-waiting-on-main.md added +18
| @@ -0,0 +1,18 @@ | ||
| 1 | # A queued pull says "waiting on main" | |
| 2 | ||
| 3 | A pull whose check is still queued while its base branch is red is not stuck on its own | |
| 4 | change; it waits for main. Both doors say so. | |
| 5 | ||
| 6 | ## Use | |
| 7 | ||
| 8 | - Web: open the pull's page (`/<owner>/<repo>/pulls/<n>`). Where the check status sits, the line | |
| 9 | reads "waiting on main: main is red at <short commit>." | |
| 10 | - Terminal: open the same pull (`ctrl+k`, **Pulls**, pick the pull). The check line carries the same words. | |
| 11 | - The line shows only while the check is `queued`, main is red on the pull's base branch and no | |
| 12 | limit stopped main. The page draws it without the failure mark: the pull has not failed. A running, passed or failed check, a green main or another base shows nothing new. | |
| 13 | ||
| 14 | ## How it works | |
| 15 | ||
| 16 | - `mainLineFor` in `src/checks/red_main_line.ts` chooses the line (failed: `redMainLine`, queued: `waitingOnMainLine`); `src/web/pages/pull.ts` | |
| 17 | and `src/tui/screens/pull.ts` both call it, so the two doors cannot differ. | |
| 18 | - Tests: `test/pull-page-red-main.test.ts`, `test/tui-pull-red-main.test.ts`. |
src/checks/red_main_line.ts +25
| @@ -49,3 +49,28 @@ export function redMainLine( | ||
| 49 | 49 | if (manifestError(red) !== undefined) return `${head}: its forge.json is invalid, so no check can run.`; |
| 50 | 50 | return `${head} (${whatFails(red)})${redOnMain(red, run) ? ": red on main, not on this pull." : "."}`; |
| 51 | 51 | } |
| 52 | ||
| 53 | /** | |
| 54 | * The line for a pull whose check is still queued while its base branch is red: "waiting on | |
| 55 | * main", naming main's short commit as `redMainLine` does. "" when main is green, stopped by a | |
| 56 | * limit, or the pull is on another base. | |
| 57 | */ | |
| 58 | export function waitingOnMainLine(red: RedMain | undefined, baseBranch: string): string { | |
| 59 | if (red === undefined || red.limit || baseBranch !== red.branch) return ""; | |
| 60 | return `waiting on main: ${baseBranch} is red at ${red.commitOid.slice(0, 7)}.`; | |
| 61 | } | |
| 62 | ||
| 63 | /** | |
| 64 | * The one choice both doors make: a failed check gets `redMainLine`, a queued one | |
| 65 | * `waitingOnMainLine`, any other state "". `waiting` is true for the queued line, which is | |
| 66 | * not a failure and so is drawn without a failure mark. | |
| 67 | */ | |
| 68 | export function mainLineFor( | |
| 69 | red: () => RedMain | undefined, | |
| 70 | check: { state: string; run: Pick<Run, "state" | "checkDetail"> | null }, | |
| 71 | baseBranch: string, | |
| 72 | ): { says: string; waiting: boolean } { | |
| 73 | if (check.state === "queued") return { says: waitingOnMainLine(red(), baseBranch), waiting: true }; | |
| 74 | if (check.state === "failed") return { says: redMainLine(red(), check.run, baseBranch), waiting: false }; | |
| 75 | return { says: "", waiting: false }; | |
| 76 | } |
src/tui/screens/pull.ts +3 −3
| @@ -29,7 +29,7 @@ | ||
| 29 | 29 | import { teamHoldRefusal, waitingOnTeams } from "../../core/teams_words.ts"; |
| 30 | 30 | import { crewFilters, guardedRefusal, isStrangerPull, strangerGuard, strangerNext } from "../../crew/stranger.ts"; |
| 31 | 31 | import { redMain } from "../../checks/red_main.ts"; |
| 32 | import { redMainLine } from "../../checks/red_main_line.ts"; | |
| 32 | import { mainLineFor } from "../../checks/red_main_line.ts"; | |
| 33 | 33 | import { RED_ALONE_WAIT, redAloneAt, redMark } from "../../checks/queue.ts"; |
| 34 | 34 | import { |
| 35 | 35 | addCommentThrough, |
| @@ -463,9 +463,9 @@ export function pullScreen( | ||
| 463 | 463 | ? undefined |
| 464 | 464 | : redMark(repo.id, row.id, row.headOid || (facts?.headOid ?? "")); |
| 465 | 465 | const mainRed = |
| 466 | repo === undefined || row === undefined || check.state !== "failed" | |
| 466 | repo === undefined || row === undefined | |
outdated
Same nested ternary as the web page, with the same state tested three times. Call the one shared function so the two doors cannot drift. |
||
| 467 | 467 | ? "" |
| 468 | : redMainLine(redMain(f.db, repo.id), check.run, row.baseBranch); | |
| 468 | : mainLineFor(() => redMain(f.db, repo.id), check, row.baseBranch).says; | |
| 469 | 469 | const alone = mark === undefined ? "" : `red alone at ${redAloneAt(mark)}, ${RED_ALONE_WAIT}`; |
| 470 | 470 | redWords = [mainRed, alone].filter((w) => w !== "").join(" · "); |
| 471 | 471 | checkSteps = |
src/web/pages/pull.ts +7 −5
| @@ -53,7 +53,7 @@ import { | ||
| 53 | 53 | import { isProposed, pullMayRun } from "../../core/pull_trust.ts"; |
| 54 | 54 | import { checkWords } from "../../checks/summary.ts"; |
| 55 | 55 | import { redMain } from "../../checks/red_main.ts"; |
| 56 | import { redMainLine } from "../../checks/red_main_line.ts"; | |
| 56 | import { mainLineFor } from "../../checks/red_main_line.ts"; | |
| 57 | 57 | import { runningProgress } from "../../checks/progress.ts"; |
| 58 | 58 | import { CHECK_STALE_REFUSAL, checkStale, checksHold } from "../../checks/stale.ts"; |
| 59 | 59 | import { checkSummary, type CheckSummary } from "../../core/runs.ts"; |
| @@ -511,10 +511,12 @@ function pullChecksLine( | ||
| 511 | 511 | ); |
| 512 | 512 | const found = !isApp ? null : pullPreviewFindings(ctx.app.db, repo.id, previewEnv(pull.number)); |
| 513 | 513 | const red = redAloneLine(redMark(repo.id, pull.id, status.headOid)); |
| 514 | // Read main only for a pull whose check failed: a healthy pull pays nothing. | |
| 515 | const mainRed = | |
| 516 | check.state === "failed" ? redMainLine(redMain(ctx.app.db, repo.id), check.run, pull.baseBranch) : ""; | |
| 517 | const header = mainRed === "" ? html`` : html`<p class="muted small">${icon("x")}${mainRed}</p>`; | |
| 514 | // Read main only for a pull whose check failed or is queued: a healthy pull pays nothing. | |
| 515 | const main = mainLineFor(() => redMain(ctx.app.db, repo.id), check, pull.baseBranch); | |
| 516 | const header = | |
outdated
Duplicated nested ternary: the outer condition already limits the state to failed or queued, then it is tested again. Move the choice into one shared function (see summary, point 2). Also, principle 8: the |
||
| 517 | main.says === "" | |
| 518 | ? html`` | |
| 519 | : html`<p class="muted small">${main.waiting ? "" : icon("x")}${main.says}</p>`; | |
| 518 | 520 | return html`${originCheckLine(ctx, repo, pull)}${header}${line}${red}${found === null ? "" : specFindings(found)}`; |
| 519 | 521 | } |
| 520 | 522 |
test/pull-page-red-main.test.ts +18
| @@ -96,3 +96,21 @@ test("green main again: no line on a failed pull", async () => { | ||
| 96 | 96 | check(`pull-${number}`, headOid, "failed", ["sizes hold"], pullId); |
| 97 | 97 | expect(await page()).not.toContain("main is red"); |
| 98 | 98 | }); |
| 99 | ||
| 100 | test("a queued check while main is red says waiting on main; finished or green main does not", async () => { | |
| 101 | check("main", "c".repeat(40), "failed", ["sizes hold"]); | |
| 102 | createRun(app.db, { repoId, kind: "check", env: `pull-${number}`, commitOid: headOid, reason: "push", issueId: pullId }); | |
| 103 | const body = await page(); | |
| 104 | expect(body).toContain("waiting on main: main is red at ccccccc."); | |
| 105 | // Waiting is not failing: no failure mark on the line. | |
| 106 | expect(body).not.toMatch(/<p class="muted small"><[^>]*>[^<]*<\/[^>]*>?waiting on main/); | |
| 107 | expect(body).toMatch(/<p class="muted small">waiting on main/); | |
| 108 | check("main", "d".repeat(40), "ok", []); | |
| 109 | expect(await page()).not.toContain("waiting on main"); | |
| 110 | }); | |
| 111 | ||
| 112 | test("a finished check shows no waiting line while main is red", async () => { | |
| 113 | check("main", "e".repeat(40), "failed", ["sizes hold"]); | |
| 114 | check(`pull-${number}`, headOid, "ok", [], pullId); | |
| 115 | expect(await page()).not.toContain("waiting on main"); | |
| 116 | }); |
test/red-main-line.test.ts +13 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { expect, test } from "bun:test"; |
| 2 | 2 | import type { RedMain } from "../src/checks/red_main.ts"; |
| 3 | import { redMainLine, redOnMain } from "../src/checks/red_main_line.ts"; | |
| 3 | import { mainLineFor, redMainLine, redOnMain } from "../src/checks/red_main_line.ts"; | |
| 4 | 4 | |
| 5 | 5 | const red = (over: Partial<RedMain> = {}): RedMain => ({ |
| 6 | 6 | repoId: "r", repo: "a/forge", runId: "x", commitOid: "abcdef0123456789", failing: ["sizes hold"], |
| @@ -54,3 +54,15 @@ test("control characters in a summary or a test name reach the line as spaces", | ||
| 54 | 54 | expect(named).toBe('main is red at abcdef0 (failing: "a ]0;pwned b").'); |
| 55 | 55 | expect(/[\u0000-\u001f\u007f-\u009f]/.test(summary + named)).toBe(false); |
| 56 | 56 | }); |
| 57 | ||
| 58 | test("mainLineFor: queued waits on main, failed names the red, anything else says nothing", () => { | |
| 59 | const r = () => red(); | |
| 60 | expect(mainLineFor(r, { state: "queued", run: null }, "main")).toEqual({ says: "waiting on main: main is red at abcdef0.", waiting: true }); | |
| 61 | expect(mainLineFor(r, { state: "queued", run: null }, "dev").says).toBe(""); | |
| 62 | expect(mainLineFor(() => undefined, { state: "queued", run: null }, "main").says).toBe(""); | |
| 63 | const f = mainLineFor(r, { state: "failed", run: failed(["x"]) }, "main"); | |
| 64 | expect(f.waiting).toBe(false); | |
| 65 | expect(f.says).toContain("main is red at abcdef0"); | |
| 66 | const never = () => { throw new Error("main read for a healthy pull"); }; | |
| 67 | expect(mainLineFor(never, { state: "ok", run: null }, "main")).toEqual({ says: "", waiting: false }); | |
| 68 | }); |
test/tui-pull-red-main.test.ts +14
| @@ -121,3 +121,17 @@ test("main green again: no red-main words on the screen", async () => { | ||
| 121 | 121 | check(`pull-${pull.number}`, pull.headOid, "failed", ["sizes hold"], pull.id); |
| 122 | 122 | expect(await screen()).not.toContain("main is red"); |
| 123 | 123 | }, 30_000); |
| 124 | ||
| 125 | test("a queued check while main is red: the screen says waiting on main; green main, none", async () => { | |
| 126 | check("main", "c".repeat(40), "failed", ["sizes hold"]); | |
| 127 | createRun(app.db, { repoId: repo.id, kind: "check", env: `pull-${pull.number}`, commitOid: pull.headOid, reason: "push", issueId: pull.id }); | |
| 128 | expect(await screen()).toContain("waiting on main: main is red at ccccccc."); | |
| 129 | check("main", "d".repeat(40), "ok", []); | |
| 130 | expect(await screen()).not.toContain("waiting on main"); | |
| 131 | }, 30_000); | |
| 132 | ||
| 133 | test("a finished check shows no waiting line while main is red", async () => { | |
| 134 | check("main", "e".repeat(40), "failed", ["sizes hold"]); | |
| 135 | check(`pull-${pull.number}`, pull.headOid, "ok", [], pull.id); | |
| 136 | expect(await screen()).not.toContain("waiting on main"); | |
| 137 | }, 30_000); |
new above
offline
The title cites #14027, but this is pull #14029. Cite the issue the pull closes, or drop the number.