Public: anyone can read this; the crew can change it.
A merged pull that names an issue ends the hold: its leftover boxes are carried into one fresh issue or closed with the commit named #15293
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/15289-a-merged-pull-that-names-an-issue-ends-t → main 0 commits fork
7 files
changed +399
−23
src/actions/box_pass.ts +63 −2
| @@ -12,12 +12,13 @@ | ||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | import type { App } from "../app.ts"; |
| 15 | import { PASS_LEAD, tickBoxes, unticked } from "../core/done_on_main.ts"; | |
| 16 | import { addComment, getIssue, setIssueState as setIssueStateCore, updateIssueText } from "../core/issues.ts"; | |
| 15 | import { BY_LANDING, deliveryOnly, landingDoneNote, PASS_LEAD, tickBoxes, tickedNote, unticked } from "../core/done_on_main.ts"; | |
| 16 | import { addComment, getIssue, setIssueState as setIssueStateCore, updateIssueText, type Issue } from "../core/issues.ts"; | |
| 17 | 17 | import { noteShipped } from "../crew/note_closed.ts"; |
| 18 | 18 | import { isStructural, pillarsOf } from "../core/pillars.ts"; |
| 19 | 19 | import { closesFromBody, type Pull } from "../core/pulls.ts"; |
| 20 | 20 | import type { Repo } from "../core/repos.ts"; |
| 21 | import { checkSummary } from "../core/runs.ts"; | |
| 21 | 22 | import { getUserById, type User } from "../core/users.ts"; |
| 22 | 23 | |
| 23 | 24 | /** Boxes of one issue the pass ticks. */ |
| @@ -153,3 +154,63 @@ export function applyBoxPass(app: App, repo: Repo, pull: Pull, reviewer: User, p | ||
| 153 | 154 | } |
| 154 | 155 | } |
| 155 | 156 | } |
| 157 | ||
| 158 | // ---- the landing's own pass (#15289) ---- | |
| 159 | ||
| 160 | /* | |
| 161 | * What a landing does to the boxes of an issue it names (#15289). A merged | |
| 162 | * pull proves its own delivery — its diff was on the forge, its check ran | |
| 163 | * the tests green, its branch was here — so a box that says only that is | |
| 164 | * ticked when the pull's check at its head was green, with a note naming | |
| 165 | * each one (`tickedNote`). An issue that keeps other boxes stays open, and | |
| 166 | * gets the already-done note naming the merge commit, so the planner may | |
| 167 | * carry what is left into a fresh issue and close this one as done. | |
| 168 | * | |
| 169 | * Only a short fixed list of phrases counts (`DELIVERY_CLAUSES`); any other | |
| 170 | * box keeps the hold. The edit and the notes are the landing's own, not a | |
| 171 | * person's answer to it (`crew/landed.ts`). | |
| 172 | */ | |
| 173 | ||
| 174 | /** | |
| 175 | * Tick the delivery boxes of `issue` when `pull` landed green; the boxes | |
| 176 | * still unticked after, as written. | |
| 177 | */ | |
| 178 | export function tickDelivery(app: App, repo: Repo, pull: Pull, issue: Issue, by: User): string[] { | |
| 179 | const left = unticked(issue.body); | |
| 180 | if (left.length === 0 || checkSummary(app.db, pull.id, pull.headOid).state !== "ok") return left; | |
| 181 | const slug = `${repo.ownerName}/${repo.name}`; | |
| 182 | const boxes = left.flatMap((text, i) => (deliveryOnly(text, slug) ? [i + 1] : [])); | |
| 183 | if (boxes.length === 0) return left; | |
| 184 | const { body, ticked } = tickBoxes(issue.body, boxes); | |
| 185 | if (!updateIssueText(app.db, issue.id, { body }).ok) return left; | |
| 186 | app.bus.append({ | |
| 187 | kind: "issue.edited", | |
| 188 | repoId: repo.id, | |
| 189 | actorId: by.id, | |
| 190 | payload: { number: issue.number, changed: ["body"], by: BY_LANDING, pull: pull.number }, | |
| 191 | }); | |
| 192 | sayOn(app, repo, issue, by, tickedNote(pull.number, ticked)); | |
| 193 | return unticked(body); | |
| 194 | } | |
| 195 | ||
| 196 | /** | |
| 197 | * The already-done note on an issue a landing leaves open, naming the merge | |
| 198 | * commit. Written as the person the crew acts for, as the crew's own | |
| 199 | * already-done note is (`crew/autonomy.ts`); as the lander when the crew is off. | |
| 200 | */ | |
| 201 | export function noteLandedDone(app: App, repo: Repo, issue: Issue, lander: User, mergeOid: string): void { | |
| 202 | if (!/^[0-9a-f]{40}$/.test(mergeOid)) return; | |
| 203 | const by = (repo.autonomyBy === null ? undefined : getUserById(app.db, repo.autonomyBy)) ?? lander; | |
| 204 | sayOn(app, repo, issue, by, landingDoneNote(mergeOid)); | |
| 205 | } | |
| 206 | ||
| 207 | function sayOn(app: App, repo: Repo, issue: Issue, by: User, body: string): void { | |
| 208 | const noted = addComment(app.db, { issueId: issue.id, authorId: by.id, body }); | |
| 209 | if (noted.ok) | |
| 210 | app.bus.append({ | |
| 211 | kind: "issue.commented", | |
| 212 | repoId: repo.id, | |
| 213 | actorId: by.id, | |
| 214 | payload: { number: issue.number, body, commentId: noted.value.id }, | |
| 215 | }); | |
| 216 | } |
src/actions/pulls.ts +8 −3
| @@ -14,10 +14,10 @@ import { requireAbility } from "./roles.ts"; | ||
| 14 | 14 | import { announceTeamWaits } from "./team_waits.ts"; |
| 15 | 15 | import { addComment as addIssueComment } from "../core/issues.ts"; |
| 16 | 16 | import { noteShipped } from "../crew/note_closed.ts"; |
| 17 | import { landedNote, leftNote, unticked } from "../core/done_on_main.ts"; | |
| 17 | import { landedNote, leftNote } from "../core/done_on_main.ts"; | |
| 18 | 18 | import { resolveOpen } from "../core/decisions.ts"; |
| 19 | 19 | import type { App } from "../app.ts"; |
| 20 | import { applyBoxPass, holdPass, landHeldPass, type BoxPass } from "./box_pass.ts"; | |
| 20 | import { applyBoxPass, holdPass, landHeldPass, noteLandedDone, tickDelivery, type BoxPass } from "./box_pass.ts"; | |
| 21 | 21 | import { landVision } from "../crew/vision.ts"; |
| 22 | 22 | import { crewRole } from "../core/agents.ts"; |
| 23 | 23 | import { |
| @@ -634,11 +634,13 @@ export async function mergePull( | ||
| 634 | 634 | // The reviewer's boxes first, so what it ticked at this head closes with it. |
| 635 | 635 | landHeldPass(app, repo, getPull(app.db, repo.id, pull.number) ?? pull); |
| 636 | 636 | const plan = pillarsOf(app.db, repo); |
| 637 | const landed = getPull(app.db, repo.id, pull.number) ?? pull; | |
| 637 | 638 | for (const n of closesFromBody(pull.body)) { |
| 638 | 639 | const issue = getIssue(app.db, repo.id, n); |
| 639 | 640 | if (!issue || issue.kind !== "issue" || issue.state !== "open") continue; |
| 640 | 641 | if (isStructural(plan, issue.id)) continue; |
| 641 | const left = unticked(issue.body); | |
| 642 | // A box only about the pull's own delivery is proven by a green landing (#15289). | |
| 643 | const left = tickDelivery(app, repo, landed, issue, writer.value); | |
| 642 | 644 | if (left.length > 0) { |
| 643 | 645 | const body = leftNote(issue.number, left); |
| 644 | 646 | const noted = addIssueComment(app.db, { |
| @@ -670,6 +672,9 @@ export async function mergePull( | ||
| 670 | 672 | payload: { number: issue.number, body: why, commentId: told.value.id }, |
| 671 | 673 | }); |
| 672 | 674 | } |
| 675 | // And the commit that landed, so the planner may carry what is left | |
| 676 | // into a fresh issue and close this one as done (#15289). | |
| 677 | noteLandedDone(app, repo, issue, writer.value, merged.value.mergeOid); | |
| 673 | 678 | continue; |
| 674 | 679 | } |
| 675 | 680 | const closed = setIssueStateCore(app.db, issue.id, "closed"); |
src/core/done_on_main.ts +75
| @@ -146,3 +146,78 @@ export function landedNote(pull: number, left: readonly string[]): string { | ||
| 146 | 146 | |
| 147 | 147 | /** What the reviewer's note on an issue starts with, when it ticked boxes at its pull's head (#8682). */ |
| 148 | 148 | export const PASS_LEAD = "Reviewed pull #"; |
| 149 | ||
| 150 | /** | |
| 151 | * The boxes a merge itself proves, as whole clauses (#15289): the pull's | |
| 152 | * diff was on the forge, its check ran the tests and the type check green, | |
| 153 | * it carried its review steps, its branch was in this repository. Matched | |
| 154 | * exactly, after `deliveryClauses` folds case, backticks, spacing and the | |
| 155 | * repository's own name; never a fuzzy reading, since a wrong tick hides | |
| 156 | * unfinished work. A clause that names any other work keeps its box. | |
| 157 | */ | |
| 158 | export const DELIVERY_CLAUSES: ReadonlySet<string> = new Set([ | |
| 159 | "the pull's diff is visible on the forge", | |
| 160 | "the pull's diff is visible on the forge (head branch in <repo>) before review is asked", | |
| 161 | "the branch is pushed to <repo> itself, not a fork, and the pull's diff shows in the review", | |
| 162 | "the branch is in <repo>", | |
| 163 | "a branch in <repo>", | |
| 164 | "bun test passes", | |
| 165 | "bun test and bun x tsc --noemit pass", | |
| 166 | "bun x tsc --noemit passes", | |
| 167 | "a page change carries review steps", | |
| 168 | "the pull carries a review block", | |
| 169 | "a review block", | |
| 170 | ]); | |
| 171 | ||
| 172 | /** | |
| 173 | * A box's clauses as `DELIVERY_CLAUSES` spells them: lower case, no backticks, `<repo>` for `slug`. | |
| 174 | */ | |
| 175 | export function deliveryClauses(text: string, slug: string): string[] { | |
| 176 | const own = slug.toLowerCase(); | |
| 177 | return text | |
| 178 | .toLowerCase() | |
| 179 | .replace(/`/g, "") | |
| 180 | .replace(/[‘’]/g, "'") | |
| 181 | .split(own) | |
| 182 | .join("<repo>") | |
| 183 | .split(";") | |
| 184 | .map((c) => c.replace(/\s+/g, " ").trim().replace(/[.!]+$/, "")) | |
| 185 | .filter((c) => c !== ""); | |
| 186 | } | |
| 187 | ||
| 188 | /** The box is only about the pull's own delivery: every clause of it is a delivery clause. */ | |
| 189 | export function deliveryOnly(text: string, slug: string): boolean { | |
| 190 | const clauses = deliveryClauses(text, slug); | |
| 191 | return clauses.length > 0 && clauses.every((c) => DELIVERY_CLAUSES.has(c)); | |
| 192 | } | |
| 193 | ||
| 194 | /** What the note on an issue starts with, when a green landing ticked its delivery boxes. */ | |
| 195 | export const TICKED_LEAD = "Ticked on the landing of pull #"; | |
| 196 | ||
| 197 | /** What marks the landing's own edit of an issue body, in the event's payload. */ | |
| 198 | export const BY_LANDING = "landing"; | |
| 199 | ||
| 200 | /** The note naming each box a green landing ticked, so a person can untick one read wrong. */ | |
| 201 | export function tickedNote(pull: number, ticked: readonly string[]): string { | |
| 202 | return `${TICKED_LEAD}${pull}, whose check was green: ${ticked.join("; ")}. Each is about the pull's own delivery, which the merge proves; untick one that meant more.`; | |
| 203 | } | |
| 204 | ||
| 205 | /** | |
| 206 | * The already-done note a landing leaves on an issue it names and leaves open, naming its commit. | |
| 207 | */ | |
| 208 | export const landingDoneNote = (mergeOid: string): string => `${DONE_NOTE}${mergeOid}`; | |
| 209 | ||
| 210 | /** | |
| 211 | * The crew wrote an already-done note on this issue after `at`: a word on | |
| 212 | * the base newer than a person's answer to a landing (`crew/landed.ts`). | |
| 213 | */ | |
| 214 | export function doneNotedSince(db: Database, issueId: string, at: string): boolean { | |
| 215 | return ( | |
| 216 | db | |
| 217 | .query<{ one: number }, [string, string]>( | |
| 218 | `SELECT 1 AS one FROM comment n WHERE n.issue_id = ?1 AND n.created_at > ?2 | |
| 219 | AND n.body LIKE '${DONE_LIKE}' AND ${BY_CREW} LIMIT 1`, | |
| 220 | ) | |
| 221 | .get(issueId, at) !== null | |
| 222 | ); | |
| 223 | } |
src/crew/held.ts +15 −3
| @@ -49,7 +49,7 @@ | ||
| 49 | 49 | import type { App } from "../app.ts"; |
| 50 | 50 | import { listCrewRoles, type Agent, type CrewRole } from "../core/agents.ts"; |
| 51 | 51 | import { readyNow, repoGraph, type Graph, type Ranked } from "../core/dependencies.ts"; |
| 52 | import { alreadyDone, BY_CREW, DONE_LIKE } from "../core/done_on_main.ts"; | |
| 52 | import { alreadyDone, BY_CREW, DONE_LIKE, unticked } from "../core/done_on_main.ts"; | |
| 53 | 53 | import { getIssuesByIds, getIssuesByNumbers, labelsForIssues, type Issue } from "../core/issues.ts"; |
| 54 | 54 | import { ALONE_GREEN_LABEL } from "../checks/alone_label.ts"; |
| 55 | 55 | import { withPlanner } from "../core/limb_replan.ts"; |
| @@ -62,7 +62,7 @@ import { proposedWork, speaksForCrew } from "./direct.ts"; | ||
| 62 | 62 | import { freshPulls, pullFor } from "./fresh_pull.ts"; |
| 63 | 63 | import { capReached, capReachedFor, runCapOf } from "./guard.ts"; |
| 64 | 64 | import { interruptionOf } from "./interrupted.ts"; |
| 65 | import { landedUnanswered } from "./landed.ts"; | |
| 65 | import { landedUnanswered, landingDoneAnswered } from "./landed.ts"; | |
| 66 | 66 | import { NO_KEY_HELD, repoHasNoKey } from "./no_key.ts"; |
| 67 | 67 | import { CREW_OFF_HELD, CREW_OFF_WORDS, crewBuildsHere } from "../core/crew_switch.ts"; |
| 68 | 68 | import { PARK_STRIKES, parkedCount } from "./parks.ts"; |
| @@ -277,8 +277,10 @@ export function heldBy( | ||
| 277 | 277 | if (proposed.has(issue.number)) return "open_pull"; |
| 278 | 278 | if (issue.assigneeId !== null && planners.has(issue.assigneeId)) return "planner"; |
| 279 | 279 | if (handed.has(issue.id)) return "with_planner"; |
| 280 | if (alreadyDone(app.db, [issue.id]).has(issue.id)) return "done_on_main"; | |
| 280 | // A landing that left boxes names what remains (#15289); its own done note waits behind it. | |
| 281 | 281 | if (landedUnanswered(app.db, repo, issue) !== undefined) return "landed"; |
| 282 | if (alreadyDone(app.db, [issue.id]).has(issue.id) && !landingDoneAnswered(app.db, repo, issue)) | |
| 283 | return "done_on_main"; | |
| 282 | 284 | if (noKey) return NO_KEY_HELD; |
| 283 | 285 | if (crewOff) return CREW_OFF_HELD; |
| 284 | 286 | if (flakes.has(issue.id)) return "full_suite_flake"; |
| @@ -399,6 +401,15 @@ const HOLD_WORDS: Readonly<Record<HoldName, string>> = { | ||
| 399 | 401 | hot_file: "a file it names is hot", |
| 400 | 402 | }; |
| 401 | 403 | |
| 404 | /** The `landed` hold, naming the boxes that remain by their text: at most three, then a count. */ | |
| 405 | export function landedWords(body: string): string { | |
| 406 | const left = unticked(body); | |
| 407 | if (left.length === 0) return HOLD_WORDS.landed; | |
| 408 | const named = left.slice(0, 3).join("; "); | |
| 409 | const more = left.length > 3 ? `; and ${left.length - 3} more` : ""; | |
| 410 | return `a merged pull closes it; ${left.length === 1 ? "this box remains" : `${left.length} boxes remain`}: ${named}${more}. Waits for a person`; | |
| 411 | } | |
| 412 | ||
| 402 | 413 | /** |
| 403 | 414 | * The hold on each held ready issue, by number, and the numbers none holds. |
| 404 | 415 | * `hot_file` names the file and its open pulls. Memory and the database only: |
| @@ -428,6 +439,7 @@ export function mapHolds( | ||
| 428 | 439 | pulls = pullsTouching(repo.id, top.path, admit); |
| 429 | 440 | } |
| 430 | 441 | } |
| 442 | if (name === "landed") detail = landedWords(issue.body); | |
| 431 | 443 | if (name === "twin") { |
| 432 | 444 | const twin = held.twins.get(issue.number); |
| 433 | 445 | if (twin !== undefined) detail = `waits for #${twin.number}, which holds the same work`; |
src/crew/landed.ts +49 −13
| @@ -12,39 +12,75 @@ | ||
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | import type { Database } from "bun:sqlite"; |
| 15 | import { LANDED_LEAD, unticked } from "../core/done_on_main.ts"; | |
| 15 | import { BY_LANDING, DONE_NOTE, doneNotedSince, LANDED_LEAD, TICKED_LEAD, unticked } from "../core/done_on_main.ts"; | |
| 16 | 16 | import type { Issue } from "../core/issues.ts"; |
| 17 | 17 | import { mergedPullClosing, type Pull } from "../core/pulls.ts"; |
| 18 | 18 | import type { Repo } from "../core/repos.ts"; |
| 19 | 19 | import { getUserById } from "../core/users.ts"; |
| 20 | 20 | import { mayDirectCrew } from "./direct.ts"; |
| 21 | 21 | |
| 22 | /** The landing's own note on the issue, which is not an answer to it. */ | |
| 22 | /** What the landing itself writes on the issue, which is not an answer to it. */ | |
| 23 | const like = (lead: string): string => `'${lead.replace(/[%_']/g, "")}%'`; | |
| 23 | 24 | const NOT_THE_NOTE = `NOT (e.kind = 'issue.commented' |
| 24 | AND json_extract(e.payload, '$.body') LIKE '${LANDED_LEAD.replace(/[%_']/g, "")}%')`; | |
| 25 | AND (json_extract(e.payload, '$.body') LIKE ${like(LANDED_LEAD)} | |
| 26 | OR json_extract(e.payload, '$.body') LIKE ${like(TICKED_LEAD)} | |
| 27 | OR json_extract(e.payload, '$.body') LIKE ${like(DONE_NOTE)})) | |
| 28 | AND NOT (e.kind = 'issue.edited' AND json_extract(e.payload, '$.by') IS '${BY_LANDING}')`; | |
| 29 | ||
| 30 | /** A landing that left `issue` open with boxes unticked, and when a person first answered it. */ | |
| 31 | export interface Landing { | |
| 32 | readonly pull: Pull; | |
| 33 | /** | |
| 34 | * The first answer since the merge by a person who may direct the crew; undefined while none has. | |
| 35 | */ | |
| 36 | readonly answeredAt: string | undefined; | |
| 37 | } | |
| 25 | 38 | |
| 26 | 39 | /** |
| 27 | 40 | * The merged pull that shipped `issue` while it stays open with boxes |
| 28 | * unticked, when no person who may direct the crew has commented on it, | |
| 29 | * edited it or reopened it since that pull landed. Undefined otherwise. | |
| 41 | * unticked, and the first word since by a person who may direct the crew: | |
| 42 | * a comment, an edit or a reopen. Undefined when no landing left it so. | |
| 30 | 43 | * Walks `event_repo_kind_number_at`. |
| 31 | 44 | */ |
| 32 | export function landedUnanswered(db: Database, repo: Repo, issue: Issue): Pull | undefined { | |
| 45 | export function landingOf(db: Database, repo: Repo, issue: Issue): Landing | undefined { | |
| 33 | 46 | if (issue.kind !== "issue" || issue.state !== "open") return undefined; |
| 34 | 47 | if (unticked(issue.body).length === 0) return undefined; |
| 35 | 48 | const pull = mergedPullClosing(db, repo.id, issue.number); |
| 36 | 49 | if (pull === undefined || pull.mergedAt === null) return undefined; |
| 37 | 50 | const actors = db |
| 38 | .query<{ actor: string }, [string, number, string]>( | |
| 39 | `SELECT DISTINCT e.actor_id AS actor FROM event e INDEXED BY event_repo_kind_number_at | |
| 51 | .query<{ actor: string; at: string }, [string, number, string]>( | |
| 52 | `SELECT e.actor_id AS actor, MIN(e.created_at) AS at FROM event e INDEXED BY event_repo_kind_number_at | |
| 40 | 53 | WHERE e.repo_id = ?1 AND e.kind IN ('issue.commented', 'issue.edited', 'issue.reopened') |
| 41 | 54 | AND json_extract(e.payload, '$.number') = ?2 AND e.created_at >= ?3 |
| 42 | AND e.actor_id IS NOT NULL AND ${NOT_THE_NOTE}`, | |
| 55 | AND e.actor_id IS NOT NULL AND ${NOT_THE_NOTE} | |
| 56 | GROUP BY e.actor_id`, | |
| 43 | 57 | ) |
| 44 | 58 | .all(repo.id, issue.number, pull.mergedAt); |
| 45 | const answered = actors.some((r) => { | |
| 59 | let answeredAt: string | undefined; | |
| 60 | for (const r of actors) { | |
| 46 | 61 | const who = getUserById(db, r.actor); |
| 47 | return who !== undefined && who.kind !== "agent" && mayDirectCrew(db, repo, who); | |
| 48 | }); | |
| 49 | return answered ? undefined : pull; | |
| 62 | if (who === undefined || who.kind === "agent" || !mayDirectCrew(db, repo, who)) continue; | |
| 63 | if (answeredAt === undefined || r.at < answeredAt) answeredAt = r.at; | |
| 64 | } | |
| 65 | return { pull, answeredAt }; | |
| 66 | } | |
| 67 | ||
| 68 | /** | |
| 69 | * The merged pull that shipped `issue` while it stays open with boxes | |
| 70 | * unticked, when no person who may direct the crew has commented on it, | |
| 71 | * edited it or reopened it since that pull landed. Undefined otherwise. | |
| 72 | */ | |
| 73 | export function landedUnanswered(db: Database, repo: Repo, issue: Issue): Pull | undefined { | |
| 74 | const landing = landingOf(db, repo, issue); | |
| 75 | return landing === undefined || landing.answeredAt !== undefined ? undefined : landing.pull; | |
| 76 | } | |
| 77 | ||
| 78 | /** | |
| 79 | * The issue's already-done note is only the landing's, and a person has | |
| 80 | * answered the landing since: their word stands over it, as it lifts the | |
| 81 | * `landed` hold. A note the crew wrote after that answer still holds. | |
| 82 | */ | |
| 83 | export function landingDoneAnswered(db: Database, repo: Repo, issue: Issue): boolean { | |
| 84 | const landing = landingOf(db, repo, issue); | |
| 85 | return landing?.answeredAt !== undefined && !doneNotedSince(db, issue.id, landing.answeredAt); | |
| 50 | 86 | } |
test/landed-held.test.ts +4 −2
| @@ -15,7 +15,7 @@ import { addComment, editIssue, openIssue } from "../src/actions/issues.ts"; | ||
| 15 | 15 | import { mergePull, openPull } from "../src/actions/pulls.ts"; |
| 16 | 16 | import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts"; |
| 17 | 17 | import {} from "../src/core/agents.ts"; |
| 18 | import { landedNote } from "../src/core/done_on_main.ts"; | |
| 18 | import { landedNote, landingDoneNote } from "../src/core/done_on_main.ts"; | |
| 19 | 19 | import type { ForgeEvent } from "../src/core/events.ts"; |
| 20 | 20 | import { getIssueById, listComments, setAssignee, type Issue } from "../src/core/issues.ts"; |
| 21 | 21 | import { getPull, mergedPullClosing, mergedPullClosingScan } from "../src/core/pulls.ts"; |
| @@ -107,7 +107,9 @@ describe("a landing with boxes unticked waits for a person", () => { | ||
| 107 | 107 | const pull = await land("lands-partial", partial); |
| 108 | 108 | expect(now(partial).state).toBe("open"); |
| 109 | 109 | const notes = listComments(app.db, partial.id).map((c) => c.body); |
| 110 | expect(notes).toEqual([landedNote(pull.number, ["two"])]); | |
| 110 | // #15289: and the merge commit, so the planner may close it as done. | |
| 111 | const mergedOid = getPull(app.db, repo.id, pull.number)!.mergedOid!; | |
| 112 | expect(notes).toEqual([landedNote(pull.number, ["two"]), landingDoneNote(mergedOid)]); | |
| 111 | 113 | expect(notes[0]).toBe( |
| 112 | 114 | `Left open after pull #${pull.number} landed: 1 unticked item remains (two). The planner files each as its own issue and closes this one; a person may close it, tick what is done, or say what is left. Until then the crew does not pick it again.`, |
| 113 | 115 | ); |
test/landing-boxes.test.ts added +185
| @@ -0,0 +1,185 @@ | ||
| 1 | /** | |
| 2 | * #15289: a merged pull that names an issue ends the hold. A green landing | |
| 3 | * ticks the boxes only about its own delivery, with a note naming each; an | |
| 4 | * issue that keeps other boxes stays open with the already-done note naming | |
| 5 | * the merge commit, and the `landed` hold says which boxes remain. | |
| 6 | */ | |
| 7 | import { seatAs } from "./helpers/seat.ts"; | |
| 8 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 9 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 10 | import { tmpdir } from "node:os"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; | |
| 14 | import { addComment, openIssue } from "../src/actions/issues.ts"; | |
| 15 | import { mergePull, openPull } from "../src/actions/pulls.ts"; | |
| 16 | import { commitToBranch, createRepo, updateRepoSettings } from "../src/actions/repos.ts"; | |
| 17 | import { | |
| 18 | alreadyDone, | |
| 19 | deliveryOnly, | |
| 20 | landingDoneNote, | |
| 21 | tickedNote, | |
| 22 | unticked, | |
| 23 | } from "../src/core/done_on_main.ts"; | |
| 24 | import { getIssueById, listComments, type Issue } from "../src/core/issues.ts"; | |
| 25 | import { getPull, type Pull } from "../src/core/pulls.ts"; | |
| 26 | import { getRepoById, type Repo } from "../src/core/repos.ts"; | |
| 27 | import { claimRun, createRun, finishRun } from "../src/core/runs.ts"; | |
| 28 | import { createUser, getUserByName, type User } from "../src/core/users.ts"; | |
| 29 | import { heldNow, mapHolds } from "../src/crew/held.ts"; | |
| 30 | ||
| 31 | const DELIVERY = "`bun test` and `bun x tsc --noEmit` pass"; | |
| 32 | const REAL = "The map lists each box by its text"; | |
| 33 | ||
| 34 | describe("deliveryOnly reads a short fixed list, never a fuzzy match", () => { | |
| 35 | test("a box only about the pull's delivery", () => { | |
| 36 | expect(deliveryOnly(DELIVERY, "trevato/forge")).toBe(true); | |
| 37 | expect(deliveryOnly("`bun test` and `bun x tsc --noEmit` pass; a `review` block.", "trevato/forge")).toBe(true); | |
| 38 | expect( | |
| 39 | deliveryOnly( | |
| 40 | "The pull's diff is visible on the forge (head branch in trevato/forge) before review is asked.", | |
| 41 | "trevato/forge", | |
| 42 | ), | |
| 43 | ).toBe(true); | |
| 44 | expect(deliveryOnly("The branch is in alice/engine", "alice/engine")).toBe(true); | |
| 45 | }); | |
| 46 | ||
| 47 | test("a box that names any other work keeps it", () => { | |
| 48 | expect(deliveryOnly("`bun test` and `bun x tsc --noEmit` pass; no new dependency.", "trevato/forge")).toBe(false); | |
| 49 | expect( | |
| 50 | deliveryOnly("A test fails without the change; `bun test` and `bun x tsc --noEmit` pass", "trevato/forge"), | |
| 51 | ).toBe(false); | |
| 52 | expect(deliveryOnly("bun test passes for the new route", "trevato/forge")).toBe(false); | |
| 53 | expect(deliveryOnly("The branch is in someone/else", "trevato/forge")).toBe(false); | |
| 54 | expect(deliveryOnly(REAL, "trevato/forge")).toBe(false); | |
| 55 | expect(deliveryOnly("", "trevato/forge")).toBe(false); | |
| 56 | }); | |
| 57 | }); | |
| 58 | ||
| 59 | describe("a green landing ticks its delivery boxes and names the commit", () => { | |
| 60 | let dir: string; | |
| 61 | let app: App; | |
| 62 | let alice: User; | |
| 63 | let repo: Repo; | |
| 64 | const fresh = () => getRepoById(app.db, repo.id)!; | |
| 65 | const now = (on: Issue) => getIssueById(app.db, on.id)!; | |
| 66 | const issue = (title: string, body: string): Issue => { | |
| 67 | const opened = openIssue(app, alice, fresh(), { title, body }); | |
| 68 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 69 | return opened.value; | |
| 70 | }; | |
| 71 | const land = async (branch: string, closes: Issue, green: boolean): Promise<Pull> => { | |
| 72 | const pushed = await commitToBranch(app, alice, fresh(), { | |
| 73 | branch, | |
| 74 | message: branch, | |
| 75 | files: [{ path: `${branch}.txt`, content: "x\n" }], | |
| 76 | }); | |
| 77 | if (!pushed.ok) throw new Error(JSON.stringify(pushed.error)); | |
| 78 | const opened = await openPull(app, alice, fresh(), { | |
| 79 | title: branch, | |
| 80 | body: `Closes #${closes.number}`, | |
| 81 | baseBranch: "main", | |
| 82 | headBranch: branch, | |
| 83 | }); | |
| 84 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 85 | const pull = getPull(app.db, repo.id, opened.value.number)!; | |
| 86 | if (green) { | |
| 87 | const run = createRun(app.db, { | |
| 88 | repoId: repo.id, | |
| 89 | kind: "check", | |
| 90 | issueId: pull.id, | |
| 91 | env: `pull-${pull.number}`, | |
| 92 | commitOid: pull.headOid, | |
| 93 | }); | |
| 94 | claimRun(app.db, run.id); | |
| 95 | finishRun(app.db, run.id, { state: "ok", summary: "all green" }); | |
| 96 | } | |
| 97 | const merged = await mergePull(app, alice, fresh(), pull, "squash"); | |
| 98 | if (!merged.ok) throw new Error(String(merged.error)); | |
| 99 | return getPull(app.db, repo.id, pull.number)!; | |
| 100 | }; | |
| 101 | const holdOf = (on: Issue) => mapHolds(fresh(), heldNow(app, fresh())).holds.get(on.number); | |
| 102 | ||
| 103 | beforeAll(async () => { | |
| 104 | dir = await mkdtemp(join(tmpdir(), "forge-landing-boxes-")); | |
| 105 | app = createApp({ dataDir: dir, port: 0 }); | |
| 106 | const a = await createUser(app.db, { | |
| 107 | origin: "seed", | |
| 108 | trusted: true, | |
| 109 | username: "alice", | |
| 110 | email: "[email protected]", | |
| 111 | password: "a-good-passphrase", | |
| 112 | adminIfFirst: true, | |
| 113 | }); | |
| 114 | if (!a.ok) throw new Error(a.error); | |
| 115 | alice = a.value; | |
| 116 | const made = await createRepo(app, alice, { name: "engine", visibility: "private" }); | |
| 117 | if (!made.ok) throw new Error(String(made.error)); | |
| 118 | for (const agent of ["atlas", "mason"]) { | |
| 119 | const created = await createAgent(app, alice, { username: agent }); | |
| 120 | if (!created.ok) throw new Error(String(created.error)); | |
| 121 | expect(addToCrew(app, alice, made.value, agent).ok).toBe(true); | |
| 122 | } | |
| 123 | seatAs(app.db, made.value.id, getUserByName(app.db, "atlas")!.id, "planner"); | |
| 124 | const set = await updateRepoSettings(app, alice, made.value, { | |
| 125 | autonomy: "autonomous", | |
| 126 | autonomyDirection: "Keep the engine small.", | |
| 127 | autonomySlots: 1, | |
| 128 | autonomyBy: alice.id, | |
| 129 | }); | |
| 130 | if (!set.ok) throw new Error(JSON.stringify(set.error)); | |
| 131 | repo = getRepoById(app.db, made.value.id)!; | |
| 132 | const seeded = await commitToBranch(app, alice, fresh(), { | |
| 133 | message: "Start", | |
| 134 | files: [{ path: "README.md", content: "# engine\n" }], | |
| 135 | }); | |
| 136 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 137 | }, 30_000); | |
| 138 | ||
| 139 | afterAll(async () => { | |
| 140 | app.close(); | |
| 141 | await rm(dir, { recursive: true, force: true }); | |
| 142 | }); | |
| 143 | ||
| 144 | test("the delivery box is ticked, the real one is named in the hold, and the commit is noted", async () => { | |
| 145 | const both = issue("Both", `- [ ] ${DELIVERY}\n- [ ] ${REAL}`); | |
| 146 | const pull = await land("lands-both", both, true); | |
| 147 | expect(now(both).state).toBe("open"); | |
| 148 | expect(unticked(now(both).body)).toEqual([REAL]); | |
| 149 | expect(now(both).body).toContain(`- [x] ${DELIVERY}`); | |
| 150 | const notes = listComments(app.db, both.id).map((c) => c.body); | |
| 151 | expect(notes[0]).toBe(tickedNote(pull.number, [DELIVERY])); | |
| 152 | expect(notes).toContain(landingDoneNote(pull.mergedOid!)); | |
| 153 | // The planner may close it as done: the note names the merge commit. | |
| 154 | expect(alreadyDone(app.db, [both.id]).get(both.id)).toEqual([pull.mergedOid!]); | |
| 155 | // The landing's own edit and notes are no answer: it is held as landed, by the box left. | |
| 156 | const hold = holdOf(both); | |
| 157 | expect(hold?.by).toBe("landed"); | |
| 158 | expect(hold?.detail).toContain(REAL); | |
| 159 | expect(hold?.detail).not.toContain(DELIVERY); | |
| 160 | }); | |
| 161 | ||
| 162 | test("without a green check nothing is ticked", async () => { | |
| 163 | const red = issue("Unchecked", `- [ ] ${DELIVERY}\n- [ ] ${REAL}`); | |
| 164 | const pull = await land("lands-unchecked", red, false); | |
| 165 | expect(unticked(now(red).body)).toEqual([DELIVERY, REAL]); | |
| 166 | expect(listComments(app.db, red.id).map((c) => c.body)).not.toContain(tickedNote(pull.number, [DELIVERY])); | |
| 167 | expect(holdOf(red)?.detail).toContain(`2 boxes remain: ${DELIVERY}; ${REAL}`); | |
| 168 | }); | |
| 169 | ||
| 170 | test("an issue whose only box left is delivery closes on a green landing", async () => { | |
| 171 | const done = issue("Delivered", `- [x] the work\n- [ ] ${DELIVERY}`); | |
| 172 | const pull = await land("lands-delivered", done, true); | |
| 173 | expect(now(done).state).toBe("closed"); | |
| 174 | expect(unticked(now(done).body)).toEqual([]); | |
| 175 | expect(listComments(app.db, done.id).map((c) => c.body)).toEqual([tickedNote(pull.number, [DELIVERY])]); | |
| 176 | }); | |
| 177 | ||
| 178 | test("a person's answer lifts both the landed hold and the landing's done note", async () => { | |
| 179 | const answered = issue("Answered", `- [ ] ${REAL}`); | |
| 180 | await land("lands-answered", answered, true); | |
| 181 | expect(holdOf(answered)?.by).toBe("landed"); | |
| 182 | expect(addComment(app, alice, fresh(), now(answered), "The box is still to do.").ok).toBe(true); | |
| 183 | expect(holdOf(answered)).toBeUndefined(); | |
| 184 | }); | |
| 185 | }); |
new above
offline