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
21 changes: 19 additions & 2 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -836,7 +836,7 @@ listed under "Waiting on you" on the Stewards page, in the digest, and by
| `approve-spec` | plugin, when the ready gate waits and the playbook's approver is `me`, or when the project steward forwards an `approval` escalation to the user | the ticket | gate approval recorded | **Approve** / **Decline** (with an optional note); Approve records the approval on the gate, as BB-13 does from any surface |
| `approve-pr` | plugin, when a linked pull request is in the owner-reviewed lane, the reviewer's latest marker is `approved`, checks are green, and no owner approval exists | the pull request | owner approval seen in the snapshot | **Approve**: posts the unsigned comment "Approved <sha> from the Stewards page" as the connected user |
| `merge` | plugin, when the lane gate is met and no worker is running, or by a steward whose worker reported a refused merge | the pull request | the pull request merged | **Merge**: the server re-checks the gate itself, squash-merges through the server's `gh` login, posts the "Merged: …" comment, and wakes the steward |
| `decide` | project steward (today's forwarded question) | the entity | answered | **Answer** (the question record's text box) |
| `decide` | project steward (today's forwarded question) | the entity | answered | **Answer** (the text box), or one button per `choices` label and **Other…** |
| `provide-secret` | steward, with the variable name and purpose | the worker thread | the worker's `bb secret request` completes | **Provide**: opens the worker thread named in the item, or wakes the steward to start the worker that will request it |
| `configure` | steward, for a step outside the repos (install an app, grant a permission, enable an event, set a setting) | the external page where it happens | the user presses Done, or the steward observes it done | **Done** (with an optional note, saved as guidance) |

Expand Down Expand Up @@ -865,6 +865,22 @@ The rules that hold:
changed", and the wake lists the binding's open items and says not to ask the
user about them in prose. Closing an item from the page or with
`bb stewards done <id>` does the same.
- **Fixed choices.** A `decide` item filed with `steward_report { needs }`
may carry `choices`, two to six short labels kept in the item's `data`; a
`steward_report { escalate }` may carry the same, kept on the escalation
and copied onto the question when the project steward forwards it. The page
shows one button per choice, a note field and **Other…** (which reveals the
text box with **Answer**); a `decide` item or question without choices
shows the text box and **Answer**, never **Done** (`configure` keeps
**Done**, since its "what" names the step being confirmed). Pressing a
choice closes with `Chose: <label>` plus the note, saves the choice (and
note) as guidance on the binding, and wakes the steward with "The user
chose <label> for <what>" under What changed. A forwarded escalation
answered by a choice resolves with the choice as its guidance, exactly as
`steward_update { guidance, resolve }` records it. `bb stewards done <id>
--choice <label> [--note …]` does the same from a thread and refuses a
label not among the item's choices. The CLI, the digest and every wake list
the choices after the item.
- **A forwarded approval is a need.** When the project steward forwards an
`approval` escalation to the user, the plugin files an `approve-spec` need
on the binding and keeps the escalation open, linked to it
Expand All @@ -873,7 +889,8 @@ The rules that hold:
page's Approve and Decline, and `bb stewards done` for Approve, record the
gate verdict and resolve the open `approval` escalations in the same step,
so the project steward is not left holding the request. A forwarded
`decision` escalation stays a question, answered in prose.
`decision` escalation stays a question; with `choices`, it is answered by a
button per label, and a choice is recorded as guidance.
- **Dedupe.** A need is keyed by (binding, kind, url) while open: a steward
that re-reports updates the wording rather than adding a row. The store
enforces it with a partial unique index.
Expand Down
8 changes: 6 additions & 2 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,12 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
action wakes the binding's steward with the closure under "What changed".
A button is shown only while the server can verify its preconditions;
otherwise the item says why not. `bb stewards done <id>` closes one from a
thread. A `blockedOn` naming the user, the owner or a human is refused
unless an open needs item says so.
thread. A `decide` item or a forwarded decision question may carry fixed
`choices` (two to six short labels): the page then shows one button per
choice, a note field and **Other…** instead of a free-text **Answer**, and
a choice is saved as guidance. `bb stewards done <id> --choice <label>`
records the same from a thread. A `blockedOn` naming the user, the owner
or a human is refused unless an open needs item says so.
- **The nightly pass** (01:00 in the project's time zone by default, done by
02:45 so bb-gate's 03:00 restarts do not cut a turn) gives every open
binding a turn, then wakes the project steward for the morning digest.
Expand Down
146 changes: 146 additions & 0 deletions plugins/stewards/app.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
// @vitest-environment jsdom
// BB-20: the Stewards page renders a decide item or question with fixed
// choices as one button per choice plus Other…, and a text-only one with
// Answer rather than Done.
import { afterEach, describe, expect, it } from "vitest";
import { fireEvent, waitFor } from "@testing-library/react";
import { loadPluginApp, renderSlot, type CapturedPluginApp, type RenderedSlot } from "@get-bb/plugin-sdk/testing/app";

type Need = {
id: string;
bindingId: string;
key: string;
kind: string;
url: string | null;
escalationId: string | null;
choices: string[];
what: string;
how: string | null;
threadId: string | null;
createdAt: number;
actionable: boolean;
why: string | null;
};

type Question = {
id: string;
question: string;
context: string | null;
choices: string[];
key: string | null;
url: string | null;
escalationId: string | null;
createdAt: number;
};

const need = (over: Partial<Need> = {}): Need => ({
id: "need_1",
bindingId: "bnd_1",
key: "ENG-12",
kind: "decide",
url: null,
escalationId: null,
choices: [],
what: "Merge or close?",
how: null,
threadId: null,
createdAt: 1_000,
actionable: true,
why: null,
...over,
});

const question = (over: Partial<Question> = {}): Question => ({
id: "qst_1",
question: "Merge or close?",
context: null,
choices: [],
key: "ENG-12",
url: null,
escalationId: null,
createdAt: 1_000,
...over,
});

let app: CapturedPluginApp | null = null;
const loadApp = async () => {
app ??= await loadPluginApp(() => import("./app.js"));
return app;
};

const renderBoard = async (needs: Need[], questions: Question[]): Promise<RenderedSlot> => {
const captured = await loadApp();
const panel = captured.navPanels[0]!;
return renderSlot(panel, { subPath: "" }, {
rpc: {
stewardsBoard: () => ({
projects: [{ projectId: "p1", name: "Acme" }],
board: {
projectId: "p1",
name: "Acme",
paused: false,
projectStewardThreadId: "thr_p",
stages: [],
digest: null,
questions,
withUser: [],
needs,
stewards: [],
stuck: [],
ended: [],
},
}),
stewardsAnswerQuestion: () => ({ ok: true, message: "closed" }),
stewardsNeedAction: () => ({ ok: true, message: "done" }),
} as never,
});
};

afterEach(() => {
app = null;
});

describe("the Stewards page's decide items and questions (BB-20)", () => {
it("shows a button per choice and Other…, not Done, for a decide item with choices", async () => {
const slot = await renderBoard([need({ choices: ["Merge", "Close", "Verify first"] })], []);
await waitFor(() => expect(slot.getByRole("button", { name: "Merge" })).toBeTruthy());
expect(slot.getByRole("button", { name: "Close" })).toBeTruthy();
expect(slot.getByRole("button", { name: "Verify first" })).toBeTruthy();
expect(slot.getByRole("button", { name: "Other…" })).toBeTruthy();
expect(slot.queryByRole("button", { name: "Done" })).toBeNull();
slot.lifecycle.unmount();
});

it("shows Answer, not Done, for a decide item without choices, and Done for configure", async () => {
const slot = await renderBoard([need({ choices: [] }), need({ id: "need_2", kind: "configure", what: "Enable the event", url: "https://example.test" })], []);
await waitFor(() => expect(slot.getByRole("button", { name: "Answer" })).toBeTruthy());
expect(slot.queryByRole("button", { name: "Other…" })).toBeNull();
expect(slot.getAllByRole("button", { name: "Done" })).toHaveLength(1);
slot.lifecycle.unmount();
});

it("shows the same buttons for a question with choices, and Answer without", async () => {
const slot = await renderBoard([], [question({ choices: ["Merge", "Close"] }), question({ id: "qst_2", choices: [] })]);
await waitFor(() => expect(slot.getByRole("button", { name: "Merge" })).toBeTruthy());
expect(slot.getByRole("button", { name: "Close" })).toBeTruthy();
expect(slot.getByRole("button", { name: "Other…" })).toBeTruthy();
expect(slot.getByRole("button", { name: "Answer" })).toBeTruthy();
slot.lifecycle.unmount();
});

it("sends the chosen label through the need action", async () => {
const slot = await renderBoard([need({ choices: ["Merge", "Close"] })], []);
await waitFor(() => expect(slot.getByRole("button", { name: "Merge" })).toBeTruthy());
fireEvent.click(slot.getByRole("button", { name: "Merge" }));
await waitFor(() => expect(slot.inspection.rpcCalls).toContainEqual({ method: "stewardsNeedAction", input: { needId: "need_1", action: "choose", note: null, choice: "Merge" } }));
slot.lifecycle.unmount();
});

it("sends the chosen label through the question answer, and Other… reveals Answer", async () => {
const slot = await renderBoard([], [question({ choices: ["Merge", "Close"] })]);
await waitFor(() => expect(slot.getByRole("button", { name: "Merge" })).toBeTruthy());
fireEvent.click(slot.getByRole("button", { name: "Merge" }));
await waitFor(() => expect(slot.inspection.rpcCalls).toContainEqual({ method: "stewardsAnswerQuestion", input: { questionId: "qst_1", answer: null, choice: "Merge" } }));
slot.lifecycle.unmount();
});
});
73 changes: 56 additions & 17 deletions plugins/stewards/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -539,21 +539,28 @@ function NeedRow({ need: n, now, onDone }: { need: Board["needs"][number]; now:
const rpc = useRpc<typeof rpcContract>();
const navigate = useBbNavigate();
const [note, setNote] = useState("");
// With choices, the text box answers a choice's note until Other… turns it
// into the free-text answer.
const [other, setOther] = useState(false);
const [state, setState] = useState<"idle" | "running" | { error: string }>("idle");
const act = (action: "approve" | "decline" | "done" | "merge" | "provide") => {
const act = (action: "approve" | "decline" | "done" | "merge" | "provide" | "choose", choice?: string) => {
setState("running");
rpc.call("stewardsNeedAction", { needId: n.id, action, note: note.trim() === "" ? null : note.trim() }).then(
(r) => {
if (!r.ok) return setState({ error: r.message });
onDone();
if (r.threadId !== null && r.threadId !== undefined) navigate.toThread(r.threadId);
},
(e: unknown) => setState({ error: message(e) }),
);
rpc
.call("stewardsNeedAction", { needId: n.id, action, note: note.trim() === "" ? null : note.trim(), ...(choice === undefined ? {} : { choice }) })
.then(
(r) => {
if (!r.ok) return setState({ error: r.message });
onDone();
if (r.threadId !== null && r.threadId !== undefined) navigate.toThread(r.threadId);
},
(e: unknown) => setState({ error: message(e) }),
);
};
const primary = "rounded-md border border-input bg-state-hover px-3 py-1 text-xs hover:bg-state-hover disabled:opacity-50";
const secondary = "rounded-md border border-input px-3 py-1 text-xs hover:bg-state-hover disabled:opacity-50";
const takesNote = n.kind === "approve-spec" || n.kind === "configure" || n.kind === "decide";
const choices = n.kind === "decide" ? n.choices : [];
const freeText = choices.length === 0 || other;
return (
<li className="flex flex-col gap-2 p-3">
<p className="flex flex-wrap items-center gap-2">
Expand All @@ -569,7 +576,7 @@ function NeedRow({ need: n, now, onDone }: { need: Board["needs"][number]; now:
value={note}
onChange={(e) => setNote(e.target.value)}
rows={1}
placeholder={n.kind === "approve-spec" ? "Note (optional)" : n.kind === "decide" ? "Your answer (optional, saved as guidance)" : "Note (optional, saved as guidance)"}
placeholder={n.kind === "approve-spec" ? "Note (optional)" : freeText ? "Your answer (optional, saved as guidance)" : "Note (optional, saved as guidance)"}
aria-label={`Note for: ${n.what}`}
className="min-w-0 flex-1 rounded-md border border-input bg-transparent px-2 py-1"
/>
Expand All @@ -596,10 +603,25 @@ function NeedRow({ need: n, now, onDone }: { need: Board["needs"][number]; now:
<button type="button" disabled={!n.actionable || state === "running"} className={primary} onClick={() => act("provide")}>
Provide
</button>
) : (
) : n.kind === "configure" ? (
<button type="button" disabled={!n.actionable || state === "running"} className={primary} onClick={() => act("done")}>
Done
</button>
) : choices.length > 0 && !other ? (
<>
{choices.map((choice) => (
<button key={choice} type="button" disabled={!n.actionable || state === "running"} className={primary} onClick={() => act("choose", choice)}>
{choice}
</button>
))}
<button type="button" disabled={!n.actionable || state === "running"} className={secondary} onClick={() => setOther(true)}>
Other…
</button>
</>
) : (
<button type="button" disabled={!n.actionable || state === "running"} className={primary} onClick={() => act("done")}>
Answer
</button>
)}
{n.threadId !== null ? <ThreadLink threadId={n.threadId}>Open the worker</ThreadLink> : null}
{typeof state === "object" ? <span className="text-destructive">{state.error}</span> : null}
Expand All @@ -611,17 +633,21 @@ function NeedRow({ need: n, now, onDone }: { need: Board["needs"][number]; now:
function QuestionRow({ question: q, now, onClosed }: { question: Board["questions"][number]; now: number; onClosed: () => void }) {
const rpc = useRpc<typeof rpcContract>();
const [answer, setAnswer] = useState("");
// With choices, the text box is the choice's note until Other… turns it
// into the free-text answer.
const [other, setOther] = useState(false);
const [state, setState] = useState<"idle" | "closing" | { error: string }>("idle");
const close = () => {
const close = (choice?: string) => {
setState("closing");
rpc.call("stewardsAnswerQuestion", { questionId: q.id, answer: answer.trim() === "" ? null : answer.trim() }).then(
rpc.call("stewardsAnswerQuestion", { questionId: q.id, answer: answer.trim() === "" ? null : answer.trim(), ...(choice === undefined ? {} : { choice }) }).then(
(r) => {
if (r.ok) onClosed();
else setState({ error: r.message });
},
(e: unknown) => setState({ error: message(e) }),
);
};
const button = "rounded-md border border-input px-3 py-1 text-xs hover:bg-state-hover disabled:opacity-50";
return (
<li className="flex flex-col gap-2 p-3">
<p className="flex flex-wrap items-center gap-2">
Expand All @@ -636,13 +662,26 @@ function QuestionRow({ question: q, now, onClosed }: { question: Board["question
value={answer}
onChange={(e) => setAnswer(e.target.value)}
rows={1}
placeholder="Your answer (optional)"
placeholder={q.choices.length > 0 && !other ? "Note (optional)" : "Your answer (optional)"}
aria-label={`Answer to: ${q.question}`}
className="min-w-0 flex-1 rounded-md border border-input bg-transparent px-2 py-1"
/>
<button type="button" disabled={state === "closing"} className="rounded-md border border-input px-3 py-1 text-xs hover:bg-state-hover disabled:opacity-50" onClick={close}>
{state === "closing" ? "Closing…" : answer.trim() === "" ? "Close" : "Answer and close"}
</button>
{q.choices.length > 0 && !other ? (
<>
{q.choices.map((choice) => (
<button key={choice} type="button" disabled={state === "closing"} className={button} onClick={() => close(choice)}>
{choice}
</button>
))}
<button type="button" disabled={state === "closing"} className={button} onClick={() => setOther(true)}>
Other…
</button>
</>
) : (
<button type="button" disabled={state === "closing"} className={button} onClick={() => close()}>
{state === "closing" ? "Closing…" : "Answer"}
</button>
)}
</div>
{typeof state === "object" ? <p className="text-destructive">{state.error}</p> : null}
</li>
Expand Down
Loading
Loading