Public: anyone can read this; the crew can change it.
Three review rounds on one pull without an approval hand it to a person in one card #1300
scout/forge:scout/1176-three-review-rounds-on-one-pull-without → main 5 commits fork 2 threads · 2 unresolved
6 files
changed +307
−25
README.md +12
| @@ -325,6 +325,18 @@ changes, a line comment — and the agent picks it up in the background, | ||
| 325 | 325 | resuming its session. A failed check re-engages it too, a bounded number of |
| 326 | 326 | times before a person must speak. |
| 327 | 327 | |
| 328 | **Three rounds, then a person.** When the crew reviewer has asked for | |
| 329 | changes three times on one pull with no approval and no word from a person | |
| 330 | who may direct the crew between, no more feedback runs start on it. The | |
| 331 | thread keeps a note ("Handed to a person by the crew:") with the three | |
| 332 | asks, and the pull becomes a **hand-over** card in asks: *Tell them what to | |
| 333 | try*, or *Close it*. Rounds are counted from the reviews, not the runs, so a | |
| 334 | restart never adds one. A person resets the count by commenting as a | |
| 335 | director (the crew then resumes) or by approving the pull from its page; the | |
| 336 | card ends when the pull is approved, closed or merged. Hand-overs can be | |
| 337 | closed in bulk like the other pull asks; the terminal screens do not list | |
| 338 | asks cards, so they show the thread note only. | |
| 339 | ||
| 328 | 340 | **Already done.** A builder that finds its issue already built on the base |
| 329 | 341 | branch declines with `DECLINED: already done on main in <commit>`, naming the |
| 330 | 342 | full or abbreviated id of each commit that did it (at most five). The forge |
src/crew/dispatch.ts +31 −18
| @@ -35,9 +35,6 @@ import { getRepoById, type Repo } from "../core/repos.ts"; | ||
| 35 | 35 | import { listReviews } from "../core/reviews.ts"; |
| 36 | 36 | import { |
| 37 | 37 | greenHead, |
| 38 | handedToPerson, | |
| 39 | handoverNote, | |
| 40 | reviewRounds, | |
| 41 | 38 | sendToReview, |
| 42 | 39 | } from "./review.ts"; |
| 43 | 40 | import { |
| @@ -52,7 +49,7 @@ import { | ||
| 52 | 49 | listQueued, |
| 53 | 50 | type Run, |
| 54 | 51 | } from "../core/runs.ts"; |
| 55 | import { getUserById } from "../core/users.ts"; | |
| 52 | import { getUserById, type User } from "../core/users.ts"; | |
| 56 | 53 | import { createLog } from "../kernel/log.ts"; |
| 57 | 54 | import { issueOfBranch, type RunReason } from "./brief.ts"; |
| 58 | 55 | import { detectClaude } from "./claude.ts"; |
| @@ -61,6 +58,10 @@ import { breakerTripped } from "./breaker.ts"; | ||
| 61 | 58 | import { |
| 62 | 59 | CAP_NOTE, |
| 63 | 60 | capReached, |
| 61 | HANDOVER_NOTE, | |
| 62 | handoverNote, | |
| 63 | handoverOf, | |
| 64 | type Handover, | |
| 64 | 65 | ISSUE_RUN_CAP, |
| 65 | 66 | recordCap, |
| 66 | 67 | skipsFeedback, |
| @@ -248,6 +249,25 @@ export async function startCrew( | ||
| 248 | 249 | return handle; |
| 249 | 250 | } |
| 250 | 251 | |
| 252 | /** Say the hand-over on the pull's thread, once per hand-over. */ | |
| 253 | function handOver( | |
| 254 | app: App, | |
| 255 | repo: Repo, | |
| 256 | issue: Issue, | |
| 257 | by: User, | |
| 258 | over: Handover, | |
| 259 | ): void { | |
| 260 | const said = listComments(app.db, issue.id).some( | |
| 261 | (c) => c.body.startsWith(HANDOVER_NOTE) && c.createdAt >= over.at, | |
| 262 | ); | |
| 263 | if (said) return; | |
| 264 | addComment(app, by, repo, issue, handoverNote(over)); | |
| 265 | log.info("handed to a person after three reviews", { | |
| 266 | repo: `${repo.ownerName}/${repo.name}`, | |
| 267 | pull: issue.number, | |
| 268 | }); | |
| 269 | } | |
| 270 | ||
| 251 | 271 | /** Queue a run about an issue for an agent, unless one is already waiting. */ |
| 252 | 272 | export function queueAgentRun( |
| 253 | 273 | app: App, |
| @@ -446,20 +466,13 @@ function route(app: App, event: ForgeEvent): void { | ||
| 446 | 466 | } |
| 447 | 467 | // The crew is off: a verdict is read by people, and wakes no one. |
| 448 | 468 | if (reviewerVerdict && repo.autonomy === "off") return; |
| 449 | if (reviewerVerdict) { | |
| 450 | // The loop is bounded: the third round hands the pull to a person. | |
| 451 | const pull = getPull(app.db, repo.id, number); | |
| 452 | if (pull && handedToPerson(app.db, repo.id, pull)) { | |
| 453 | // One card: a re-sent verdict does not post a second. | |
| 454 | const last = listComments(app.db, issue.id, { kind: "comment" }).at(-1); | |
| 455 | if (!last?.body.startsWith("Handed to a person")) | |
| 456 | addComment( | |
| 457 | app, | |
| 458 | actor, | |
| 459 | repo, | |
| 460 | issue, | |
| 461 | handoverNote(reviewRounds(app.db, repo.id, pull)), | |
| 462 | ); | |
| 469 | // The third changes-requested with no approval or person's word | |
| 470 | // between is a person's to answer: one card on the pull, and no | |
| 471 | // feedback run, now or for the verdicts after (`guard.ts`). | |
| 472 | if (reviewerVerdict && event.payload["state"] === "changes_requested") { | |
| 473 | const over = handoverOf(app.db, repo, issue.id); | |
| 474 | if (over !== undefined) { | |
| 475 | handOver(app, repo, issue, actor, over); | |
| 463 | 476 | return; |
| 464 | 477 | } |
| 465 | 478 | } |
src/crew/guard.ts +95
| @@ -176,3 +176,98 @@ export function guardCounts( | ||
| 176 | 176 | rows.find((r) => r.answer === answer)?.n ?? 0; |
| 177 | 177 | return { skipped: of("skipped"), capped: of("capped") }; |
| 178 | 178 | } |
| 179 | ||
| 180 | /** Crew `changes_requested` verdicts on one pull, with no approval or person's word between, before it is a person's. */ | |
| 181 | export const HANDOVER_ROUNDS = 3; | |
| 182 | ||
| 183 | /** What the hand-over card starts with: the thread's own record of it, and what `handover` ignores as a person's word. */ | |
| 184 | export const HANDOVER_NOTE = "Handed to a person by the crew:"; | |
| 185 | ||
| 186 | export interface Handover { | |
| 187 | /** The crew reviewer's verdicts that asked for changes, oldest first. */ | |
| 188 | readonly reviews: readonly { id: string; author: string; body: string; at: string }[]; | |
| 189 | /** When the third one landed: the card's age. */ | |
| 190 | readonly at: string; | |
| 191 | } | |
| 192 | ||
| 193 | /** | |
| 194 | * Whether `pullId` has had `HANDOVER_ROUNDS` crew `changes_requested` verdicts | |
| 195 | * since the last approval or the last word of a person who may direct the | |
| 196 | * crew. Counted from the verdict rows, never the runs: a run a restart | |
| 197 | * repeats is one verdict. | |
| 198 | */ | |
| 199 | export function handoverOf( | |
| 200 | db: Database, | |
| 201 | repo: Repo, | |
| 202 | pullId: string, | |
| 203 | ): Handover | undefined { | |
| 204 | // The common pull has fewer than three crew verdicts: one cheap count | |
| 205 | // answers it before the approval, comment and director lookups. | |
| 206 | const crewAsked = db | |
| 207 | .query<{ n: number }, [string, string]>( | |
| 208 | `SELECT COUNT(*) AS n FROM review r | |
| 209 | JOIN repo_crew c ON c.user_id = r.author_id AND c.repo_id = ?2 | |
| 210 | WHERE r.issue_id = ?1 AND r.state = 'changes_requested' AND c.role = 'reviewer'`, | |
| 211 | ) | |
| 212 | .get(pullId, repo.id)!.n; | |
| 213 | if (crewAsked < HANDOVER_ROUNDS) return undefined; | |
| 214 | const approved = | |
| 215 | db | |
| 216 | .query<{ at: string | null }, [string]>( | |
| 217 | "SELECT MAX(created_at) AS at FROM review WHERE issue_id = ?1 AND state = 'approved'", | |
| 218 | ) | |
| 219 | .get(pullId)?.at ?? ""; | |
| 220 | const spoke = db | |
| 221 | .query<{ id: string; at: string }, [string]>( | |
| 222 | `SELECT author_id AS id, MAX(created_at) AS at FROM comment | |
| 223 | WHERE issue_id = ?1 AND origin_author IS NULL AND kind != 'review' | |
| 224 | AND body NOT LIKE '${HANDOVER_NOTE}%' | |
| 225 | GROUP BY author_id`, | |
| 226 | ) | |
| 227 | .all(pullId); | |
| 228 | const directors = new Set( | |
| 229 | directorsAmong( | |
| 230 | db, | |
| 231 | repo, | |
| 232 | spoke.map((s) => s.id), | |
| 233 | ), | |
| 234 | ); | |
| 235 | const since = spoke | |
| 236 | .filter((s) => directors.has(s.id)) | |
| 237 | .map((s) => s.at) | |
| 238 | .reduce((a, b) => (a > b ? a : b), approved); | |
| 239 | const rounds = db | |
| 240 | .query< | |
| 241 | { id: string; author: string; body: string; at: string }, | |
| 242 | [string, string, string] | |
| 243 | >( | |
| 244 | `SELECT r.id AS id, u.username AS author, r.body AS body, r.created_at AS at | |
| 245 | FROM review r JOIN user u ON u.id = r.author_id | |
| 246 | JOIN repo_crew c ON c.user_id = r.author_id AND c.repo_id = ?3 | |
| 247 | WHERE r.issue_id = ?1 AND r.state = 'changes_requested' | |
| 248 | AND r.created_at > ?2 AND c.role = 'reviewer' | |
| 249 | ORDER BY r.created_at, r.id`, | |
| 250 | ) | |
| 251 | .all(pullId, since, repo.id); | |
| 252 | if (rounds.length < HANDOVER_ROUNDS) return undefined; | |
| 253 | return { reviews: rounds, at: rounds[HANDOVER_ROUNDS - 1]!.at }; | |
| 254 | } | |
| 255 | ||
| 256 | /** One line per review, for the card and the thread: who asked, and the first line of what. */ | |
| 257 | export function handoverLines(h: Handover): string[] { | |
| 258 | return h.reviews.slice(0, HANDOVER_ROUNDS).map((r, n) => { | |
| 259 | const first = (r.body.split("\n").find((l) => l.trim() !== "") ?? "no words") | |
| 260 | .trim() | |
| 261 | .slice(0, 140); | |
| 262 | return `${n + 1}. ${r.author}: ${first}`; | |
| 263 | }); | |
| 264 | } | |
| 265 | ||
| 266 | /** The note the pull's thread keeps of the hand-over. */ | |
| 267 | export function handoverNote(h: Handover): string { | |
| 268 | return [ | |
| 269 | `${HANDOVER_NOTE} the reviewer asked for changes three times with no approval between, so no more feedback runs start here until you say what to try.`, | |
| 270 | "", | |
| 271 | ...handoverLines(h), | |
| 272 | ].join("\n"); | |
| 273 | } |
src/web/studio/asks.ts +49 −6
| @@ -47,6 +47,7 @@ import { | ||
| 47 | 47 | } from "../../crew/autonomy.ts"; |
| 48 | 48 | import { breakerParked, WAITING_NOTES } from "../../crew/breaker.ts"; |
| 49 | 49 | import { CHECK_FAILED_LIMIT } from "../../crew/dispatch.ts"; |
| 50 | import { handoverLines, handoverOf, type Handover } from "../../crew/guard.ts"; | |
| 50 | 51 | import { isStalePull, mergesAgainSince } from "../../crew/stale_asks.ts"; |
| 51 | 52 | import { waitsForPerson, type ReviewWait } from "../../crew/review.ts"; |
| 52 | 53 | import type { Ctx } from "../../http/context.ts"; |
| @@ -94,7 +95,7 @@ export function writableAppsOf(ctx: Ctx, user: User | undefined) { | ||
| 94 | 95 | ); |
| 95 | 96 | } |
| 96 | 97 | |
| 97 | export type DecisionKind = "stopped" | "look" | "review" | "paused" | "parked" | "declined"; | |
| 98 | export type DecisionKind = "stopped" | "look" | "review" | "paused" | "parked" | "declined" | "handover"; | |
| 98 | 99 | |
| 99 | 100 | /** Dollars as a person reads them: cents when small, whole when not. */ |
| 100 | 101 | const dollars = (n: number): string => (n < 10 ? n.toFixed(2) : n.toFixed(0)); |
| @@ -150,6 +151,11 @@ export const ASK_WORDS: Readonly<Record<DecisionKind, AskWords>> = { | ||
| 150 | 151 | options: ["Tell them"], |
| 151 | 152 | ifNothing: "nothing more starts on it", |
| 152 | 153 | }, |
| 154 | handover: { | |
| 155 | decision: "The reviewer asked for changes three times: what should the builder try?", | |
| 156 | options: ["Tell them what to try", "Close it"], | |
| 157 | ifNothing: "no more feedback runs start; the pull waits for you", | |
| 158 | }, | |
| 153 | 159 | declined: { |
| 154 | 160 | decision: "The planner declined the direction: answer it?", |
| 155 | 161 | options: ["Answer the planner"], |
| @@ -179,6 +185,7 @@ export const KIND_TIER: Readonly<Record<DecisionKind, Consequence>> = { | ||
| 179 | 185 | declined: { score: 70, why: "the planner has stopped for this app" }, |
| 180 | 186 | stopped: { score: 50, why: "red, and the crew stopped" }, |
| 181 | 187 | review: { score: 45, why: "an agent's change waits for a review" }, |
| 188 | handover: { score: 55, why: "three reviews without an approval: handed to a person" }, | |
| 182 | 189 | parked: { score: 40, why: "parked by the crew" }, |
| 183 | 190 | look: { score: 30, why: "green, waiting" }, |
| 184 | 191 | }; |
| @@ -221,6 +228,8 @@ interface AskCandidate { | ||
| 221 | 228 | readonly stoppedByDecider?: boolean; |
| 222 | 229 | /** For "declined": the declining run and what the planner said. */ |
| 223 | 230 | readonly decline?: { readonly runId: string; readonly words: string }; |
| 231 | /** For "handover": the reviews that asked for changes. */ | |
| 232 | readonly handover?: Handover; | |
| 224 | 233 | } |
| 225 | 234 | |
| 226 | 235 | /** |
| @@ -270,6 +279,22 @@ function askCandidatesFor( | ||
| 270 | 279 | const who = issue.authorName; |
| 271 | 280 | // The crew is on it: that is working, not a question for a person. |
| 272 | 281 | if (activeRunFor(db, "agent", issue.id) !== undefined) continue; |
| 282 | // Three reviews without an approval: the crew stopped, and says so | |
| 283 | // before anything about the check (`guard.ts`). | |
| 284 | const over = handoverOf(db, repo, issue.id); | |
| 285 | if (over !== undefined) { | |
| 286 | out.push({ | |
| 287 | kind: "handover", | |
| 288 | id: `handover:${pull.id}`, | |
| 289 | since: over.at, | |
| 290 | repo, | |
| 291 | pull, | |
| 292 | who, | |
| 293 | authorIsAgent: issue.authorIsAgent, | |
| 294 | handover: over, | |
| 295 | }); | |
| 296 | continue; | |
| 297 | } | |
| 273 | 298 | if (check?.state === "failed") { |
| 274 | 299 | // Automatic retries, and the limit that stops them, are the crew's |
| 275 | 300 | // own machinery — a person's own failing pull never accrues tries, |
| @@ -553,14 +578,14 @@ function waitingOn( | ||
| 553 | 578 | } |
| 554 | 579 | |
| 555 | 580 | /** How an ask that is no longer asked ended, when nobody dismissed it. */ |
| 556 | function endOf( | |
| 581 | export function endOf( | |
| 557 | 582 | db: Database, |
| 558 | 583 | viewerId: string, |
| 559 | 584 | askId: string, |
| 560 | 585 | raisedAt: string, |
| 561 | 586 | ): Exclude<AskEnd, "dismissed"> { |
| 562 | 587 | const [kind, what] = askId.split(":") as [DecisionKind, string]; |
| 563 | if (kind === "look" || kind === "review" || kind === "stopped") { | |
| 588 | if (kind === "look" || kind === "review" || kind === "stopped" || kind === "handover") { | |
| 564 | 589 | const pull = getIssueById(db, what); |
| 565 | 590 | // Shipped or closed: someone decided. Held by the one it asked: they |
| 566 | 591 | // answered "not yet". Still open otherwise: the cause went away. |
| @@ -638,6 +663,8 @@ function lineOf(c: AskCandidate): string { | ||
| 638 | 663 | return `the crew parked #${c.issue!.number} after three failed runs`; |
| 639 | 664 | if (c.kind === "declined") |
| 640 | 665 | return "the planner declined the direction and waits for you"; |
| 666 | if (c.kind === "handover") | |
| 667 | return `"${c.pull?.title ?? ""}" had three reviews asking for changes and waits for you`; | |
| 641 | 668 | const title = c.pull?.title ?? ""; |
| 642 | 669 | if (c.kind === "review") |
| 643 | 670 | return `"${title}" waits for your review: ${reviewWhy(c.reviewWait)}`; |
| @@ -662,6 +689,7 @@ export const ROW_PLURAL: Readonly<Record<DecisionKind, (n: number) => string>> = | ||
| 662 | 689 | review: (n) => `${n} agent changes wait for your review`, |
| 663 | 690 | stopped: (n) => `the crew stopped on ${n} changes`, |
| 664 | 691 | parked: (n) => `the crew parked ${n} issues after three failed runs`, |
| 692 | handover: (n) => `${n} changes had three reviews asking for changes and wait for you`, | |
| 665 | 693 | declined: (n) => `the planner declined ${n} times and waits for you`, |
| 666 | 694 | paused: (n) => `${n} pauses at the ceiling`, |
| 667 | 695 | }; |
| @@ -790,6 +818,16 @@ export function decisionsFor( | ||
| 790 | 818 | says: `The planner declined the direction: \u201c${c.decline.words}\u201d. It plans nothing more until you answer on #${c.issue.number}.`, |
| 791 | 819 | short: `the planner declined the direction: \u201c${c.decline.words}\u201d`, |
| 792 | 820 | }; |
| 821 | if (c.kind === "handover" && c.pull && c.handover) | |
| 822 | return { | |
| 823 | kind: "handover", | |
| 824 | id: `handover:${c.pull.id}`, | |
| 825 | repo: c.repo, | |
| 826 | pull: c.pull, | |
| 827 | who: c.who, | |
| 828 | says: `The reviewer asked for changes three times with no approval between, so the crew stopped. ${handoverLines(c.handover).join(" ")} Say what to try (or approve it on its page), or close it.`, | |
| 829 | short: `"${c.pull.title}" had three reviews asking for changes`, | |
| 830 | }; | |
| 793 | 831 | if (c.kind === "stopped" && c.pull) { |
| 794 | 832 | const tries = c.tries ?? 0; |
| 795 | 833 | const stopped = c.stoppedByDecider ?? false; |
| @@ -861,7 +899,7 @@ export function decisionForm(d: Decision): Html | null { | ||
| 861 | 899 | if (pull === undefined) return null; |
| 862 | 900 | const base = repoBase(d.repo); |
| 863 | 901 | const own = html`id="${askFormId(d)}" method="post" hidden`; |
| 864 | if (d.kind === "stopped") | |
| 902 | if (d.kind === "stopped" || d.kind === "handover") | |
| 865 | 903 | return html`<form ${own} action="${base}/pulls/${pull.number}/state"> |
| 866 | 904 | <input type="hidden" name="state" value="closed" /> |
| 867 | 905 | </form>`; |
| @@ -893,7 +931,7 @@ export function decisionButtons(ctx: Ctx, d: Decision): { primary: Html; others: | ||
| 893 | 931 | : getAppByRepo(ctx.app.db, d.repo.id) === undefined |
| 894 | 932 | ? undefined |
| 895 | 933 | : `${base}/app/pull-${pull.number}/open`; |
| 896 | if (d.kind === "stopped" && pull) | |
| 934 | if ((d.kind === "stopped" || d.kind === "handover") && pull) | |
| 897 | 935 | return { |
| 898 | 936 | primary: btn("Tell them", { |
| 899 | 937 | href: `${changeHref(base, pull.number)}#comment-body`, |
| @@ -1002,7 +1040,12 @@ export function asksAnswer(ctx: Ctx, user: User) { | ||
| 1002 | 1040 | */ |
| 1003 | 1041 | export function askItemsOf(issue: Issue): string[] { |
| 1004 | 1042 | return issue.kind === "pull" |
| 1005 | ? [`ask:look:${issue.id}`, `ask:review:${issue.id}`, `ask:stopped:${issue.id}`] | |
| 1043 | ? [ | |
| 1044 | `ask:look:${issue.id}`, | |
| 1045 | `ask:review:${issue.id}`, | |
| 1046 | `ask:stopped:${issue.id}`, | |
| 1047 | `ask:handover:${issue.id}`, | |
| 1048 | ] | |
| 1006 | 1049 | : [`ask:parked:${issue.id}`]; |
| 1007 | 1050 | } |
| 1008 | 1051 |
src/web/studio/asks_page.ts +2 −1
| @@ -51,7 +51,7 @@ const ASK_KIND_WORDS: Readonly<Record<string, string>> = { | ||
| 51 | 51 | }; |
| 52 | 52 | |
| 53 | 53 | /** The kinds a bulk action takes: a ceiling and a planner's decline are decided where they live. */ |
| 54 | const BULK_KINDS: ReadonlySet<Decision["kind"]> = new Set(["look", "review", "stopped", "parked"]); | |
| 54 | const BULK_KINDS: ReadonlySet<Decision["kind"]> = new Set(["look", "review", "stopped", "handover", "parked"]); | |
| 55 | 55 | |
| 56 | 56 | /** A row's box for the bulk form, which sits apart (`form="asks-bulk"`): forms do not nest. */ |
| 57 | 57 | const pick = (d: Decision, picked: ReadonlySet<string>): Html | null => |
| @@ -153,6 +153,7 @@ const KIND_LABEL: Readonly<Record<Decision["kind"], string>> = { | ||
| 153 | 153 | look: "Ready to ship", |
| 154 | 154 | review: "Needs review", |
| 155 | 155 | stopped: "Stopped", |
| 156 | handover: "Handed over", | |
| 156 | 157 | parked: "Parked", |
| 157 | 158 | declined: "Declined", |
| 158 | 159 | paused: "Paused", |
test/crew-loop.test.ts +118
| @@ -25,6 +25,9 @@ import { serve, type Servers } from "../src/http/server.ts"; | ||
| 25 | 25 | import { driveRepo, settleAgentRun } from "../src/crew/autonomy.ts"; |
| 26 | 26 | import { startCrew, queueAgentRun, type CrewHandle } from "../src/crew/dispatch.ts"; |
| 27 | 27 | import { getAgent } from "../src/core/agents.ts"; |
| 28 | import type { Ctx } from "../src/http/context.ts"; | |
| 29 | import { setIssueState } from "../src/actions/issues.ts"; | |
| 30 | import { ASK_WORDS, KIND_TIER, askLinesFor, decisionActions, decisionForm, decisionsFor, endOf } from "../src/web/studio/asks.ts"; | |
| 28 | 31 | import { breakerParked, breakerTripped } from "../src/crew/breaker.ts"; |
| 29 | 32 | |
| 30 | 33 | describe("an agent's own comment never starts its next run", () => { |
| @@ -384,4 +387,119 @@ describe("a crew reviewer's changes-requested wakes the builder", () => { | ||
| 384 | 387 | await settle(); |
| 385 | 388 | expect(feedback(pull).length).toBe(0); |
| 386 | 389 | }); |
| 390 | ||
| 391 | /** The builder's queued follow-ups end, so each round is counted on its own. */ | |
| 392 | const settleFeedback = (pull: Pull) => { | |
| 393 | for (const r of feedback(pull)) { | |
| 394 | claimRun(app.db, r.id); | |
| 395 | finishRun(app.db, r.id, { state: "ok", summary: "Pushed a fix." }); | |
| 396 | } | |
| 397 | }; | |
| 398 | const verdict = async (pull: Pull, body: string, state = "changes_requested") => { | |
| 399 | await submitReview(app, sentinel, fresh(), pull, { | |
| 400 | state: state as "changes_requested", | |
| 401 | body, | |
| 402 | }); | |
| 403 | await settle(); | |
| 404 | }; | |
| 405 | const handoverNotes = (pull: Pull) => | |
| 406 | listComments(app.db, pull.id).filter((c) => | |
| 407 | c.body.startsWith("Handed to a person by the crew:"), | |
| 408 | ); | |
| 409 | ||
| 410 | test("the third changes-requested hands the pull to a person; a fourth queues nothing", async () => { | |
| 411 | const set = await updateRepoSettings(app, alice, fresh(), { | |
| 412 | autonomy: "autonomous", | |
| 413 | autonomyCeilingUsd: 100, | |
| 414 | autonomyBy: alice.id, | |
| 415 | }); | |
| 416 | if (!set.ok) throw new Error(JSON.stringify(set.error)); | |
| 417 | const pull = await masonPull("rounds"); | |
| 418 | await verdict(pull, "Round one: the token is logged."); | |
| 419 | expect(feedback(pull).length).toBe(1); | |
| 420 | settleFeedback(pull); | |
| 421 | await verdict(pull, "Round two: still logged."); | |
| 422 | expect(feedback(pull).length).toBe(2); | |
| 423 | settleFeedback(pull); | |
| 424 | expect(handoverNotes(pull).length).toBe(0); | |
| 425 | await verdict(pull, "Round three: and the retry loops."); | |
| 426 | expect(feedback(pull).length).toBe(2); | |
| 427 | const notes = handoverNotes(pull); | |
| 428 | expect(notes.length).toBe(1); | |
| 429 | expect(notes[0]!.body).toContain("1. sentinel: Round one"); | |
| 430 | expect(notes[0]!.body).toContain("3. sentinel: Round three"); | |
| 431 | // Not parked, not closed: it is still open and asks a person. | |
| 432 | expect(getIssueById(app.db, pull.id)!.state).toBe("open"); | |
| 433 | const asked = askLinesFor(app.db, alice).filter((a) => a.kind === "handover"); | |
| 434 | expect(asked.length).toBe(1); | |
| 435 | expect(asked[0]!.number).toBe(pull.number); | |
| 436 | await verdict(pull, "Round four."); | |
| 437 | expect(feedback(pull).length).toBe(2); | |
| 438 | expect(handoverNotes(pull).length).toBe(1); | |
| 439 | }); | |
| 440 | ||
| 441 | test("a person's comment resets the count", async () => { | |
| 442 | const pull = await masonPull("reset-comment"); | |
| 443 | await verdict(pull, "One."); | |
| 444 | settleFeedback(pull); | |
| 445 | await verdict(pull, "Two."); | |
| 446 | settleFeedback(pull); | |
| 447 | await verdict(pull, "Three."); | |
| 448 | expect(handoverNotes(pull).length).toBe(1); | |
| 449 | addComment(app, alice, fresh(), getIssueById(app.db, pull.id)!, "Try the other way."); | |
| 450 | await settle(); | |
| 451 | settleFeedback(pull); | |
| 452 | expect(askLinesFor(app.db, alice).some((a) => a.number === pull.number && a.kind === "handover")).toBe(false); | |
| 453 | const before = feedback(pull).length; | |
| 454 | await verdict(pull, "Four, a new first round."); | |
| 455 | expect(feedback(pull).length).toBe(before + 1); | |
| 456 | }); | |
| 457 | ||
| 458 | test("an approval resets the count", async () => { | |
| 459 | const pull = await masonPull("reset-approval"); | |
| 460 | await verdict(pull, "One."); | |
| 461 | settleFeedback(pull); | |
| 462 | await verdict(pull, "Two."); | |
| 463 | settleFeedback(pull); | |
| 464 | await verdict(pull, "Fine now.", "approved"); | |
| 465 | await verdict(pull, "Three."); | |
| 466 | expect(handoverNotes(pull).length).toBe(0); | |
| 467 | }); | |
| 468 | test("the hand-over card offers three words, a close and a way to speak; closing or approving ends it", async () => { | |
| 469 | const pull = await masonPull("card"); | |
| 470 | await verdict(pull, "One."); | |
| 471 | settleFeedback(pull); | |
| 472 | await verdict(pull, "Two."); | |
| 473 | settleFeedback(pull); | |
| 474 | await verdict(pull, "Three."); | |
| 475 | expect(ASK_WORDS.handover.options).toEqual(["Tell them what to try", "Close it"]); | |
| 476 | expect(KIND_TIER.handover).toBeDefined(); | |
| 477 | const ctx = { | |
| 478 | app, | |
| 479 | request: new Request("http://forge.test/"), | |
| 480 | url: new URL("http://forge.test/"), | |
| 481 | params: {}, | |
| 482 | auth: { user: alice, scope: undefined, via: "session" }, | |
| 483 | theme: undefined, | |
| 484 | } as Ctx; | |
| 485 | const card = decisionsFor(ctx, [fresh()]).find((d) => d.kind === "handover"); | |
| 486 | expect(card?.pull?.number).toBe(pull.number); | |
| 487 | expect(card!.consequence.why).toBe(KIND_TIER.handover.why); | |
| 488 | expect(card!.says).toContain("Say what to try"); | |
| 489 | expect(askLinesFor(app.db, alice).find((a) => a.kind === "handover")!.words).toEqual(ASK_WORDS.handover); | |
| 490 | const form = String(decisionForm(card!)); | |
| 491 | expect(form).toContain(`/pulls/${pull.number}/state`); | |
| 492 | expect(form).toContain('value="closed"'); | |
| 493 | const actions = String(decisionActions(ctx, card!)); | |
| 494 | expect(actions).toContain("Tell them"); | |
| 495 | expect(actions).toContain("Close"); | |
| 496 | expect(actions).not.toContain("Approve"); | |
| 497 | const ask = `handover:${pull.id}`; | |
| 498 | const raised = new Date(0).toISOString(); | |
| 499 | expect(endOf(app.db, alice.id, ask, raised)).toBe("expired"); | |
| 500 | await verdict(pull, "Fine now.", "approved"); | |
| 501 | expect(askLinesFor(app.db, alice).some((a) => a.number === pull.number && a.kind === "handover")).toBe(false); | |
| 502 | await setIssueState(app, alice, fresh(), getIssueById(app.db, pull.id)!, "closed"); | |
| 503 | expect(endOf(app.db, alice.id, ask, raised)).toBe("acted"); | |
| 504 | }); | |
| 387 | 505 | }); |
new above
offline
Four queries per call, and it is called for every open pull on every asks build. Return early on a cheap count of crew changes_requested rows (<3) before the comment and director lookups.