From 85695c6ba2d53b9ded08071ec79d416437d4fc71 Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Tue, 3 Nov 2026 18:27:57 +0000 Subject: [PATCH] Changes-requested: live results in review_gates, re-read blocked PRs each merge run, fail a batch whose PR has changes requested --- src/dash/api/queue.ts | 2 +- src/merge/batch-store.ts | 4 ++- src/merge/batch.ts | 13 +++++-- src/merge/changes-requested.ts | 54 ++++++++++++++++++++++++---- src/merge/index.ts | 7 +++- src/merge/queue.ts | 14 ++++++-- src/review/discussion.ts | 8 ++--- src/schema.sql | 10 ++++++ test/changes-requested.test.ts | 36 +++++++++++++++++-- test/merge.test.ts | 10 ++++++ web/src/api/mock/queueFixtures.ts | 1 + web/src/api/types.ts | 2 ++ web/src/modules/queue/mergeParts.tsx | 1 + 13 files changed, 141 insertions(+), 21 deletions(-) diff --git a/src/dash/api/queue.ts b/src/dash/api/queue.ts index c2a5db37..33965c37 100644 --- a/src/dash/api/queue.ts +++ b/src/dash/api/queue.ts @@ -20,7 +20,7 @@ export const toRow = (e: QueueEntry): QueueRow => ({ verdict: e.verdict, reason: e.reason, fixes: e.fixes, ci: (CI.includes(e.ci) ? e.ci : "unknown") as QueueRow["ci"], mergeable: MERGEABLE[e.mergeable] ?? "unknown", state: e.state as QueueState, path: e.path, outsideRule: e.outsideRule, decisionId: e.decisionId, answer: e.answer, - refusedReason: e.refusedReason, reviewedAt: e.reviewedAt, verify: e.verify, + refusedReason: e.refusedReason, note: e.note, reviewedAt: e.reviewedAt, verify: e.verify, }); /** `repo#number` cursor of the last row of a page. */ diff --git a/src/merge/batch-store.ts b/src/merge/batch-store.ts index a593a3e0..d37e67f9 100644 --- a/src/merge/batch-store.ts +++ b/src/merge/batch-store.ts @@ -8,6 +8,8 @@ export type BatchState = (typeof BATCH_STATES)[number]; export const ACTIVE_BATCH: BatchState[] = ["checking", "open"]; /** Summary of a batch whose PR a person closed: its PRs stay out of batches until they change. */ +/** Summary of a batch that failed because a maintainer requested changes on its PR: its members are held like those of a batch a person closed. */ +export const BLOCKED_BY_REVIEW = "a maintainer requested changes on the batch PR"; export const CLOSED_BY_PERSON = "the batch PR was closed by a person"; export const MAX_BATCH = 10; @@ -92,7 +94,7 @@ export function batchStates(db: DatabaseSync, repo?: string): Map(); for (const r of rows) { - if (r.state === "failed" && r.n !== 1 && r.summary !== CLOSED_BY_PERSON) continue; + if (r.state === "failed" && r.n !== 1 && r.summary !== CLOSED_BY_PERSON && r.summary !== BLOCKED_BY_REVIEW) continue; out.set(`${r.repo}#${r.number}@${r.head_oid}`, r.state === "checking" ? "batch-checking" : r.state === "open" ? "in-batch" : "batch-failed"); } return out; diff --git a/src/merge/batch.ts b/src/merge/batch.ts index 43696faa..da552809 100644 --- a/src/merge/batch.ts +++ b/src/merge/batch.ts @@ -26,7 +26,7 @@ import { refreshChecks } from "../review/checks.ts"; import { type Verdict, outcomeOf, summariseFailure } from "../verify/results.ts"; import { rustPlan } from "../worker/rust.ts"; import { BatchGit } from "./batch-git.ts"; -import { ACTIVE_BATCH, CLOSED_BY_PERSON, activeBatches, admits, batchSizeOf, getBatch, growBatchSize, insertBatch, membersOf, nextBranch, restartCheck, shrinkBatchSize, updateBatch, type BatchMember, type BatchRow } from "./batch-store.ts"; +import { ACTIVE_BATCH, BLOCKED_BY_REVIEW, CLOSED_BY_PERSON, activeBatches, admits, batchSizeOf, getBatch, growBatchSize, insertBatch, membersOf, nextBranch, restartCheck, shrinkBatchSize, updateBatch, type BatchMember, type BatchRow } from "./batch-store.ts"; import { mergeApprovalOf } from "./approval.ts"; import { ORG, prInfo, viewerOf, mergeRun, DEFAULT_MERGE_COMMAND, type CommandResult } from "./index.ts"; import { liveGateChecked } from "../review/discussion.ts"; @@ -346,7 +346,16 @@ export async function runBatches(db: DatabaseSync, params: BatchParams, log: (li // The batch PR is ours but a maintainer may review it too. const own = await liveGateChecked(db, d.querier, repo, b.pr_number!, "", log); if (own === null) { s.waiting.push(b.branch); return; } - if (own.blocked) return supersede(b, members, `the batch PR has a review: ${own.blocked}`); + if (own.blocked) { + // Rebuilding would only open a new PR around the review: the batch fails and its PRs wait for a new head. + updateBatch(db, b.id, at(), { state: "failed", summary: BLOCKED_BY_REVIEW }); + await closePr(b, `Closing: ${own.blocked}. The PRs in it are held until they change.`); + for (const m of members) stage.run(repo, m.number, "hold", at(), ACTOR, `the batch PR ${b.branch} has changes requested; held at ${short(m.head_oid)}`); + s.failed.push(...members.map((m) => m.number)); + for (const m of members) await release(m.number); + log(` ${b.branch}: ${own.blocked}; its PRs are held until they change`); + return; + } for (const m of members) { const gate = await liveGateChecked(db, d.querier, repo, m.number, m.head_oid, log); if (gate === null) { s.waiting.push(b.branch); return; } diff --git a/src/merge/changes-requested.ts b/src/merge/changes-requested.ts index 695a5890..407159a8 100644 --- a/src/merge/changes-requested.ts +++ b/src/merge/changes-requested.ts @@ -7,6 +7,7 @@ // `authorAssociation` is relative to the viewer: a private org member can show as CONTRIBUTOR or NONE. // The mirror stores only the association, so there a reviewer blocks unless the association says a stranger. import type { DatabaseSync } from "node:sqlite"; +import type { Querier } from "../mirror.ts"; export type ReviewFact = { id?: string | null; author: string | null; association: string | null; state: string | null; at: string | null }; @@ -48,12 +49,51 @@ export function refuseLive(formal: ReviewFact[], decision?: string | null): stri return decision === "CHANGES_REQUESTED" ? REASON : null; } -/** Association stored for a review a writers-only read returned: the read's own association is relative to the viewer and may say NONE. */ -export const WRITER = "WRITER"; +/** Failed live reads in a row after which the queue says so. */ +export const GATE_FAILURES = 3; -/** Writes what a live read saw back to the mirror, so the queue agrees with it before the next sync. Existing rows keep their text. */ -export function recordFormalReviews(db: DatabaseSync, repo: string, number: number, formal: ReviewFact[]): void { - const up = db.prepare(`INSERT INTO comments (repo, number, id, kind, author, created_at, body, review_state, counted, author_association) - VALUES (?, ?, ?, 'review', ?, ?, '', ?, 0, ?) ON CONFLICT (id) DO UPDATE SET review_state = excluded.review_state, author_association = excluded.author_association`); - for (const r of formal) if (r.id && r.author) up.run(repo, number, r.id, r.author, r.at, r.state, WRITER); +export type Gate = { blocked: boolean; by: string[]; readAt: string; failures: number }; + +/** What the live reads stored for the PRs, as `repo#number`. */ +export function gatesOf(db: DatabaseSync, repo?: string): Map { + const rows = db.prepare(`SELECT repo, number, blocked, by_login, read_at, failures FROM review_gates ${repo ? "WHERE repo = ?" : ""}`).all(...(repo ? [repo] : [])) as + { repo: string; number: number; blocked: number | null; by_login: string | null; read_at: string | null; failures: number }[]; + return new Map(rows.map((r) => [`${r.repo}#${r.number}`, { blocked: r.blocked === 1, by: r.by_login ? r.by_login.split(",") : [], readAt: r.read_at ?? "", failures: r.failures }])); } + +/** Stores a successful live read. The table is ours, so a sync cannot wipe it; the queue trusts it over the mirror until the PR changes. */ +export function recordGate(db: DatabaseSync, repo: string, number: number, formal: ReviewFact[], decision: string | null | undefined, at = new Date().toISOString()): string | null { + const reason = refuseLive(formal, decision); + db.prepare(`INSERT INTO review_gates (repo, number, blocked, by_login, read_at, failures) VALUES (?, ?, ?, ?, ?, 0) + ON CONFLICT (repo, number) DO UPDATE SET blocked = excluded.blocked, by_login = excluded.by_login, read_at = excluded.read_at, failures = 0`) + .run(repo, number, reason ? 1 : 0, blockedByWriters(formal).join(","), at); + return reason; +} + +export function recordGateFailure(db: DatabaseSync, repo: string, number: number): void { + db.prepare("INSERT INTO review_gates (repo, number, failures) VALUES (?, ?, 1) ON CONFLICT (repo, number) DO UPDATE SET failures = failures + 1").run(repo, number); +} + +const SMALL_QUERY = `query($owner: String!, $name: String!, $number: Int!) { repository(owner: $owner, name: $name) { pullRequest(number: $number) { reviewDecision ${FORMAL_REVIEWS} } } }`; +type Formal = { id?: string; author?: { login?: string } | null; authorAssociation?: string; submittedAt?: string; createdAt?: string; state?: string }; + +/** The writers-only reviews as facts. */ +export const factsOf = (nodes: Formal[]): ReviewFact[] => + nodes.map((n) => ({ id: n.id ?? null, author: n.author?.login ?? null, association: n.authorAssociation ?? null, state: n.state ?? null, at: n.submittedAt ?? n.createdAt ?? null })); + +/** A small live read of one PR's formal reviews, stored. Returns the block reason or null; a failed read is counted and returns undefined. */ +export async function readGate(db: DatabaseSync, q: Querier, owner: string, repo: string, number: number, log: (line: string) => void = () => {}): Promise { + try { + const res = await q.query(SMALL_QUERY, { owner, name: repo, number }); + const pr = res?.repository?.pullRequest; + if (!pr) throw new Error("no such PR"); + return recordGate(db, repo, number, factsOf((pr.latestOpinionatedReviews?.nodes ?? []) as Formal[]), pr.reviewDecision); + } catch (e) { + recordGateFailure(db, repo, number); + log(` ${repo}#${number}: could not read its reviews (${String((e as Error).message ?? e).replace(/\s+/g, " ").slice(0, 200)})`); + return undefined; + } +} + +/** The note the queue shows when live reads keep failing. */ +export const failureNote = (n: number): string => `reviews could not be read from GitHub ${n} times in a row`; diff --git a/src/merge/index.ts b/src/merge/index.ts index 42d1cde1..660fbd98 100644 --- a/src/merge/index.ts +++ b/src/merge/index.ts @@ -20,6 +20,7 @@ import { actionable, ask, factsOf, getDecision } from "../decisions.ts"; import { assignTo, mergeViaCommand, MERGE_RECORDED_ENV, type Writer } from "../github/write.ts"; import { Client, markMerged, type Querier } from "../mirror.ts"; import { refreshChecks } from "../review/checks.ts"; +import { readGate } from "./changes-requested.ts"; import { liveGateChecked } from "../review/discussion.ts"; import { fillReviewSummaries } from "../review/summary.ts"; import { verificationOf } from "../verify/results.ts"; @@ -205,6 +206,11 @@ export async function runMerge(db: DatabaseSync, params: MergeParams, log: (line log(`merge ${repo}: not in the pipeline scope; nothing done`); return { runId, repo, dryRun, states: {}, attempted: [], merged: [], refused: [], asked: [] }; } + const d = deps ?? defaultDeps(); + // A PR in changes-requested is read live again each run: the mirror alone can block wrongly (the association is relative to the viewer) and a blocked PR never reaches the merge-time read. + if (!dryRun) { + for (const e of buildQueue(db, { repo, merged: "exclude" })) if (e.state === "changes-requested") await readGate(db, d.querier, ORG, repo, e.number, log); + } const queue = buildQueue(db, { repo }); const open = queue.filter((e) => e.state !== "merged"); const states = countStates(queue); @@ -227,7 +233,6 @@ export async function runMerge(db: DatabaseSync, params: MergeParams, log: (line log(`merge ${repo}: dry run, nothing called or written`); return summary; } - const d = deps ?? defaultDeps(); // A Merge? question open for a PR a maintainer has since blocked no longer applies. const withdrawn = withdrawBlockedQuestions(db, open, at()); diff --git a/src/merge/queue.ts b/src/merge/queue.ts index 662b3eae..49aa1a18 100644 --- a/src/merge/queue.ts +++ b/src/merge/queue.ts @@ -7,7 +7,7 @@ import { actionable } from "../decisions.ts"; import { backlogHeld, duplicateHeld, notOwnIntegrationSql } from "../dupes/held.ts"; import { headOf } from "../review/candidates.ts"; import { changedSince, discussionState, staleReviews } from "../review/discussion.ts"; -import { refuseReviews, type ReviewFact } from "./changes-requested.ts"; +import { failureNote, GATE_FAILURES, gatesOf, reasonFor, refuseReviews, type ReviewFact } from "./changes-requested.ts"; import { batchStates } from "./batch-store.ts"; import { mergeHolds } from "./holds.ts"; import { getRule, STATS_SQL, tierOf, type Tier } from "../whitelist.ts"; @@ -75,6 +75,8 @@ export type QueueEntry = { reviewedAt: string; /** An operator holds the PR's merge (src/merge/controls.ts): it is reviewed and fixed as usual but does not merge, alone or in a batch. */ held: boolean; + /** A line on the state: why a maintainer's review blocks it, or that its reviews cannot be read. */ + note: string | null; /** The verification of the PR's current head, or null when there is none. */ verify: { state: string; kind: string | null; summary: string | null; note: string | null } | null; }; @@ -178,6 +180,7 @@ export function buildQueue(db: DatabaseSync, opts: QueueOptions = {}): QueueEntr // The mirror keeps the latest 10 reviews of a PR; GitHub's review decision covers an older block that fell out of them. const reviewRows = db.prepare("SELECT author, author_association AS association, review_state AS state, created_at AS at FROM comments WHERE repo = ? AND number = ? AND kind = 'review'"); + const gates = gatesOf(db, opts.repo); const holds = mergeHolds(db, opts.repo); const noCiMemo = new Map(); const noCi = (repo: string) => noCiMemo.get(repo) ?? (noCiMemo.set(repo, repoHasNoCi(db, repo)), noCiMemo.get(repo)!); @@ -214,11 +217,16 @@ export function buildQueue(db: DatabaseSync, opts: QueueOptions = {}): QueueEntr const e: QueueEntry = { repo: r.repo, number: r.number, title: r.title ?? "", author: r.author, tier, head: r.r_head, size, label, verdict: r.verdict, reason: r.reason, fixes, ci, mergeable, state: "needs-decision", path: null, outsideRule, - decisionId: asked ? id : null, noCi: ci === "none" && noCi(r.repo), answer, refusedReason: null, reviewedAt: r.r_at, verify, held: holds.has(`${r.repo}#${r.number}`), + decisionId: asked ? id : null, noCi: ci === "none" && noCi(r.repo), answer, refusedReason: null, reviewedAt: r.r_at, verify, held: holds.has(`${r.repo}#${r.number}`), note: null, }; const open = r.state === "OPEN" && !mergedByUs; // A maintainer's formal block comes before everything else: the PR is never asked about, batched or merged while it stands. - if (open && refuseReviews(reviewRows.all(r.repo, r.number) as ReviewFact[], r.review_decision)) { e.state = "changes-requested"; out.push(e); continue; } + // A live read newer than the PR's last change decides; otherwise the mirrored reviews do. + const gate = gates.get(`${r.repo}#${r.number}`); + const live = gate && gate.readAt > (r.updated_at ?? "") ? gate : null; + const why = live ? (live.blocked ? reasonFor(live.by) : null) : refuseReviews(reviewRows.all(r.repo, r.number) as ReviewFact[], r.review_decision); + if (open && gate && gate.failures >= GATE_FAILURES) e.note = failureNote(gate.failures); + if (open && why) { e.state = "changes-requested"; e.note = why; out.push(e); continue; } e.state = stateOf(e, r.state === "MERGED" || mergedByUs, last, open && (backlogHeld(db, r.repo, r.number) ? "backlog" : duplicateHeld(db, r.repo, r.number) ? "duplicate" : null), r.r_final === 1 && !(open && (stale.has(`${r.repo}#${r.number}@${r.r_head}`) || (r.o_at !== null && changedSince(state.get(`${r.repo}#${r.number}`), r.o_seen ?? r.o_at, r.o_hash))))); const batch = inBatch.get(`${r.repo}#${r.number}@${r.r_head}`); if (batch && BATCHABLE.includes(e.state)) e.state = batch; diff --git a/src/review/discussion.ts b/src/review/discussion.ts index 90053aa0..0ed48c12 100644 --- a/src/review/discussion.ts +++ b/src/review/discussion.ts @@ -6,7 +6,7 @@ import { createHash } from "node:crypto"; import type { DatabaseSync } from "node:sqlite"; import { audit } from "../dash/audit.ts"; import type { Querier } from "../mirror.ts"; -import { FORMAL_REVIEWS, recordFormalReviews, refuseLive, type ReviewFact } from "../merge/changes-requested.ts"; +import { FORMAL_REVIEWS, recordGate, recordGateFailure, type ReviewFact } from "../merge/changes-requested.ts"; import { ENTRY_LIMIT, TOTAL_LIMIT, type DiscussionEntry } from "./parse.ts"; /** Setting that holds the pipeline account's login (also read by src/merge/queue.ts). */ @@ -269,12 +269,11 @@ export async function ensurePipelineLogin(db: DatabaseSync, q: Querier): Promise * Just before a merge: reads the PR's discussion and reviews live in one query. `moved`: a counted entry newer than * the final review's snapshot (and different from what it read) exists; the PR's reviews are then marked stale so the * pipeline reviews it again. `blocked`: a maintainer's changes-requested review stands. Either way the caller must - * not merge. What the read saw of the formal reviews is written back to the mirror. + * not merge. What the read saw of the formal reviews is stored in review_gates. */ export async function liveGate(db: DatabaseSync, q: Querier, repo: string, number: number, head: string): Promise<{ moved: boolean; blocked: string | null }> { const live = await liveDiscussion(q, db, repo, number); - recordFormalReviews(db, repo, number, live.formal); - const blocked = refuseLive(live.formal, live.reviewDecision); + const blocked = recordGate(db, repo, number, live.formal, live.reviewDecision); const snap = (db.prepare(`SELECT COALESCE(o.seen_at, o.at) AS seen, o.disc_hash AS hash FROM opus_reviews o JOIN reviews r ON r.repo = o.repo AND r.number = o.number AND r.head_oid = o.head_oid AND o.at >= r.at WHERE o.repo = ? AND o.number = ? AND o.head_oid = ? AND o.verdict IS NOT NULL`).get(repo, number, head) ?? db.prepare("SELECT COALESCE(seen_at, at) AS seen, disc_hash AS hash FROM reviews WHERE repo = ? AND number = ? AND head_oid = ?").get(repo, number, head)) as { seen: string; hash: string | null } | undefined; @@ -300,6 +299,7 @@ export async function liveGateChecked(db: DatabaseSync, q: Querier, repo: string try { return await withRetry(() => liveGate(db, q, repo, number, head)); } catch (e) { + recordGateFailure(db, repo, number); log(` ${repo}#${number}: could not read its discussion and reviews (${String((e as Error).message ?? e).replace(/\s+/g, " ").slice(0, 200)}); skipped this run`); return null; } diff --git a/src/schema.sql b/src/schema.sql index 350cafd3..2ef52094 100644 --- a/src/schema.sql +++ b/src/schema.sql @@ -335,6 +335,16 @@ CREATE TABLE IF NOT EXISTS sync_runs ( ); CREATE INDEX IF NOT EXISTS sync_runs_started ON sync_runs(started_at); +-- What the last live read of a PR's formal reviews found (changes-requested.ts); sync never touches it. +CREATE TABLE IF NOT EXISTS review_gates ( + repo TEXT NOT NULL, number INTEGER NOT NULL, + blocked INTEGER, -- 1 when a reviewer with write access has changes requested; NULL before any read + by_login TEXT, -- those reviewers, comma separated + read_at TEXT, -- ISO time of the last successful read + failures INTEGER NOT NULL DEFAULT 0, -- reads that failed since the last success + PRIMARY KEY (repo, number) +); + -- CI and merge state of open PRs at their head commit, for review candidates. -- Written by `autocraft checks` and the Review stage; sync never touches it. CREATE TABLE IF NOT EXISTS pr_checks ( diff --git a/test/changes-requested.test.ts b/test/changes-requested.test.ts index c0d5f57d..9b12f584 100644 --- a/test/changes-requested.test.ts +++ b/test/changes-requested.test.ts @@ -2,7 +2,7 @@ import assert from "node:assert/strict"; import { join } from "node:path"; import { describe, test } from "node:test"; import type { DatabaseSync } from "node:sqlite"; -import { changesRequestedBy, type ReviewFact } from "../src/merge/changes-requested.ts"; +import { changesRequestedBy, failureNote, recordGate, recordGateFailure, type ReviewFact } from "../src/merge/changes-requested.ts"; import { runBatches } from "../src/merge/batch.ts"; import { activeBatches, membersOf, setBatchSize } from "../src/merge/batch-store.ts"; import { askMergeDecisions } from "../src/merge/index.ts"; @@ -74,6 +74,35 @@ describe("changes requested: queue", () => { }); }); +describe("changes requested: live reads", () => { + const ana: ReviewFact = { id: "x", author: "ana", association: "NONE", state: "CHANGES_REQUESTED", at: "2026-01-03T00:00:00Z" }; + test("a live read survives a sync, and decides over the mirror until the PR changes", () => { + const db = fresh([{ n: 1 }]); + recordGate(db, "app", 1, [ana], null); + // A sync rewrites the PR's comments and knows nothing of the block. + db.prepare("DELETE FROM comments WHERE repo = 'app' AND number = 1").run(); + assert.equal(states(db)[1], "changes-requested"); + // A newer live read that finds none clears it even though the mirror says otherwise. + review(db, 1, "bo", "CHANGES_REQUESTED", "CONTRIBUTOR", "2026-01-03T00:00:00Z"); + recordGate(db, "app", 1, [], null); + assert.equal(states(db)[1], "ready"); + // The PR changes after the read: the mirror decides again until the next read. + db.prepare("UPDATE items SET updated_at = '2999-01-01T00:00:00Z' WHERE number = 1").run(); + assert.equal(states(db)[1], "changes-requested"); + }); + + test("the queue says so after three failed reads in a row", () => { + const db = fresh([{ n: 1 }]); + const note = () => buildQueue(db, { repo: "app" })[0]!.note; + recordGateFailure(db, "app", 1); recordGateFailure(db, "app", 1); + assert.equal(note(), null); + recordGateFailure(db, "app", 1); + assert.equal(note(), failureNote(3)); + recordGate(db, "app", 1, [], null); + assert.equal(note(), null); + }); +}); + describe("changes requested: decisions", () => { test("a hold answer stands when the PR becomes blocked; a merge answer is set aside", () => { const db = fresh([{ n: 1, author: "newcomer" }, { n: 2, author: "newcomer" }]); @@ -142,7 +171,7 @@ describe("changes requested: batches", () => { assert.deepEqual(states(db), { 1: "batch-checking", 2: "changes-requested", 3: "batch-checking" }); }); - test("a review on the batch PR itself stops the merge", async () => { + test("a review on the batch PR itself fails the batch and holds its PRs", async () => { const db = fresh([{ n: 1 }, { n: 2 }]); const w = world(); const d = deps(w, join(dir, "cr3")); @@ -163,6 +192,9 @@ describe("changes requested: batches", () => { const s = await runBatches(db, { repo: "app" }, quiet, d); assert.deepEqual(s.merged, []); assert.ok(!w.log.some((l) => l.startsWith("safe-merge-test"))); + assert.deepEqual(s.superseded, []); + assert.deepEqual(activeBatches(db, "app"), []); + assert.deepEqual(states(db), { 1: "batch-failed", 2: "batch-failed" }); }); test("a member that gets a changes-requested review before the batch PR merges is dropped, and nothing merges", async () => { diff --git a/test/merge.test.ts b/test/merge.test.ts index 8c0f93ee..341f8916 100644 --- a/test/merge.test.ts +++ b/test/merge.test.ts @@ -83,6 +83,7 @@ function fakes(log: Log, f: Fake = {}): MergeDeps & { calls: () => number } { spent: 0, remaining: 5000, async query(query: string, vars: object) { if (query.includes("reviewThreads")) return { repository: { pullRequest: { author: null, comments: { nodes: f.discussion ?? [] }, reviews: { nodes: [] }, formal: { nodes: f.formal ?? [] }, reviewThreads: { nodes: [] } } } }; + if (query.includes("latestOpinionatedReviews")) return { repository: { pullRequest: { reviewDecision: null, latestOpinionatedReviews: { nodes: f.formal ?? [] } } } }; n++; const v = vars as { n?: number; id?: string }; if (query.includes("viewer")) { log.push("viewer"); return { viewer: { login: "pipeline-bot", id: "U1" } }; } @@ -203,6 +204,15 @@ describe("merge queue", () => { assert.equal(stateOf(db, 1), "changes-requested"); }); + test("a block the mirror guessed wrongly is cleared by the live read of the next run", async () => { + const db = fresh(); + // The association is relative to the viewer: a writer can show as CONTRIBUTOR. + db.prepare("INSERT INTO comments (repo, number, id, kind, author, created_at, body, review_state, author_association) VALUES ('app', 1, 'r1', 'review', 'ana', ?, '', 'CHANGES_REQUESTED', 'CONTRIBUTOR')").run(T0); + assert.equal(stateOf(db, 1), "changes-requested"); + const s = await runMerge(db, { repo: "app", dryRun: false, only: (e) => e.number === 1 }, quiet, fakes([], { formal: [] })); + assert.deepEqual(s.merged, ["app#1"]); + }); + test("an operator's merge answer makes a PR eligible; others' answers are ignored", async () => { const db = fresh(); await runMerge(db, { repo: "app", dryRun: false, limit: 0 }, quiet, fakes([])); diff --git a/web/src/api/mock/queueFixtures.ts b/web/src/api/mock/queueFixtures.ts index db54ed18..182f1a70 100644 --- a/web/src/api/mock/queueFixtures.ts +++ b/web/src/api/mock/queueFixtures.ts @@ -54,6 +54,7 @@ const ROWS: QueueRow[] = (() => { outsideRule, decisionId: state === "needs-decision" || state === "decision-answered-merge" || state === "declined" ? mergeDecision : null, answer: state === "decision-answered-merge" ? "merge" : state === "declined" ? (i ? "close" : "hold") : null, refusedReason: state === "refused" ? "safe-merge: required check 'build (linux)' has not finished" : null, + note: state === "changes-requested" ? "changes requested by a maintainer (reviewer)" : null, reviewedAt: new Date(NOW - (k + 1) * 3_600_000 * 5).toISOString(), verify: verifyFor(state, i), }); diff --git a/web/src/api/types.ts b/web/src/api/types.ts index fe1d0d3d..f4698d34 100644 --- a/web/src/api/types.ts +++ b/web/src/api/types.ts @@ -1026,6 +1026,8 @@ export interface QueueRow { decisionId: string | null; answer: string | null; refusedReason: string | null; + /** Why a maintainer's review blocks the PR, or that its reviews cannot be read; null otherwise. */ + note: string | null; reviewedAt: string; /** The Verify stage's result at the reviewed head; null when none. `summary` is the failure or error text, or the plan's reason. */ verify: { state: string; kind: string | null; summary: string | null; note: string | null } | null; diff --git a/web/src/modules/queue/mergeParts.tsx b/web/src/modules/queue/mergeParts.tsx index 09d27772..8c7753b2 100644 --- a/web/src/modules/queue/mergeParts.tsx +++ b/web/src/modules/queue/mergeParts.tsx @@ -105,6 +105,7 @@ function DecisionLink({ row }: { row: QueueRow }) { /** Why it waits, in one line: refusal reason, or what keeps it outside the rule. */ function Why({ row }: { row: QueueRow }) { if (row.state === "refused" && row.refusedReason) return {row.refusedReason}; + if (row.note) return {row.note}; if (row.outsideRule.length) return outside the rule: {row.outsideRule.join(", ")}; return null; }