From 466735f546071c6077a687b20c1dffc776523dca Mon Sep 17 00:00:00 2001 From: Dylan Trotter Date: Mon, 19 Oct 2026 02:05:45 +0000 Subject: [PATCH] stewards: flag a move into build only from spec with the gate really unmet (BB-7) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Moved into a build stage before the ready gate passed" fired on every Todo → In Progress, because gateState counts an unreported checklist item as unmet and the steward has not re-reported right after an approval, and on every In Review → In Progress of a worker's normal loop. It is now raised only when the ticket enters build from a spec stage and gateKnownUnmet says so: approval is needed and missing, voided or stale for the current spec, or a checklist item was reported met: false. Co-Authored-By: Claude Opus 5.5 --- plugins/stewards/reconcile.test.ts | 14 ++++++- plugins/stewards/reconcile.ts | 14 +++++++ plugins/stewards/server.test.ts | 63 ++++++++++++++++++++++++++++++ plugins/stewards/server.ts | 7 ++-- 4 files changed, 94 insertions(+), 4 deletions(-) diff --git a/plugins/stewards/reconcile.test.ts b/plugins/stewards/reconcile.test.ts index d5354587..b6aed99a 100644 --- a/plugins/stewards/reconcile.test.ts +++ b/plugins/stewards/reconcile.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from "vitest"; import { parsePlaybook } from "./config.js"; import { comment, issue, pull } from "./fixtures.js"; -import { approvalWanted, diffObserved, endingDeadline, followingThrough, gateState, isCommentNews, lifecycle, resolveChecklistItem, specHash, stuckDue, unheardWait } from "./reconcile.js"; +import { approvalWanted, diffObserved, endingDeadline, followingThrough, gateKnownUnmet, gateState, isCommentNews, lifecycle, resolveChecklistItem, specHash, stuckDue, unheardWait } from "./reconcile.js"; import { readyStateSchema } from "./store.js"; import { GITHUB_REVIEWS, LINEAR_TICKETS } from "./templates.js"; @@ -151,6 +151,18 @@ describe("the ready gate", () => { expect(approvalWanted(gateState(tickets, ready({ checklist: allMet, substantial: true, approval }), "changed"))).toBe(true); }); + it("is known unmet on a missing or stale approval or an item reported unmet, not on an unreported item", () => { + const hash = specHash(issue(), "thr_s"); + const approval = { at: 1, specHash: hash, by: "thr_p" }; + expect(gateKnownUnmet(tickets, ready({}), hash)).toBe(true); + expect(gateKnownUnmet(tickets, ready({ approval }), hash)).toBe(false); + expect(gateKnownUnmet(tickets, ready({ approval, checklist: allMet.slice(1) }), hash)).toBe(false); + expect(gateKnownUnmet(tickets, ready({ approval }), "changed")).toBe(true); + expect(gateKnownUnmet(tickets, ready({ substantial: false }), hash)).toBe(false); + expect(gateKnownUnmet(tickets, ready({ approval, checklist: [{ ...allMet[0]!, met: false }] }), hash)).toBe(true); + expect(gateKnownUnmet(tickets, ready({ checklist: allMet, approval }), hash)).toBe(false); + }); + it("knows a reported item by its number or the playbook's own words, never a paraphrase", () => { const items = ["The problem, as observed: the current behaviour and where in the code it comes from", "What is out of scope"]; expect(resolveChecklistItem(items, 1)).toBe(items[0]); diff --git a/plugins/stewards/reconcile.ts b/plugins/stewards/reconcile.ts index 29a516b0..dc65184b 100644 --- a/plugins/stewards/reconcile.ts +++ b/plugins/stewards/reconcile.ts @@ -224,6 +224,20 @@ export function gateState(playbook: Playbook, ready: ReadyState, currentSpecHash return { none: false, checklistMet, unmet, substantial: ready.substantial, approvalNeeded, approved, approvalStale, passed }; } +/** + * Whether the gate is shut on something known rather than merely not yet + * reported: approval is needed and the current spec has none (missing, + * voided or stale), or the steward reported a checklist item unmet. An item + * the steward has not reported does not count, so a ticket moved on right + * after its approval, before the steward reports again, is not flagged. + */ +export function gateKnownUnmet(playbook: Playbook, ready: ReadyState, currentSpecHash: string): boolean { + const gate = gateState(playbook, ready, currentSpecHash); + if (gate.passed) return false; + if (gate.approvalNeeded && (!gate.approved || gate.approvalStale)) return true; + return gate.unmet.some((item) => reportedItem(ready, item)?.met === false); +} + /** * Whether the gate waits on its approver: the checklist is met, the ticket * is (or may be) substantial, and the current spec has no approval. The diff --git a/plugins/stewards/server.test.ts b/plugins/stewards/server.test.ts index 50f02827..3b2f5959 100644 --- a/plugins/stewards/server.test.ts +++ b/plugins/stewards/server.test.ts @@ -288,6 +288,69 @@ describe("a Linear ticket steward", () => { expect(wake).toContain(`Your thread id is ${steward}.`); }); + // BB-7: flagged on every Todo → In Progress, approval seconds old, and on + // every In Review → In Progress of a worker's normal loop. + describe("moving into build before the ready gate passed", () => { + const flagged = /before the ready gate passed/u; + const base = { phase: "Todo", summary: "Specified.", nextAction: "Move to In Progress", actor: "steward" }; + const inProgress = (over: Parameters[0] = {}) => issue({ state: "In Progress", stateType: "started", ...over }); + /** A bound ticket in Todo, with its project steward and steward. */ + const bound = async () => { + const t = await setup(); + t.entities.set("uuid-12", issue()); + await t.ring("linear", "uuid-12"); + const [project, steward] = t.spawns.map((x) => x.id) as [string, string]; + const wakes = () => t.sends.filter((s) => s.threadId === steward).map((s) => s.text); + /** Move the ticket, and return the wake it brought. */ + const move = async (entity: EntitySnapshot) => { + const before = wakes().length; + t.entities.set("uuid-12", entity); + await t.ring("linear", "uuid-12"); + expect(wakes().length).toBeGreaterThan(before); + return wakes().at(-1)!; + }; + return { t, project, steward, move }; + }; + + it("is raised entering build from spec with no approval", async () => { + const { move } = await bound(); + expect(await move(inProgress())).toMatch(flagged); + }); + + it("is not raised with a current approval and no checklist report yet", async () => { + const { t, project, move } = await bound(); + expect((await t.tool("steward_update", { binding: "ENG-12", approve: true }, project)).error).toBe(false); + expect(await move(inProgress())).not.toMatch(flagged); + }); + + it("is raised when the approval is stale for the current spec", async () => { + const { t, project, move } = await bound(); + await t.tool("steward_update", { binding: "ENG-12", approve: true }, project); + expect(await move(inProgress({ description: "Users cannot log in. Also SSO." }))).toMatch(flagged); + }); + + it("is raised when the approval was voided", async () => { + const { t, project, steward, move } = await bound(); + await t.tool("steward_update", { binding: "ENG-12", approve: true }, project); + expect((await t.tool("steward_report", { ...base, voidApproval: true }, steward)).error).toBe(false); + expect(await move(inProgress())).toMatch(flagged); + }); + + it("is raised when a reported checklist item is unmet, approval or not", async () => { + const { t, steward, move } = await bound(); + const checklist = [1, 2, 3, 4].map((item) => ({ item, met: item !== 4 })); + expect((await t.tool("steward_report", { ...base, ready: { checklist, substantial: false } }, steward)).error).toBe(false); + expect(await move(inProgress())).toMatch(flagged); + }); + + it("is never raised moving back from review", async () => { + const { move } = await bound(); + // No approval and nothing reported: a gate that is really unmet. + expect(await move(issue({ state: "In Review", stateType: "started" }))).not.toMatch(flagged); + expect(await move(inProgress())).not.toMatch(flagged); + }); + }); + it("tells the steward its own thread id and that the linear tools sign for it", async () => { const t = await setup(); t.entities.set("uuid-12", issue()); diff --git a/plugins/stewards/server.ts b/plugins/stewards/server.ts index da094c56..52051b12 100644 --- a/plugins/stewards/server.ts +++ b/plugins/stewards/server.ts @@ -37,7 +37,7 @@ import { type ProjectFile, } from "./config.js"; import { nightlyDue, stillNight } from "./nightly.js"; -import { advanced, approvalWanted, diffObserved, endingDeadline, followingThrough, gateState, hasLabel, isCommentNews, lifecycle, newestCommentAt, phaseAndStage, resolveChecklistItem, specHash, stuckDue, unheardWait, type Change } from "./reconcile.js"; +import { advanced, approvalWanted, diffObserved, endingDeadline, followingThrough, gateKnownUnmet, gateState, hasLabel, isCommentNews, lifecycle, newestCommentAt, phaseAndStage, resolveChecklistItem, specHash, stuckDue, unheardWait, type Change } from "./reconcile.js"; import { SOURCE_PLUGIN_IDS, STEWARDS_PLUGIN_ID, @@ -942,8 +942,9 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P const workerRunning = store.workers(b.id).some((w) => w.status === "running"); const fresh = prev === null ? [] : diffObserved(prev, observed, { own: ownThreads(b), stewardThreadId: b.threadId, approved: ready.approval !== null, cursor: b.commentCursor, workerRunning }); changes.push(...fresh); - const gate = gateState(playbook, ready, currentSpec); - if (stage === "build" && b.stage !== "build" && !gate.passed && prev !== null) { + // Only an entry into build from spec: review → build is the worker's + // normal loop, and an unreported checklist is not an unmet one. + if (stage === "build" && b.stage === "spec" && prev !== null && gateKnownUnmet(playbook, ready, currentSpec)) { changes.push({ text: `Moved into a build stage (${entity.state}) before the ready gate passed`, actionable: true }); } if (b.requeueAt !== null && b.requeueAt <= now()) changes.push({ text: "Requeue time came", actionable: true });