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

A changes-requested review with only a body is invisible: the pull's API, its reviews list and a repeat review request all say nothing #18184

opened this in answer to

Merged 14h 9m ago, live in production

torque/forge:torque/18181-a-changes-requested-review-with-only-a-b → main 0 commits fork 3 threads · 3 unresolved

  • Merged. torque/18181-a-changes-requested-review-with-only-a-b was merged into main as 1b94cba.

Review

Sign in to review this change.
21 files changed +286 −59
docs/features/flow-waiting.md +1 −1
@@ -24,7 +24,7 @@ Each stalled row carries one form button, never a silent wait: an approved pull
2424
2525 A pull whose check on its head has been green for more than six hours and that has not landed says, in one line, what it waits for and the one thing that unblocks it: "Green for 30 hours, not landed: it waits for review. To unblock: a reviewer reviews it on its current head."
2626
27 The cause is the first that holds: a hold, a conflict with the base, a chapter, then whoever acts next (a person, the builder after changes were asked, a reviewer, the landing queue). `waitsFor` in `src/core/landing.ts` words it; `pullWaitsFor` in `src/flow/waits_for.ts` reads the facts.
27 The cause is the first that holds: a hold, a conflict with the base, a chapter, then whoever acts next (a person, the builder, said as the Next line says it, "waits on its author: changes requested", a reviewer, the landing queue). `waitsFor` in `src/core/landing.ts` words it; `pullWaitsFor` in `src/flow/waits_for.ts` reads the facts.
2828
2929 Where it shows:
3030
docs/features/review-requests.md +3 −1
@@ -6,4 +6,6 @@ row: Ask the crew to review a person's pull
66
77 The crew reviews its own agents' pulls on its own; a person's pull is reviewed once asked. `POST /api/v1/repos/:owner/:name/pulls/:number/review-requests` with `{"reviewer": "<agent>"}` (optional; without it, the reviewer with the fewest queued or running runs), the "Ask the crew to review" button on the pull page, or an `@mention` of a crew reviewer in a pull comment by a person who writes the repository. The ask is one row (`review_request`); from it the review runs like an agent pull's (same rounds, verdicts and lapse, the clock starting at the ask), and an approval on the head lets `landIfGreen` land it.
88
9 From the terminal, press `K` on a pull's screen (a reviewer's username, or empty for the least busy). Over MCP, `request_review {app, pull, reviewer?}` plans by default and asks with `dryRun: false`. Without a name the least busy reviewer is chosen and kept, so every door answers with who was asked. A later mention of the reviewer already asked does not ask again or restart the clock. An agent cannot ask, and a held pull is not reviewed. An app whose reviews are off lands a green pull without one, asked or not.
9 From the terminal, press `K` on a pull's screen (a reviewer's username, or empty for the least busy). Over MCP, `request_review {app, pull, reviewer?}` asks; `dryRun: true` only plans. Without a name the least busy reviewer is chosen and kept, so every door answers with who was asked. A later mention of the reviewer already asked does not ask again or restart the clock. An agent cannot ask, and a held pull is not reviewed. An app whose reviews are off lands a green pull without one, asked or not.
10
11 A head that already has a changes-requested review is not asked again (#18181): every door answers "already reviewed: changes requested by <who> at <time>", the review's first lines, and "Push a change, then ask again."; the API answers 409 `already_reviewed` with the review. A pull's API answer carries `latestReview` (state, reviewer, `at`, body, `current`) and `changesRequested` (the review asking for changes on the head, else null); `GET …/pulls/:n/reviews` lists reviews, body-only ones too, each with its line `comments` (`src/core/review_list.ts` shapes both). The shape changed: `/reviews` was a flat comment list and is now reviews with nested comments. A line comment carries no review id, so it is grouped under a review by author, commit and nearest time: a heuristic, not a link. The pull's Next line reads "waits on its author: changes requested".
src/actions/review_requests.ts +17
@@ -13,6 +13,7 @@ import type { Agent } from "../core/agents.ts";
1313 import { getHold } from "../core/holds.ts";
1414 import { setReviewRequest, type ReviewRequest } from "../core/review_requests.ts";
1515 import type { Pull } from "../core/pulls.ts";
16 import { changesBrief, firstLines, type ReviewBrief } from "../core/review_list.ts";
1617 import { canRead, canWrite, type Repo } from "../core/repos.ts";
1718 import type { User } from "../core/users.ts";
1819 import { createLog } from "../kernel/log.ts";
@@ -27,6 +28,7 @@ export type ReviewRequestError =
2728 | "not_open"
2829 | "agent_pull"
2930 | "held"
31 | "already_reviewed"
3032 | "no_reviewer"
3133 | "not_reviewer";
3234
@@ -56,6 +58,7 @@ export function requestReview(
5658 if (pull.state !== "open" || pull.mergedAt !== null) return err("not_open");
5759 if (pull.authorIsAgent) return err("agent_pull");
5860 if (getHold(app.db, pull.id) !== undefined) return err("held");
61 if (reviewedAlready(app, pull) !== null) return err("already_reviewed");
5962 const crew = reviewersOf(app.db, repo.id);
6063 if (crew.length === 0) return err("no_reviewer");
6164 let named: Agent | undefined;
@@ -83,6 +86,20 @@ export function requestReview(
8386 return ok({ request, reviewer: chosen.user.username });
8487 }
8588
89 /**
90 * The review that already asks for changes on this pull's head, or null (#18181): a head with one
91 * is not reviewed again until something is pushed.
92 */
93 export function reviewedAlready(app: App, pull: Pull): ReviewBrief | null {
94 return changesBrief(app.db, pull.id, pull.headOid);
95 }
96
97 /** The refusal's words: the state, when, who, the first lines, and what to do. */
98 export function alreadyReviewedWords(r: ReviewBrief): string {
99 const said = firstLines(r.body);
100 return `already reviewed: changes requested by ${r.reviewer} at ${r.at.slice(0, 16).replace("T", " ")} UTC${said === "" ? "" : `: ${said}`}. Push a change, then ask again.`;
101 }
102
86103 /** The crew reviewer an @mention in this text names, if one is. */
87104 export function mentionedReviewer(
88105 app: App,
src/contract/openapi/routes/getApiV1ReposOwnerNamePullsNumberReviews.ts +1 −1
@@ -1,4 +1,4 @@
11 import { ref, list } from "../schema_kit.ts";
22 import { REPO, type Route } from "../shared.ts";
33
4 export const route: Route = { method: "get", path: `${REPO}/pulls/{number}/reviews`, summary: "List a pull's line-anchored review comments", detail: "List a pull's line-anchored review comments, each with its `anchor` and whether it is `outdated`", auth: false, role: "anonymous", response: list(ref("ReviewComment")), refuses: [404] };
4 export const route: Route = { method: "get", path: `${REPO}/pulls/{number}/reviews`, summary: "List a pull's reviews with their line comments", detail: "List a pull's reviews, each with its state, reviewer, time and body, and its line comments under it (each with its `anchor` and whether it is `outdated`); a review with only a body is listed", auth: false, role: "anonymous", response: list(ref("ReviewWithLines")), refuses: [404] };
src/contract/openapi/schemas/pull.ts +36
@@ -67,6 +67,8 @@ const PULL_DETAIL: Schema = obj(
6767 approvedAt: orNull(str),
6868 approval: orNull(APPROVAL),
6969 approvedAgainst: orNull(str),
70 latestReview: orNull(ref("ReviewBrief")),
71 changesRequested: orNull(ref("ReviewBrief")),
7072 variantSiblings: list(int),
7173 mergeable: bool,
7274 conflicts: list(str),
@@ -172,6 +174,38 @@ const REVIEW_COMMENT: Schema = obj(
172174 ["untrusted"],
173175 );
174176
177 /**
178 * A review as a pull's answer carries it: the newest, or the one asking for changes on the head.
179 */
180 const REVIEW_BRIEF: Schema = obj({
181 id: str,
182 state: words("approved", "changes_requested", "commented"),
183 reviewer: str,
184 at: str,
185 body: str,
186 commit: str,
187 current: bool,
188 });
189
190 /**
191 * One review with its line comments under it; line comments given outside a review come as one with
192 * a null id.
193 */
194 const REVIEW_WITH_LINES: Schema = obj(
195 {
196 id: orNull(str),
197 state: words("approved", "changes_requested", "commented"),
198 reviewer: str,
199 at: str,
200 body: str,
201 commit: str,
202 current: bool,
203 comments: list(ref("ReviewComment")),
204 untrusted: str,
205 },
206 ["untrusted"],
207 );
208
175209 const CHECKS: Schema = obj(
176210 { head: str, state: str, required: bool, why: str, run: orNull(ref("Run")), looks: list(ref("Look")), runs: list(ref("Run")) },
177211 ["why"],
@@ -188,6 +222,8 @@ export const PULL_SCHEMAS: Readonly<Record<string, Schema>> = {
188222 FileChange: FILE_CHANGE,
189223 Review: REVIEW,
190224 ReviewComment: REVIEW_COMMENT,
225 ReviewBrief: REVIEW_BRIEF,
226 ReviewWithLines: REVIEW_WITH_LINES,
191227 Checks: CHECKS,
192228 PullStored: PULL_STORED,
193229 Merged: MERGED,
src/core/changes_words.ts added +5
@@ -0,0 +1,5 @@
1 /**
2 * The one wording for a pull that waits on its author after a changes-requested review. A leaf:
3 * core and flow both read it.
4 */
5 export const CHANGES = "waits on its author: changes requested";
src/core/landing.ts +2 −1
@@ -9,6 +9,7 @@
99 */
1010
1111 import type { Database } from "bun:sqlite";
12 import { CHANGES } from "./changes_words.ts";
1213 import type { App } from "../app.ts";
1314 import { isAncestor } from "../git/builds.ts";
1415 import { repoDir } from "../git/repos.ts";
@@ -180,7 +181,7 @@ export function waitsFor(f: StallFacts, now: Date = new Date()): WaitsFor | null
180181 case "person":
181182 return { cause: "person", says: `it waits for a person: ${f.next.why}`, action: "a person who writes the repository merges it or requests changes" };
182183 case "builder":
183 return { cause: "changes", says: "changes were asked on this head", action: "the builder pushes what the review asked" };
184 return { cause: "changes", says: CHANGES, action: "the builder pushes what the review asked" };
184185 case "reviewer":
185186 return { cause: "review", says: "it waits for review", action: "a reviewer reviews it on its current head" };
186187 case "queue":
src/core/review_list.ts added +84
@@ -0,0 +1,84 @@
1 /**
2 * A pull's reviews as a client reads them (#18181): the verdict with its reviewer, time and body,
3 * and the line comments under it. A review with only a body is a review: it is never left out
4 * because it anchored nothing to a line.
5 */
6
7 import type { Database } from "bun:sqlite";
8 import { listReviews, reviewsOnHead, type Review, type ReviewComment, type ReviewState } from "./reviews.ts";
9
10 export interface ReviewBrief {
11 readonly id: string;
12 readonly state: ReviewState;
13 readonly reviewer: string;
14 /** When it was given, ISO 8601 UTC. */
15 readonly at: string;
16 readonly body: string;
17 readonly commit: string;
18 /** Whether it was given on the head the pull stands at now. */
19 readonly current: boolean;
20 }
21
22 /** One review as the API says it; `current` compares its commit with `headOid`. */
23 export function reviewBrief(r: Review, headOid: string): ReviewBrief {
24 return {
25 id: r.id,
26 state: r.state,
27 reviewer: r.originAuthor ?? r.authorName,
28 at: r.createdAt,
29 body: r.body,
30 commit: r.commitOid,
31 current: r.commitOid === headOid,
32 };
33 }
34
35 /** The pull's newest review, as the API says it; null with none. */
36 export function latestBrief(db: Database, issueId: string, headOid: string): ReviewBrief | null {
37 const r = listReviews(db, issueId).at(-1);
38 return r === undefined ? null : reviewBrief(r, headOid);
39 }
40
41 /**
42 * The review asking for changes on `headOid` (a reviewer's current verdict there); null with none.
43 */
44 export function changesBrief(db: Database, issueId: string, headOid: string): ReviewBrief | null {
45 const r = reviewsOnHead(db, issueId, headOid).find((x) => x.state === "changes_requested");
46 return r === undefined ? null : reviewBrief(r, headOid);
47 }
48
49 /**
50 * A line comment holds no review id, so it goes under the review its author gave on the same
51 * commit nearest in time; one with no such review is left over.
52 */
53 export function underReviews<C extends ReviewComment>(
54 reviews: readonly Review[],
55 comments: readonly C[],
56 ): { readonly byReview: Map<string, C[]>; readonly loose: C[] } {
57 const byReview = new Map<string, C[]>();
58 const loose: C[] = [];
59 for (const c of comments) {
60 let best: Review | undefined;
61 let gap = Infinity;
62 for (const r of reviews) {
63 if (r.authorName !== c.authorName || r.commitOid !== c.commitOid) continue;
64 const d = Math.abs(Date.parse(r.createdAt) - Date.parse(c.createdAt));
65 if (d < gap) {
66 gap = d;
67 best = r;
68 }
69 }
70 if (best === undefined) loose.push(c);
71 else byReview.set(best.id, [...(byReview.get(best.id) ?? []), c]);
72 }
73 return { byReview, loose };
74 }
75
76 /** The first `n` non-empty lines of a review's body, for a refusal that quotes it. */
77 export function firstLines(body: string, n = 3): string {
78 return body
79 .split("\n")
80 .map((l) => l.trim())
81 .filter((l) => l !== "")
82 .slice(0, n)
83 .join(" / ");
84 }
src/flow/next_actor.ts +5 −1
@@ -5,6 +5,7 @@
55 */
66
77 import type { Database } from "bun:sqlite";
8 import { CHANGES } from "../core/changes_words.ts";
89 import { getHold } from "../core/holds.ts";
910 import type { Pull } from "../core/pulls.ts";
1011 import { checkSummary, type CheckSummary, type RunState } from "../core/runs.ts";
@@ -63,6 +64,9 @@ export function noQueueLands(repo: { readonly autonomy: string; readonly autonom
6364 return repo.autonomy !== "autonomous" || repo.autonomyBy === null;
6465 }
6566
67 /** The Next line for a head a reviewer sent back (#18181): the author is who acts. */
outdated

src/core/landing.ts:183 still says 'changes were asked on this head'. Use this one wording everywhere (and update docs/features/flow-waiting.md:27).

68 export { CHANGES };
69
6670 const WAITING = {
6771 none: "waiting for its check",
6872 queued: "its check is queued",
@@ -83,7 +87,7 @@ export function nextActor(i: NextInput): Next {
8387 return { who: "queue", why: WAITING[i.check] };
8488 }
8589 if (i.changesRequested > 0)
86 return { who: "builder", why: i.askedBy == null ? "changes were asked on this head" : `changes were asked on this head: ${i.askedBy}`, changes: true };
90 return { who: "builder", why: i.askedBy == null ? CHANGES : `${CHANGES}: ${i.askedBy}`, changes: true };
8791 if (i.check === "failed") return { who: "builder", why: "its check is red" };
8892 if (i.wall != null && i.wall.length > 0) return { who: "person", why: wallAsk(i.wall) };
8993 if (i.approvals > 0) {
src/flow/pull_pane.ts +2 −2
@@ -18,7 +18,7 @@ import { DRAFT_LINE, isTalkDraft, TALK_DRAFT_LINE, type Pull } from "../core/pul
1818 import type { Repo } from "../core/repos.ts";
1919 import { activeRunFor, checkSummary, type CheckSummary, type RunState } from "../core/runs.ts";
2020 import { queuePlace, type Place } from "../checks/place.ts";
21 import { nextOfPull, type Next } from "./next_actor.ts";
21 import { CHANGES, nextOfPull, type Next } from "./next_actor.ts";
2222 import { deployedSince } from "./path.ts";
2323 import { span } from "./pipeline.ts";
2424
@@ -121,7 +121,7 @@ export function paneOf(f: PaneFacts): Pane {
121121 return { state: "checking", tone: "attn", sentence: `Its check is queued${placeWords(c.place)}`, verbs: ["watch", "stop"], evidence: [] };
122122 const n = f.next;
123123 if (n !== null && n.changes === true && c.state !== "failed")
124 return { state: "changes", tone: "attn", sentence: cap(n.why.replace(/^changes were asked on this head: /, "")), verbs: [], evidence: [] };
124 return { state: "changes", tone: "attn", sentence: cap(n.why.replace(`${CHANGES}: `, "")), verbs: [], evidence: [] };
outdated

The regex copies the Next wording. Export the CHANGES constant from next_actor.ts and build the strip from it so the two cannot drift.

125125 if (c.state === "failed")
126126 return {
127127 state: "red",
src/http/api/pulls.ts +40 −22
@@ -8,6 +8,7 @@
88 */
99
1010 import { approvedAgainst } from "../../core/approval_at.ts";
11 import { changesBrief, latestBrief, reviewBrief, underReviews } from "../../core/review_list.ts";
1112 import { reviewsDemanded } from "../../crew/review.ts";
1213 import { pullWaitsFor } from "../../flow/waits_for.ts";
1314 import { parseAttestation } from "../../core/attestation.ts";
@@ -45,7 +46,7 @@ import { stepsWords } from "../../core/review_steps.ts";
4546 import { lookUrl } from "../../core/looks.ts";
4647 import { pullFit, pullLooks } from "../../looks/readable.ts";
4748 import { holdPull, releasePull } from "../../actions/holds.ts";
48 import { requestReview } from "../../actions/review_requests.ts";
49 import { alreadyReviewedWords, requestReview, reviewedAlready } from "../../actions/review_requests.ts";
4950 import { getHold, type Hold } from "../../core/holds.ts";
5051 import {
5152 getPull,
@@ -417,6 +418,10 @@ export function pullRoutes(router: Router<Handler>): void {
417418 approval: status.reviews?.approval ?? null,
418419 // The same approval as one line, "<head7> against <base7>" (null with none).
419420 approvedAgainst: approvedAgainst(status.reviews?.approval),
421 // The newest review, whatever its state or whether it has a line comment (#18181), and the
422 // one asking for changes on the head the pull stands at now (null with none).
423 latestReview: latestBrief(ctx.app.db, found.pull.id, status.headOid),
424 changesRequested: live ? changesBrief(ctx.app.db, found.pull.id, status.headOid) : null,
420425 variantSiblings: variantSiblings(ctx.app.db, [found.pull])[0] ?? [],
421426 ...(live ? { mergeable: status.mergeable, conflicts: status.conflicts } : {}),
422427 proposal: pullProposalOf(ctx.app.db, found.pull.id) ?? null,
@@ -587,11 +592,15 @@ export function pullRoutes(router: Router<Handler>): void {
587592 found.pull,
588593 str(input.reviewer),
589594 );
590 if (!asked.ok)
595 if (!asked.ok) {
596 const review = asked.error === "already_reviewed" ? reviewedAlready(ctx.app, found.pull) : null;
597 if (review !== null)
598 return json({ error: "already_reviewed", message: alreadyReviewedWords(review), review }, 409);
591599 return respondAccess(
592600 asked.error,
593601 asked.error === "not_open" || asked.error === "held" ? 409 : 422,
594602 );
603 }
595604 return json(
596605 {
597606 requested: true,
@@ -778,31 +787,40 @@ export function pullRoutes(router: Router<Handler>): void {
778787 const found = loadPull(ctx);
779788 if ("error" in found) return found.error;
780789 const marked = await timePhaseAsync(ctx.request, "reviews", async () => {
781 const { diff } = await pullDiff(
790 const { diff, status } = await pullDiff(
782791 await pullDirOf(ctx, found.repo, found.pull),
783792 found.pull,
784793 );
785 return withOutdated(
786 readerMarked(
787 ctx,
788 found.repo.id,
789 listReviewComments(ctx.app.db, found.pull.id),
790 ),
794 const comments = withOutdated(
795 readerMarked(ctx, found.repo.id, listReviewComments(ctx.app.db, found.pull.id)),
791796 diff,
792 );
797 ).map((c) => ({ ...c, anchor: anchorId(c.path, c.side, c.line) }));
798 return { comments, headOid: status.headOid };
799 });
800 // Reviews with their line comments under them (#18181): a review with only a body is one.
801 return timePhase(ctx.request, "render", () => {
802 const reviews = listReviews(ctx.app.db, found.pull.id);
803 const { byReview, loose } = underReviews(reviews, marked.comments);
804 const items = readerMarked(ctx, found.repo.id, reviews).map((r) => ({
805 ...reviewBrief(r, marked.headOid),
806 ...(r.untrusted === undefined ? {} : { untrusted: r.untrusted }),
807 comments: byReview.get(r.id) ?? [],
808 }));
809 // Line comments given outside any review keep a place, grouped by who left them.
810 const by = new Map<string, typeof loose>();
811 for (const c of loose) by.set(c.authorName, [...(by.get(c.authorName) ?? []), c]);
812 const alone = [...by].map(([reviewer, comments]) => ({
813 id: null,
814 state: "commented" as const,
815 reviewer,
816 at: comments[0]!.createdAt,
817 body: "",
818 commit: comments[0]!.commitOid,
819 current: comments[0]!.commitOid === marked.headOid,
820 comments,
821 }));
822 return json([...items, ...alone]);
793823 });
794 return timePhase(ctx.request, "render", () =>
795 json(
796 marked.map(
797 // The thread this comment belongs to, so a client can resolve it
798 // without reassembling the key itself.
799 (comment) => ({
800 ...comment,
801 anchor: anchorId(comment.path, comment.side, comment.line),
802 }),
803 ),
804 ),
805 );
806824 },
807825 );
808826
src/http/mcp/tools/request_review.ts +9 −5
@@ -1,10 +1,10 @@
1 import { requestReview } from "../../../actions/review_requests.ts";
1 import { alreadyReviewedWords, requestReview, reviewedAlready } from "../../../actions/review_requests.ts";
22 import { getPull } from "../../../core/pulls.ts";
33 import { good, bad, type Tool, str, APP_ARG, planRepo, isAnswer } from "../shared.ts";
44
55 export const tool: Tool = {
66 name: "request_review",
7 doc: "`{ app, pull, reviewer?, dryRun? }`: ask the crew to review a person's pull, by the reviewer named or the least busy; a person who can write, never an agent; plans unless `dryRun: false`",
7 doc: "`{ app, pull, reviewer?, dryRun? }`: ask the crew to review a person's pull, by the reviewer named or the least busy; a person who can write, never an agent; acts unless `dryRun: true`, which only plans",
88 description: "Ask the crew to review a person's pull: the reviewer named, else the least busy.",
99 inputSchema: {
1010 type: "object",
@@ -17,7 +17,7 @@ export const tool: Tool = {
1717 required: ["app", "pull"],
1818 },
1919 writes: true,
20 dryByDefault: true,
20 readsWhen: (args) => args["dryRun"] === true,
2121 run(ctx, user, args) {
2222 const repo = planRepo(ctx, user, args);
2323 if (isAnswer(repo)) return repo;
@@ -28,9 +28,13 @@ export const tool: Tool = {
2828 : undefined;
2929 if (pull === undefined)
3030 return bad("no_such_pull", `no pull #${String(n)}`);
31 const dry = args["dryRun"] !== false;
31 const dry = args["dryRun"] === true;
3232 const name = `${repo.ownerName}/${repo.name}#${pull.number}`;
3333 const asked = requestReview(ctx.app, user, repo, pull, str(args["reviewer"]), dry);
34 if (!asked.ok && asked.error === "already_reviewed") {
35 const review = reviewedAlready(ctx.app, pull);
36 if (review !== null) return bad("already_reviewed", alreadyReviewedWords(review));
37 }
3438 if (!asked.ok)
3539 return bad(
3640 asked.error,
@@ -48,7 +52,7 @@ export const tool: Tool = {
4852 );
4953 return good({
5054 says: dry
51 ? `Would ask ${asked.value.reviewer} to review ${name}. Nothing changed; send dryRun: false to do it.`
55 ? `Would ask ${asked.value.reviewer} to review ${name}. Nothing changed; leave out dryRun to do it.`
5256 : `Asked ${asked.value.reviewer} to review ${name}.`,
5357 reviewer: asked.value.reviewer,
5458 dryRun: dry,
src/tui/screens/pull.ts +5 −2
@@ -154,7 +154,7 @@ import { FINISH_REFUSALS, finishConflicts } from "../../actions/finish-conflicts
154154 import { PROPOSE_WHY, proposalOf, proposeResolution } from "../../crew/proposal.ts";
155155 import { conflictScreen } from "./conflicts.ts";
156156 import { reviewScreen } from "./review.ts";
157 import { requestReview } from "../../actions/review_requests.ts";
157 import { alreadyReviewedWords, requestReview, reviewedAlready } from "../../actions/review_requests.ts";
158158 import { RunList, maySteer, openRunLog, steerPrompt } from "./runlist.ts";
159159 import { runTone } from "./runwords.ts";
160160 import { Composer, threadLines, type ThreadEntry } from "./thread.ts";
@@ -1583,7 +1583,10 @@ export function pullScreen(
15831583 hint: "A reviewer's username. Enter asks; Esc cancels.",
15841584 onSubmit: (value) => {
15851585 const asked = requestReview(f.app, f.user, target, row, value.trim());
1586 if (!asked.ok) return errorText(asked.error);
1586 if (!asked.ok) {
1587 const review = asked.error === "already_reviewed" ? reviewedAlready(f.app, row) : null;
1588 return review === null ? errorText(asked.error) : alreadyReviewedWords(review);
1589 }
15871590 ctx.toast(`asked ${asked.value.reviewer} to review`, "success");
15881591 runAsync(ctx, reload);
15891592 return undefined;
src/web/studio/actions.ts +6 −4
@@ -14,7 +14,7 @@ import { COMPOSER_FIELDS, claimShare, refuseTell, releaseShare } from "../share_
1414 import { mayView } from "../../core/sealed.ts";
1515 import { shipsPastReviews } from "./land_as_is.ts";
1616 import { holdPull, releasePull } from "../../actions/holds.ts";
17 import { requestReview } from "../../actions/review_requests.ts";
17 import { alreadyReviewedWords, requestReview, reviewedAlready } from "../../actions/review_requests.ts";
1818 import { addComment } from "../../actions/issues.ts";
1919 import { overTellLimit, parseFrom, tellTooLongWords } from "../../actions/tell_from.ts";
2020 import { seatEmptyCrew } from "../../actions/seat_crew.ts";
@@ -538,9 +538,11 @@ export async function reviewRequestSubmit(ctx: Ctx): Promise<Response> {
538538 ? "That is not a reviewer on this crew."
539539 : asked.error === "held"
540540 ? "Release the hold first; no rule reviews a held change."
541 : asked.error === "agent_pull"
542 ? "The crew already reviews its own changes."
543 : "Only an open change can be reviewed.",
541 : asked.error === "already_reviewed"
542 ? ((r) => (r === null ? "Changes were already requested on this head. Push a change, then ask again." : alreadyReviewedWords(r)))(reviewedAlready(ctx.app, found.pull))
outdated

reviewedAlready(...)! can be null; this throws if the review is gone by now. Fall back to a plain sentence, and fix the indentation of the nested ternary.

543 : asked.error === "agent_pull"
544 ? "The crew already reviews its own changes."
545 : "Only an open change can be reviewed.",
544546 }),
545547 });
546548 }
test/api-reader-marks.test.ts +1 −1
@@ -212,7 +212,7 @@ describe("a reader's words over the API carry the brief's mark", () => {
212212 const verdicts = await get(`/pulls/${pullNumber}/review-states`);
213213 expect(first(verdicts, "mallory").untrusted).toBe(READER);
214214 expect(first(verdicts, "alice").untrusted).toBeUndefined();
215 const lines = await get(`/pulls/${pullNumber}/reviews`);
215 const lines = (await get(`/pulls/${pullNumber}/reviews`)).flatMap((r: { comments: Said[] }) => r.comments);
216216 expect(first(lines, "mallory").untrusted).toBe(READER);
217217 expect(first(lines, "alice").untrusted).toBeUndefined();
218218 });
test/next_actor.test.ts +4 −4
@@ -13,7 +13,7 @@ const base: NextInput = {
1313 const cases: [string, Partial<NextInput>, Actor, string][] = [
1414 ["held", { held: { by: "sam", why: "wait for legal" }, approvals: 1, check: "ok" }, "person", "sam holds it: wait for legal"],
1515 ["conflicted", { conflicted: true, approvals: 1, check: "ok" }, "builder", "it conflicts with its base"],
16 ["changes asked", { changesRequested: 1, check: "ok" }, "builder", "changes were asked on this head"],
16 ["changes asked", { changesRequested: 1, check: "ok" }, "builder", "waits on its author: changes requested"],
1717 ["red", { check: "failed", approvals: 1 }, "builder", "its check is red"],
1818 ["pushed since review", { pushedSince: 1, check: "ok" }, "reviewer", "pushed since the last review"],
1919 ["no review", { check: "running" }, "reviewer", "no review yet"],
@@ -24,12 +24,12 @@ const cases: [string, Partial<NextInput>, Actor, string][] = [
2424 ["approved, running", { approvals: 1, check: "running" }, "queue", "approved, its check is running"],
2525 // The access wall (#7847): a person decides, however approved and green.
2626 ["walled, approved and green", { approvals: 1, check: "ok", wall: ["anyone signed out could read pack records"] }, "person", "the access wall holds it for a person to decide: anyone signed out could read pack records. Allow it (merge) or send it back"],
27 ["walled, sent back", { approvals: 1, check: "ok", changesRequested: 1, wall: ["anyone signed out could read pack records"] }, "builder", "changes were asked on this head"],
27 ["walled, sent back", { approvals: 1, check: "ok", changesRequested: 1, wall: ["anyone signed out could read pack records"] }, "builder", "waits on its author: changes requested"],
2828 // Reviews off (#11666): nobody waits for a review, but a verdict on the head still counts.
2929 ["reviews off, green", { check: "ok", reviewOff: true }, "queue", "green, reviews are off: it lands"],
3030 ["reviews off, no check", { reviewOff: true }, "queue", "no check yet"],
3131 ["reviews off, running", { check: "running", reviewOff: true }, "queue", "its check is running"],
32 ["reviews off, changes asked", { changesRequested: 1, check: "ok", reviewOff: true }, "builder", "changes were asked on this head"],
32 ["reviews off, changes asked", { changesRequested: 1, check: "ok", reviewOff: true }, "builder", "waits on its author: changes requested"],
3333 ["reviews off, red", { check: "failed", reviewOff: true }, "builder", "its check is red"],
3434 // No queue lands where autonomy is off (#16452): a ready pull waits for a person's merge.
3535 ["person lands, approved, running", { approvals: 1, check: "running", personLands: true }, "queue", "approved, its check is running"],
@@ -40,7 +40,7 @@ describe("nextActor", () => {
4040 for (const [name, input, who, why] of cases)
4141 // A hold says so as a flag too (the pull pane reads it as its own state, flow/pull_pane.ts).
4242 test(name, () => {
43 const want: Next = name === "held" ? { who, why, held: true } : why.startsWith("changes were asked") ? { who, why, changes: true } : { who, why };
43 const want: Next = name === "held" ? { who, why, held: true } : why.startsWith("waits on its author") ? { who, why, changes: true } : { who, why };
4444 expect(nextActor({ ...base, ...input })).toEqual(want);
4545 });
4646 });
test/parity.test.ts +2 −2
@@ -641,7 +641,7 @@ describe("parity: full control through actions and the API", () => {
641641 "GET",
642642 `/api/v1/repos/alice/pub/pulls/${n}/reviews`,
643643 );
644 expect(reviews.list.map((r) => r.outdated)).toEqual([false, false]);
644 expect(reviews.list.flatMap((r: any) => r.comments).map((r: any) => r.outdated)).toEqual([false, false]);
645645
646646 // Rewrite line 2 on the head branch: the new-side comment goes stale, the
647647 // old-side one (anchored to base content) stays current.
@@ -654,7 +654,7 @@ describe("parity: full control through actions and the API", () => {
654654 },
655655 });
656656 reviews = await call("GET", `/api/v1/repos/alice/pub/pulls/${n}/reviews`);
657 expect(reviews.list.map((r) => [r.side, r.outdated])).toEqual([
657 expect(reviews.list.flatMap((r: any) => r.comments).map((r: any) => [r.side, r.outdated])).toEqual([
658658 ["new", true],
659659 ["old", false],
660660 ]);
test/pull-pane.test.ts +2 −2
@@ -101,7 +101,7 @@ test("each state says one sentence, offers at most three verbs from the map, and
101101 {
102102 ...base,
103103 check: check("ok"),
104 next: { who: "builder", why: "changes were asked on this head: juniper asked for changes (review 12)", changes: true },
104 next: { who: "builder", why: "waits on its author: changes requested: juniper asked for changes (review 12)", changes: true },
105105 },
106106 "Juniper asked for changes (review 12)",
107107 [],
@@ -157,7 +157,7 @@ test("the page draws each verb with its key from the map through its own door, a
157157 test("the changes state is the next actor's flag, not its wording: a reworded reason keeps it, the words alone do not make it", () => {
158158 const ok = { ...base, check: check("ok") };
159159 expect(paneOf({ ...ok, next: { who: "builder", why: "a reviewer wants another pass", changes: true } }).state).toBe("changes");
160 expect(paneOf({ ...ok, next: { who: "builder", why: "changes were asked on this head" } }).state).not.toBe("changes");
160 expect(paneOf({ ...ok, next: { who: "builder", why: "waits on its author: changes requested" } }).state).not.toBe("changes");
161161 });
162162
163163 let dir: string;
test/pull-waits-for.test.ts +1 −1
@@ -41,7 +41,7 @@ describe("waitsFor, from the facts", () => {
4141 [{ chapter: "outside Two: the crew builds only what the open chapter holds" }, "chapter", "Green for 7 hours, not landed: held by a chapter, outside Two: the crew builds only what the open chapter holds. To unblock: the owner opens the chapter its issue is in, or moves the issue into the open one."],
4242 [{ held: true, next: { who: "person", why: "alice holds it: wait for the demo" } }, "held", "Green for 7 hours, not landed: it is held: alice holds it: wait for the demo. To unblock: the holder releases the hold, or a writer merges it."],
4343 [{ next: { who: "person", why: "allow a new host" } }, "person", "Green for 7 hours, not landed: it waits for a person: allow a new host. To unblock: a person who writes the repository merges it or requests changes."],
44 [{ next: { who: "builder", why: "changes were asked on this head" } }, "changes", "Green for 7 hours, not landed: changes were asked on this head. To unblock: the builder pushes what the review asked."],
44 [{ next: { who: "builder", why: "x" } }, "changes", "Green for 7 hours, not landed: waits on its author: changes requested. To unblock: the builder pushes what the review asked."],
4545 ];
4646 for (const [over, cause, line] of cases) {
4747 const w = waitsFor(facts(over), NOW);
test/review-request.test.ts +52 −3
@@ -30,6 +30,7 @@ import { pullScreen } from "../src/tui/screens/pull.ts";
3030 import { local } from "../src/tui/screens/where.ts";
3131 import { headlessTerminal } from "../src/tui/term/terminal.ts";
3232 import { settleApp } from "./helpers/tui.ts";
33 import { nextOfPull } from "../src/flow/next_actor.ts";
3334 import { sweepReviews, waitsForReviewer } from "../src/crew/review.ts";
3435
3536 describe("asking the crew to review", () => {
@@ -269,15 +270,15 @@ describe("asking the crew to review", () => {
269270 );
270271 expect(typeof ((await res2.json()) as any).reviewer).toBe("string");
271272
272 // MCP: a plan by default, a read-only token may plan, the ask on dryRun: false.
273 // MCP: it asks by default; `dryRun: true` plans, and a read-only token may only plan.
273274 const viaMcp = await greenPull("by-mcp");
274275 const args = { app: "alice/engine", pull: viaMcp.number, reviewer: "mason" };
275 const planned = await mcp(args, ro);
276 const planned = await mcp({ ...args, dryRun: true }, ro);
276277 expect(planned.value.says).toContain("Would ask mason");
277278 expect(getReviewRequest(app.db, viaMcp.id)).toBeUndefined();
278279 expect((await mcp({ ...args, reviewer: "nobody" })).error).toContain("not_reviewer");
279280 expect((await mcp({ ...args, pull: 999 })).error).toContain("no_such_pull");
280 const done = await mcp({ ...args, dryRun: false });
281 const done = await mcp(args);
281282 expect(done.value.says).toBe(`Asked mason to review alice/engine#${viaMcp.number}.`);
282283 expect(getReviewRequest(app.db, viaMcp.id)!.reviewerId).toBe(mason.id);
283284
@@ -307,4 +308,52 @@ describe("asking the crew to review", () => {
307308 servers.stop();
308309 }
309310 });
311
312 test("a changes-requested review with only a body is found in the pull, the reviews list and the repeat ask (#18181)", async () => {
313 const servers: Servers = await serve(app);
314 try {
315 const rw = createToken(app.db, alice.id, "t18181", "rw").token;
316 const get = async (path: string) =>
317 (await fetch(`${servers.url}/api/v1/repos/alice/engine${path}`, { headers: { authorization: `Bearer ${rw}` } })).json() as Promise<any>;
318 const pull = await greenPull("body-only");
319 const sent = submitReview(app.db, {
320 issueId: pull.id,
321 authorId: quill.id,
322 state: "changes_requested",
323 body: "HIGH: the engine drops the last frame.\nMEDIUM: no test.",
324 commitOid: pull.headOid,
325 });
326 expect(sent.ok).toBe(true);
327
328 const detail = await get(`/pulls/${pull.number}?diff=0`);
329 expect(detail.latestReview).toMatchObject({ state: "changes_requested", reviewer: "quill", current: true });
330 expect(detail.latestReview.body).toContain("HIGH");
331 expect(detail.changesRequested.reviewer).toBe("quill");
332
333 const list = await get(`/pulls/${pull.number}/reviews`);
334 expect(list).toHaveLength(1);
335 expect(list[0]).toMatchObject({ state: "changes_requested", reviewer: "quill", comments: [] });
336 expect(list[0].body).toContain("drops the last frame");
337
338 const again = await fetch(`${servers.url}/api/v1/repos/alice/engine/pulls/${pull.number}/review-requests`, {
339 method: "POST",
340 headers: { authorization: `Bearer ${rw}`, "content-type": "application/json" },
341 body: "{}",
342 });
343 expect(again.status).toBe(409);
344 const refused = (await again.json()) as any;
345 expect(refused.error).toBe("already_reviewed");
346 expect(refused.message).toContain("changes requested by quill");
347 expect(refused.message).toContain("HIGH: the engine drops the last frame.");
348 expect(refused.message).toContain("Push a change, then ask again.");
349 expect(refused.review.state).toBe("changes_requested");
350
351 expect(nextOfPull(app.db, pull, { headOid: pull.headOid, conflicts: 0 }, fresh())!).toMatchObject({
352 who: "builder",
353 why: expect.stringContaining("waits on its author: changes requested"),
354 });
355 } finally {
356 servers.stop();
357 }
358 });
310359 });
test/reviews-states.test.ts +8 −6
@@ -492,9 +492,11 @@ describe("review states, and the merge they gate", () => {
492492 );
493493 expect(comment.status).toBe(201);
494494
495 const comments = await read<{ anchor: string }[]>(
496 await as("ada", "GET", `/api/v1/repos/acme/lib/pulls/${number}/reviews`),
497 );
495 const comments = (
496 await read<{ comments: { anchor: string }[] }[]>(
497 await as("ada", "GET", `/api/v1/repos/acme/lib/pulls/${number}/reviews`),
498 )
499 ).flatMap((r) => r.comments);
498500 const anchor = comments[0]!.anchor;
499501 expect(anchor).toMatch(/^[0-9a-f]{16}$/);
500502
@@ -568,9 +570,9 @@ describe("review states, and the merge they gate", () => {
568570 })
569571 ).status,
570572 ).toBe(201);
571 const [first] = await read<{ anchor: string }[]>(
572 await as("ada", "GET", `${pull}/reviews`),
573 );
573 const [first] = (
574 await read<{ comments: { anchor: string }[] }[]>(await as("ada", "GET", `${pull}/reviews`))
575 ).flatMap((r) => r.comments);
574576 expect(
575577 (await as("ada", "POST", `${pull}/threads/${first!.anchor}/resolve`, {}))
576578 .status,

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs