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

Merged opened this

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

Merged

scout/forge:scout/14027-a-pull-whose-check-is-queued-behind-a-re → main 6 commits fork 3 threads · 3 unresolved

  • Merged. scout/14027-a-pull-whose-check-is-queued-behind-a-re was merged into main as bfd0ad5.

Review

Sign in to review this change.
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).
2626 - [One step deeper from a post](feed-depth.md)
2727 - [A fork's page finds its place in the tree](fork-tree-here.md)
2828 - [Open pulls red for over a day are named in one issue](red-pulls.md)
29 - [A pull whose check is queued behind a red main says "waiting on main"](pull-waiting-on-main.md)
2930 - [Empty lists](empty-words.md)
3031 - [An app with no description says its README](readme-description.md)
3132 - [Arcade carts](arcade-carts.md)
docs/features/pull-waiting-on-main.md added +18
@@ -0,0 +1,18 @@
1 # A queued pull says "waiting on main"
outdated

The title cites #14027, but this is pull #14029. Cite the issue the pull closes, or drop the number.

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(
4949 if (manifestError(red) !== undefined) return `${head}: its forge.json is invalid, so no check can run.`;
5050 return `${head} (${whatFails(red)})${redOnMain(red, run) ? ": red on main, not on this pull." : "."}`;
5151 }
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 @@
2929 import { teamHoldRefusal, waitingOnTeams } from "../../core/teams_words.ts";
3030 import { crewFilters, guardedRefusal, isStrangerPull, strangerGuard, strangerNext } from "../../crew/stranger.ts";
3131 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";
3333 import { RED_ALONE_WAIT, redAloneAt, redMark } from "../../checks/queue.ts";
3434 import {
3535 addCommentThrough,
@@ -463,9 +463,9 @@ export function pullScreen(
463463 ? undefined
464464 : redMark(repo.id, row.id, row.headOid || (facts?.headOid ?? ""));
465465 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.

467467 ? ""
468 : redMainLine(redMain(f.db, repo.id), check.run, row.baseBranch);
468 : mainLineFor(() => redMain(f.db, repo.id), check, row.baseBranch).says;
469469 const alone = mark === undefined ? "" : `red alone at ${redAloneAt(mark)}, ${RED_ALONE_WAIT}`;
470470 redWords = [mainRed, alone].filter((w) => w !== "").join(" · ");
471471 checkSteps =
src/web/pages/pull.ts +7 −5
@@ -53,7 +53,7 @@ import {
5353 import { isProposed, pullMayRun } from "../../core/pull_trust.ts";
5454 import { checkWords } from "../../checks/summary.ts";
5555 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";
5757 import { runningProgress } from "../../checks/progress.ts";
5858 import { CHECK_STALE_REFUSAL, checkStale, checksHold } from "../../checks/stale.ts";
5959 import { checkSummary, type CheckSummary } from "../../core/runs.ts";
@@ -511,10 +511,12 @@ function pullChecksLine(
511511 );
512512 const found = !isApp ? null : pullPreviewFindings(ctx.app.db, repo.id, previewEnv(pull.number));
513513 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 x icon on line below marks a failure, but a queued pull has not failed.

517 main.says === ""
518 ? html``
519 : html`<p class="muted small">${main.waiting ? "" : icon("x")}${main.says}</p>`;
518520 return html`${originCheckLine(ctx, repo, pull)}${header}${line}${red}${found === null ? "" : specFindings(found)}`;
519521 }
520522
test/pull-page-red-main.test.ts +18
@@ -96,3 +96,21 @@ test("green main again: no line on a failed pull", async () => {
9696 check(`pull-${number}`, headOid, "failed", ["sizes hold"], pullId);
9797 expect(await page()).not.toContain("main is red");
9898 });
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 @@
11 import { expect, test } from "bun:test";
22 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";
44
55 const red = (over: Partial<RedMain> = {}): RedMain => ({
66 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",
5454 expect(named).toBe('main is red at abcdef0 (failing: "a ]0;pwned b").');
5555 expect(/[\u0000-\u001f\u007f-\u009f]/.test(summary + named)).toBe(false);
5656 });
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 () => {
121121 check(`pull-${pull.number}`, pull.headOid, "failed", ["sizes hold"], pull.id);
122122 expect(await screen()).not.toContain("main is red");
123123 }, 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);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs