Public: anyone can read this; the crew can change it.
A guided review's doors: the terminal walks and sets the steps, a how-to, the MCP read and the brief line #14229
Check · Review · Land · Live — No review yet.
scout/forge:scout/14002-a-guided-review-s-doors-the-terminal-wal → main 2 commits fork
10 files
changed +328
−3
AGENTS.md +1
| @@ -56,6 +56,7 @@ The check queue hands work to a runner through `src/checks/runner.ts` (#13652, R | ||
| 56 | 56 | The capacity setting `children.awake` (boot default `FORGE_CHILD_AWAKE_MAX`) counts forges in use; a wake or a spawn at the ceiling puts the longest-idle forge to sleep first (`roomFor` in `src/spawn/host.ts`), and the boot never opens a child past it. Hosted children the boot opens (so their apps come back) are exempt from `awakeCount` until a credentialed request reaches them or they sleep (`bootOpened` in `src/spawn/host.ts`). The exempt set holds only body ids of existing finished children and is emptied when the parent closes, so it is bounded by the number of children. Cell children are always counted. The boot starts only the forges that were awake and in use when the parent stopped (`awake-at-stop.json` under the data directory, written by `closeHostedChildren`, read and removed once by `bootHostedChildren`, `src/spawn/awake_at_stop.ts`), up to the ceiling; a crash leaves no file, so nothing starts and forges wake on their next request. A sleeping cell forge with a run due has its wake armed. The idle sweeper starts at boot. |
| 57 | 57 | |
| 58 | 58 | An app token's requests go behind people's and repeat reads are 304s (`src/http/app_turn.ts`, `repeat_reads.ts`, `perf/asking.ts`): see `docs/features/app-asking.md`. |
| 59 | `src/core/review_steps.ts`: `reads`, per database, what each pull's review script was last read as (the kept row and the description's block, by pull id); `saveSteps` is the only writer of the row and keeps the entry, a new description body reads again; at most 2000 pulls, dropped whole past that, gone on restart. Its terminal door is `src/tui/screens/pull_review.ts` (`V` walks, `E` sets; `readAnswerLine`/`setWords` in `actions/review_steps.ts` give the page and the terminal the same gates). | |
| 59 | 60 | `src/core/reports.ts`: `closedSet`, the ids of repositories whose owner closed reports from outside (#12321), read once per database and kept by `setReportsClosed`, the only writer, so every repository page's head link costs no statement; at most one id per closed repository, gone on restart (the rows are `report_closed`). `src/core/contribute_token.ts`: `openSet`, the ids of repositories that allow outside agents, read once per database and kept by `setContributeOpen`, the only writer, at most one id per allowing repository, gone on restart; a raw SQL write to `contribute_open` bypasses it. The terminal door for reports is `r` on the outside agents screen (`setOutsideReports`, admins). |
| 60 | 61 | `src/spawn/births.ts`: `states`, per forge, the births in flight, the spawns waiting their turn (first in, first out, signed-in people ahead of strangers; at most 4 × `spawn.births_at_once` wait, strangers at most `spawn.births_at_once` of those, the rest are answered at once with their place; each waits 15 s at most, then is answered with its place) and the mean of the births measured (#13822); a birth is counted until its forge answers or 5 minutes pass; at most `spawn.births_at_once` in flight, gone on restart. The limits that bound a surge (`spawn.*`, `forges.wakes_per_forge_hour`) are settings on /admin/limits. |
| 61 | 62 | `src/web/studio/waiting_on_me.ts`: `waitingRows`, each viewer's issues and pulls that wait for them, held 10 seconds per viewer (at most 500 viewers, gone on restart) so the board's live lanes share one `decisionsFor` read; the terminal door is `src/tui/screens/waiting_for_me.ts` (palette entry for any person). |
docs/features/README.md +1
| @@ -221,6 +221,7 @@ Read with the guide page [Ship and undo](../guide-ship-and-undo.md). | ||
| 221 | 221 | - [](look-count.md) |
| 222 | 222 | - [](pull-verdict.md) |
| 223 | 223 | - [](pull-looks.md) |
| 224 | - [](review-steps.md) | |
| 224 | 225 | - [](approval-base.md) |
| 225 | 226 | - [](approved-week.md) |
| 226 | 227 | - [](build-cache.md) |
docs/features/review-steps.md added +9
| @@ -0,0 +1,9 @@ | ||
| 1 | # A guided review | |
| 2 | ||
| 3 | A builder ends a page-changing pull with a fenced `review` block (1 to 12 steps of `{ go, look, expect, ask? }`), or a writer sets the script; a reviewer walks it in the preview and the answers go back as ONE comment on the pull. | |
| 4 | ||
| 5 | - **Page and API** — `GET /api/v1/repos/:owner/:name/pulls/:number/review` lists the steps with the preview address and the forge's deep link `/<owner>/<name>/pulls/<n>/review/<step>`; a writer sets them with `PUT` on the same path. | |
| 6 | - **Terminal** — on an app's pull, `V` walks the steps: `o` opens the step's page in the preview (or shows its address to copy), `w` works, `b` broken (a one-line note follows), `s` skip. After the last answer one comment is sent, the same as the page's. `E` lets a writer set the script from one line of JSON; a bad list says which step is wrong and sets nothing. | |
| 7 | - **MCP** — the `pull` tool carries `reviewSteps`, the same list as the API. | |
| 8 | ||
| 9 | Both doors use `readAnswerLine`, `setReviewSteps` and `setWords` in `src/actions/review_steps.ts`, so they give the same answers and refusals. The script's shape is `src/core/review_steps.ts`. |
src/actions/review_steps.ts +22
| @@ -15,6 +15,7 @@ import { | ||
| 15 | 15 | saveSteps, |
| 16 | 16 | stepPath, |
| 17 | 17 | stepsOf, |
| 18 | stepsWords, | |
| 18 | 19 | type ReviewStep, |
| 19 | 20 | type StepsError, |
| 20 | 21 | } from "../core/review_steps.ts"; |
| @@ -73,6 +74,27 @@ export function readAnswers(count: number, get: (key: string) => string | null): | ||
| 73 | 74 | return out; |
| 74 | 75 | } |
| 75 | 76 | |
| 77 | /** | |
| 78 | * One answer typed in the terminal: `w` (works), `b <note>` (broken, the note optional), `s` | |
| 79 | * (skip, a note optional). Anything else is refused, so the terminal and the page share a gate. | |
| 80 | */ | |
| 81 | export function readAnswerLine(line: string): StepAnswer | undefined { | |
| 82 | const m = /^\s*([wbs])(?:\s+([\s\S]*))?$/i.exec(line); | |
| 83 | if (m === null) return undefined; | |
| 84 | const v: Verdict = { w: "works", b: "broken", s: "skipped" }[m[1]!.toLowerCase() as "w" | "b" | "s"] as Verdict; | |
| 85 | const read = readAnswers(1, (k) => (k === "v1" ? v : k === "n1" ? (m[2] ?? "") : null)); | |
| 86 | return read?.[0]; | |
| 87 | } | |
| 88 | ||
| 89 | /** The words for a refused script write, for the page's message and the terminal's toast. */ | |
| 90 | export function setWords(error: StepsSetError): string { | |
| 91 | if (error === "unauthorized") return "sign in to set the review steps"; | |
| 92 | if (error === "forbidden") return "only a writer sets the review steps"; | |
| 93 | if (error === "not_found") return "no such pull"; | |
| 94 | if (error === "not_open") return "the pull is not open"; | |
| 95 | return stepsWords(error); | |
| 96 | } | |
| 97 | ||
| 76 | 98 | const WORD: Readonly<Record<Verdict, string>> = { |
| 77 | 99 | works: "works", |
| 78 | 100 | broken: "does not work", |
src/crew/brief.ts +1
| @@ -224,6 +224,7 @@ export function systemPrompt(input: BriefInput): string { | ||
| 224 | 224 | "- The bar is the forge's own: small modules named for one concept, every input validated at the boundary and every output escaped, the security floor in " + |
| 225 | 225 | (isForge(repo) ? "`src/http/respond.ts` (`securityFloor`)" : "`src/server.ts`") + |
| 226 | 226 | " kept on every response, no dependency without a reason in the pull, and a page that answers in milliseconds. `AGENTS.md` in the repository says how this app is shaped; keep its shape.", |
| 227 | "- A pull that changes what a page shows ends its description with a fenced `review` block: a JSON list of 1 to 12 steps `{ \"go\": \"/path\", \"look\": \"css selector\", \"expect\": \"one sentence a reviewer can check\", \"ask\": \"optional question\" }`; the reviewer walks them in the preview.", | |
| 227 | 228 | ...(input.previewUrl === undefined |
| 228 | 229 | ? [] |
| 229 | 230 | : [ |
src/http/mcp/tools/pull.ts +3 −1
| @@ -12,6 +12,7 @@ import { appView } from "../../../actions/apps.ts"; | ||
| 12 | 12 | import { countThread, listComments } from "../../../core/issues.ts"; |
| 13 | 13 | import { landingLine } from "../../../flow/landing_line.ts"; |
| 14 | 14 | import { pullLooks } from "../../../looks/readable.ts"; |
| 15 | import { reviewSteps } from "../../../actions/review_steps.ts"; | |
| 15 | 16 | import { isCrew } from "../../../core/agents.ts"; |
| 16 | 17 | import { markReaders } from "../../../crew/direct.ts"; |
| 17 | 18 | import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts"; |
| @@ -23,7 +24,7 @@ const PULL_COMMENTS = 10; | ||
| 23 | 24 | |
| 24 | 25 | export const tool: Tool = { |
| 25 | 26 | name: "pull", |
| 26 | doc: "`{ repo, number }`: a pull's title, state, head and base, `summary` (two or three sentences: what changed, what was verified), and for an open pull whether it merges into the base's current head (`mergeable`) and the paths that stop it (`conflicts`), and `next: { who, why }` (open only; who acts next: builder, reviewer, queue or person), `step: { step, why, done }` (check, review, land or live; null once closed unlanded), and `comments` (the newest 10: author, body, at, `untrusted` on an outsider's), `commentsTotal` and `commentsNext` (older: `GET …/issues/:number/comments?cursor=`), and `looks` (newest first: `{ id, width, says, by, commit, url, at }`, the same as `GET …/pulls/:number/looks`), and `eta: { minutes, says }` (approved open pull only, else null), and `check: { state, baseOid }`: the latest check's state and the base tip it was merged with (empty when it merged nothing), `checkStale` (the base has moved since that check) and `checkedAgainst` (that base tip, or null; the same as `GET …/pulls/:number`); `mergeable` and `conflicts` are the same fields as `GET …/pulls/:number`, `check` is `state` and `run.baseOid` from `GET …/pulls/:number/checks`; draws the `ui://forge/pull` card: `#N title`, state with check and conflicts while open, `head → base` linked to the pull, and the preview link when the pull has an environment", | |
| 27 | doc: "`{ repo, number }`: a pull's title, state, head and base, `summary` (two or three sentences: what changed, what was verified), and for an open pull whether it merges into the base's current head (`mergeable`) and the paths that stop it (`conflicts`), and `next: { who, why }` (open only; who acts next: builder, reviewer, queue or person), `step: { step, why, done }` (check, review, land or live; null once closed unlanded), and `comments` (the newest 10: author, body, at, `untrusted` on an outsider's), `commentsTotal` and `commentsNext` (older: `GET …/issues/:number/comments?cursor=`), and `looks` (newest first: `{ id, width, says, by, commit, url, at }`, the same as `GET …/pulls/:number/looks`), and `eta: { minutes, says }` (approved open pull only, else null), and `check: { state, baseOid }`: the latest check's state and the base tip it was merged with (empty when it merged nothing), `checkStale` (the base has moved since that check) and `checkedAgainst` (that base tip, or null; the same as `GET …/pulls/:number`); `mergeable` and `conflicts` are the same fields as `GET …/pulls/:number`, `check` is `state` and `run.baseOid` from `GET …/pulls/:number/checks`; `reviewSteps` (the guided review's steps, as `GET …/pulls/:number/review`), draws the `ui://forge/pull` card: `#N title`, state with check and conflicts while open, `head → base` linked to the pull, and the preview link when the pull has an environment", | |
| 27 | 28 | description: |
| 28 | 29 | "A pull: title, state, head, base; open: `mergeable`, `conflicts`, `checkStale`, `checkedAgainst`, `check`.", |
| 29 | 30 | inputSchema: { |
| @@ -69,6 +70,7 @@ export const tool: Tool = { | ||
| 69 | 70 | commentsTotal: total, |
| 70 | 71 | commentsNext: comments.length > 0 && comments.length < total ? comments[0]!.id : null, |
| 71 | 72 | looks: pullLooks(ctx.app, repo, pull, user), |
| 73 | reviewSteps: reviewSteps(ctx.app, user, repo, pull), | |
| 72 | 74 | number: pull.number, |
| 73 | 75 | title: pull.title, |
| 74 | 76 | state: pull.mergedAt !== null ? "merged" : pull.state, |
src/tui/screens/pull.ts +11 −1
| @@ -54,6 +54,7 @@ import { openEnvUrl } from "../../actions/apps.ts"; | ||
| 54 | 54 | import { listRepoRuns, mayReadRunLog } from "../../actions/runs.ts"; |
| 55 | 55 | import { pullLooks, type PullLook } from "../../looks/readable.ts"; |
| 56 | 56 | import { pullLooksScreen } from "./pulllooks.ts"; |
| 57 | import { pullReviewScreen, setStepsPrompt } from "./pull_review.ts"; | |
| 57 | 58 | import { combinedView, combinedWords, type CombinedView } from "../../core/combined_view.ts"; |
| 58 | 59 | import { previewEnv } from "../../apps/data.ts"; |
| 59 | 60 | import { findingsWords, pullPreviewFindings } from "../../core/preview_findings.ts"; |
| @@ -1169,7 +1170,8 @@ export function pullScreen( | ||
| 1169 | 1170 | ? [binding(["O"], "open the preview")] |
| 1170 | 1171 | : []), |
| 1171 | 1172 | ...(isApp ? [binding(["P"], "open production")] : []), |
| 1172 | ...(isApp ? [binding(["I"], "looks")] : []), | |
| 1173 | ...(isApp ? [binding(["I"], "looks"), binding(["V"], "walk the review steps")] : []), | |
| 1174 | ...(isApp && mayWrite() ? [binding(["E"], "set the review steps")] : []), | |
| 1173 | 1175 | ...(takeBackKey ? [binding(["T"], "take it back")] : []), |
| 1174 | 1176 | ...(isApp && preview !== undefined && !takeBackKey |
| 1175 | 1177 | ? [binding(["T"], "the preview's terminal")] |
| @@ -1462,6 +1464,14 @@ export function pullScreen( | ||
| 1462 | 1464 | if (pull !== undefined) ctx.push(pullLooksScreen(f, ctx, repo, pull)); |
| 1463 | 1465 | return true; |
| 1464 | 1466 | } |
| 1467 | if ((e.key === "V" || e.key === "E") && isApp && repo !== undefined && detail !== undefined) { | |
| 1468 | const pull = getPull(f.db, repo.id, number); | |
| 1469 | if (pull === undefined) return true; | |
| 1470 | if (e.key === "V") ctx.push(pullReviewScreen(f, ctx, repo, pull, () => runAsync(ctx, reload))); | |
| 1471 | else if (mayWrite() && pull.state === "open") | |
| 1472 | setStepsPrompt(f, ctx, screen, repo, pull, () => undefined); | |
| 1473 | return true; | |
| 1474 | } | |
| 1465 | 1475 | if (e.key === "P" && isApp) { |
| 1466 | 1476 | openProduction(); |
| 1467 | 1477 | return true; |
src/tui/screens/pull_review.ts added +133
| @@ -0,0 +1,133 @@ | ||
| 1 | /** | |
| 2 | * `V` on an app's pull: walk its review steps one by one. `o` opens the step's page in the | |
| 3 | * preview (or shows its address to copy), `w` works, `b` broken with a note, `s` skip; after the | |
| 4 | * last answer ONE comment goes to the pull, the same as the page's. `setStepsPrompt` (`E`) lets a | |
| 5 | * writer set the script from a JSON list. Gates are `actions/review_steps.ts`'s. | |
| 6 | */ | |
| 7 | ||
| 8 | import { | |
| 9 | readAnswerLine, | |
| 10 | reviewSteps, | |
| 11 | sendReviewAnswers, | |
| 12 | setReviewSteps, | |
| 13 | setWords, | |
| 14 | type StepAnswer, | |
| 15 | } from "../../actions/review_steps.ts"; | |
| 16 | import type { Pull } from "../../core/pulls.ts"; | |
| 17 | import type { Repo } from "../../core/repos.ts"; | |
| 18 | import type { Ctx, Screen } from "../app/app.ts"; | |
| 19 | import { binding } from "../app/keys.ts"; | |
| 20 | import type { Session } from "../session.ts"; | |
| 21 | import { style } from "../term/style.ts"; | |
| 22 | import { emptyState } from "../ui/widgets.ts"; | |
| 23 | import { openLink, promptScreen } from "./common.ts"; | |
| 24 | ||
| 25 | const plain = (text: string): string => text.replace(/[\p{Cc}\p{Cf}\u2028\u2029]/gu, " "); | |
| 26 | ||
| 27 | export function pullReviewScreen(f: Session, ctx: Ctx, repo: Repo, pull: Pull, onSent: () => void): Screen { | |
| 28 | const steps = reviewSteps(f.app, f.user, repo, pull); | |
| 29 | const answers: StepAnswer[] = []; | |
| 30 | let sending = false; | |
| 31 | const screen: Screen = { | |
| 32 | title: `Review · #${pull.number}`, | |
| 33 | get keys() { | |
| 34 | return steps.length === 0 | |
| 35 | ? [binding(["esc", "q"], "back")] | |
| 36 | : [ | |
| 37 | binding(["o"], "open the step"), | |
| 38 | binding(["w"], "works"), | |
| 39 | binding(["b"], "broken"), | |
| 40 | binding(["s"], "skip"), | |
| 41 | binding(["esc", "q"], "back"), | |
| 42 | ]; | |
| 43 | }, | |
| 44 | render(area, s) { | |
| 45 | const c = ctx.theme.c; | |
| 46 | if (steps.length === 0) { | |
| 47 | emptyState(s, area, c, { | |
| 48 | title: "No review steps", | |
| 49 | body: "A writer sets them with E, or the pull's description carries a review block.", | |
| 50 | }); | |
| 51 | return; | |
| 52 | } | |
| 53 | const step = steps[Math.min(answers.length, steps.length - 1)]!; | |
| 54 | const rows = [ | |
| 55 | `Step ${step.step} of ${steps.length}`, | |
| 56 | "", | |
| 57 | `Look at: ${plain(step.look)}`, | |
| 58 | `Expect: ${plain(step.expect)}`, | |
| 59 | ...(step.ask === null ? [] : [`Ask: ${plain(step.ask)}`]), | |
| 60 | `Page: ${plain(step.url ?? step.link)}`, | |
| 61 | ]; | |
| 62 | rows.forEach((r, i) => { | |
| 63 | if (i < area.h) s.text(area.x, area.y + i, r.slice(0, area.w), style(c.fg, c.bg), area.x + area.w); | |
| 64 | }); | |
| 65 | }, | |
| 66 | key(e) { | |
| 67 | if (e.key === "esc" || e.key === "q") { | |
| 68 | ctx.pop(); | |
| 69 | return true; | |
| 70 | } | |
| 71 | const step = steps[answers.length]; | |
| 72 | if (step === undefined || sending) return true; | |
| 73 | if (e.key === "o") { | |
| 74 | if (step.url === null) ctx.toast("this step's page is not open to you", "attn"); | |
| 75 | else openLink(ctx, step.url); | |
| 76 | return true; | |
| 77 | } | |
| 78 | const take = (a: StepAnswer | undefined): void => { | |
| 79 | if (a === undefined) return; | |
| 80 | answers.push(a); | |
| 81 | ctx.invalidate(); | |
| 82 | if (answers.length < steps.length) return; | |
| 83 | sending = true; | |
| 84 | void sendReviewAnswers(f.app, f.user, repo, pull, answers).then((out) => { | |
| 85 | ctx.toast(out.ok ? "sent your answers as one comment" : "could not send the answers", out.ok ? "success" : "danger"); | |
| 86 | if (out.ok) { | |
| 87 | onSent(); | |
| 88 | ctx.pop(); | |
| 89 | } else sending = false; | |
| 90 | }); | |
| 91 | }; | |
| 92 | if (e.key === "w" || e.key === "s") take(readAnswerLine(e.key)); | |
| 93 | else if (e.key === "b") | |
| 94 | ctx.push( | |
| 95 | promptScreen(ctx, screen, { | |
| 96 | title: `Step ${step.step} does not work`, | |
| 97 | label: "Note", | |
| 98 | hint: "What went wrong, one line (optional). Enter records it.", | |
| 99 | onSubmit: (value) => { | |
| 100 | take(readAnswerLine(`b ${value}`)); | |
| 101 | return undefined; | |
| 102 | }, | |
| 103 | }), | |
| 104 | ); | |
| 105 | return true; | |
| 106 | }, | |
| 107 | }; | |
| 108 | return screen; | |
| 109 | } | |
| 110 | ||
| 111 | /** `E`: a writer sets the script from a JSON list of `{ go, look, expect, ask? }`. */ | |
| 112 | export function setStepsPrompt(f: Session, ctx: Ctx, parent: Screen, repo: Repo, pull: Pull, done: () => void): void { | |
| 113 | ctx.push( | |
| 114 | promptScreen(ctx, parent, { | |
| 115 | title: `Review steps · #${pull.number}`, | |
| 116 | label: "JSON", | |
| 117 | hint: 'One line: [{"go":"/","look":"main","expect":"…"}]. Enter sets; Esc cancels.', | |
| 118 | onSubmit: (value) => { | |
| 119 | let raw: unknown; | |
| 120 | try { | |
| 121 | raw = JSON.parse(value); | |
| 122 | } catch { | |
| 123 | return "that is not JSON: a list of { go, look, expect, ask? }"; | |
| 124 | } | |
| 125 | const out = setReviewSteps(f.app, f.user, repo, pull, raw); | |
| 126 | if (!out.ok) return setWords(out.error); | |
| 127 | ctx.toast(`${out.value.length} review step${out.value.length === 1 ? "" : "s"} set`, "success"); | |
| 128 | done(); | |
| 129 | return undefined; | |
| 130 | }, | |
| 131 | }), | |
| 132 | ); | |
| 133 | } |
test/review-steps.test.ts +17 −1
| @@ -10,7 +10,7 @@ import { tmpdir } from "node:os"; | ||
| 10 | 10 | import { join } from "node:path"; |
| 11 | 11 | import { openPull } from "../src/actions/pulls.ts"; |
| 12 | 12 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 13 | import { answersComment, readAnswers } from "../src/actions/review_steps.ts"; | |
| 13 | import { answersComment, readAnswerLine, readAnswers, setWords } from "../src/actions/review_steps.ts"; | |
| 14 | 14 | import { createApp, type App } from "../src/app.ts"; |
| 15 | 15 | import { AppsRuntime, type EnvStatus } from "../src/apps/runtime.ts"; |
| 16 | 16 | import { tourJs, tourResponse, TOUR_ASSET_PATH } from "../src/apps/tour.ts"; |
| @@ -79,6 +79,22 @@ describe("the answers", () => { | ||
| 79 | 79 | }); |
| 80 | 80 | }); |
| 81 | 81 | |
| 82 | describe("the terminal's answer line", () => { | |
| 83 | test("w, b <note> and s are the only answers", () => { | |
| 84 | expect(readAnswerLine("w")).toEqual({ verdict: "works", note: "" }); | |
| 85 | expect(readAnswerLine(" b the list\u0007 is empty ")).toEqual({ verdict: "broken", note: "the list is empty" }); | |
| 86 | expect(readAnswerLine("s")).toEqual({ verdict: "skipped", note: "" }); | |
| 87 | expect(readAnswerLine("great")).toBeUndefined(); | |
| 88 | expect(readAnswerLine("")).toBeUndefined(); | |
| 89 | expect(readAnswerLine("b" + "x".repeat(600))).toBeUndefined(); | |
| 90 | expect(readAnswerLine("b " + "x".repeat(600))!.note.length).toBe(500); | |
| 91 | }); | |
| 92 | test("a refused write has words", () => { | |
| 93 | expect(setWords("forbidden")).toContain("writer"); | |
| 94 | expect(setWords("step_2")).toContain("step 2"); | |
| 95 | }); | |
| 96 | }); | |
| 97 | ||
| 82 | 98 | describe("the tour's tag", () => { |
| 83 | 99 | const tour = { repo: "a/b", pull: 3, steps: [{ go: "/", look: "h1", expect: 'say "hi" <b>' }] }; |
| 84 | 100 | test("is written only with a script, escaped, and points at a content-addressed file", () => { |
test/tui-pull-review.test.ts added +130
| @@ -0,0 +1,130 @@ | ||
| 1 | /** | |
| 2 | * A guided review from the terminal (#14002): `V` walks the steps and sends ONE comment; `E` sets | |
| 3 | * them. | |
| 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 { openPull } from "../src/actions/pulls.ts"; | |
| 10 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { createApp, type App as Forge } from "../src/app.ts"; | |
| 12 | import { createApp as insertApp } from "../src/core/apps.ts"; | |
| 13 | import { listComments } from "../src/core/issues.ts"; | |
| 14 | import { getPull, type Pull } from "../src/core/pulls.ts"; | |
| 15 | import type { Repo } from "../src/core/repos.ts"; | |
| 16 | import { stepsOf } from "../src/core/review_steps.ts"; | |
| 17 | import { createUser, type User } from "../src/core/users.ts"; | |
| 18 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 19 | import { pullScreen } from "../src/tui/screens/pull.ts"; | |
| 20 | import { local } from "../src/tui/screens/where.ts"; | |
| 21 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 22 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 23 | import { quietLogs } from "./helpers/globals.ts"; | |
| 24 | import { settleApp } from "./helpers/tui.ts"; | |
| 25 | ||
| 26 | quietLogs(); | |
| 27 | ||
| 28 | let dataDir: string; | |
| 29 | let forge: Forge; | |
| 30 | let alice: User; | |
| 31 | let bob: User; | |
| 32 | let repo: Repo; | |
| 33 | let pull: Pull; | |
| 34 | ||
| 35 | beforeAll(async () => { | |
| 36 | dataDir = await mkdtemp(join(tmpdir(), "forge-tui-review-")); | |
| 37 | forge = createApp({ dataDir, port: 0, url: "https://forge.test" }); | |
| 38 | const a = await seedAdmin(forge, { username: "alice", email: "[email protected]", password: "a-long-passphrase" }); | |
| 39 | if (!a.ok) throw new Error("signup failed"); | |
| 40 | alice = a.value; | |
| 41 | const b = await createUser(forge.db, { | |
| 42 | origin: "seed", | |
| 43 | trusted: true, | |
| 44 | username: "bob", | |
| 45 | email: "[email protected]", | |
| 46 | password: "a-long-passphrase", | |
| 47 | }); | |
| 48 | if (!b.ok) throw new Error(b.error); | |
| 49 | bob = b.value; | |
| 50 | const r = await createRepo(forge, alice, { name: "tour", visibility: "public" }); | |
| 51 | if (!r.ok) throw new Error("repo creation failed"); | |
| 52 | repo = r.value; | |
| 53 | await commitToBranch(forge, alice, repo, { message: "seed", files: [{ path: "README.md", content: "# s\n" }] }); | |
| 54 | await commitToBranch(forge, alice, repo, { | |
| 55 | branch: "feature/one", | |
| 56 | base: "main", | |
| 57 | message: "One", | |
| 58 | files: [{ path: "one.ts", content: "export const one = 1;\n" }], | |
| 59 | }); | |
| 60 | const o = await openPull(forge, alice, repo, { title: "Pull one", body: "", baseBranch: "main", headBranch: "feature/one" }); | |
| 61 | if (!o.ok) throw new Error(String(o.error)); | |
| 62 | pull = o.value; | |
| 63 | insertApp(forge.db, { repoId: repo.id, slug: "tour", access: "public" }); | |
| 64 | }); | |
| 65 | ||
| 66 | afterAll(async () => { | |
| 67 | forge.close(); | |
| 68 | await rm(dataDir, { recursive: true, force: true }); | |
| 69 | }); | |
| 70 | ||
| 71 | async function open(user: User) { | |
| 72 | const { app, session } = createForgeApp( | |
| 73 | forge, | |
| 74 | { sshUsername: user.username, remoteAddress: "127.0.0.1", user }, | |
| 75 | { terminal: headlessTerminal(160, 50), exitHooks: false }, | |
| 76 | ); | |
| 77 | app.start(); | |
| 78 | app.ctx.push(pullScreen(session, app.ctx, local(session, repo), pull.number)); | |
| 79 | await settleApp(app); | |
| 80 | const press = async (...keys: string[]) => { | |
| 81 | for (const key of keys) app.dispatch({ type: "key", key, ctrl: false, alt: false, shift: false }); | |
| 82 | await settleApp(app); | |
| 83 | }; | |
| 84 | return { app, press, text: () => app.screen.toText() }; | |
| 85 | } | |
| 86 | ||
| 87 | const SCRIPT = JSON.stringify([ | |
| 88 | { go: "/", look: "main h1", expect: "The heading says Hello" }, | |
| 89 | { go: "/about", look: "#team", expect: "Three people", ask: "Readable?" }, | |
| 90 | ]); | |
| 91 | ||
| 92 | test("a writer sets the steps with E; a bad list says why and sets nothing", async () => { | |
| 93 | const h = await open(alice); | |
| 94 | await h.press("E", ..."not json", "enter"); | |
| 95 | expect(h.text()).toContain("not JSON"); | |
| 96 | await h.press("esc"); | |
| 97 | await h.press("E", ...'[{"go":"https://x.example/","look":"a","expect":"b"}]', "enter"); | |
| 98 | expect(h.text()).toContain("step 1 needs go"); | |
| 99 | expect(stepsOf(forge.db, getPull(forge.db, repo.id, pull.number)!)).toEqual([]); | |
| 100 | await h.press("esc"); | |
| 101 | await h.press("E", ...SCRIPT, "enter"); | |
| 102 | expect(stepsOf(forge.db, getPull(forge.db, repo.id, pull.number)!)).toHaveLength(2); | |
| 103 | h.app.stop(); | |
| 104 | }); | |
| 105 | ||
| 106 | test("a reader without write cannot set steps", async () => { | |
| 107 | const h = await open(bob); | |
| 108 | await h.press("E"); | |
| 109 | expect(h.text()).not.toContain("Review steps"); | |
| 110 | h.app.stop(); | |
| 111 | }); | |
| 112 | ||
| 113 | test("V walks the steps and sends one comment", async () => { | |
| 114 | const before = listComments(forge.db, pull.id, {}).length; | |
| 115 | const h = await open(alice); | |
| 116 | await h.press("V"); | |
| 117 | expect(h.text()).toContain("Step 1 of 2"); | |
| 118 | expect(h.text()).toContain("The heading says Hello"); | |
| 119 | await h.press("w"); | |
| 120 | expect(h.text()).toContain("Step 2 of 2"); | |
| 121 | await h.press("b", ..."list is empty", "enter"); | |
| 122 | await new Promise((r) => setTimeout(r, 50)); | |
| 123 | await h.press(); | |
| 124 | const comments = listComments(forge.db, pull.id, {}); | |
| 125 | expect(comments.length).toBe(before + 1); | |
| 126 | const body = comments[comments.length - 1]!.body; | |
| 127 | expect(body).toContain("1 of 2 steps work, 1 do not, 0 not tried."); | |
| 128 | expect(body).toContain("Note: list is empty"); | |
| 129 | h.app.stop(); | |
| 130 | }); |
new above
offline