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

The maintenance board names the one stalled step in the flow and the single action that unblocks it #14527

Merged opened this

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

Merged

scout/forge:scout/14504-the-maintenance-board-names-the-one-stal → main 11 commits fork 2 threads · 2 unresolved

  • Merged. scout/14504-the-maintenance-board-names-the-one-stal was merged into main as 26a3105.

Review

Sign in to review this change.
11 files changed +293 −34
docs/features/maintenance-stalled.md added +18
@@ -0,0 +1,18 @@
1 ---
2 topic: Your apps
3 row: The one stalled step on the maintenance board, and the button that unblocks it
4 ---
5
6 # The stalled step
7
8 `/maintenance` names the one pull that has been quiet longest past the 14-day window, how long it has been untouched, and one button, "Ask if still wanted". It says only what is known: the pull is open and has had no push, comment or review. When more pulls are quiet it counts them. A pull whose finding was quieted for the day is left out, as on the rest of the board.
9
10 ## On the page
11
12 Sign in as a forge admin and open `/maintenance`. The "Stalled" row sits under the status line; press the button to post the nudge comment on that pull. The button is not shown to agent accounts, and the POST goes through the same same-origin-checked route as the pulls list (`/maintenance/stale/<id>/nudge`).
13
14 ## In the terminal
15
16 Open Maintenance from the palette (admins who are people). The first line reads `Stalled: <repo>#N untouched for N days`; press `a` to ask. The line and the key are not offered to anyone else, and the "For information" view (`l`) leaves them out. The same list is on its own screen under "Pulls untouched for 14 days".
17
18 The finder is `src/maintenance/stalled.ts` (`stalledStep`, `stalledNow`); the action is `nudge` in `src/maintain/stale_pulls.ts`, shared by both doors.
src/maintenance/stalled.ts added +49
@@ -0,0 +1,49 @@
1 /**
2 * The one stalled step of the flow, for the top of /maintenance (#14504). The step is a pull that
3 * is open and untouched past the stale window (what is known; not whether anyone reviews it). Only
4 * one card, by design: the oldest wait, with a count of the others. Plain data in (the stale pulls,
5 * oldest first), plain data out.
6 */
7
8 import { plural } from "../kernel/plural.ts";
9 import type { Database } from "bun:sqlite";
10 import { stalePulls, type StalePull } from "../maintain/stale_pulls.ts";
11 import { quieted, quietKeys } from "./quiet.ts";
12
13 export interface Stalled {
14 /** The pull, as `repo#N`. */
15 readonly step: string;
16 /** What is known of it, in plain words: it is open and has had no activity for this long. */
17 readonly says: string;
18 readonly ageDays: number;
19 readonly id: string;
20 /** The one thing that unblocks it: a POST to this path. */
21 readonly action: string;
22 readonly label: string;
23 /** How many other pulls wait as well. */
24 readonly others: number;
25 }
outdated

Plain words: '<repo>#N waits for review' asserts a state the data does not know; the pull is only open and quiet past the window. Say 'is quiet' / 'has had no activity', matching what the finder measures. Also add the terminal's rendering of this same step by reusing stalledStep from src/tui/.

26
27 /** The oldest waiting pull as the stalled step; undefined when nothing stalls. */
28 export function stalledStep(pulls: readonly StalePull[]): Stalled | undefined {
29 const oldest = [...pulls].sort((a, b) => a.lastTouched.localeCompare(b.lastTouched) || a.id.localeCompare(b.id))[0];
30 if (oldest === undefined) return undefined;
31 return {
32 step: `${oldest.repo}#${String(oldest.number)}`,
33 says: `untouched for ${plural(oldest.ageDays, "day")}${pulls.length > 1 ? `; ${plural(pulls.length - 1, "other pull is", "other pulls are")} quiet too` : ""}`,
34 ageDays: oldest.ageDays,
35 id: oldest.id,
36 action: `/maintenance/stale/${oldest.id}/nudge`,
37 label: "Ask if still wanted",
38 others: pulls.length - 1,
39 };
40 }
41
42 /**
43 * The stalled step as the board stands now, a finding quieted for the day left out; the page's
44 * rule.
45 */
46 export function stalledNow(db: Database, now: Date): Stalled | undefined {
47 const hidden = quietKeys(quieted(db), "stale-pulls");
48 return stalledStep(stalePulls(db, now).filter((p) => !hidden.has(p.id)));
49 }
src/tui/screens/maintenance.ts +19 −2
@@ -12,6 +12,8 @@ import { findingLines } from "../../maintenance/findings.ts";
1212 import { LEVEL_WORDS, nextLevel, returnLevel, stateLevel, type Level } from "../../maintenance/level.ts";
1313 import { dutyStates } from "../../maintain/pause.ts";
1414 import { duties, quietLine, splitDuties } from "../../maintenance/duties.ts";
15 import { stalledNow } from "../../maintenance/stalled.ts";
16 import { STALE_WORDS, nudge } from "../../maintain/stale_pulls.ts";
1517 import { ABOUT_TO_STOP_ROWS, prepare, resumeNow, status } from "../../maintenance/service.ts";
1618 import { probeStandby, withStandby, type Standby } from "../../maintenance/standby.ts";
1719 import type { Ctx, Screen } from "../app/app.ts";
@@ -54,20 +56,23 @@ export function maintenanceLines(f: Session, standby?: Standby, level?: Level):
5456 const quietText = quiet.length === 0 ? [] : wrap(`${quietLine(quiet.length, loud.length === 0)}: ${quiet.map((d) => d.name).join(", ")}`, INNER);
5557 const dutyText = (ds: typeof loud): string[] => ds.flatMap((d) => wrap(filedText(f.app.db, d, f.user), INNER));
5658 const lead = wrap(s.says, INNER);
59 // The one stalled step, as on the page; it waits on a person, so the calm view leaves it out.
60 const step = stalledNow(f.db, new Date());
61 const stalled = step === undefined || level === "fyi" || f.user?.isAdmin !== true || f.user.kind === "agent" ? [] : [...wrap(`Stalled: ${step.step} ${step.says} (a asks if still wanted)`, INNER), ""];
5762 const findings = findingLines(f.app.db).flatMap((l) => wrap(l, INNER));
5863 // Findings quieted (#14557): numbered, so `b` can bring one back; when each is back.
5964 const hidden = quieted(f.app.db).flatMap((q, i) => wrap(`${String(i + 1)}. quieted until ${when(q.until)}: ${q.label}`, INNER));
6065 const hiddenText = hidden.length === 0 ? [] : ["", ...hidden];
6166 // A paused duty waits on a person to resume it, as on the page.
6267 const paused = dutyStates(f.app.db).filter((d) => d.paused).flatMap((d) => wrap(d.says, INNER));
63 if (level === undefined) return [...lead, "", ...facts, ...checks, "", ...dutyText(loud), ...paused, ...quietText, ...findings, ...hiddenText];
68 if (level === undefined) return [...stalled, ...lead, "", ...facts, ...checks, "", ...dutyText(loud), ...paused, ...quietText, ...findings, ...hiddenText];
6469 // The same split as the page, by the same rule (maintenance/level.ts): what waits on a person,
6570 // and what is only to read.
6671 const needs = stateLevel(s.phase) === "needs-you" || returnLevel(last?.healthy) === "needs-you";
6772 const overdue = loud.filter((d) => d.overdue);
6873 const out =
6974 level === "needs-you"
70 ? [...(needs ? [...lead, "", ...facts, ...checks, ""] : []), ...dutyText(overdue), ...paused]
75 ? [...stalled, ...(needs ? [...lead, "", ...facts, ...checks, ""] : []), ...dutyText(overdue), ...paused]
7176 : [...(needs ? [] : [...lead, "", ...facts, ...checks, ""]), ...dutyText(loud.filter((d) => !d.overdue)), ...quietText, ...findings, ...hiddenText];
7277 return out.length === 0 ? [level === "needs-you" ? "Nothing here needs you." : "Nothing here to read."] : out;
7378 }
@@ -175,6 +180,16 @@ export function maintenanceScreen(f: Session, ctx: Ctx): Screen {
175180 learnLive();
176181 };
177182
183 /**
184 * Ask the stalled pull whether it is still wanted: the page's button, through the same `nudge`.
185 */
186 const doAsk = (): void => {
187 const step = stalledNow(f.db, new Date());
188 if (step === undefined) return say("Nothing is stalled.");
189 const r = nudge(f.app, f.user, step.id);
190 say(r.ok ? r.value.says : STALE_WORDS[r.error]);
191 };
192
178193 const screen: Screen = {
179194 title: "Maintenance",
180195 get keys() {
@@ -186,6 +201,7 @@ export function maintenanceScreen(f: Session, ctx: Ctx): Screen {
186201 : idle
187202 ? [binding(["p"], "prepare for maintenance")]
188203 : [binding(["c"], "check again, retake the backup"), binding(["e"], "end maintenance")]),
204 ...(!mayAct() || busy || stalledNow(f.db, new Date()) === undefined ? [] : [binding(["a"], "ask the stalled pull: still wanted?")]),
189205 ...(!mayAct() || busy ? [] : [...(live.length > 0 ? [binding(["z"], "quiet a finding for a day")] : []), ...(quieted(f.app.db).length > 0 ? [binding(["b"], "bring a quieted finding back")] : [])]),
190206 binding(["enter", "esc", "q"], "close"),
191207 ];
@@ -214,6 +230,7 @@ export function maintenanceScreen(f: Session, ctx: Ctx): Screen {
214230 level = nextLevel(level);
215231 ctx.invalidate();
216232 } else if (!mayAct() || busy) return true;
233 else if (e.key === "a") doAsk();
217234 else if (e.key === "p" && idle) ctx.push(askPrepare());
218235 else if (e.key === "c" && !idle) doPrepare("");
219236 else if (e.key === "e" && !idle) ctx.push(askEnd());
src/web/pages/maintenance.ts +11
@@ -12,6 +12,7 @@ import { duties, quietLine, splitDuties } from "../../maintenance/duties.ts";
1212 import { LEVELS, LEVEL_WORDS, dutiesLevel, levelOf, returnLevel, stateLevel, type Level } from "../../maintenance/level.ts";
1313 import { findingRows, findingsJson, seenWords } from "../../maintenance/findings.ts";
1414 import { NOTHING_FILED, filedPieces } from "../../maintenance/filed.ts";
15 import { stalledStep } from "../../maintenance/stalled.ts";
1516 import { statusWithStandby } from "../../maintenance/standby.ts";
1617 import { ABOUT_TO_STOP_ROWS, prepare, resumeNow, status } from "../../maintenance/service.ts";
1718 import type { Ctx } from "../../http/context.ts";
@@ -77,6 +78,15 @@ export function needsYou(o: { phase: string; healthy?: boolean; overdue: number;
7778 return out;
7879 }
7980
81 /** The one stalled step as a row of the board: the pull, how long it was quiet, the one button. */
82 function stalledCard(s: ReturnType<typeof stalledStep>, withAction: boolean): Html | null {
83 if (s === undefined) return null;
84 return html`<dl id="maintenance-stalled" class="status-rows mb" data-stalled="${s.id}">${fact(
85 "Stalled",
outdated

Principles 7 and 8 (rows over boxes; plain words): this is a hand-rolled section with an inline icon, strong and muted span, not a named component or a row from docs/DESIGN.md. Use the existing row/finding pattern the board already renders. Also ${String(s.ageDays)} days reads '1 days' for one day: use plural(). Say 'untouched for N days' so the age is the fact.

86 html`${s.step} ${s.says}${withAction ? html` <form method="post" action="${s.action}" class="inline">${btn(s.label, { variant: "outline" })}</form>` : null}`,
87 )}</dl>`;
88 }
89
8090 /**
8191 * GET /maintenance.json: the findings the board lists, for an agent; the same admin rule as the
8292 * page.
@@ -203,6 +213,7 @@ async function maintenanceAnswer(ctx: Ctx): Promise<Response> {
203213 const calm = asked === "fyi";
204214 const body = html`<div class="page-head"><h1>Maintenance</h1></div>
205215 ${calm ? null : statusLine}
216 ${calm ? null : stalledCard(stalledStep(stalePending), ctx.auth.user!.kind !== "agent")}
206217 ${idle || calm ? null : html`<p id="maintenance-says" class="muted">${s.says}</p>
207218 <div class="form-actions mb"><form method="post" action="/maintenance/resume">${btn("End maintenance now")}</form></div>`}
208219 ${strip}
test/helpers/stale-pull.ts added +15
@@ -0,0 +1,15 @@
1 import type { App } from "../../src/app.ts";
2 import type { User } from "../../src/core/users.ts";
3 import { id } from "../../src/kernel/id.ts";
4
5 let seq = 0;
6
7 /** An open pull in `repoId`, quiet for `days` days (30 by default), opened by `author`; its id. */
8 export function stalePull(app: App, repoId: string, author: User, days = 30, title = "Quiet"): string {
9 const issue = id();
10 const n = ++seq;
11 const at = new Date(Date.now() - days * 86_400_000).toISOString();
12 app.db.query("INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state, created_at, updated_at) VALUES (?1, ?2, ?3, 'pull', ?4, '', ?5, 'open', ?6, ?6)").run(issue, repoId, n, `${title} ${n}`, author.id, at);
13 app.db.query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id) VALUES (?1, 'main', ?2, ?3, ?3, ?4)").run(issue, `b/${n}`, "0".repeat(40), repoId);
14 return issue;
15 }
test/helpers/tui-maintenance.ts added +19
@@ -0,0 +1,19 @@
1 import type { App } from "../../src/app.ts";
2 import type { User } from "../../src/core/users.ts";
3 import { createForgeApp } from "../../src/tui/forge.ts";
4 import { maintenanceScreen } from "../../src/tui/screens/maintenance.ts";
5 import { headlessTerminal } from "../../src/tui/term/terminal.ts";
6 import { settleApp, settleUntil } from "./tui.ts";
7
8 /**
9 * The terminal's maintenance screen open for `user`: its session, its text, and a way to press
10 * keys.
11 */
12 export async function openMaintenance(app: App, user: User) {
13 const terminal = headlessTerminal(120, 40);
14 const { app: tui, session } = createForgeApp(app, { sshUsername: user.username, remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user }, { terminal, exitHooks: false });
15 tui.start();
16 tui.ctx.push(maintenanceScreen(session, tui.ctx));
17 await settleUntil(tui, "Maintenance");
18 return { tui, terminal, session, text: () => tui.screen.toText(), press: async (keys: string) => { terminal.feed(keys); await settleApp(tui); } };
19 }
test/maintain-stale-web.test.ts +3 −11
@@ -7,14 +7,14 @@ import { createApp, type App } from "../src/app.ts";
77 import { getIssueById, listComments } from "../src/core/issues.ts";
88 import { createRepo, type Repo } from "../src/core/repos.ts";
99 import { createUser, type User } from "../src/core/users.ts";
10 import { id } from "../src/kernel/id.ts";
1110 import { serve, type Servers } from "../src/http/server.ts";
1211 import { Session } from "../src/tui/session.ts";
1312 import { actOnStale, staleLines } from "../src/tui/screens/stalepulls.ts";
13 import { stalePull as seedPull } from "./helpers/stale-pull.ts";
1414 import { quietLogs } from "./helpers/globals.ts";
1515
1616 quietLogs();
17 let dir = "", app: App, servers: Servers, admin: User, person: User, repo: Repo, seq = 0;
17 let dir = "", app: App, servers: Servers, admin: User, person: User, repo: Repo;
1818 let adminCookie = "", personCookie = "";
1919
2020 async function user(name: string, isAdmin: boolean): Promise<User> {
@@ -31,15 +31,7 @@ async function login(username: string): Promise<string> {
3131 });
3232 return (res.headers.get("set-cookie") ?? "").split(";")[0] ?? "";
3333 }
34 /** An open pull, quiet for 30 days, opened by `author`. */
35 function stalePull(author: User): string {
36 const issue = id();
37 const n = ++seq;
38 const at = new Date(Date.now() - 30 * 86_400_000).toISOString();
39 app.db.query("INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state, created_at, updated_at) VALUES (?1, ?2, ?3, 'pull', ?4, '', ?5, 'open', ?6, ?6)").run(issue, repo.id, n, `Quiet <b>${n}</b>`, author.id, at);
40 app.db.query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id) VALUES (?1, 'main', ?2, ?3, ?3, ?4)").run(issue, `b/${n}`, "0".repeat(40), repo.id);
41 return issue;
42 }
34 const stalePull = (author: User): string => seedPull(app, repo.id, author, 30, "Quiet <b>");
4335 const post = (path: string, cookie: string, origin = servers.url): Promise<Response> =>
4436 fetch(`${servers.url}${path}`, { method: "POST", redirect: "manual", headers: { "content-type": "application/x-www-form-urlencoded", origin, cookie }, body: "" });
4537
test/maintenance-level.test.ts +4 −1
@@ -109,7 +109,10 @@ test("the terminal's level filter narrows the same way", async () => {
109109 const all = maintenanceLines(f, undefined).join("\n");
110110 const needs = maintenanceLines(f, undefined, "needs-you").join("\n");
111111 const fyi = maintenanceLines(f, undefined, "fyi").join("\n");
112 expect(needs).toBe("Nothing here needs you.");
112 // The fixture holds a stale pull, which waits on a person: the stalled step is the one thing
113 // here.
114 expect(needs).toContain("Stalled: ");
115 expect(fyi).not.toContain("Stalled: ");
113116 expect(nextLevel(undefined)).toBe("needs-you");
114117 expect(fyi.length).toBeGreaterThan(0);
115118 expect(fyi).not.toBe("Nothing here needs you.");
test/maintenance-stalled.test.ts added +79
@@ -0,0 +1,79 @@
1 /**
2 * The stalled card on /maintenance (#14504): the oldest waiting pull, its age, one button; none
3 * when nothing stalls.
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { createRepo, type Repo } from "../src/core/repos.ts";
11 import { createUser, type User } from "../src/core/users.ts";
12 import { stalledStep } from "../src/maintenance/stalled.ts";
13 import type { StalePull } from "../src/maintain/stale_pulls.ts";
14 import { serve, type Servers } from "../src/http/server.ts";
15 import { quietLogs } from "./helpers/globals.ts";
16 import { adminCookie as signedIn, seedAdmin } from "./helpers/admin.ts";
17 import { stalePull as seedPull } from "./helpers/stale-pull.ts";
18
19 quietLogs();
20 let dir = "", app: App, servers: Servers, admin: User, person: User, repo: Repo;
21 let adminCookie = "";
22
23 const stalePull = (author: User): string => seedPull(app, repo.id, author);
24 const post = (path: string, cookie: string, origin = servers.url): Promise<Response> =>
25 fetch(`${servers.url}${path}`, { method: "POST", redirect: "manual", headers: { "content-type": "application/x-www-form-urlencoded", origin, cookie }, body: "" });
26
27 beforeAll(async () => {
28 dir = await mkdtemp(join(tmpdir(), "forge-stalled-"));
29 app = createApp({ dataDir: dir, port: 0 });
30 servers = await serve(app);
31 const boss = await seedAdmin(app, { username: "boss", email: "[email protected]" });
32 if (!boss.ok) throw new Error("admin");
33 admin = boss.value;
34 const pat = await createUser(app.db, { username: "pat", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true });
35 if (!pat.ok) throw new Error("person");
36 person = pat.value;
37 const made = await createRepo(app.db, app.reposRoot, { ownerId: admin.id, name: "r", visibility: "public", description: "r" });
38 if (!made.ok) throw new Error("repo");
39 repo = made.value;
40 adminCookie = await signedIn(app, { username: "chief", email: "[email protected]" });
41 });
42 afterAll(async () => {
43 servers.stop();
44 app.close();
45 await rm(dir, { recursive: true, force: true });
46 });
47 const read = async (): Promise<string> => await (await fetch(`${servers.url}/maintenance`, { headers: { cookie: adminCookie } })).text();
48
49 test("no card when nothing stalls", async () => {
50 expect(await read()).not.toContain("maintenance-stalled");
51 });
52
53 test("one card: the oldest step, its age, one POST button with a same-origin check and a receipt; the rest counted", async () => {
54 stalePull(person);
55 stalePull(person);
56 const page = await read();
57 expect(page.match(/id="maintenance-stalled"/g)?.length).toBe(1);
58 const card = page.slice(page.indexOf('id="maintenance-stalled"'), page.indexOf("</dl>", page.indexOf('id="maintenance-stalled"')));
59 expect(card).not.toContain("waits for review");
60 expect(card).toContain("untouched for 30 days");
61 expect(card).toContain("1 other pull is quiet too");
62 expect(card.match(/<form /g)?.length).toBe(1);
63 expect(card).toContain('method="post"');
64 const shown = /data-stalled="([^"]+)"/.exec(card)![1]!;
65 expect(card).toContain(`action="/maintenance/stale/${shown}/nudge"`);
66 const cross = await post(`/maintenance/stale/${shown}/nudge`, adminCookie, "https://evil.example");
67 expect(cross.status).toBeGreaterThanOrEqual(400);
68 const done = await post(`/maintenance/stale/${shown}/nudge`, adminCookie);
69 expect(done.status).toBe(303);
70 const rows = app.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM maintenance_run WHERE duty = 'stale-pulls'").get();
71 expect(rows?.n).toBeGreaterThan(0);
72 });
73
74 test("the age reads one day, not 1 days, and says only what is known", () => {
75 const p: StalePull = { id: "x", repo: "r", number: 3, title: "t", ageDays: 1, lastTouched: "2026-01-01T00:00:00Z", byAgent: false };
76 const s = stalledStep([p])!;
77 expect(s.says).toBe("untouched for 1 day");
78 expect(s.step).toBe("r#3");
79 });
test/tui-maintenance-quiet.test.ts +7 −20
@@ -9,37 +9,24 @@ import { join } from "node:path";
99 import { createApp, type App } from "../src/app.ts";
1010 import { createRepo } from "../src/core/repos.ts";
1111 import { createUser, type User } from "../src/core/users.ts";
12 import { id } from "../src/kernel/id.ts";
1312 import { quieted } from "../src/maintenance/quiet.ts";
14 import { createForgeApp } from "../src/tui/forge.ts";
15 import { maintenanceScreen } from "../src/tui/screens/maintenance.ts";
16 import { headlessTerminal } from "../src/tui/term/terminal.ts";
13 import { openMaintenance } from "./helpers/tui-maintenance.ts";
1714 import { quietLogs } from "./helpers/globals.ts";
18 import { settleApp, settleUntil } from "./helpers/tui.ts";
15 import { settleUntil } from "./helpers/tui.ts";
16 import { stalePull as seedPull } from "./helpers/stale-pull.ts";
1917
2018 quietLogs();
21 let dir = "", app: App, admin: User, person: User, seq = 0;
19 let dir = "", app: App, admin: User, person: User;
2220
2321 const must = (r: { ok: boolean; value?: unknown }): User => {
2422 if (!r.ok) throw new Error("user");
2523 return r.value as User;
2624 };
2725 function stalePull(repoId: string, author: User): { id: string; n: number } {
28 const issue = id();
29 const n = ++seq;
30 const at = new Date(Date.now() - 30 * 86_400_000).toISOString();
31 app.db.query("INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state, created_at, updated_at) VALUES (?1, ?2, ?3, 'pull', ?4, '', ?5, 'open', ?6, ?6)").run(issue, repoId, n, `Findable ${n}`, author.id, at);
32 app.db.query("INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id) VALUES (?1, 'main', ?2, ?3, ?3, ?4)").run(issue, `b/${n}`, "0".repeat(40), repoId);
33 return { id: issue, n };
34 }
35 async function open(user: User) {
36 const terminal = headlessTerminal(120, 40);
37 const { app: tui, session } = createForgeApp(app, { sshUsername: user.username, remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user }, { terminal, exitHooks: false });
38 tui.start();
39 tui.ctx.push(maintenanceScreen(session, tui.ctx));
40 await settleUntil(tui, "Maintenance");
41 return { tui, terminal, text: () => tui.screen.toText(), press: async (keys: string) => { terminal.feed(keys); await settleApp(tui); } };
26 const made = seedPull(app, repoId, author);
27 return { id: made, n: app.db.query<{ number: number }, [string]>("SELECT number FROM issue WHERE id = ?1").get(made)!.number };
4228 }
29 const open = (user: User) => openMaintenance(app, user);
4330
4431 beforeAll(async () => {
4532 dir = await mkdtemp(join(tmpdir(), "forge-tui-quiet-"));
test/tui-maintenance-stalled.test.ts added +69
@@ -0,0 +1,69 @@
1 /**
2 * The terminal's maintenance screen shows the stalled step and presses the same nudge (#14504),
3 * for an admin who is a person and no one else.
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { createRepo } from "../src/core/repos.ts";
11 import { createUser, type User } from "../src/core/users.ts";
12 import { maintenanceLines } from "../src/tui/screens/maintenance.ts";
13 import { seedAdmin } from "./helpers/admin.ts";
14 import { openMaintenance } from "./helpers/tui-maintenance.ts";
15 import { quietLogs } from "./helpers/globals.ts";
16 import { stalePull } from "./helpers/stale-pull.ts";
17
18 quietLogs();
19 let dir = "", app: App, admin: User, person: User, repoId = "";
20
21 const open = (user: User) => openMaintenance(app, user);
22
23 beforeAll(async () => {
24 dir = await mkdtemp(join(tmpdir(), "forge-tui-stalled-"));
25 app = createApp({ dataDir: dir, port: 0 });
26 const boss = await seedAdmin(app, { username: "boss", email: "[email protected]" });
27 if (!boss.ok) throw new Error("admin");
28 admin = boss.value;
29 const pat = await createUser(app.db, { username: "pat", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true });
30 if (!pat.ok) throw new Error("person");
31 person = pat.value;
32 const made = await createRepo(app.db, app.reposRoot, { ownerId: admin.id, name: "r", visibility: "public", description: "r" });
33 if (!made.ok) throw new Error("repo");
34 repoId = made.value.id;
35 });
36 afterAll(async () => {
37 app.close();
38 await rm(dir, { recursive: true, force: true });
39 });
40
41 test("no stalled line when nothing stalls", async () => {
42 const t = await open(admin);
43 expect(t.text()).not.toContain("Stalled:");
44 expect(t.text()).not.toContain("ask the stalled pull");
45 });
46
47 test("an admin sees the oldest quiet pull in words that claim no review, and presses the nudge", async () => {
48 stalePull(app, repoId, person, 20);
49 const oldest = stalePull(app, repoId, person, 30);
50 const t = await open(admin);
51 const text = t.text();
52 expect(text).toContain("Stalled: boss/r#");
53 expect(text).toContain("untouched for 30 days");
54 expect(text.replace(/[│\s]+/g, " ")).toContain("1 other pull is quiet too");
55 expect(text).not.toContain("waits for review");
56 expect(maintenanceLines(t.session, undefined, "fyi").join("\n")).not.toContain("Stalled:");
57 const before = app.db.query<{ n: number }, [string]>("SELECT COUNT(*) AS n FROM comment WHERE issue_id = ?1").get(oldest)?.n ?? 0;
58 await t.press("a");
59 const after = app.db.query<{ n: number }, [string]>("SELECT COUNT(*) AS n FROM comment WHERE issue_id = ?1").get(oldest)?.n ?? 0;
60 expect(after).toBe(before + 1);
61 });
62
63 test("an agent-kind or non-admin session sees no stalled line and its key does nothing", async () => {
64 const t = await open(person);
65 expect(t.text()).not.toContain("Stalled:");
66 const before = app.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM comment").get()?.n;
67 await t.press("a");
68 expect(app.db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM comment").get()?.n).toBe(before);
69 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs