Public: anyone can read this; the crew can change it.
A review's approval is recorded against its head and base; when either moves it reads 'moved since approval' #12548
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/12524-a-review-s-approval-is-recorded-against → main 5 commits fork
9 files
changed +228
−32
docs/features/approval-base.md +1
| @@ -5,6 +5,7 @@ An approval is recorded against the head and the base tip it was given for. When | ||
| 5 | 5 | - **Page:** the reviews chip in the merge box on the pull's Files step reads "the base moved since the approval" in red. Nothing is added while the approval is current. |
| 6 | 6 | - **API:** `GET /api/v1/repos/:owner/:name/pulls/:number` carries `approvedAt: { at, head, base, current }`, or `null` when no one's latest verdict approves. `base` is `null` for an approval given before the base was recorded; `current` is `false` once the head or the base moved. |
| 7 | 7 | - **MCP:** `pulls` with a `repo` carries `movedSinceApproval` on each row; the card says "moved since approval". |
| 8 | - **Inbox:** a green pull's "look" row, and a pull's "waiting" row, on `/asks` and the home's ask lines end "moved since approval" once the head or the base is no longer the one approved. The base is the one the stale-asks sweep last read (no git on the request); before a sweep has read it only the head is compared. One rule for the inbox and MCP: `src/core/approval_at.ts`. | |
| 8 | 9 | - **Terminal:** the pull screen's merge box adds "the base moved since the approval" after the approval count. |
| 9 | 10 | |
| 10 | 11 | It is information, not a gate: the base moves with every landing, so refusing a merge on it would ask for a new approval after every unrelated merge. A moved head still dismisses the approval, as before. |
src/core/approval_at.ts added +28
| @@ -0,0 +1,28 @@ | ||
| 1 | /** | |
| 2 | * Whether a pull has moved since its approval (#12524, #1133's third bullet). | |
| 3 | * An approval is recorded against the head it was given on and the base tip | |
| 4 | * it was given against (`review.commit_oid`, `review.base_oid`; | |
| 5 | * `approvalRecord` in `reviews.ts`). When either has moved since, the | |
| 6 | * approval no longer speaks for what would land, and every row that shows the | |
| 7 | * pull says "moved since approval": the inbox (`web/studio/asks.ts`) and the | |
| 8 | * MCP pull list (`http/mcp/tools/pulls.ts`) read this one rule. | |
| 9 | * | |
| 10 | * Plain data in, a boolean out: no query, no git. A base not read (undefined) | |
| 11 | * is not a move, so a cold cache never claims one; an approval from before | |
| 12 | * the base was recorded is judged by its head alone. | |
| 13 | */ | |
| 14 | ||
| 15 | import { approvalRecord, type Review } from "./reviews.ts"; | |
| 16 | ||
| 17 | /** The words every row says when `movedSinceApproval` holds. */ | |
| 18 | export const MOVED_SINCE_APPROVAL = "moved since approval"; | |
| 19 | ||
| 20 | export function movedSinceApproval( | |
| 21 | reviews: readonly Review[], | |
| 22 | headOid: string, | |
| 23 | baseOid: string | undefined, | |
| 24 | ): boolean { | |
| 25 | const approval = approvalRecord(reviews, headOid, baseOid ?? ""); | |
| 26 | if (approval === null) return false; | |
| 27 | return baseOid === undefined || baseOid === "" ? approval.head !== headOid : !approval.current; | |
| 28 | } |
src/core/reviews.ts +3 −1
| @@ -392,9 +392,11 @@ export function reviewSummary( | ||
| 392 | 392 | export function reviewSummariesFor( |
| 393 | 393 | db: Database, |
| 394 | 394 | pulls: readonly { readonly id: string; readonly headOid: string }[], |
| 395 | /** These pulls' reviews (`listReviewsFor`), when the caller already read them for a wider set. */ | |
| 396 | given?: ReadonlyMap<string, readonly Review[]>, | |
| 395 | 397 | ): Map<string, ReviewSummary> { |
| 396 | 398 | const ids = pulls.map((p) => p.id); |
| 397 | const reviews = listReviewsFor(db, ids); | |
| 399 | const reviews = given ?? listReviewsFor(db, ids); | |
| 398 | 400 | const rows = new Map<string, AgentVerdictRow[]>(); |
| 399 | 401 | for (const row of agentVerdictRows(db, ids)) { |
| 400 | 402 | const list = rows.get(row.issue_id); |
src/crew/review.ts +4 −2
| @@ -25,7 +25,7 @@ import { getIssueById, LIST_LIMIT_MAX } from "../core/issues.ts"; | ||
| 25 | 25 | import { listPulls, pullDiff, type Pull, pullDir} from "../core/pulls.ts"; |
| 26 | 26 | import { getRepoById, PILLAR_MAX, type Repo } from "../core/repos.ts"; |
| 27 | 27 | import { teamsOfPull, teamVerdicts } from "../core/issue_teams.ts"; |
| 28 | import { listReviews, reviewSummariesFor, reviewSummary } from "../core/reviews.ts"; | |
| 28 | import { listReviews, reviewSummariesFor, reviewSummary, type Review } from "../core/reviews.ts"; | |
| 29 | 29 | import { verdictForHead } from "../core/runs.ts"; |
| 30 | 30 | import { getTeam } from "../core/teams.ts"; |
| 31 | 31 | import { createLog } from "../kernel/log.ts"; |
| @@ -391,6 +391,8 @@ export function reviewWaitsFor( | ||
| 391 | 391 | pulls: readonly { readonly repo: Repo; readonly pull: Pull }[], |
| 392 | 392 | now = new Date(), |
| 393 | 393 | handovers?: ReadonlyMap<string, Handover>, |
| 394 | /** The pulls' reviews, when the caller read them already (`listReviewsFor`): not read again. */ | |
| 395 | reviews?: ReadonlyMap<string, readonly Review[]>, | |
| 394 | 396 | ): Map<string, ReviewWaits> { |
| 395 | 397 | const out = new Map<string, ReviewWaits>(); |
| 396 | 398 | // An app with reviews off waits on none (#11666). |
| @@ -400,7 +402,7 @@ export function reviewWaitsFor( | ||
| 400 | 402 | ); |
| 401 | 403 | const held = holdsFor(db, agents.map((p) => p.pull.id)); |
| 402 | 404 | const unheld = agents.filter((p) => !held.has(p.pull.id)); |
| 403 | const seen = reviewSummariesFor(db, unheld.map((p) => p.pull)); | |
| 405 | const seen = reviewSummariesFor(db, unheld.map((p) => p.pull), reviews); | |
| 404 | 406 | // A verdict on the head is the gate's answer: nobody waits. |
| 405 | 407 | const open = unheld.filter((p) => { |
| 406 | 408 | const s = seen.get(p.pull.id)!; |
src/crew/stale_asks.ts +10
| @@ -79,6 +79,16 @@ export function staleGreen( | ||
| 79 | 79 | return checkStale(check ?? null, known.base); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | /** | |
| 83 | * The base tip the last sweep read for this pull at this head, or undefined | |
| 84 | * when no sweep has read one: what an approval is compared with on the | |
| 85 | * inbox's rows (`movedSinceApproval`), with no git on the request path. | |
| 86 | */ | |
| 87 | export function knownBase(db: Database, pullId: string, headOid: string): string | undefined { | |
| 88 | const known = knownByDb.get(db)?.get(pullId); | |
| 89 | return known !== undefined && known.head === headOid && known.base !== "" ? known.base : undefined; | |
| 90 | } | |
| 91 | ||
| 82 | 92 | /** |
| 83 | 93 | * How many files stop this pull, at this head, from merging, as the last |
| 84 | 94 | * sweep found it: 0 when it merges, or when no sweep has answered yet. |
src/http/mcp/tools/pulls.ts +3 −11
| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | import { refTip } from "../../../git/read.ts"; |
| 2 | 2 | import { canRead, getReposByIds } from "../../../core/repos.ts"; |
| 3 | 3 | import { mayView, sealedScope } from "../../../core/sealed.ts"; |
| 4 | import { approvalRecord, listReviewsFor, reviewSummariesFor } from "../../../core/reviews.ts"; | |
| 4 | import { listReviewsFor, reviewSummariesFor } from "../../../core/reviews.ts"; | |
| 5 | import { movedSinceApproval } from "../../../core/approval_at.ts"; | |
| 5 | 6 | import { listPulls, openPullPileRows, pullDir, pullMergeStates, pullsByIssueIds } from "../../../core/pulls.ts"; |
| 6 | 7 | import { checkSummary } from "../../../core/runs.ts"; |
| 7 | 8 | import type { Ctx } from "../../context.ts"; |
| @@ -54,7 +55,7 @@ export const tool: Tool = { | ||
| 54 | 55 | head: p.headBranch, |
| 55 | 56 | check: checkSummary(db, p.id, p.headOid).state, |
| 56 | 57 | approvals: reviews.get(p.id)?.approvals ?? 0, |
| 57 | movedSinceApproval: movedSince(approvals.get(p.id) ?? [], p.headOid, bases[i]), | |
| 58 | movedSinceApproval: movedSinceApproval(approvals.get(p.id) ?? [], p.headOid, bases[i]), | |
| 58 | 59 | changesRequested: reviews.get(p.id)?.changesRequested ?? 0, |
| 59 | 60 | mergeable: merge[i]?.mergeable ?? null, |
| 60 | 61 | })), |
| @@ -104,12 +105,3 @@ function pile(ctx: Ctx, user: User, args: Args): Answer { | ||
| 104 | 105 | }); |
| 105 | 106 | } |
| 106 | 107 | |
| 107 | /** | |
| 108 | * An approval stands for a head and a base: true when either moved since. An unread base is | |
| 109 | * not a move. | |
| 110 | */ | |
| 111 | function movedSince(reviews: Parameters<typeof approvalRecord>[0], head: string, base: string | undefined): boolean { | |
| 112 | const approval = approvalRecord(reviews, head, base ?? ""); | |
| 113 | if (approval === null) return false; | |
| 114 | return base === undefined ? approval.head !== head : !approval.current; | |
| 115 | } |
src/web/studio/asks.ts +36 −11
| @@ -32,7 +32,8 @@ import { | ||
| 32 | 32 | listOpenPullsVisibleTo, |
| 33 | 33 | type Issue, |
| 34 | 34 | } from "../../core/issues.ts"; |
| 35 | import { reviewSummary } from "../../core/reviews.ts"; | |
| 35 | import { listReviewsFor, reviewSummary, type Review } from "../../core/reviews.ts"; | |
| 36 | import { MOVED_SINCE_APPROVAL, movedSinceApproval } from "../../core/approval_at.ts"; | |
| 36 | 37 | import { mayView } from "../../core/sealed.ts"; |
| 37 | 38 | import { closesFromBody, getPull, joinMany, type Pull } from "../../core/pulls.ts"; |
| 38 | 39 | import { |
| @@ -59,7 +60,7 @@ import { | ||
| 59 | 60 | } from "../../crew/autonomy.ts"; |
| 60 | 61 | import { breakerParked, WAITING_NOTES } from "../../crew/breaker.ts"; |
| 61 | 62 | import { handoversOf, passReasonOf, type Handover } from "../../crew/guard.ts"; |
| 62 | import { conflictsOf, isLandedPull, isStalePull, mergesAgainSince, staleGreen } from "../../crew/stale_asks.ts"; | |
| 63 | import { conflictsOf, isLandedPull, isStalePull, knownBase, mergesAgainSince, staleGreen } from "../../crew/stale_asks.ts"; | |
| 63 | 64 | import { reviewSays } from "../../crew/review_says.ts"; |
| 64 | 65 | import { reviewerPaused } from "../../crew/reviewer_paused.ts"; |
| 65 | 66 | import { reviewWaitsFor, type ReviewWait } from "../../crew/review.ts"; |
| @@ -303,6 +304,9 @@ interface AskCandidate { | ||
| 303 | 304 | readonly why?: string; |
| 304 | 305 | /** For "handover" and "waiting": what the crew advised, when it wrote one. */ |
| 305 | 306 | readonly recommendation?: Recommendation; |
| 307 | /** For "look" and "waiting": the pull was approved, and its head or base has moved since | |
| 308 | * (`approval_at.ts`). */ | |
| 309 | readonly movedSinceApproval?: boolean; | |
| 306 | 310 | } |
| 307 | 311 | |
| 308 | 312 | /** How a handed-over pull says why: the rounds, and the hand-over. */ |
| @@ -372,17 +376,24 @@ function askCandidatesFor( | ||
| 372 | 376 | const tried = automaticRunsSinceFor(db, spoke); |
| 373 | 377 | const stuckReds = sameRedTwiceFor(db, spoke); |
| 374 | 378 | const retries = latestDecisionsFor(db, red.map((p) => p.id), "retry"); |
| 379 | const green = settled.flatMap((p) => { | |
| 380 | const pull = joined.get(p.id)!; | |
| 381 | const check = checks.get(p.id); | |
| 382 | return check?.state === "ok" && (!isStalePull(db, pull.id, pull.headOid) || isLandedPull(db, pull.id, pull.headOid)) && !staleGreen(db, pull, check) | |
| 383 | ? [{ repo: byId.get(p.repoId)!, pull }] | |
| 384 | : []; | |
| 385 | }); | |
| 386 | // The green pulls' verdicts, read once (none when none is green): the | |
| 387 | // review wait below counts them in place of its own read, and a ship-it | |
| 388 | // ask compares its approval with the head and base (#12524). | |
| 389 | const verdicts: Map<string, readonly Review[]> = | |
| 390 | green.length === 0 ? new Map() : listReviewsFor(db, green.map((g) => g.pull.id)); | |
| 375 | 391 | const waits = reviewWaitsFor( |
| 376 | 392 | db, |
| 377 | settled.flatMap((p) => { | |
| 378 | const pull = joined.get(p.id)!; | |
| 379 | const check = checks.get(p.id); | |
| 380 | return check?.state === "ok" && (!isStalePull(db, pull.id, pull.headOid) || isLandedPull(db, pull.id, pull.headOid)) && !staleGreen(db, pull, check) | |
| 381 | ? [{ repo: byId.get(p.repoId)!, pull }] | |
| 382 | : []; | |
| 383 | }), | |
| 393 | green, | |
| 384 | 394 | new Date(), |
| 385 | 395 | handedOver, |
| 396 | verdicts, | |
| 386 | 397 | ); |
| 387 | 398 | const first = out.length; |
| 388 | 399 | let crews: Map<string, string[]> | undefined; |
| @@ -512,6 +523,9 @@ function askCandidatesFor( | ||
| 512 | 523 | const acted = lastPersonAction(db, idle); |
| 513 | 524 | const nowMs = Date.now(); |
| 514 | 525 | const stale = idle.filter((p) => nowMs - Date.parse(acted.get(p.id)!) > WAIT_LIMIT_MS); |
| 526 | // An idle pull that was not green has had no verdicts read yet: read them only for those. | |
| 527 | const unread = stale.filter((p) => !verdicts.has(p.id) && !green.some((g) => g.pull.id === p.id)).map((p) => p.id); | |
| 528 | if (unread.length > 0) for (const [id, list] of listReviewsFor(db, unread)) verdicts.set(id, list); | |
| 515 | 529 | const advice = recommendationsFor(db, [...stale.map((p) => p.id), ...out.slice(first).filter((a) => a.kind === "handover").map((a) => a.pull!.id)]); |
| 516 | 530 | for (const issue of stale) { |
| 517 | 531 | const since = acted.get(issue.id)!; |
| @@ -534,6 +548,16 @@ function askCandidatesFor( | ||
| 534 | 548 | const rec = a.kind === "handover" ? advice.get(a.pull!.id) : undefined; |
| 535 | 549 | if (rec !== undefined) out[i] = { ...a, recommendation: rec }; |
| 536 | 550 | } |
| 551 | // A ship-it ask on an approved pull says when the approval is for another | |
| 552 | // head or base (#12524), from the verdicts read above and the base the sweep read. | |
| 553 | for (let i = first; i < out.length; i++) { | |
| 554 | const a = out[i]!; | |
| 555 | if (a.pull === undefined || (a.kind !== "look" && a.kind !== "waiting")) continue; | |
| 556 | const reviews = verdicts.get(a.pull.id); | |
| 557 | if (reviews === undefined) continue; | |
| 558 | if (movedSinceApproval(reviews, a.pull.headOid, knownBase(db, a.pull.id, a.pull.headOid))) | |
| 559 | out[i] = { ...a, movedSinceApproval: true }; | |
| 560 | } | |
| 537 | 561 | // Pauses, parked issues, declines and waves carry no pull: one pull's page |
| 538 | 562 | // never shows them, so it never reads them. |
| 539 | 563 | if (only === undefined) repoAsksInto(db, out, repos, byId); |
| @@ -1045,7 +1069,8 @@ function lineOf(c: AskCandidate): string { | ||
| 1045 | 1069 | return `proposes "${c.proposal?.title ?? ""}" and waits for your nod`; |
| 1046 | 1070 | if (c.kind === "declined") |
| 1047 | 1071 | return "the planner declined the direction and waits for you"; |
| 1048 | if (c.kind === "waiting") return `"${c.pull?.title ?? ""}" is ${c.why ?? "waiting"} for a person`; | |
| 1072 | const moved = c.movedSinceApproval === true ? `, ${MOVED_SINCE_APPROVAL}` : ""; | |
| 1073 | if (c.kind === "waiting") return `"${c.pull?.title ?? ""}" is ${c.why ?? "waiting"} for a person${moved}`; | |
| 1049 | 1074 | if (c.kind === "handover") |
| 1050 | 1075 | return `"${c.pull?.title ?? ""}" had three reviews asking for changes and waits for you`; |
| 1051 | 1076 | const title = c.pull?.title ?? ""; |
| @@ -1053,7 +1078,7 @@ function lineOf(c: AskCandidate): string { | ||
| 1053 | 1078 | return `"${title}" waits for your review: ${reviewWhy(c.reviewWait, reviewerPaused(c.repo))}`; |
| 1054 | 1079 | return c.kind === "stopped" |
| 1055 | 1080 | ? `the crew stopped on "${title}"` |
| 1056 | : `"${title}" is green, waiting for your look`; | |
| 1081 | : `"${title}" is green, waiting for your look${moved}`; | |
| 1057 | 1082 | } |
| 1058 | 1083 | |
| 1059 | 1084 | /** Why an agent's change waits for a person's review, in a clause. */ |
src/web/studio/decisions.ts +14 −7
| @@ -21,11 +21,17 @@ import { thumbLook } from "../pages/looks.ts"; | ||
| 21 | 21 | import { changeHref } from "./nouns.ts"; |
| 22 | 22 | import { flatten } from "./note.ts"; |
| 23 | 23 | import { testsClause } from "./words.ts"; |
| 24 | import { MOVED_SINCE_APPROVAL } from "../../core/approval_at.ts"; | |
| 24 | 25 | import { reviewerPaused } from "../../crew/reviewer_paused.ts"; |
| 25 | 26 | import type { Database } from "bun:sqlite"; |
| 26 | 27 | import type { User } from "../../core/users.ts"; |
| 27 | 28 | import { reviewWhy, scoredFor, waitingSplit, type Decision, type Scored } from "./asks.ts"; |
| 28 | 29 | |
| 30 | /** An approved pull whose head or base moved since says so on its row (#12524). */ | |
| 31 | const movedShort = (moved: boolean | undefined): string => (moved === true ? ` · ${MOVED_SINCE_APPROVAL}` : ""); | |
| 32 | const movedSays = (moved: boolean | undefined): string => | |
| 33 | moved === true ? " It was approved, and its head or base has moved since that approval." : ""; | |
| 34 | ||
| 29 | 35 | /** Dollars as a person reads them: cents when small, whole when not. */ |
| 30 | 36 | const dollars = (n: number): string => (n < 10 ? n.toFixed(2) : n.toFixed(0)); |
| 31 | 37 | |
| @@ -140,8 +146,8 @@ export function decisionsFor( | ||
| 140 | 146 | repo: c.repo, |
| 141 | 147 | pull: c.pull, |
| 142 | 148 | who: c.who, |
| 143 | says: `"${c.pull.title}" is ${c.why ?? "waiting"}, and no person has acted on it. Ship it, say what to change, or close it.`, | |
| 144 | short: c.why ?? "waiting for a person", | |
| 149 | says: `"${c.pull.title}" is ${c.why ?? "waiting"}, and no person has acted on it.${movedSays(c.movedSinceApproval)} Ship it, say what to change, or close it.`, | |
| 150 | short: (c.why ?? "waiting for a person") + movedShort(c.movedSinceApproval), | |
| 145 | 151 | why: c.why, |
| 146 | 152 | recommendation: c.recommendation, |
| 147 | 153 | }; |
| @@ -185,11 +191,12 @@ export function decisionsFor( | ||
| 185 | 191 | pull: c.pull, |
| 186 | 192 | who: c.who, |
| 187 | 193 | says: c.authorIsAgent |
| 188 | ? `${c.who} finished "${c.pull.title}" and the check is green${clause === "" ? "" : ` (${clause})`}. Look at the preview, then ship it or say what is off.` | |
| 189 | : `"${c.pull.title}" is green — ${clause === "" ? "" : `${clause}, `}ready for a look. Ship it, or say what is off.`, | |
| 190 | short: c.authorIsAgent | |
| 191 | ? `${c.who} finished it; the check is green${clause === "" ? "" : ` (${clause})`}` | |
| 192 | : `green — ${clause === "" ? "" : `${clause}, `}ready for a look`, | |
| 194 | ? `${c.who} finished "${c.pull.title}" and the check is green${clause === "" ? "" : ` (${clause})`}.${movedSays(c.movedSinceApproval)} Look at the preview, then ship it or say what is off.` | |
| 195 | : `"${c.pull.title}" is green — ${clause === "" ? "" : `${clause}, `}ready for a look.${movedSays(c.movedSinceApproval)} Ship it, or say what is off.`, | |
| 196 | short: | |
| 197 | (c.authorIsAgent | |
| 198 | ? `${c.who} finished it; the check is green${clause === "" ? "" : ` (${clause})`}` | |
| 199 | : `green — ${clause === "" ? "" : `${clause}, `}ready for a look`) + movedShort(c.movedSinceApproval), | |
| 193 | 200 | ...(picture === undefined ? {} : { picture }), |
| 194 | 201 | }; |
| 195 | 202 | } |
test/approval-moved-inbox.test.ts added +129
| @@ -0,0 +1,129 @@ | ||
| 1 | /** | |
| 2 | * An approved pull's inbox row says "moved since approval" once its head or | |
| 3 | * its base is no longer the one the approval was given against (#12524): | |
| 4 | * approve, move the base, re-check green on the new base, and the row changes. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { openPull, submitReview } from "../src/actions/pulls.ts"; | |
| 11 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { movedSinceApproval } from "../src/core/approval_at.ts"; | |
| 14 | import { getPull, type Pull } from "../src/core/pulls.ts"; | |
| 15 | import type { Repo } from "../src/core/repos.ts"; | |
| 16 | import type { Review } from "../src/core/reviews.ts"; | |
| 17 | import { claimRun, createRun, finishRun, setRunBase } from "../src/core/runs.ts"; | |
| 18 | import { createSession } from "../src/core/sessions.ts"; | |
| 19 | import { createUser, type User } from "../src/core/users.ts"; | |
| 20 | import { sweepStaleAsks } from "../src/crew/stale_asks.ts"; | |
| 21 | import { resolveOid } from "../src/git/merge.ts"; | |
| 22 | import { repoDir } from "../src/git/repos.ts"; | |
| 23 | import { forgeHttp, type ForgeHttp } from "../src/http/server.ts"; | |
| 24 | import { askLinesFor } from "../src/web/studio/asks.ts"; | |
| 25 | import { quietLogs } from "./helpers/globals.ts"; | |
| 26 | import { promote } from "./helpers/members.ts"; | |
| 27 | ||
| 28 | quietLogs(); | |
| 29 | ||
| 30 | describe("movedSinceApproval", () => { | |
| 31 | const review = (over: Partial<Review>): Review => ({ | |
| 32 | id: "1", authorId: "a", authorName: "a", originAuthor: null, state: "approved", | |
| 33 | body: "", commitOid: "h1", baseOid: "b1", createdAt: "t", ...over, | |
| 34 | }); | |
| 35 | test("no approval has nothing to move from", () => { | |
| 36 | expect(movedSinceApproval([], "h1", "b2")).toBe(false); | |
| 37 | expect(movedSinceApproval([review({ state: "commented" })], "h2", "b2")).toBe(false); | |
| 38 | }); | |
| 39 | test("moved when the head or the base differs from the approval's", () => { | |
| 40 | expect(movedSinceApproval([review({})], "h1", "b1")).toBe(false); | |
| 41 | expect(movedSinceApproval([review({})], "h1", "b2")).toBe(true); | |
| 42 | expect(movedSinceApproval([review({})], "h2", "b1")).toBe(true); | |
| 43 | }); | |
| 44 | test("an unread base is no move; only the head is judged", () => { | |
| 45 | expect(movedSinceApproval([review({})], "h1", undefined)).toBe(false); | |
| 46 | expect(movedSinceApproval([review({})], "h1", "")).toBe(false); | |
| 47 | expect(movedSinceApproval([review({})], "h2", undefined)).toBe(true); | |
| 48 | }); | |
| 49 | test("an approval from before bases were recorded is judged by its head", () => { | |
| 50 | expect(movedSinceApproval([review({ baseOid: "" })], "h1", "b9")).toBe(false); | |
| 51 | }); | |
| 52 | }); | |
| 53 | ||
| 54 | describe("the inbox row of an approved pull", () => { | |
| 55 | let dataDir: string; | |
| 56 | let app: App; | |
| 57 | let http: ForgeHttp; | |
| 58 | let alice: User; | |
| 59 | let bob: User; | |
| 60 | let repo: Repo; | |
| 61 | let pull: Pull; | |
| 62 | let cookie = ""; | |
| 63 | ||
| 64 | const put = async (branch: string, path: string) => { | |
| 65 | const done = await commitToBranch(app, alice, repo, { branch, message: `edit ${path}`, files: [{ path, content: `${path}\n` }] }); | |
| 66 | if (!done.ok) throw new Error(JSON.stringify(done.error)); | |
| 67 | }; | |
| 68 | const mainTip = async () => (await resolveOid(repoDir(app.reposRoot, "alice", "lib"), "refs/heads/main"))!; | |
| 69 | const green = (baseOid: string) => { | |
| 70 | const run = createRun(app.db, { repoId: repo.id, kind: "check", issueId: pull.id, env: "pull-1", commitOid: pull.headOid }); | |
| 71 | claimRun(app.db, run.id); | |
| 72 | finishRun(app.db, run.id, { state: "ok", summary: "all green" }); | |
| 73 | setRunBase(app.db, run.id, baseOid); | |
| 74 | }; | |
| 75 | const row = () => askLinesFor(app.db, alice).find((r) => r.items.includes(`look:${pull.id}`)); | |
| 76 | /** The asks page: the inbox, where each ask is drawn with its short line. */ | |
| 77 | const asks = async () => (await http.handle(new Request("http://forge.test/asks", { headers: { cookie } }))).text(); | |
| 78 | ||
| 79 | beforeAll(async () => { | |
| 80 | dataDir = await mkdtemp(join(tmpdir(), "forge-approval-moved-")); | |
| 81 | app = createApp({ dataDir, port: 0, host: "forge.test" }); | |
| 82 | http = forgeHttp(app); | |
| 83 | const mk = async (username: string, first: boolean) => { | |
| 84 | const made = await createUser(app.db, { | |
| 85 | origin: "seed", trusted: true, username, email: `${username}@forge.local`, | |
| 86 | password: "a-good-passphrase", adminIfFirst: first, | |
| 87 | }); | |
| 88 | if (!made.ok) throw new Error(made.error); | |
| 89 | return made.value; | |
| 90 | }; | |
| 91 | alice = await mk("alice", true); | |
| 92 | bob = await mk("bob", false); | |
| 93 | promote(app.db, bob); | |
| 94 | app.db.run("UPDATE user SET is_admin = 1 WHERE id = ?1", [bob.id]); | |
| 95 | bob = { ...bob, isAdmin: true }; | |
| 96 | cookie = `forge_session=${createSession(app.db, alice.id).token}`; | |
| 97 | const made = await createRepo(app, alice, { name: "lib", visibility: "public" }); | |
| 98 | if (!made.ok) throw new Error(String(made.error)); | |
| 99 | repo = made.value; | |
| 100 | await put("main", "a.md"); | |
| 101 | await put("feat", "f.md"); | |
| 102 | const opened = await openPull(app, alice, repo, { title: "Feat", baseBranch: "main", headBranch: "feat" }); | |
| 103 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 104 | pull = getPull(app.db, repo.id, opened.value.number)!; | |
| 105 | green(await mainTip()); | |
| 106 | await sweepStaleAsks(app); | |
| 107 | }, 60_000); | |
| 108 | ||
| 109 | afterAll(async () => { | |
| 110 | app.close(); | |
| 111 | await rm(dataDir, { recursive: true, force: true }); | |
| 112 | }); | |
| 113 | ||
| 114 | test("approved on the current base: the row asks for a look and says nothing moved", async () => { | |
| 115 | const approved = await submitReview(app, bob, repo, pull, { state: "approved" }); | |
| 116 | if (!approved.ok) throw new Error(String(approved.error)); | |
| 117 | expect(row()?.line).toBe(`lib: "Feat" is green, waiting for your look`); | |
| 118 | expect(await asks()).toContain("ready for a look"); | |
| 119 | expect(await asks()).not.toContain("moved since approval"); | |
| 120 | }); | |
| 121 | ||
| 122 | test("the base moves and the pull is checked green again: the row says moved since approval", async () => { | |
| 123 | await put("main", "b.md"); | |
| 124 | green(await mainTip()); | |
| 125 | await sweepStaleAsks(app); | |
| 126 | expect(row()?.line).toBe(`lib: "Feat" is green, waiting for your look, moved since approval`); | |
| 127 | expect(await asks()).toContain("moved since approval"); | |
| 128 | }, 60_000); | |
| 129 | }); |
new above
offline