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
56 changes: 56 additions & 0 deletions plugins/stewards/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2155,6 +2155,62 @@ describe("needs you items", () => {
expect(t.hooks.store.openNeeds(b.id).find((n) => n.kind === "merge")).toBeDefined();
});

it("refuses an approve-pr the gate cannot hold, names the missing step and files nothing (BB-21)", async () => {
const t = await withPull([]);
const b = t.binding();
const report = await t.tool(
"steward_report",
{ ...base, actor: "me", needs: [{ kind: "approve-pr", url: "https://github.com/acme/web/pull/7", what: "Approve acme/web#7 on GitHub" }] },
t.steward,
);
expect(report.error).toBe(false);
expect(report.text).toMatch(/approve-pr for https:\/\/github\.com\/acme\/web\/pull\/7 not filed: no reviewer round yet\./u);
expect(report.text).toMatch(/build-tickets review loop first/u);
expect(t.hooks.store.openNeeds(b.id).some((n) => n.kind === "approve-pr")).toBe(false);
expect((await t.harness.behavior.runCli(["needs", "--project", "p1"])).stdout).toBe("Nothing is waiting on the user.");
});

it("refuses a merge the gate cannot hold, naming the missing step (BB-21)", async () => {
const t = await withPull([marker]);
const b = t.binding();
const report = await t.tool(
"steward_report",
{ ...base, actor: "me", needs: [{ kind: "merge", url: "https://github.com/acme/web/pull/7", what: "Merge acme/web#7" }] },
t.steward,
);
expect(report.error).toBe(false);
expect(report.text).toMatch(/merge for https:\/\/github\.com\/acme\/web\/pull\/7 not filed: owner approval needed\./u);
expect(t.hooks.store.openNeeds(b.id).some((n) => n.kind === "merge")).toBe(false);
});

it("files an approve-pr the owner-lane gate holds (BB-21)", async () => {
const t = await withPull([marker]);
const b = t.binding();
const report = await t.tool(
"steward_report",
{ ...base, actor: "me", needs: [{ kind: "approve-pr", url: "https://github.com/acme/web/pull/7", what: "Approve acme/web#7 on GitHub" }] },
t.steward,
);
expect(report.error).toBe(false);
expect(report.text).not.toMatch(/not filed/u);
expect(t.hooks.store.openNeeds(b.id).some((n) => n.kind === "approve-pr")).toBe(true);
expect((await t.harness.behavior.runCli(["needs", "--project", "p1"])).stdout).toMatch(/approve-pr, ENG-12/u);
});

it("records the gate's missing text when sync closes an approve-pr need (BB-21)", async () => {
const t = await withPull([marker]);
const b = t.binding();
expect(t.hooks.store.openNeeds(b.id).some((n) => n.kind === "approve-pr")).toBe(true);
// The reviewer's round goes away, so the open item no longer holds; the
// closure records what the gate is missing, not the generic line.
t.entities.set("acme/web#7", pull({}, { checks: { state: "success", failing: [] } }));
await t.ring("linear", "uuid-12");
const closed = t.hooks.store.needs(b.id, true).find((n) => n.kind === "approve-pr")!;
expect(closed.status).toBe("done");
expect(closed.resolution).toMatch(/no reviewer round yet/u);
expect(closed.resolution).not.toMatch(/not waiting for an owner approval/u);
});

it("files merge only when the gate is met and no worker runs, and the page action merges through gh", async () => {
const t = await withPull([marker, owner]);
const b = t.binding();
Expand Down
25 changes: 21 additions & 4 deletions plugins/stewards/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
filedBy: "plugin",
});
} else {
store.closeNeedByKey(b.id, "approve-pr", url, g.ownerApproved ? "Owner approval is present." : "The pull request is not waiting for an owner approval.");
store.closeNeedByKey(b.id, "approve-pr", url, g.ownerApproved ? "Owner approval is present." : `${g.missing ?? "The pull request is not waiting for an owner approval."}`);
}
if (g.gateMet) {
// A steward's own merge item (a refused merge) is left alone while a
Expand Down Expand Up @@ -2987,7 +2987,23 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
});
const requested = playbook === null ? null : await syncApprovalRequest(b, playbook);
const scheduling = playbook === null ? null : await syncScheduleRequest(b, playbook);
// An `approve-pr` or `merge` item is filed only when the lane gate
// can hold it: the page's Approve and Merge buttons are already
// guarded this way, and filing one the gate cannot hold would be
// closed again by syncNeeds in this same call, silently.
const refused: string[] = [];
for (const n of input.needs ?? []) {
if (n.kind === "approve-pr" || n.kind === "merge") {
const url = n.url ?? n.worker ?? b.url ?? "";
const wanted = lc(url);
const pull = b.lastSnapshot === null ? undefined : observedPulls(b, b.lastSnapshot).find((p) => [p.url, p.key, p.id].some((v) => v !== null && lc(v) === wanted));
const gate = pull === undefined ? null : prGate(pull);
const holdable = gate !== null && (n.kind === "approve-pr" ? gate.needsOwnerApproval : gate.gateMet);
if (!holdable) {
refused.push(`${n.kind} for ${url === "" ? "the pull request" : url} not filed: ${gate?.missing ?? "the pull request has not been observed yet"}. The owner is asked only once the reviewer's marker says approved; the worker must run the build-tickets review loop first.`);
continue;
}
}
store.fileNeed({
bindingId: b.id,
kind: n.kind,
Expand All @@ -3003,6 +3019,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
filedBy: "steward",
});
}
const refusalNote = refused.length === 0 ? "" : ` ${refused.join(" ")}`;
if (playbook !== null && b.lastSnapshot !== null) await syncNeeds(b, b.lastSnapshot, playbook, anyWorkerInFlight(store.workers(b.id)));
const requests = [requested === null ? null : "approval", scheduling === null ? null : "scheduling"].filter((r) => r !== null);
if (raised !== null && !(raised.route === "project" && requests.length > 0)) await deliver(b, raised);
Expand Down Expand Up @@ -3035,12 +3052,12 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
const askedAbout = store.binding(b.id)?.scheduleAsked ?? b.scheduleAsked;
if (schedule !== undefined) gateNote += ` Scheduling is with the project steward (${schedule.id}): ${b.entityKey} touches what ${askedAbout.join(", ")} ${askedAbout.length === 1 ? "is" : "are"} already changing. Start no workers and do not move the ticket into a build state until it decides; wait for its guidance or hold.`;
if (b.ending === "terminal") {
if (b.followThrough === null) return `Reported.${escalated} The binding ends when this turn does: running workers are stopped and the thread is archived. End the turn now.`;
return `Reported.${escalated} The binding stays open to follow through until ${iso(followThroughUntil!)}; running workers keep going. You will be woken when a worker finishes or something actionable changes, or in ${formatDuration(requeueMs)}. End the turn now.`;
if (b.followThrough === null) return `Reported.${refusalNote}${escalated} The binding ends when this turn does: running workers are stopped and the thread is archived. End the turn now.`;
return `Reported.${refusalNote}${escalated} The binding stays open to follow through until ${iso(followThroughUntil!)}; running workers keep going. You will be woken when a worker finishes or something actionable changes, or in ${formatDuration(requeueMs)}. End the turn now.`;
}
const archived = archiveWhenIdle && store.openEscalations(b.id).length === 0 ? " Your thread is archived when the turn ends, and comes back on that wake." : "";
const recorded = opsTickets.length === 0 ? "" : ` Recorded ${opsTickets.map((t) => `${t.ticket} (${t.did})`).join(", ")} against ${opsTickets.length === 1 ? "its fingerprint" : "their fingerprints"}.`;
return `Reported.${recorded}${gateNote}${escalated} You will be woken when something actionable changes, or in ${formatDuration(requeueMs)}.${archived} End the turn now.`;
return `Reported.${recorded}${refusalNote}${gateNote}${escalated} You will be woken when something actionable changes, or in ${formatDuration(requeueMs)}.${archived} End the turn now.`;
} catch (error) {
return toolError(error);
}
Expand Down
Loading