Public: anyone can read this; the crew can change it.
A changes-requested pull always moves: the requested pass reassigns it to its builder, as the steward has had to by hand #2852
mason/forge:mason/2847-a-changes-requested-pull-always-moves-th → main 2 commits fork
8 files
changed +244
−47
src/core/requested.ts +40 −6
| @@ -21,6 +21,8 @@ export interface RequestedPull { | ||
| 21 | 21 | readonly pullId: string; |
| 22 | 22 | readonly number: number; |
| 23 | 23 | readonly headOid: string; |
| 24 | /** The verdict itself. */ | |
| 25 | readonly reviewId: string; | |
| 24 | 26 | /** The head the verdict was passed on. */ |
| 25 | 27 | readonly reviewedOid: string; |
| 26 | 28 | readonly reviewerId: string; |
| @@ -30,12 +32,21 @@ export interface RequestedPull { | ||
| 30 | 32 | |
| 31 | 33 | /** Oldest verdict first; one repository's when `repoId` is given, else every one's. */ |
| 32 | 34 | export function requestedPulls(db: Database, repoId?: string): RequestedPull[] { |
| 33 | return db | |
| 34 | .query<RequestedPull, [string | null]>( | |
| 35 | return requestedQuery(db).all(repoId ?? null, null); | |
| 36 | } | |
| 37 | ||
| 38 | /** The one pull's row, when its crew reviewer's latest word asks for changes. */ | |
| 39 | export function requestedPull(db: Database, pullId: string): RequestedPull | undefined { | |
| 40 | return requestedQuery(db).get(null, pullId) ?? undefined; | |
| 41 | } | |
| 42 | ||
| 43 | const requestedQuery = (db: Database) => | |
| 44 | db | |
| 45 | .query<RequestedPull, [string | null, string | null]>( | |
| 35 | 46 | `SELECT i.repo_id AS repoId, o.username || '/' || r.name AS repo, |
| 36 | 47 | r.visibility = 'public' AS isPublic, |
| 37 | 48 | i.id AS pullId, i.number AS number, p.head_oid AS headOid, |
| 38 | v.commit_oid AS reviewedOid, v.author_id AS reviewerId, v.created_at AS at | |
| 49 | v.id AS reviewId, v.commit_oid AS reviewedOid, v.author_id AS reviewerId, v.created_at AS at | |
| 39 | 50 | FROM issue i JOIN pull p ON p.issue_id = i.id |
| 40 | 51 | JOIN repo r ON r.id = i.repo_id JOIN user o ON o.id = r.owner_id |
| 41 | 52 | JOIN review v ON v.id = ( |
| @@ -46,11 +57,34 @@ export function requestedPulls(db: Database, repoId?: string): RequestedPull[] { | ||
| 46 | 57 | WHERE i.kind = 'pull' AND i.state = 'open' AND p.merged_at IS NULL |
| 47 | 58 | AND v.state = 'changes_requested' |
| 48 | 59 | AND (?1 IS NULL OR i.repo_id = ?1) |
| 60 | AND (?2 IS NULL OR i.id = ?2) | |
| 49 | 61 | ORDER BY v.created_at, i.number`, |
| 50 | ) | |
| 51 | .all(repoId ?? null); | |
| 52 | } | |
| 62 | ); | |
| 53 | 63 | |
| 54 | 64 | /** Whether a push has come since the verdict: the reviewer owes the next word, not the builder. */ |
| 55 | 65 | export const verdictIsStale = (p: RequestedPull): boolean => |
| 56 | 66 | p.reviewedOid !== p.headOid; |
| 67 | ||
| 68 | /** A run that answered a verdict on the head it was passed on, which is still the head: so it pushed nothing. */ | |
| 69 | export interface Unanswered { | |
| 70 | readonly actorId: string | null; | |
| 71 | readonly summary: string; | |
| 72 | } | |
| 73 | ||
| 74 | /** | |
| 75 | * The runs other than a review that started on the pull after the verdict | |
| 76 | * at `at` and ended, oldest first (#2847). Read while the verdict is on the | |
| 77 | * head, each is a run that ended without a push. A follow-up skipped for | |
| 78 | * having nothing new never ran, and is not one. | |
| 79 | */ | |
| 80 | export function unansweredRuns(db: Database, pullId: string, at: string): Unanswered[] { | |
| 81 | return db | |
| 82 | .query<Unanswered, [string, string]>( | |
| 83 | `SELECT actor_id AS actorId, summary FROM run | |
| 84 | WHERE issue_id = ?1 AND kind = 'agent' AND reason != 'review' | |
| 85 | AND created_at > ?2 AND state IN ('ok','failed') | |
| 86 | AND summary NOT LIKE 'skipped: %' | |
| 87 | ORDER BY created_at, id`, | |
| 88 | ) | |
| 89 | .all(pullId, at); | |
| 90 | } |
src/crew/autonomy.ts +14 −4
| @@ -85,6 +85,7 @@ import { | ||
| 85 | 85 | } from "./dispatch.ts"; |
| 86 | 86 | import { getUserById, type User } from "../core/users.ts"; |
| 87 | 87 | import { grantedAccounts } from "../core/subscriptions.ts"; |
| 88 | import { requestedPull, unansweredRuns, verdictIsStale } from "../core/requested.ts"; | |
| 88 | 89 | import { reviewSummary } from "../core/reviews.ts"; |
| 89 | 90 | import { standing } from "../core/standing.ts"; |
| 90 | 91 | import { pace, type Pace } from "./pacing.ts"; |
| @@ -111,7 +112,7 @@ import { | ||
| 111 | 112 | markReaders, |
| 112 | 113 | } from "./direct.ts"; |
| 113 | 114 | import { crewOffInPreview } from "./preview.ts"; |
| 114 | import { moveRequested } from "./requested.ts"; | |
| 115 | import { moveRequested, requestedWords, UNANSWERED_RUNS } from "./requested.ts"; | |
| 115 | 116 | import { reviewersOf, sendToReview, sweepReviews } from "./review.ts"; |
| 116 | 117 | |
| 117 | 118 | const log = createLog("autonomy"); |
| @@ -922,8 +923,10 @@ function noteAlreadyDone( | ||
| 922 | 923 | /** |
| 923 | 924 | * A builder's run on its pull that ended without a push while the crew's |
| 924 | 925 | * reviewer still asks for changes on the head: the request was not |
| 925 | * answered, and nothing will answer it. The pull is parked rather than | |
| 926 | * left waiting on a verdict that will not move. | |
| 926 | * answered. The crew reviewer's verdict gets one more run, told what this | |
| 927 | * one answered (`requested.ts`, #2847); once that is spent too, nothing | |
| 928 | * will answer it, and the pull is parked rather than left waiting on a | |
| 929 | * verdict that will not move. | |
| 927 | 930 | */ |
| 928 | 931 | function answeredWithoutChange( |
| 929 | 932 | app: App, |
| @@ -938,6 +941,13 @@ function answeredWithoutChange( | ||
| 938 | 941 | if (!pull || pull.mergedAt !== null) return false; |
| 939 | 942 | if (reviewSummary(app.db, pull.id, pull.headOid).changesRequested === 0) |
| 940 | 943 | return false; |
| 944 | const requested = requestedPull(app.db, pull.id); | |
| 945 | if ( | |
| 946 | requested !== undefined && | |
| 947 | !verdictIsStale(requested) && | |
| 948 | unansweredRuns(app.db, pull.id, requested.at).length < UNANSWERED_RUNS | |
| 949 | ) | |
| 950 | return false; | |
| 941 | 951 | return parkPull( |
| 942 | 952 | app, |
| 943 | 953 | repo, |
| @@ -1140,7 +1150,7 @@ export async function autonomyTick( | ||
| 1140 | 1150 | ...(requested.length === 0 |
| 1141 | 1151 | ? {} |
| 1142 | 1152 | : { |
| 1143 | requested: `${requested.filter((m) => m.did !== "not moved").length}/${requested.length} moved`, | |
| 1153 | requested: requestedWords(requested), | |
| 1144 | 1154 | }), |
| 1145 | 1155 | spent: `${status.spentTodayUsd.toFixed(2)}/${status.ceilingUsd}`, |
| 1146 | 1156 | ...(status.paused === null ? {} : { paused: status.paused }), |
src/crew/brief.ts +19 −2
| @@ -14,7 +14,7 @@ import type { Pull } from "../core/pulls.ts"; | ||
| 14 | 14 | import { OUTSIDE_LABEL, OUTSIDE_TITLE, saysOutside } from "../core/reports.ts"; |
| 15 | 15 | import type { Repo } from "../core/repos.ts"; |
| 16 | 16 | import { READER } from "./direct.ts"; |
| 17 | import { newsSince } from "./news.ts"; | |
| 17 | import { newsSince, type UnansweredVerdict } from "./news.ts"; | |
| 18 | 18 | import { |
| 19 | 19 | REVIEW_ROUNDS, |
| 20 | 20 | type Review, |
| @@ -195,6 +195,8 @@ export interface TaskInput extends BriefInput { | ||
| 195 | 195 | | undefined; |
| 196 | 196 | /** For `review`: the pull's diff against its base, capped. */ |
| 197 | 197 | readonly reviewDiff?: string | undefined; |
| 198 | /** For feedback on a pull: the verdict the last run left without a push (`news.ts`). */ | |
| 199 | readonly unanswered?: UnansweredVerdict | undefined; | |
| 198 | 200 | /** For `review`: the change touches `src/web/`, so the review is held to docs/DESIGN.md. */ |
| 199 | 201 | readonly design?: boolean | undefined; |
| 200 | 202 | /** For `review`: an earlier review run on this pull ended with no verdict. */ |
| @@ -504,10 +506,25 @@ function taskBody(input: TaskInput): string { | ||
| 504 | 506 | out.push(`- ${c.path}:${c.line} — ${said(c.authorName)}: ${oneLine(c.body)}`); |
| 505 | 507 | } |
| 506 | 508 | for (const c of news.comments) out.push("", quote(c.authorName, c.body)); |
| 509 | const unanswered = input.unanswered; | |
| 510 | const heard = news.comments.length + news.reviews.length + news.lines.length > 0; | |
| 511 | // Asked again, with what the last run said instead of pushing (#2847). | |
| 512 | if (unanswered !== undefined && !heard) | |
| 513 | out.push( | |
| 514 | "", | |
| 515 | `${said(unanswered.reviewer)} requested changes on this head${unanswered.body.trim() === "" ? "." : ":"}`, | |
| 516 | ...(unanswered.body.trim() === "" ? [] : [indent(unanswered.body)]), | |
| 517 | "", | |
| 518 | "Your last run on it ended without a push, answering:", | |
| 519 | indent(unanswered.answer.trim() || "(nothing)"), | |
| 520 | "", | |
| 521 | "This is the one more run the verdict gets: push the changes it asks for, or, if you are sure it is wrong, say exactly why in your last message. After this run the pull waits for a person.", | |
| 522 | ); | |
| 507 | 523 | // A hand-over is the news, in words, whether or not anyone wrote. |
| 508 | 524 | if (handed.length > 0) out.push("", ...handed); |
| 509 | 525 | if ( |
| 510 | news.comments.length + news.reviews.length + news.lines.length === 0 && | |
| 526 | !heard && | |
| 527 | unanswered === undefined && | |
| 511 | 528 | handed.length === 0 && |
| 512 | 529 | input.paused !== true |
| 513 | 530 | ) { |
src/crew/news.ts +41 −2
| @@ -3,7 +3,8 @@ | ||
| 3 | 3 | * since the agent's last run on the task began that are not its own. The brief |
| 4 | 4 | * quotes exactly these, and a feedback run with none is not started — the |
| 5 | 5 | * agent would only read its own reply as the newest word and decline, at |
| 6 | * full price. One rule, asked by the brief and by the dispatcher. | |
| 6 | * full price. One rule, asked by the brief and by the dispatcher. A | |
| 7 | * verdict the last run left unanswered is news to one more (#2847). | |
| 7 | 8 | */ |
| 8 | 9 | |
| 9 | 10 | import type { Database } from "bun:sqlite"; |
| @@ -11,6 +12,7 @@ import type { Agent } from "../core/agents.ts"; | ||
| 11 | 12 | import { getIssue, listComments, type Issue } from "../core/issues.ts"; |
| 12 | 13 | import { getPull } from "../core/pulls.ts"; |
| 13 | 14 | import type { Repo } from "../core/repos.ts"; |
| 15 | import { requestedPull, unansweredRuns, verdictIsStale } from "../core/requested.ts"; | |
| 14 | 16 | import { listReviewComments, listReviews } from "../core/reviews.ts"; |
| 15 | 17 | import { issueOfBranch } from "./brief.ts"; |
| 16 | 18 | |
| @@ -138,6 +140,42 @@ export function plannerNothingNew( | ||
| 138 | 140 | return (moved?.n ?? 0) === 0; |
| 139 | 141 | } |
| 140 | 142 | |
| 143 | /** A verdict one run since has left unanswered, as the next run is told it again. */ | |
| 144 | export interface UnansweredVerdict { | |
| 145 | readonly reviewer: string; | |
| 146 | readonly body: string; | |
| 147 | /** What that run said instead of pushing: its reply on the pull, else its summary. */ | |
| 148 | readonly answer: string; | |
| 149 | } | |
| 150 | ||
| 151 | /** | |
| 152 | * The crew reviewer's verdict asking for changes on the pull's head, when | |
| 153 | * exactly one run since ended without a push (#2847). It is news once more: | |
| 154 | * one more run is told it with what the last one answered, and after that | |
| 155 | * run it is a person's (`crew/requested.ts`). | |
| 156 | */ | |
| 157 | export function unansweredVerdict( | |
| 158 | db: Database, | |
| 159 | issue: Issue, | |
| 160 | ): UnansweredVerdict | undefined { | |
| 161 | if (issue.kind !== "pull") return undefined; | |
| 162 | const requested = requestedPull(db, issue.id); | |
| 163 | if (requested === undefined || verdictIsStale(requested)) return undefined; | |
| 164 | const runs = unansweredRuns(db, issue.id, requested.at); | |
| 165 | if (runs.length !== 1) return undefined; | |
| 166 | const verdict = listReviews(db, issue.id).find((r) => r.id === requested.reviewId); | |
| 167 | if (verdict === undefined) return undefined; | |
| 168 | const run = runs[0]!; | |
| 169 | const reply = listComments(db, issue.id, { kind: "comment" }) | |
| 170 | .filter((c) => c.authorId === run.actorId && c.createdAt > requested.at) | |
| 171 | .at(-1); | |
| 172 | return { | |
| 173 | reviewer: verdict.authorName, | |
| 174 | body: verdict.body, | |
| 175 | answer: reply?.body ?? run.summary, | |
| 176 | }; | |
| 177 | } | |
| 178 | ||
| 141 | 179 | /** Whether a feedback run of `agent` on `issue` would find nothing new to act on. */ |
| 142 | 180 | export function nothingNew( |
| 143 | 181 | db: Database, |
| @@ -153,5 +191,6 @@ export function nothingNew( | ||
| 153 | 191 | since: feedbackSince(db, repo, issue, agent), |
| 154 | 192 | agentName: agent.user.username, |
| 155 | 193 | }); |
| 156 | return news.comments.length + news.reviews.length + news.lines.length === 0; | |
| 194 | if (news.comments.length + news.reviews.length + news.lines.length > 0) return false; | |
| 195 | return unansweredVerdict(db, issue) === undefined; | |
| 157 | 196 | } |
src/crew/requested.ts +38 −20
| @@ -8,10 +8,12 @@ | ||
| 8 | 8 | * is asked again. The verdict was about code that is no longer there, |
| 9 | 9 | * so it never blocks; a head that was never sent is sent however long |
| 10 | 10 | * it has been green (`sendToReview`'s `stale`). |
| 11 | * - On the current head, with no run in flight on the pull and none | |
| 12 | * started since the verdict: a feedback run is queued to the pull's | |
| 13 | * builder, one being assigned when the pull has none. One run per pull, | |
| 14 | * and each takes a builder slot — `free` is how many the tick has. | |
| 11 | * - On the current head, with no run in flight on the pull: a feedback | |
| 12 | * run is queued to the pull's builder, one being assigned when the pull | |
| 13 | * has none. A run since the verdict that ended without a push gets one | |
| 14 | * more, told the verdict and what it answered (`news.ts`); a second and | |
| 15 | * the pull waits for a person (#2847). One run per pull, and each takes | |
| 16 | * a builder slot — `free` is how many the tick has. | |
| 15 | 17 | * |
| 16 | 18 | * Every pull it passes over gets one line saying why, said once until the |
| 17 | 19 | * reason changes, so a stall is never silent and never a flood. |
| @@ -24,7 +26,12 @@ import { getHold } from "../core/holds.ts"; | ||
| 24 | 26 | import { getIssueById } from "../core/issues.ts"; |
| 25 | 27 | import { getPull } from "../core/pulls.ts"; |
| 26 | 28 | import type { Repo } from "../core/repos.ts"; |
| 27 | import { requestedPulls, verdictIsStale, type RequestedPull } from "../core/requested.ts"; | |
| 29 | import { | |
| 30 | requestedPulls, | |
| 31 | unansweredRuns, | |
| 32 | verdictIsStale, | |
| 33 | type RequestedPull, | |
| 34 | } from "../core/requested.ts"; | |
| 28 | 35 | import { reviewSummary } from "../core/reviews.ts"; |
| 29 | 36 | import { activeRunFor } from "../core/runs.ts"; |
| 30 | 37 | import { getUserById } from "../core/users.ts"; |
| @@ -36,6 +43,11 @@ import { pickBuilder } from "./route.ts"; | ||
| 36 | 43 | |
| 37 | 44 | const log = createLog("crew"); |
| 38 | 45 | |
| 46 | /** Runs a verdict on the head gets that end without a push before a person has it (#2847). */ | |
| 47 | export const UNANSWERED_RUNS = 2; | |
| 48 | ||
| 49 | const WAITS_FOR_A_PERSON = `${UNANSWERED_RUNS} runs since the verdict ended without a push; waits for a person`; | |
| 50 | ||
| 39 | 51 | /** What the tick did with one pull: moved it, or why not. */ |
| 40 | 52 | export type RequestedMove = |
| 41 | 53 | | { readonly pull: number; readonly did: "asked reviewer" } |
| @@ -82,6 +94,23 @@ export async function moveRequested( | ||
| 82 | 94 | return moves; |
| 83 | 95 | } |
| 84 | 96 | |
| 97 | /** | |
| 98 | * The tick line's count: what moved out of how many, and why the rest did | |
| 99 | * not, most first — `2/8 moved; 5 handed to a person after the review | |
| 100 | * rounds, 1 a run is in flight`. A pull that waits for a person is not a | |
| 101 | * stall, and the line says which it is. | |
| 102 | */ | |
| 103 | export function requestedWords(moves: readonly RequestedMove[]): string { | |
| 104 | const why = new Map<string, number>(); | |
| 105 | for (const m of moves) if (m.did === "not moved") why.set(m.why, (why.get(m.why) ?? 0) + 1); | |
| 106 | const moved = `${moves.length - [...why.values()].reduce((a, b) => a + b, 0)}/${moves.length} moved`; | |
| 107 | if (why.size === 0) return moved; | |
| 108 | const rest = [...why] | |
| 109 | .sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])) | |
| 110 | .map(([w, n]) => `${n} ${w}`); | |
| 111 | return `${moved}; ${rest.join(", ")}`; | |
| 112 | } | |
| 113 | ||
| 85 | 114 | const notMoved = (p: RequestedPull, why: string): RequestedMove => ({ |
| 86 | 115 | pull: p.number, |
| 87 | 116 | did: "not moved", |
| @@ -132,8 +161,10 @@ function followUp( | ||
| 132 | 161 | return notMoved(requested, "past the review rounds; the verdict is advice"); |
| 133 | 162 | if (activeRunFor(app.db, "agent", pull.id) !== undefined) |
| 134 | 163 | return notMoved(requested, "a run is in flight"); |
| 135 | if (startedSince(app, pull.id, requested.at)) | |
| 136 | return notMoved(requested, "a run since the verdict ended without a push"); | |
| 164 | // One run that ended without a push gets one more, told the verdict and | |
| 165 | // its own answer (`news.ts`); after that the pull is a person's (#2847). | |
| 166 | if (unansweredRuns(app.db, pull.id, requested.at).length >= UNANSWERED_RUNS) | |
| 167 | return notMoved(requested, WAITS_FOR_A_PERSON); | |
| 137 | 168 | if (builders.length === 0) return notMoved(requested, "no builder on the crew"); |
| 138 | 169 | const assignee = issue.assigneeId; |
| 139 | 170 | let builder = builders.find((b) => b.user.id === assignee); |
| @@ -168,19 +199,6 @@ function followUp( | ||
| 168 | 199 | }; |
| 169 | 200 | } |
| 170 | 201 | |
| 171 | /** Whether a run other than a review started on the pull after the verdict. */ | |
| 172 | function startedSince(app: App, pullId: string, at: string): boolean { | |
| 173 | return ( | |
| 174 | app.db | |
| 175 | .query<{ n: number }, [string, string]>( | |
| 176 | `SELECT COUNT(*) AS n FROM run WHERE issue_id = ?1 AND kind = 'agent' | |
| 177 | AND reason != 'review' AND created_at > ?2 | |
| 178 | AND summary NOT LIKE 'skipped: %'`, | |
| 179 | ) | |
| 180 | .get(pullId, at)!.n > 0 | |
| 181 | ); | |
| 182 | } | |
| 183 | ||
| 184 | 202 | /** A move is always said; a why-not once, until it changes. */ |
| 185 | 203 | function say(repo: Repo, requested: RequestedPull, move: RequestedMove): void { |
| 186 | 204 | const where = { repo: `${repo.ownerName}/${repo.name}`, pull: requested.number }; |
src/crew/runner.ts +3 −1
| @@ -138,7 +138,7 @@ import { grantSecrets, parseDeclaration, type Grant } from "./grant.ts"; | ||
| 138 | 138 | import { historyHolds, scrubTree } from "./leak.ts"; |
| 139 | 139 | import { workdirFor } from "./workdir.ts"; |
| 140 | 140 | import { readersAmong, voiceOf } from "./direct.ts"; |
| 141 | import { feedbackSince } from "./news.ts"; | |
| 141 | import { feedbackSince, unansweredVerdict } from "./news.ts"; | |
| 142 | 142 | import { handedOverPulls, SKIP_SUMMARY, skipsFeedback } from "./guard.ts"; |
| 143 | 143 | import { passportEnv } from "./passport_env.ts"; |
| 144 | 144 | |
| @@ -942,6 +942,8 @@ async function work( | ||
| 942 | 942 | ), |
| 943 | 943 | ), |
| 944 | 944 | since, |
| 945 | unanswered: | |
| 946 | reason === "feedback" && pull ? unansweredVerdict(app.db, issue) : undefined, | |
| 945 | 947 | checkSummary: failedCheck?.run?.summary, |
| 946 | 948 | resolution: |
| 947 | 949 | reason === "resolve" && pull |
test/requested.test.ts +72 −6
| @@ -11,10 +11,11 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 11 | 11 | import { tmpdir } from "node:os"; |
| 12 | 12 | import { join } from "node:path"; |
| 13 | 13 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; |
| 14 | import { addComment } from "../src/actions/issues.ts"; | |
| 14 | 15 | import { openPull } from "../src/actions/pulls.ts"; |
| 15 | 16 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 16 | 17 | import { createApp, type App } from "../src/app.ts"; |
| 17 | import { setCrewRole } from "../src/core/agents.ts"; | |
| 18 | import { getAgent, setCrewRole } from "../src/core/agents.ts"; | |
| 18 | 19 | import { getIssueById } from "../src/core/issues.ts"; |
| 19 | 20 | import { getPull, type Pull } from "../src/core/pulls.ts"; |
| 20 | 21 | import { getRepoById, type Repo } from "../src/core/repos.ts"; |
| @@ -22,7 +23,9 @@ import { submitReview } from "../src/core/reviews.ts"; | ||
| 22 | 23 | import { claimRun, createRun, finishRun, listRuns } from "../src/core/runs.ts"; |
| 23 | 24 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; |
| 24 | 25 | import { autonomyTick } from "../src/crew/autonomy.ts"; |
| 25 | import { moveRequested } from "../src/crew/requested.ts"; | |
| 26 | import { moveRequested, requestedWords } from "../src/crew/requested.ts"; | |
| 27 | import { unansweredVerdict } from "../src/crew/news.ts"; | |
| 28 | import { taskPrompt } from "../src/crew/brief.ts"; | |
| 26 | 29 | import { requestedSays, requestedWaits } from "../src/flow/requested.ts"; |
| 27 | 30 | import { serve, type Servers } from "../src/http/server.ts"; |
| 28 | 31 | import { createToken } from "../src/core/tokens.ts"; |
| @@ -119,6 +122,14 @@ describe("a pull with changes requested always moves", () => { | ||
| 119 | 122 | app.db.query("UPDATE issue SET assignee_id = NULL WHERE id = ?1").run(pull.id); |
| 120 | 123 | return pull; |
| 121 | 124 | }; |
| 125 | /** Every agent run in flight ends as having answered without a push. */ | |
| 126 | const endRuns = (summary: string) => | |
| 127 | app.db | |
| 128 | .query( | |
| 129 | `UPDATE run SET state = 'ok', summary = ?1, started_at = created_at, finished_at = created_at | |
| 130 | WHERE kind = 'agent' AND state IN ('queued','running')`, | |
| 131 | ) | |
| 132 | .run(summary); | |
| 122 | 133 | const clearRuns = () => |
| 123 | 134 | app.db.query("UPDATE run SET state = 'ok' WHERE kind = 'agent' AND state IN ('queued','running')").run(); |
| 124 | 135 | |
| @@ -215,14 +226,66 @@ describe("a pull with changes requested always moves", () => { | ||
| 215 | 226 | did: "not moved", |
| 216 | 227 | why: "a run is in flight", |
| 217 | 228 | }); |
| 218 | // A run that answered nothing is not asked again. | |
| 219 | clearRuns(); | |
| 229 | // A run that ended without a push gets one more, told the verdict and its answer (#2847). | |
| 230 | endRuns("no changes pushed: I think it is fine"); | |
| 231 | addComment(app, builder, fresh(), getIssueById(app.db, pull.id)!, "I think it is fine as it is."); | |
| 232 | expect(unansweredVerdict(app.db, getIssueById(app.db, pull.id)!)).toEqual({ | |
| 233 | reviewer: "quill", | |
| 234 | body: "Fix the one thing.", | |
| 235 | answer: "I think it is fine as it is.", | |
| 236 | }); | |
| 237 | const retry = await moveRequested(app, fresh(), 1); | |
| 238 | expect(retry.find((m) => m.pull === pull.number)?.did).toBe("queued feedback"); | |
| 239 | expect(runs(pull, "feedback")).toHaveLength(2); | |
| 240 | // ...once: a second one that ends without a push leaves it to a person. | |
| 241 | endRuns("no changes pushed: still fine"); | |
| 242 | expect(unansweredVerdict(app.db, getIssueById(app.db, pull.id)!)).toBeUndefined(); | |
| 220 | 243 | const after = await moveRequested(app, fresh(), 1); |
| 221 | expect(after.find((m) => m.pull === pull.number)?.did).toBe("not moved"); | |
| 222 | expect(runs(pull, "feedback")).toHaveLength(1); | |
| 244 | expect(after.find((m) => m.pull === pull.number)).toEqual({ | |
| 245 | pull: pull.number, | |
| 246 | did: "not moved", | |
| 247 | why: "2 runs since the verdict ended without a push; waits for a person", | |
| 248 | }); | |
| 249 | expect(runs(pull, "feedback")).toHaveLength(2); | |
| 223 | 250 | app.db.query("UPDATE issue SET state = 'closed' WHERE id = ?1").run(pull.id); |
| 224 | 251 | }); |
| 225 | 252 | |
| 253 | test("the run after one that ended without a push is told the verdict and what it answered", async () => { | |
| 254 | const pull = await currentShape(); | |
| 255 | const prompt = taskPrompt({ | |
| 256 | agent: getAgent(app.db, builder.id)!, | |
| 257 | repo: fresh(), | |
| 258 | issue: getIssueById(app.db, pull.id)!, | |
| 259 | pull: reload(pull), | |
| 260 | branch: "b", | |
| 261 | forgeUrl: "http://forge", | |
| 262 | isApp: false, | |
| 263 | resuming: true, | |
| 264 | reason: "feedback", | |
| 265 | comments: [], | |
| 266 | reviews: [], | |
| 267 | reviewComments: [], | |
| 268 | since: new Date().toISOString(), | |
| 269 | unanswered: { reviewer: "quill", body: "Fix the one thing.", answer: "I think it is fine." }, | |
| 270 | }); | |
| 271 | expect(prompt).toContain("@quill requested changes on this head:\n Fix the one thing."); | |
| 272 | expect(prompt).toContain("Your last run on it ended without a push, answering:\n I think it is fine."); | |
| 273 | expect(prompt).not.toContain("The feedback was not captured in words"); | |
| 274 | app.db.query("UPDATE issue SET state = 'closed' WHERE id = ?1").run(pull.id); | |
| 275 | }); | |
| 276 | ||
| 277 | test("the tick line says what moved and why the rest did not", () => { | |
| 278 | expect( | |
| 279 | requestedWords([ | |
| 280 | { pull: 1, did: "asked reviewer" }, | |
| 281 | { pull: 2, did: "not moved", why: "a run is in flight" }, | |
| 282 | { pull: 3, did: "not moved", why: "handed to a person after the review rounds" }, | |
| 283 | { pull: 4, did: "not moved", why: "handed to a person after the review rounds" }, | |
| 284 | ]), | |
| 285 | ).toBe("1/4 moved; 2 handed to a person after the review rounds, 1 a run is in flight"); | |
| 286 | expect(requestedWords([{ pull: 1, did: "asked reviewer" }])).toBe("1/1 moved"); | |
| 287 | }); | |
| 288 | ||
| 226 | 289 | test("an approval after the request: nothing to move", async () => { |
| 227 | 290 | const pull = await currentShape(); |
| 228 | 291 | submitReview(app.db, { |
| @@ -301,5 +364,8 @@ describe("a pull with changes requested always moves", () => { | ||
| 301 | 364 | expect(runs(stale, "review")).toHaveLength(1); |
| 302 | 365 | expect(runs(current, "feedback")).toHaveLength(1); |
| 303 | 366 | expect(runs(current, "feedback")[0]!.actorId).toBe(builder.id); |
| 367 | // A second tick starts no second one. | |
| 368 | await autonomyTick(app, new Date(), async () => 0); | |
| 369 | expect(runs(current, "feedback")).toHaveLength(1); | |
| 304 | 370 | }); |
| 305 | 371 | }); |
test/review-gate.test.ts +17 −6
| @@ -282,20 +282,31 @@ describe("the review gate", () => { | ||
| 282 | 282 | expect(await landIfGreen(app, fresh(), pull)).toBe(true); |
| 283 | 283 | }); |
| 284 | 284 | |
| 285 | test("a builder's run that answers a change request without pushing parks the pull", async () => { | |
| 285 | test("a builder's run that answers a change request without pushing parks the pull, after one more (#2847)", async () => { | |
| 286 | 286 | setCrewRole(app.db, repo.id, quill.id, "reviewer"); |
| 287 | 287 | setCrewRole(app.db, repo.id, mason.id, "builder"); |
| 288 | 288 | const pull = await greenPull(mason, "unmoved"); |
| 289 | 289 | askChanges(pull, quill); |
| 290 | expect( | |
| 291 | settleAgentRun(app, fresh(), { | |
| 290 | /** A feedback run of mason's on the pull, ended without a push. */ | |
| 291 | const unmoved = (summary: string, n: number) => { | |
| 292 | const run = createRun(app.db, { repoId: repo.id, kind: "agent", issueId: pull.id, actorId: mason.id, reason: "feedback" }); | |
| 293 | claimRun(app.db, run.id); | |
| 294 | finishRun(app.db, run.id, { state: "ok", summary }); | |
| 295 | app.db | |
| 296 | .query("UPDATE run SET created_at = ?2 WHERE id = ?1") | |
| 297 | .run(run.id, new Date(Date.now() + n * 1000).toISOString()); | |
| 298 | return settleAgentRun(app, fresh(), { | |
| 292 | 299 | issueId: pull.id, |
| 293 | 300 | state: "ok", |
| 294 | summary: "no changes pushed: I think it is fine", | |
| 301 | summary, | |
| 295 | 302 | reason: "feedback", |
| 296 | 303 | actorId: mason.id, |
| 297 | }), | |
| 298 | ).toBe(true); | |
| 304 | }); | |
| 305 | }; | |
| 306 | // The first gets one more run, told the verdict again. | |
| 307 | expect(unmoved("no changes pushed: I think it is fine", 1)).toBe(false); | |
| 308 | expect(getPull(app.db, repo.id, pull.number)?.state).toBe("open"); | |
| 309 | expect(unmoved("no changes pushed: still fine", 2)).toBe(true); | |
| 299 | 310 | expect(getPull(app.db, repo.id, pull.number)?.state).toBe("closed"); |
| 300 | 311 | |
| 301 | 312 | // One that pushed is answering, and is left alone. |
new above
offline