Public: anyone can read this; the crew can change it.
Terminal: the /review queue — list, merge, close, request changes, reply, then the next item #5191
scout/forge:scout/5189-terminal-the-review-queue-list-merge-clo → main 4 commits fork 6 threads · 6 unresolved
README.md +12 −3
| @@ -448,10 +448,19 @@ thoughts, then the issues you can write to that are not shipped, oldest first | ||
| 448 | 448 | only, shows a guest nothing, and names nothing of a placement in a repository |
| 449 | 449 | you cannot read. |
| 450 | 450 | |
| 451 | The review queue: `Ctrl+K`, then **Review queue**, is `/review` in the terminal — the asks | |
| 452 | waiting on you from the same `waitingOn`, newest first. On the row under the cursor: | |
| 453 | `m` merges a pull, `x` closes it (or an issue), `v` opens the verdict card (approve, | |
| 454 | request changes, comment), `c` replies, `enter` gives the web address, `r` refreshes. | |
| 455 | Each is the pull and issue screens' own gated call (`mergePull`, `setIssueStateThrough`, | |
| 456 | `submitReview`, `addCommentThrough`); a refusal is a toast, and after an act the | |
| 457 | cursor rests on the next ask. `m` and `x` are irreversible and sit beside the | |
| 458 | movement keys, so each opens a confirm dialog that starts on Cancel (`l` then | |
| 459 | `enter` chooses the act); nothing lands on the keypress. On an ask with no thread | |
| 460 | (a proposed wave) `m`, `x` and `c` say so in a toast; `enter` opens it on the web. | |
| 461 | ||
| 451 | 462 | Review: `/review` lists the asks waiting on you, one row each (title, repository, |
| 452 | age, why, and the crew's advice or that it has not advised yet), newest first. A pull's row also carries the check verdict for its head (the pull page's badge: passed, failed, running, cancelled, or none) in the row's trail, and, when its repository is an app, an "Open the preview" link under it (shown for any app, even before a preview is deployed); and, when the pull has a look the viewer may fetch, its preview thumbnail beside production's under that (sized, lazy, never inside the row's link; the pull's is the only link, named for a screen reader, and production's is a named picture; a viewer who may not fetch it sees none); all of it comes from the database, never git. The row's trail also says the pull's size (`3 files changed, +40 −7`), kept per base and head commit (`src/web/studio/review_evidence.ts`); a request never waits on git: until the stat is kept the row says "Diff loading — reload for the size" while the app computes it in the background (at most 4 at once, stopped by closing the app), and a failed stat says "Diff size unavailable" and is not asked again for a minute, so a bad pull cannot spawn git on every visit. Visits while a stat is running share it. Each row also carries its actions under it, as plain form POSTs to `/review/act` (same-origin checked, `rw` scope): on a pull **Merge** (through the same landing gate as anywhere, so a red or unreviewed head is refused with the gate's sentence), **Close**, **Request changes** (with a text box) and **Reply** (with a text box); on an issue **Close** and **Reply**. After an action the page answers 303 to `/review#<the next ask>` (the first that followed it and still waits, else the first left, else `/review`), and the acted ask is gone; a refusal comes back to the same row with its reason. Keys: `j`/`k` move between rows, and on the focused row `m` merges, `c` closes and `r` jumps to the Request-changes box; keys are ignored while a text box has focus, and `?` lists them. `/asks` links to it, and signed out it sends you to sign-in. The terminal has no page of its | |
| 453 | own for it: the same asks are the dashboard's On you card (acting from the terminal is tracked in #5189). The terminal has no page of its | |
| 454 | own for it: the same asks are the dashboard's On you card. | |
| 463 | age, why, and the crew's advice or that it has not advised yet), newest first. A pull's row also carries the check verdict for its head (the pull page's badge: passed, failed, running, cancelled, or none) in the row's trail, and, when its repository is an app, an "Open the preview" link under it (shown for any app, even before a preview is deployed); and, when the pull has a look the viewer may fetch, its preview thumbnail beside production's under that (sized, lazy, never inside the row's link; the pull's is the only link, named for a screen reader, and production's is a named picture; a viewer who may not fetch it sees none); all of it comes from the database, never git. The row's trail also says the pull's size (`3 files changed, +40 −7`), kept per base and head commit (`src/web/studio/review_evidence.ts`); a request never waits on git: until the stat is kept the row says "Diff loading — reload for the size" while the app computes it in the background (at most 4 at once, stopped by closing the app), and a failed stat says "Diff size unavailable" and is not asked again for a minute, so a bad pull cannot spawn git on every visit. Visits while a stat is running share it. Each row also carries its actions under it, as plain form POSTs to `/review/act` (same-origin checked, `rw` scope): on a pull **Merge** (through the same landing gate as anywhere, so a red or unreviewed head is refused with the gate's sentence), **Close**, **Request changes** (with a text box) and **Reply** (with a text box); on an issue **Close** and **Reply**. After an action the page answers 303 to `/review#<the next ask>` (the first that followed it and still waits, else the first left, else `/review`), and the acted ask is gone; a refusal comes back to the same row with its reason. Keys: `j`/`k` move between rows, and on the focused row `m` merges, `c` closes and `r` jumps to the Request-changes box; keys are ignored while a text box has focus, and `?` lists them. `/asks` links to it, and signed out it sends you to sign-in. The terminal's **Review queue** (above) lists the same asks and acts on them. | |
| 455 | 464 | |
| 456 | 465 | A client's forge: `Ctrl+K`, then **New forge** (any signed-in person's, as the |
| 457 | 466 | page is), is `/forges/new` in the terminal — name, for whom, what it is for, |
src/tui/forge.ts +9
| @@ -35,6 +35,7 @@ import { chainScreen } from "./screens/chain.ts"; | ||
| 35 | 35 | import { canSeeMemory } from "../boards/memory.ts"; |
| 36 | 36 | import { boardsScreen } from "./screens/boards.ts"; |
| 37 | 37 | import { askedScreen } from "./screens/asked.ts"; |
| 38 | import { queueScreen } from "./screens/queue.ts"; | |
| 38 | 39 | import { deciderScreen } from "./screens/decider.ts"; |
| 39 | 40 | import { forgesScreen } from "./screens/forges.ts"; |
| 40 | 41 | import { clientRows } from "../spawn/clients.ts"; |
| @@ -231,6 +232,14 @@ export function forgeCommands(session: Session): (ctx: Ctx) => Command[] { | ||
| 231 | 232 | hint: "your thoughts and what became of them", |
| 232 | 233 | run: () => ctx.push(askedScreen(session, ctx)), |
| 233 | 234 | }); |
| 235 | // Every ask waiting on you, as /review lists them, with the buttons. | |
| 236 | if (session.signedIn) | |
| 237 | commands.push({ | |
| 238 | id: "review", | |
| 239 | title: "Review queue", | |
| 240 | hint: "asks waiting on you: merge, close, review, reply, then the next", | |
| 241 | run: () => ctx.push(queueScreen(session, ctx)), | |
| 242 | }); | |
| 234 | 243 | if (session.signedIn) |
| 235 | 244 | commands.push({ |
| 236 | 245 | id: "decider", |
src/tui/screens/queue.ts added +202
| @@ -0,0 +1,202 @@ | ||
| 1 | /** | |
Whole screen is scope the direction did not ask for (#5189 is Later, no pillar). Hold until a pillar is named. |
||
| 2 | * `/review` in the terminal (#5189): every ask waiting on the viewer, newest | |
| 3 | * first, from the same `waitingOn` the web page reads — so what is listed is | |
| 4 | * the gate's and not this screen's. Each row is acted on with the pull and | |
| 5 | * issue screens' own gated calls (`mergePull`, `setIssueStateThrough`, | |
| 6 | * `submitReview`, `addCommentThrough`); a refusal comes back as a toast. After | |
| 7 | * an act the queue is read again and the cursor stays where it was, which is | |
| 8 | * now the next item. | |
| 9 | */ | |
| 10 | ||
| 11 | import type { Database } from "bun:sqlite"; | |
| 12 | import { addCommentThrough, setIssueStateThrough } from "../../actions/issues.ts"; | |
| 13 | import { mergePull, submitReview } from "../../actions/pulls.ts"; | |
| 14 | import { getIssue } from "../../core/issues.ts"; | |
| 15 | import { getPull } from "../../core/pulls.ts"; | |
| 16 | import { listReposVisibleTo, type Repo } from "../../core/repos.ts"; | |
| 17 | import type { User } from "../../core/users.ts"; | |
| 18 | import { err, ok } from "../../kernel/result.ts"; | |
| 19 | import { waitingOn } from "../../web/studio/asks.ts"; | |
| 20 | import type { Ctx, Screen } from "../app/app.ts"; | |
| 21 | import { binding } from "../app/keys.ts"; | |
| 22 | import type { Session } from "../session.ts"; | |
| 23 | import { style } from "../term/style.ts"; | |
| 24 | import { truncate } from "../term/width.ts"; | |
| 25 | import { fill, len, split } from "../ui/layout.ts"; | |
| 26 | import { emptyState } from "../ui/widgets.ts"; | |
| 27 | import { ListState, confirmScreen, drawList, errorText, hitList, metaOf, openOnWeb, promptScreen, relTime, runAsync, type ListRow } from "./common.ts"; | |
| 28 | import { reviewScreen } from "./review.ts"; | |
| 29 | ||
| 30 | /** One line of plain text: a title may carry newlines or escapes the terminal must not obey. */ | |
| 31 | const plain = (text: string): string => | |
| 32 | // eslint-disable-next-line no-control-regex | |
| 33 | text.replace(/[\u0000-\u001f\u007f-\u009f]+/g, " ").trim(); | |
| 34 | ||
| 35 | export interface QueueLine extends ListRow { | |
| 36 | readonly repo: Repo; | |
| 37 | /** The pull or issue number the actions work on; absent for an ask about no thread. */ | |
| 38 | readonly number?: number; | |
| 39 | readonly isPull: boolean; | |
| 40 | readonly path: string; | |
| 41 | } | |
| 42 | ||
| 43 | /** The asks waiting on the viewer as rows, newest decision first. A guest has none. */ | |
| 44 | export function queueLines(db: Database, viewer: User | undefined): QueueLine[] { | |
| 45 | if (viewer === undefined) return []; | |
| 46 | const repos = listReposVisibleTo(db, viewer, { limit: 200, withoutArchived: true }); | |
| 47 | return waitingOn(db, viewer, repos) | |
| 48 | .sort((a, b) => Date.parse(b.since) - Date.parse(a.since)) | |
| 49 | .map((a) => { | |
| 50 | const base = `/${a.repo.ownerName}/${a.repo.name}`; | |
| 51 | const thread = a.pull ?? a.issue; | |
| 52 | return { | |
| 53 | title: plain(a.pull?.title ?? a.issue?.title ?? a.proposal?.title ?? `${a.repo.name} is waiting on you`), | |
| 54 | tone: "attn" as const, | |
| 55 | secondary: plain(`${a.repo.ownerName}/${a.repo.name}${thread ? ` #${thread.number}` : ""} · ${a.why ?? a.consequence.why}`), | |
| 56 | meta: metaOf(a.pull ? "pull" : a.issue ? "issue" : "ask", relTime(a.since)), | |
| 57 | repo: a.repo, | |
| 58 | ...(thread === undefined ? {} : { number: thread.number }), | |
| 59 | isPull: a.pull !== undefined, | |
| 60 | path: a.pull ? `${base}/pulls/${a.pull.number}` : a.issue ? `${base}/issues/${a.issue.number}` : base, | |
| 61 | }; | |
| 62 | }); | |
| 63 | } | |
| 64 | ||
| 65 | export function queueScreen(f: Session, ctx: Ctx): Screen { | |
| 66 | const state = new ListState(); | |
| 67 | let lines: QueueLine[] = []; | |
| 68 | const read = (): void => { | |
| 69 | lines = queueLines(f.db, f.user); | |
| 70 | state.clamp(lines.length); | |
| 71 | }; | |
| 72 | const open = (index: number): void => { | |
| 73 | const line = lines[index]; | |
| 74 | if (line) openOnWeb(f, ctx, line.path, "That ask"); | |
| 75 | }; | |
| 76 | /** Run a gated call on the row under the cursor; on success say so and read the queue again. */ | |
| 77 | const act = ( | |
| 78 | verb: "Merge" | "Close", | |
| 79 | done: string, | |
| 80 | call: (line: QueueLine & { number: number }) => Promise<{ ok: boolean; error?: unknown }>, | |
outdated
A row without a number returns silently, so the key looks dead. Toast a reason, as |
||
| 81 | ): void => { | |
| 82 | const line = lines[state.index]; | |
| 83 | if (line?.number === undefined) { | |
| 84 | ctx.toast(`${verb} needs a pull or an issue; this ask has no thread, press enter to open it`, "attn"); | |
| 85 | return; | |
| 86 | } | |
| 87 | const at = line as QueueLine & { number: number }; | |
| 88 | // Irreversible, and next to the movement keys: one slipped key must not land it. | |
| 89 | // The dialog opens on Cancel, so enter alone does nothing. | |
| 90 | ctx.push( | |
| 91 | confirmScreen(ctx, screen, { | |
| 92 | title: `${verb} #${at.number}`, | |
| 93 | body: [`${plain(at.title)} (${at.repo.ownerName}/${at.repo.name})`], | |
| 94 | actions: [{ label: "Cancel", variant: "ghost" }, { label: verb }], | |
| 95 | selected: 0, | |
| 96 | onChoose: (choice) => { | |
| 97 | if (choice !== 1) return; | |
| 98 | runAsync(ctx, async () => { | |
| 99 | const result = await call(at); | |
| 100 | if (!result.ok) { | |
| 101 | ctx.toast(errorText(String(result.error)), "danger"); | |
| 102 | return; | |
| 103 | } | |
| 104 | read(); | |
| 105 | ctx.toast(done, "success"); | |
| 106 | }); | |
| 107 | }, | |
| 108 | }), | |
| 109 | ); | |
| 110 | }; | |
| 111 | const screen: Screen = { | |
| 112 | title: "Review", | |
outdated
Merge has no test. Add one for a successful merge and one for a refusal toast. |
||
| 113 | keys: [ | |
| 114 | binding(["j", "k"], "move"), | |
| 115 | binding(["m"], "merge"), | |
| 116 | binding(["x"], "close"), | |
| 117 | binding(["v"], "verdict"), | |
| 118 | binding(["c"], "reply"), | |
| 119 | binding(["enter"], "open"), | |
| 120 | binding(["r"], "refresh"), | |
outdated
The verdict card path (including the author-cannot-approve rule) is untested. Add a test that drives |
||
| 121 | ], | |
outdated
|
||
| 122 | load: async () => read(), | |
| 123 | render(area, s) { | |
| 124 | const c = ctx.theme.c; | |
| 125 | const [head, body] = split(area, "v", [len(1), fill(1)]); | |
| 126 | const n = lines.length; | |
| 127 | s.text(head!.x, head!.y, truncate(n === 0 ? "All fine" : `${n} ${n === 1 ? "ask" : "asks"}, newest first`, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); | |
| 128 | if (n === 0) { | |
| 129 | emptyState(s, body!, c, { title: "Nothing to review", body: "When the crew needs a person, it shows up here." }); | |
| 130 | return; | |
| 131 | } | |
| 132 | drawList(s, body!, c, state, lines); | |
| 133 | hitList(ctx, body!, state, n, { open }); | |
| 134 | }, | |
| 135 | key(e) { | |
| 136 | if (state.key(e, lines.length)) return true; | |
| 137 | if (e.key === "enter") open(state.index); | |
| 138 | else if (e.key === "r") runAsync(ctx, async () => read()); | |
| 139 | else if (e.key === "m") | |
| 140 | act("Merge", "merged", async (l) => { | |
| 141 | const row = l.isPull ? getPull(f.db, l.repo.id, l.number) : undefined; | |
| 142 | return row === undefined ? err("not_found") : mergePull(f.app, f.user, l.repo, row, "merge"); | |
| 143 | }); | |
| 144 | else if (e.key === "x") | |
| 145 | act("Close", "closed", async (l) => { | |
| 146 | const issue = getIssue(f.db, l.repo.id, l.number); | |
| 147 | return issue === undefined ? err("not_found") : setIssueStateThrough(f.app, f.user, l.repo, issue, "closed"); | |
| 148 | }); | |
| 149 | else if (e.key === "v") { | |
| 150 | const l = lines[state.index]; | |
| 151 | const row = l?.isPull && l.number !== undefined ? getPull(f.db, l.repo.id, l.number) : undefined; | |
| 152 | if (l === undefined || row === undefined) { | |
| 153 | ctx.toast("a verdict is for a pull", "danger"); | |
| 154 | return true; | |
| 155 | } | |
| 156 | ctx.push( | |
| 157 | reviewScreen(ctx, { | |
| 158 | parent: screen, | |
| 159 | title: `Review #${row.number}`, | |
| 160 | mayApprove: f.user !== undefined && row.authorId !== f.user.id, | |
| 161 | head: row.headOid, | |
| 162 | submit: async (input) => { | |
| 163 | const sent = await submitReview(f.app, f.user, l.repo, row, { | |
| 164 | state: input.state, | |
| 165 | ...(input.body.trim() === "" ? {} : { body: input.body.trim() }), | |
| 166 | }); | |
| 167 | if (!sent.ok) return err(errorText(String(sent.error))); | |
| 168 | read(); | |
| 169 | ctx.toast("review submitted", "success"); | |
| 170 | return ok(sent.value); | |
| 171 | }, | |
| 172 | }), | |
| 173 | ); | |
| 174 | } else if (e.key === "c") { | |
| 175 | const l = lines[state.index]; | |
| 176 | const issue = l?.number === undefined ? undefined : getIssue(f.db, l.repo.id, l.number); | |
| 177 | if (l === undefined || issue === undefined) { | |
| 178 | ctx.toast("Reply needs a pull or an issue; this ask has no thread, press enter to open it", "attn"); | |
| 179 | return true; | |
| 180 | } | |
| 181 | ctx.push( | |
| 182 | promptScreen(ctx, screen, { | |
| 183 | title: `Reply on #${issue.number}`, | |
| 184 | label: "Comment", | |
| 185 | onSubmit: (text) => { | |
| 186 | if (text === "") return "write something first"; | |
| 187 | return addCommentThrough(f.app, f.user, l.repo, issue, text).then((r) => { | |
| 188 | if (!r.ok) ctx.toast(errorText(String(r.error)), "danger"); | |
| 189 | else { | |
| 190 | read(); | |
| 191 | ctx.toast("comment posted", "success"); | |
| 192 | } | |
| 193 | }); | |
| 194 | }, | |
| 195 | }), | |
| 196 | ); | |
| 197 | } else return false; | |
| 198 | return true; | |
| 199 | }, | |
| 200 | }; | |
| 201 | return screen; | |
| 202 | } |
test/tui-queue.test.ts added +221
| @@ -0,0 +1,221 @@ | ||
| 1 | /** | |
| 2 | * /review in the terminal (#5189): the queue is `waitingOn`'s, newest first; | |
| 3 | * close and reply go through the gated issue calls, and the cursor lands on | |
| 4 | * the next item. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { openPull } from "../src/actions/pulls.ts"; | |
| 11 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { getPull } from "../src/core/pulls.ts"; | |
| 13 | import { listReviews } from "../src/core/reviews.ts"; | |
| 14 | import { errorText } from "../src/tui/screens/common.ts"; | |
| 15 | import type { Repo } from "../src/core/repos.ts"; | |
| 16 | import { createApp, type App } from "../src/app.ts"; | |
| 17 | import { createIssue, getIssue, listComments, setAssignee } from "../src/core/issues.ts"; | |
| 18 | import { createUser, type User } from "../src/core/users.ts"; | |
| 19 | import { createForgeApp, forgeCommands, Session } from "../src/tui/forge.ts"; | |
| 20 | import { queueLines, queueScreen } from "../src/tui/screens/queue.ts"; | |
| 21 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 22 | import { quietLogs } from "./helpers/globals.ts"; | |
| 23 | import { settleApp } from "./helpers/tui.ts"; | |
| 24 | import { promote } from "./helpers/members.ts"; | |
| 25 | ||
| 26 | quietLogs(); | |
| 27 | ||
| 28 | let dir: string; | |
| 29 | let app: App; | |
| 30 | let alice: User; | |
| 31 | let repoId: string; | |
| 32 | let bob: User; | |
| 33 | let lobby: Repo; | |
| 34 | ||
| 35 | const identity = (user?: User) => ({ sshUsername: user?.username ?? "git", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user }); | |
| 36 | ||
| 37 | const ask = (title: string, at: string) => { | |
| 38 | const r = createIssue(app.db, { repoId, authorId: alice.id, title }); | |
| 39 | if (!r.ok) throw new Error(r.error); | |
| 40 | setAssignee(app.db, r.value.id, alice.id); | |
| 41 | app.db.query("UPDATE issue SET updated_at = ?1 WHERE id = ?2").run(at, r.value.id); | |
| 42 | return r.value; | |
| 43 | }; | |
| 44 | ||
| 45 | beforeAll(async () => { | |
| 46 | dir = await mkdtemp(join(tmpdir(), "forge-tui-queue-")); | |
| 47 | app = createApp({ dataDir: dir, port: 0 }); | |
| 48 | const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 49 | if (!made.ok) throw new Error(made.error); | |
| 50 | alice = made.value; | |
| 51 | promote(app.db, alice); | |
| 52 | const repo = await createRepo(app, alice, { name: "lobby", visibility: "public" }); | |
| 53 | if (!repo.ok) throw new Error(String(repo.error)); | |
| 54 | repoId = repo.value.id; | |
| 55 | lobby = repo.value; | |
| 56 | const b = await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" }); | |
| 57 | if (!b.ok) throw new Error(b.error); | |
| 58 | bob = b.value; | |
| 59 | promote(app.db, bob); | |
| 60 | const seeded = await commitToBranch(app, alice, lobby, { message: "seed", files: [{ path: "README.md", content: "hi\n" }] }); | |
| 61 | if (!seeded.ok) throw new Error(String(seeded.error)); | |
| 62 | }); | |
| 63 | afterAll(async () => { | |
| 64 | app.db.close(); | |
| 65 | await rm(dir, { recursive: true, force: true }); | |
| 66 | }); | |
| 67 | ||
| 68 | /** A pull on its own branch, written by `author` and waiting on `assignee`. */ | |
| 69 | async function waitingPull(branch: string, author: User, assignee: User, at: string) { | |
| 70 | const made = await commitToBranch(app, alice, lobby, { branch, message: branch, files: [{ path: `${branch}.txt`, content: "x\n" }] }); | |
| 71 | if (!made.ok) throw new Error(String(made.error)); | |
| 72 | const pull = await openPull(app, author, lobby, { title: `Pull ${branch}`, baseBranch: "main", headBranch: branch }); | |
| 73 | if (!pull.ok) throw new Error(String(pull.error)); | |
| 74 | setAssignee(app.db, pull.value.id, assignee.id); | |
| 75 | app.db.query("UPDATE issue SET updated_at = ?1 WHERE id = ?2").run(at, pull.value.id); | |
| 76 | return pull.value; | |
| 77 | } | |
| 78 | ||
| 79 | async function open(as: User = alice) { | |
| 80 | const terminal = headlessTerminal(120, 30); | |
| 81 | const { app: tui, session } = createForgeApp(app, identity(as), { terminal, exitHooks: false }); | |
| 82 | tui.start(); | |
| 83 | tui.ctx.push(queueScreen(session, tui.ctx)); | |
| 84 | await settleApp(tui); | |
| 85 | return { tui, terminal }; | |
| 86 | } | |
| 87 | ||
| 88 | /** Put the cursor on the ask about `number`, by its place in the queue now, not by what earlier tests left. */ | |
| 89 | const moveTo = (user: User, number: number): string => { | |
| 90 | const at = queueLines(app.db, user).findIndex((l) => l.number === number); | |
| 91 | if (at < 0) throw new Error(`#${number} is not in the queue`); | |
| 92 | return "j".repeat(at); | |
| 93 | }; | |
| 94 | /** The dialog opens on Cancel: right, then enter, chooses the act. */ | |
| 95 | const CONFIRM = "l\r"; | |
| 96 | ||
| 97 | describe("the review queue screen", () => { | |
| 98 | test("lists what waits on the viewer, and nothing for a guest", () => { | |
| 99 | const issue = ask("Sweep the path", new Date().toISOString()); | |
| 100 | const lines = queueLines(app.db, alice); | |
| 101 | expect(lines.map((l) => l.title)).toContain("Sweep the path"); | |
| 102 | expect(lines.find((l) => l.number === issue.number)?.path).toBe(`/alice/lobby/issues/${issue.number}`); | |
| 103 | expect(queueLines(app.db, undefined)).toEqual([]); | |
| 104 | }); | |
| 105 | ||
| 106 | test("closing the ask under the cursor removes it and the next one is under the cursor", async () => { | |
| 107 | const a = ask("First ask", "2030-01-02T00:00:00.000Z"); | |
| 108 | const b = ask("Second ask", "2030-01-01T00:00:00.000Z"); | |
| 109 | const { tui, terminal } = await open(); | |
| 110 | const titles = () => queueLines(app.db, alice).map((l) => l.number); | |
| 111 | const start = titles(); | |
| 112 | expect(start.indexOf(a.number)).toBeLessThan(start.indexOf(b.number)); | |
| 113 | terminal.feed(moveTo(alice, a.number) + "x"); | |
| 114 | await settleApp(tui); | |
| 115 | expect(getIssue(app.db, repoId, a.number)?.state).toBe("open"); | |
| 116 | terminal.feed(CONFIRM); | |
| 117 | await settleApp(tui); | |
| 118 | expect(getIssue(app.db, repoId, a.number)?.state).toBe("closed"); | |
| 119 | const text = tui.screen.toText(); | |
| 120 | expect(text).not.toContain("First ask"); | |
| 121 | expect(text).toContain("Second ask"); | |
| 122 | tui.stop?.(); | |
| 123 | }); | |
| 124 | ||
| 125 | test("reply posts a comment through the gated call", async () => { | |
| 126 | const q = ask("Needs an answer", "2031-01-01T00:00:00.000Z"); | |
| 127 | const { tui, terminal } = await open(); | |
| 128 | terminal.feed(moveTo(alice, q.number) + "c"); | |
| 129 | await settleApp(tui); | |
| 130 | terminal.feed("looks good\r"); | |
| 131 | await settleApp(tui); | |
| 132 | expect(listComments(app.db, q.id).map((c) => c.body)).toContain("looks good"); | |
| 133 | tui.stop?.(); | |
| 134 | }); | |
| 135 | ||
| 136 | test("m merges the pull under the cursor, through mergePull", async () => { | |
| 137 | const pull = await waitingPull("f-merge", bob, alice, "2040-01-01T00:00:00.000Z"); | |
| 138 | const { tui, terminal } = await open(); | |
| 139 | terminal.feed(moveTo(alice, pull.number) + "m"); | |
| 140 | await settleApp(tui); | |
| 141 | // Nothing lands on the keypress itself; Cancel is the default. | |
| 142 | terminal.feed("\r"); | |
| 143 | await settleApp(tui); | |
| 144 | expect(getPull(app.db, lobby.id, pull.number)?.mergedAt).toBeNull(); | |
| 145 | terminal.feed("m" + CONFIRM); | |
| 146 | await settleApp(tui); | |
| 147 | expect(getPull(app.db, lobby.id, pull.number)?.mergedAt).not.toBeNull(); | |
| 148 | expect(tui.screen.toText()).not.toContain("Pull f-merge"); | |
| 149 | tui.stop?.(); | |
| 150 | }); | |
| 151 | ||
| 152 | test("m by a viewer who may not write is refused with a toast and merges nothing", async () => { | |
| 153 | const pull = await waitingPull("f-refused", alice, bob, "2041-01-01T00:00:00.000Z"); | |
| 154 | const { tui, terminal } = await open(bob); | |
| 155 | terminal.feed(moveTo(bob, pull.number) + "m" + CONFIRM); | |
| 156 | await settleApp(tui); | |
| 157 | expect(getPull(app.db, lobby.id, pull.number)?.mergedAt).toBeNull(); | |
| 158 | expect(tui.screen.toText()).toContain(errorText("forbidden")); | |
| 159 | tui.stop?.(); | |
| 160 | }); | |
| 161 | ||
| 162 | test("x closes a pull exactly as the pull screen does, and refuses who may not", async () => { | |
| 163 | const mine = await waitingPull("f-close", bob, bob, "2042-01-01T00:00:00.000Z"); | |
| 164 | const notMine = await waitingPull("f-keep", alice, bob, "2041-06-01T00:00:00.000Z"); | |
| 165 | const { tui, terminal } = await open(bob); | |
| 166 | terminal.feed(moveTo(bob, mine.number) + "x" + CONFIRM); | |
| 167 | await settleApp(tui); | |
| 168 | // The author may close their own pull; the pull row follows the issue row. | |
| 169 | expect(getPull(app.db, lobby.id, mine.number)?.state).toBe("closed"); | |
| 170 | // The next ask is another's pull: a reader who did not write it is refused. | |
| 171 | terminal.feed("k".repeat(5) + moveTo(bob, notMine.number) + "x" + CONFIRM); | |
| 172 | await settleApp(tui); | |
| 173 | expect(getPull(app.db, lobby.id, notMine.number)?.state).toBe("open"); | |
| 174 | expect(tui.screen.toText()).toContain(errorText("forbidden")); | |
| 175 | tui.stop?.(); | |
| 176 | }); | |
| 177 | ||
| 178 | test("v submits a verdict through submitReview, and the author is not offered approve", async () => { | |
| 179 | const theirs = await waitingPull("f-verdict", bob, alice, "2043-01-01T00:00:00.000Z"); | |
| 180 | const { tui, terminal } = await open(); | |
| 181 | terminal.feed(moveTo(alice, theirs.number) + "v"); | |
| 182 | await settleApp(tui); | |
| 183 | expect(tui.screen.toText()).toContain("approve"); | |
| 184 | terminal.feed("l"); | |
| 185 | await settleApp(tui); | |
| 186 | terminal.feed("\x04"); | |
| 187 | await settleApp(tui); | |
| 188 | expect(listReviews(app.db, theirs.id).map((r) => r.state)).toEqual(["changes_requested"]); | |
| 189 | tui.stop?.(); | |
| 190 | ||
| 191 | const mineToo = await waitingPull("f-own", alice, alice, "2044-01-01T00:00:00.000Z"); | |
| 192 | const own = await open(); | |
| 193 | own.terminal.feed(moveTo(alice, mineToo.number) + "v"); | |
| 194 | await settleApp(own.tui); | |
| 195 | const text = own.tui.screen.toText(); | |
| 196 | expect(text).toContain("request changes"); | |
| 197 | expect(text).not.toContain("approve"); | |
| 198 | own.tui.stop?.(); | |
| 199 | }); | |
| 200 | ||
| 201 | test("m, x and c on an ask with no thread say why instead of doing nothing", async () => { | |
| 202 | app.db | |
| 203 | .query("INSERT INTO plan_proposal (id, repo_id, author_id, title, why, issues, state, created_at) VALUES ('p-q', ?1, ?2, 'A wave', 'because', '[]', 'pending', '2099-01-01T00:00:00.000Z')") | |
| 204 | .run(repoId, alice.id); | |
| 205 | const { tui, terminal } = await open(); | |
| 206 | expect(queueLines(app.db, alice)[0]?.number).toBeUndefined(); | |
| 207 | for (const key of ["m", "x", "c"]) { | |
| 208 | terminal.feed(key); | |
| 209 | await settleApp(tui); | |
| 210 | expect(tui.screen.toText()).toContain("no thread"); | |
| 211 | } | |
| 212 | tui.stop?.(); | |
| 213 | app.db.query("DELETE FROM plan_proposal WHERE id = 'p-q'").run(); | |
| 214 | }); | |
| 215 | ||
| 216 | test("the palette offers the door to the signed in only", () => { | |
| 217 | const ids = (u?: User) => forgeCommands(new Session(app, identity(u)))({} as never).map((c) => c.id); | |
| 218 | expect(ids(alice)).toContain("review"); | |
| 219 | expect(ids()).not.toContain("review"); | |
| 220 | }); | |
| 221 | }); |
This now contradicts the paragraph above it. The terminal does have a Review queue. Drop or reword the sentence.