Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,13 @@ The rules that hold:
connected user, or, for an entry the decide list marks `project`, a
project-steward approval recorded in the store and bound to the head sha
(BB-30); a signed comment is a thread's, never the owner's. An unknown
lane is owner-reviewed, not no-review. The merge
lane is owner-reviewed, not no-review. Any comment whose first line opens
a `bb-review` marker is a round, however it is spelled: a marker missing
`verdict=` reads its verdict from a bare word (`changes-requested`) or as
`unreadable`, and one missing `lane=` is the owner's, so a malformed later
round closes the gate rather than leaving an earlier `approved` as the
latest word (bb-plugins#88 asked the owner to approve a head the reviewer
had just rejected that way). The merge
button, the item the plugin files and the wake's "Lane gate" line all read
it, so a steward is told whether a pull request's gate is met in the same
words the button acts on.
Expand Down
21 changes: 20 additions & 1 deletion plugins/stewards/reconcile.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from "vitest";
import { parsePlaybook, phaseOf } from "./config.js";
import { comment, issue, pull } from "./fixtures.js";
import { approvalWanted, answerDiffers, anyWorkerInFlight, asksForOpenApproval, classifyApproval, commentDiffersFromRecommendation, compactDue, diffObserved, endingDeadline, followingThrough, gateKnownUnmet, gateState, isCommentNews, isOwnStageMove, lifecycle, markerLaneChange, namesUserAsBlocker, ownerApproval, prGate, resolveChecklistItem, reviewMarker, specHash, stuckDue, unheardWait, workerInFlight, workerReportedTerminal } from "./reconcile.js";
import { approvalWanted, answerDiffers, anyWorkerInFlight, asksForOpenApproval, classifyApproval, commentDiffersFromRecommendation, compactDue, diffObserved, endingDeadline, followingThrough, gateKnownUnmet, gateState, isCommentNews, isOwnStageMove, lifecycle, markerLaneChange, namesUserAsBlocker, ownerApproval, prGate, resolveChecklistItem, reviewMarker, specHash, stuckDue, UNREADABLE_VERDICT, unheardWait, workerInFlight, workerReportedTerminal } from "./reconcile.js";
import { readyStateSchema } from "./store.js";
import { GITHUB_REVIEWS, LINEAR_TICKETS } from "./templates.js";

Expand Down Expand Up @@ -433,6 +433,25 @@ describe("the pull request gate (build-tickets)", () => {
expect(prGate(pull({ comments: [marker(earlier, "approved", "no-review")] }, { checks: { state: "failure", failing: ["ci"] } })).missing).toMatch(/checks failure/u);
});

it("reads a malformed later marker as a round that is not approved, never as the earlier approval (bb-plugins#88)", () => {
// The reviewer's round 2 on bb-plugins#88 was `<!-- bb-review round=2 sha=S changes-requested -->`:
// no `verdict=`, no `lane=`. Skipping it would make round 1's `approved` the latest word
// and file an approve-pr item for the owner on a head the reviewer had just rejected.
const bad = comment({ id: "m-bad", author: "trotterdylan", body: "<!-- bb-review round=2 sha=ccccccc3 changes-requested -->\n\n## Review round 2", signedBy: "thr_reviewer", createdAt: "2026-10-14T16:30:00Z" });
expect(reviewMarker(bad.body)).toEqual({ round: 2, sha: "ccccccc3", verdict: "changes-requested", lane: null });
const gate = prGate(pull({ comments: [marker(head, "approved", "owner-reviewed"), bad] }, green));
expect(gate).toMatchObject({ gateMet: false, needsOwnerApproval: false, lane: null, missing: "reviewer verdict: changes-requested" });
// A marker with nothing readable at all still closes the gate, in the owner's lane.
const empty = comment({ id: "m-empty", author: "trotterdylan", body: "<!-- bb-review -->", signedBy: "thr_reviewer", createdAt: "2026-10-14T16:40:00Z" });
expect(reviewMarker(empty.body)).toEqual({ round: 0, sha: "", verdict: UNREADABLE_VERDICT, lane: null });
expect(prGate(pull({ comments: [marker(head, "approved", "no-review"), empty] }, green))).toMatchObject({ gateMet: false, needsOwnerApproval: false, missing: `reviewer verdict: ${UNREADABLE_VERDICT}` });
// A marker that names no lane is not a lane change.
expect(markerLaneChange([marker(head, "approved", "owner-reviewed")], [marker(head, "approved", "owner-reviewed"), bad])).toBeNull();
// Keys in another order, or a verdict that is not approved, still read.
expect(reviewMarker("<!-- bb-review lane=no-review verdict=approved sha=abc round=3 -->")).toEqual({ round: 3, sha: "abc", verdict: "approved", lane: "no-review" });
expect(reviewMarker("<!-- bb-reviewer round=1 -->")).toBeNull();
});

it("waits on the owner in the owner-reviewed lane, and closes once they approve", () => {
const waiting = prGate(pull({ comments: [marker(head, "approved", "owner-reviewed")] }, green));
expect(waiting).toMatchObject({ gateMet: false, needsOwnerApproval: true, missing: "owner approval needed" });
Expand Down
41 changes: 35 additions & 6 deletions plugins/stewards/reconcile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,45 @@ export type Change = { text: string; actionable: boolean; own?: boolean; byUser?
export const workerInFlight = (w: Pick<Worker, "status">): boolean => w.status === "running" || w.status === "finished";
export const anyWorkerInFlight = (workers: readonly Pick<Worker, "status">[]): boolean => workers.some(workerInFlight);

/** A reviewer's machine-readable verdict, as `pr-reviewer` posts it on the first line of a comment. */
export type ReviewMarker = { round: number; sha: string; verdict: string; lane: string };
/**
* A reviewer's machine-readable verdict, as `pr-reviewer` posts it on the
* first line of a comment. `lane` is null when the marker did not name one
* (the gate then treats the pull request as the owner's).
*/
export type ReviewMarker = { round: number; sha: string; verdict: string; lane: string | null };

const REVIEW_MARKER = /^<!--\s*bb-review\s+round=(\d+)\s+sha=(\S+)\s+verdict=(\S+)\s+lane=(\S+)\s*-->/u;
const REVIEW_MARKER = /^<!--\s*bb-review\b([^>]*?)-->/u;

/** The reviewer's marker on a comment, or null for any other comment. */
/** The verdict a marker without `verdict=` is read as: never `approved`. */
export const UNREADABLE_VERDICT = "unreadable";

/**
* The reviewer's marker on a comment, or null for any other comment. Any
* first line that opens a `bb-review` comment is a marker, however it is
* spelled: a round whose keys are missing or misspelled still closes the
* gate, because the alternative is to read the previous round's `approved`
* as the latest word. A missing `verdict=` is read from a bare word in the
* marker (`changes-requested`) and otherwise is `unreadable`; neither is
* `approved`.
*/
export function reviewMarker(body: string): ReviewMarker | null {
const first = body.split("\n", 1)[0]!.trim();
const m = REVIEW_MARKER.exec(first);
return m === null ? null : { round: Number(m[1]), sha: m[2]!, verdict: m[3]!, lane: m[4]! };
if (m === null) return null;
const keyed = new Map<string, string>();
const bare: string[] = [];
for (const token of m[1]!.trim().split(/\s+/u).filter((t) => t !== "")) {
const eq = token.indexOf("=");
if (eq > 0) keyed.set(token.slice(0, eq).toLowerCase(), token.slice(eq + 1));
else bare.push(token);
}
const round = Number(keyed.get("round") ?? "");
return {
round: Number.isInteger(round) && round > 0 ? round : 0,
sha: keyed.get("sha") ?? "",
verdict: keyed.get("verdict") ?? bare[0] ?? UNREADABLE_VERDICT,
lane: keyed.get("lane") ?? null,
};
}

/** The newest reviewer marker in a comment list, by comment time. */
Expand All @@ -59,7 +88,7 @@ export function latestReviewMarker(comments: readonly SnapshotComment[]): Review
export function markerLaneChange(before: readonly SnapshotComment[], after: readonly SnapshotComment[]): { from: string; to: string } | null {
const b = latestReviewMarker(before);
const a = latestReviewMarker(after);
if (b === null || a === null || b.lane === a.lane) return null;
if (b === null || a === null || b.lane === null || a.lane === null || b.lane === a.lane) return null;
return { from: b.lane, to: a.lane };
}

Expand Down
Loading