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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14504-the-maintenance-board-names-the-one-stal → main 11 commits fork 2 threads · 2 unresolved
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 | } | |
| 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"; | ||
| 12 | 12 | import { LEVEL_WORDS, nextLevel, returnLevel, stateLevel, type Level } from "../../maintenance/level.ts"; |
| 13 | 13 | import { dutyStates } from "../../maintain/pause.ts"; |
| 14 | 14 | 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"; | |
| 15 | 17 | import { ABOUT_TO_STOP_ROWS, prepare, resumeNow, status } from "../../maintenance/service.ts"; |
| 16 | 18 | import { probeStandby, withStandby, type Standby } from "../../maintenance/standby.ts"; |
| 17 | 19 | import type { Ctx, Screen } from "../app/app.ts"; |
| @@ -54,20 +56,23 @@ export function maintenanceLines(f: Session, standby?: Standby, level?: Level): | ||
| 54 | 56 | const quietText = quiet.length === 0 ? [] : wrap(`${quietLine(quiet.length, loud.length === 0)}: ${quiet.map((d) => d.name).join(", ")}`, INNER); |
| 55 | 57 | const dutyText = (ds: typeof loud): string[] => ds.flatMap((d) => wrap(filedText(f.app.db, d, f.user), INNER)); |
| 56 | 58 | 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), ""]; | |
| 57 | 62 | const findings = findingLines(f.app.db).flatMap((l) => wrap(l, INNER)); |
| 58 | 63 | // Findings quieted (#14557): numbered, so `b` can bring one back; when each is back. |
| 59 | 64 | const hidden = quieted(f.app.db).flatMap((q, i) => wrap(`${String(i + 1)}. quieted until ${when(q.until)}: ${q.label}`, INNER)); |
| 60 | 65 | const hiddenText = hidden.length === 0 ? [] : ["", ...hidden]; |
| 61 | 66 | // A paused duty waits on a person to resume it, as on the page. |
| 62 | 67 | 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]; | |
| 64 | 69 | // The same split as the page, by the same rule (maintenance/level.ts): what waits on a person, |
| 65 | 70 | // and what is only to read. |
| 66 | 71 | const needs = stateLevel(s.phase) === "needs-you" || returnLevel(last?.healthy) === "needs-you"; |
| 67 | 72 | const overdue = loud.filter((d) => d.overdue); |
| 68 | 73 | const out = |
| 69 | 74 | level === "needs-you" |
| 70 | ? [...(needs ? [...lead, "", ...facts, ...checks, ""] : []), ...dutyText(overdue), ...paused] | |
| 75 | ? [...stalled, ...(needs ? [...lead, "", ...facts, ...checks, ""] : []), ...dutyText(overdue), ...paused] | |
| 71 | 76 | : [...(needs ? [] : [...lead, "", ...facts, ...checks, ""]), ...dutyText(loud.filter((d) => !d.overdue)), ...quietText, ...findings, ...hiddenText]; |
| 72 | 77 | return out.length === 0 ? [level === "needs-you" ? "Nothing here needs you." : "Nothing here to read."] : out; |
| 73 | 78 | } |
| @@ -175,6 +180,16 @@ export function maintenanceScreen(f: Session, ctx: Ctx): Screen { | ||
| 175 | 180 | learnLive(); |
| 176 | 181 | }; |
| 177 | 182 | |
| 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 | ||
| 178 | 193 | const screen: Screen = { |
| 179 | 194 | title: "Maintenance", |
| 180 | 195 | get keys() { |
| @@ -186,6 +201,7 @@ export function maintenanceScreen(f: Session, ctx: Ctx): Screen { | ||
| 186 | 201 | : idle |
| 187 | 202 | ? [binding(["p"], "prepare for maintenance")] |
| 188 | 203 | : [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?")]), | |
| 189 | 205 | ...(!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")] : [])]), |
| 190 | 206 | binding(["enter", "esc", "q"], "close"), |
| 191 | 207 | ]; |
| @@ -214,6 +230,7 @@ export function maintenanceScreen(f: Session, ctx: Ctx): Screen { | ||
| 214 | 230 | level = nextLevel(level); |
| 215 | 231 | ctx.invalidate(); |
| 216 | 232 | } else if (!mayAct() || busy) return true; |
| 233 | else if (e.key === "a") doAsk(); | |
| 217 | 234 | else if (e.key === "p" && idle) ctx.push(askPrepare()); |
| 218 | 235 | else if (e.key === "c" && !idle) doPrepare(""); |
| 219 | 236 | 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"; | ||
| 12 | 12 | import { LEVELS, LEVEL_WORDS, dutiesLevel, levelOf, returnLevel, stateLevel, type Level } from "../../maintenance/level.ts"; |
| 13 | 13 | import { findingRows, findingsJson, seenWords } from "../../maintenance/findings.ts"; |
| 14 | 14 | import { NOTHING_FILED, filedPieces } from "../../maintenance/filed.ts"; |
| 15 | import { stalledStep } from "../../maintenance/stalled.ts"; | |
| 15 | 16 | import { statusWithStandby } from "../../maintenance/standby.ts"; |
| 16 | 17 | import { ABOUT_TO_STOP_ROWS, prepare, resumeNow, status } from "../../maintenance/service.ts"; |
| 17 | 18 | import type { Ctx } from "../../http/context.ts"; |
| @@ -77,6 +78,15 @@ export function needsYou(o: { phase: string; healthy?: boolean; overdue: number; | ||
| 77 | 78 | return out; |
| 78 | 79 | } |
| 79 | 80 | |
| 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 |
||
| 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 | ||
| 80 | 90 | /** |
| 81 | 91 | * GET /maintenance.json: the findings the board lists, for an agent; the same admin rule as the |
| 82 | 92 | * page. |
| @@ -203,6 +213,7 @@ async function maintenanceAnswer(ctx: Ctx): Promise<Response> { | ||
| 203 | 213 | const calm = asked === "fyi"; |
| 204 | 214 | const body = html`<div class="page-head"><h1>Maintenance</h1></div> |
| 205 | 215 | ${calm ? null : statusLine} |
| 216 | ${calm ? null : stalledCard(stalledStep(stalePending), ctx.auth.user!.kind !== "agent")} | |
| 206 | 217 | ${idle || calm ? null : html`<p id="maintenance-says" class="muted">${s.says}</p> |
| 207 | 218 | <div class="form-actions mb"><form method="post" action="/maintenance/resume">${btn("End maintenance now")}</form></div>`} |
| 208 | 219 | ${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"; | ||
| 7 | 7 | import { getIssueById, listComments } from "../src/core/issues.ts"; |
| 8 | 8 | import { createRepo, type Repo } from "../src/core/repos.ts"; |
| 9 | 9 | import { createUser, type User } from "../src/core/users.ts"; |
| 10 | import { id } from "../src/kernel/id.ts"; | |
| 11 | 10 | import { serve, type Servers } from "../src/http/server.ts"; |
| 12 | 11 | import { Session } from "../src/tui/session.ts"; |
| 13 | 12 | import { actOnStale, staleLines } from "../src/tui/screens/stalepulls.ts"; |
| 13 | import { stalePull as seedPull } from "./helpers/stale-pull.ts"; | |
| 14 | 14 | import { quietLogs } from "./helpers/globals.ts"; |
| 15 | 15 | |
| 16 | 16 | 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; | |
| 18 | 18 | let adminCookie = "", personCookie = ""; |
| 19 | 19 | |
| 20 | 20 | async function user(name: string, isAdmin: boolean): Promise<User> { |
| @@ -31,15 +31,7 @@ async function login(username: string): Promise<string> { | ||
| 31 | 31 | }); |
| 32 | 32 | return (res.headers.get("set-cookie") ?? "").split(";")[0] ?? ""; |
| 33 | 33 | } |
| 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>"); | |
| 43 | 35 | const post = (path: string, cookie: string, origin = servers.url): Promise<Response> => |
| 44 | 36 | fetch(`${servers.url}${path}`, { method: "POST", redirect: "manual", headers: { "content-type": "application/x-www-form-urlencoded", origin, cookie }, body: "" }); |
| 45 | 37 |
test/maintenance-level.test.ts +4 −1
| @@ -109,7 +109,10 @@ test("the terminal's level filter narrows the same way", async () => { | ||
| 109 | 109 | const all = maintenanceLines(f, undefined).join("\n"); |
| 110 | 110 | const needs = maintenanceLines(f, undefined, "needs-you").join("\n"); |
| 111 | 111 | 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: "); | |
| 113 | 116 | expect(nextLevel(undefined)).toBe("needs-you"); |
| 114 | 117 | expect(fyi.length).toBeGreaterThan(0); |
| 115 | 118 | 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"; | ||
| 9 | 9 | import { createApp, type App } from "../src/app.ts"; |
| 10 | 10 | import { createRepo } from "../src/core/repos.ts"; |
| 11 | 11 | import { createUser, type User } from "../src/core/users.ts"; |
| 12 | import { id } from "../src/kernel/id.ts"; | |
| 13 | 12 | 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"; | |
| 17 | 14 | 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"; | |
| 19 | 17 | |
| 20 | 18 | quietLogs(); |
| 21 | let dir = "", app: App, admin: User, person: User, seq = 0; | |
| 19 | let dir = "", app: App, admin: User, person: User; | |
| 22 | 20 | |
| 23 | 21 | const must = (r: { ok: boolean; value?: unknown }): User => { |
| 24 | 22 | if (!r.ok) throw new Error("user"); |
| 25 | 23 | return r.value as User; |
| 26 | 24 | }; |
| 27 | 25 | 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 }; | |
| 42 | 28 | } |
| 29 | const open = (user: User) => openMaintenance(app, user); | |
| 43 | 30 | |
| 44 | 31 | beforeAll(async () => { |
| 45 | 32 | 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 | }); |
new above
offline
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/.