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
38 changes: 37 additions & 1 deletion plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1264,6 +1264,42 @@ The pure grouping and ordering live in `sidebar.ts` and are unit tested; the
component joins them to `experimental_useSidebarThreads` and polls
`stewardsSidebar` on the board's half-minute visibility-aware cadence.

**The Needs you block and the count badge (BB-46).** The sidebar is where the
user already looks, so what waits on them is shown there, not only on the
Stewards page. Each tab carries a count pill when its project has anything
waiting; the compact picker shows the summed count and per-project counts in
its options. Above In flight, a **Needs you** block lists one row per item
with the entity key (opening the entity), one line of text, and a question's
or `decide` item's fixed `choices` as small buttons. A choice makes exactly
the write the page makes (`stewardsAnswerQuestion` with `answer: null` for a
question, `stewardsNeedAction { action: "choose" }` for a `decide` item) and
refetches; a row without choices, or a `provide-secret` item, opens the
Stewards page at that project, where the free-text answer and the secret form
live. The block adds no write path of its own.

**One source of truth.** `server.ts`'s `needsYou(projectId, { actionableOnly
})` builds the board's `questions`, `withUser` and `needs` lists in one place;
the board calls it unfiltered and the sidebar calls it with `actionableOnly`,
so the two surfaces cannot drift and a non-actionable need is on the page but
not in the sidebar's count or items. `stewardsSidebar` carries, per project,
`needs: { count, items }` with the same row shapes, each tagged
`question`/`withUser`/`need` so the app knows which RPC a choice calls.

**Realtime, not the poll.** The store takes an optional
`onNeedsYouChange(projectId)` callback, wired in `server.ts` to
`bb.realtime.publish("needs-you-changed", { projectId })`; the store stays
free of bb. The callback fires from the store's mutation points — a question
filed (`ask`) or answered (`answer`, `answerQuestionOnly`, `answerEscalation`),
an escalation filed route-`me` (`escalate`) or forwarded to the user or
resolved (`reroute`, `resolve`, `approve`, `decline`), a need filed, updated or
closed (`fileNeed`, `closeNeed`, `closeNeeds`, `closeNeedByKey`), and a binding
ended or reopened (`patch`) — so a steward's own tools publish as well as the
page's buttons. A synchronous coalescing guard makes one question filed or
answered publish exactly one event even when the operation nests (`answer`
resolves its escalation). Every open sidebar refetches when the event names a
project it shows, and the board page refetches when it names its project; the
half-minute poll remains the fallback.

**The default provider, checked (BB-44 criterion 1).** With
`sidebar.threadListProvider` unset it is `__automatic__`, which bb resolves to
"the first installed thread list plugin other than the bundled
Expand All @@ -1290,7 +1326,7 @@ choice explicit. The preference is server-synced, so a flip is per server:
every window of one bb server shows the same list. Each developer has their
own server behind bb-gate, so it is per developer in practice.

The "Needs you" block and the tab badge are a separate ticket.


## Known limits

Expand Down
23 changes: 22 additions & 1 deletion plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
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 item says so.
unless an open item says so. The sidebar's **Needs you** block and count
badge show the same items, so a question reaches you where you already look
(BB-46).
- **One escalation chain (BB-30).** Every hop is one `escalations` row: a
worker's `bb stewards escalate` goes to its steward, a steward's
`steward_report { escalate }` to the project steward, and only the
Expand Down Expand Up @@ -328,6 +330,25 @@ is left alone. The write is best-effort: a failure is logged and the sidebar
keeps working. (`bb.onInstall` is not usable here; it does not run for
plugins baked into the `bb-server` image.)

**The Needs you block and the tab badge (BB-46).** Each tab shows a small
count pill when the project has anything waiting on you, and the compact
viewport's picker shows the summed count beside it and per-project counts in
its options. Above **In flight**, a **Needs you** block lists one row per
item: the entity key opens the entity, one line of what, and a question's or
`decide` item's fixed `choices` as small buttons. A choice makes the same
write the page does (`stewardsAnswerQuestion` for a question,
`stewardsNeedAction { action: "choose" }` for a `decide` item) and refetches;
a row without choices, or a `provide-secret` item, opens the Stewards page at
that project. The block and the board page read one server function
(`needsYou`), so the sidebar and the page can never disagree; a
non-actionable need is on the page but not in the sidebar. The count and the
items come from `stewardsSidebar`; the plugin publishes
`needs-you-changed { projectId }` on its realtime channel whenever a question
is opened or answered, an escalation is filed with or forwarded to the user
or resolved, a need is filed, updated or closed, or a binding ends or reopens
— including from a steward's own tools — so every open sidebar and the board
page refresh within seconds. The half-minute poll stays as the fallback.

**Per client or per server?** Checked on a dev server: the preference is
**server-synced**, so a flip is per server, not per browser. Every open
window of that bb server shows the same list, and the choice survives a
Expand Down
150 changes: 150 additions & 0 deletions plugins/stewards/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { fireEvent, waitFor } from "@testing-library/react";
import { loadPluginApp, renderSlot, type CapturedPluginApp, type RenderedSlot } from "@get-bb/plugin-sdk/testing/app";
import { NEEDS_YOU_CHANGED } from "./channels.js";

type Need = {
id: string;
Expand Down Expand Up @@ -281,3 +282,152 @@ describe("the sidebar-footer toggle (BB-45)", () => {
slot.lifecycle.unmount();
});
});

// BB-46: the sidebar's count badge and "Needs you" block, fed by the
// `stewardsSidebar` call and refreshed over the realtime channel.
const sidebarProjects = [
{ id: "p1", name: "Acme", isPersonal: false, href: "/projects/p1", settingsHref: "/projects/p1/settings" },
{ id: "p2", name: "Beta", isPersonal: false, href: "/projects/p2", settingsHref: "/projects/p2/settings" },
];

const sidebarData = (p1Needs: { count: number; items: unknown[] }, p2Needs: { count: number; items: unknown[] } = { count: 0, items: [] }) => ({
projects: [
{ projectId: "p1", name: "Acme", projectStewardThreadId: null, needs: p1Needs, bindings: [], ended: [] },
{ projectId: "p2", name: "Beta", projectStewardThreadId: null, needs: p2Needs, bindings: [], ended: [] },
],
});

describe("the stewards sidebar's needs you block (BB-46)", () => {
const questionItem = (over: Record<string, unknown> = {}) => ({
type: "question",
id: "qst_1",
question: "Which approach?",
context: null,
choices: [],
key: "ENG-12",
url: "https://linear.app/acme/issue/ENG-12",
escalationId: null,
createdAt: 1_000,
...over,
});
const needItem = (over: Record<string, unknown> = {}) => ({
type: "need",
id: "need_1",
bindingId: "bnd_1",
key: "ENG-12",
kind: "decide",
url: null,
entityUrl: "https://linear.app/acme/issue/ENG-12",
escalationId: null,
choices: [],
lessonId: null,
what: "Hold or start?",
how: null,
destination: null,
threadId: null,
createdAt: 1_000,
actionable: true,
why: null,
...over,
});

const renderSidebar = async (rpc: Record<string, unknown>, props: Record<string, unknown> = {}): Promise<RenderedSlot> => {
const captured = await loadApp();
const list = captured.threadLists[0]!;
return renderSlot(list, { activeThreadId: null, activeProjectId: "p1", isCompactViewport: false, onNavigate: () => {}, searchQuery: "", ...props } as never, {
sidebarThreads: { projects: sidebarProjects, threads: [] },
rpc,
} as never);
};

it("shows a count badge on a tab only when the count is non-zero", async () => {
const slot = await renderSidebar({ stewardsSidebar: () => sidebarData({ count: 2, items: [questionItem()] }, { count: 0, items: [] }) });
await waitFor(() => expect(slot.getByLabelText("2 waiting on you")).toBeTruthy());
expect(slot.queryByLabelText("0 waiting on you")).toBeNull();
slot.lifecycle.unmount();
});

it("sums the count on the compact picker and shows per-project counts in its options", async () => {
const slot = await renderSidebar(
{ stewardsSidebar: () => sidebarData({ count: 2, items: [questionItem(), needItem()] }, { count: 1, items: [needItem({ id: "need_2" })] }) },
{ isCompactViewport: true },
);
await waitFor(() => expect(slot.getByLabelText("3 waiting on you")).toBeTruthy());
expect(slot.getByRole("option", { name: "Acme (2)" })).toBeTruthy();
expect(slot.getByRole("option", { name: "Beta (1)" })).toBeTruthy();
slot.lifecycle.unmount();
});

it("sends a question's choice through stewardsAnswerQuestion with the page's arguments", async () => {
const slot = await renderSidebar({
stewardsSidebar: () => sidebarData({ count: 1, items: [questionItem({ choices: ["Merge", "Close"] })] }),
stewardsAnswerQuestion: () => ({ ok: true, message: "closed" }),
});
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();
});

it("sends a decide need's choice through stewardsNeedAction with the page's arguments", async () => {
const slot = await renderSidebar({
stewardsSidebar: () => sidebarData({ count: 1, items: [needItem({ choices: ["Hold", "Start"] })] }),
stewardsNeedAction: () => ({ ok: true, message: "done" }),
});
await waitFor(() => expect(slot.getByRole("button", { name: "Hold" })).toBeTruthy());
fireEvent.click(slot.getByRole("button", { name: "Hold" }));
await waitFor(() => expect(slot.inspection.rpcCalls).toContainEqual({ method: "stewardsNeedAction", input: { needId: "need_1", action: "choose", note: null, choice: "Hold" } }));
slot.lifecycle.unmount();
});

it("opens the board for a row without choices", async () => {
const slot = await renderSidebar({ stewardsSidebar: () => sidebarData({ count: 1, items: [needItem({ kind: "configure", choices: [] })] }) });
await waitFor(() => expect(slot.getByRole("button", { name: "Open" })).toBeTruthy());
fireEvent.click(slot.getByRole("button", { name: "Open" }));
await waitFor(() => expect(slot.inspection.navigateCalls).toContainEqual({ method: "toPluginPanel", path: "board", options: { subPath: "p1" } }));
slot.lifecycle.unmount();
});

it("refetches on a realtime event for a shown project and ignores an unknown one", async () => {
let calls = 0;
const slot = await renderSidebar({
stewardsSidebar: () => {
calls += 1;
return sidebarData({ count: 0, items: [] });
},
});
await waitFor(() => expect(calls).toBe(1));
await slot.emitRealtime(NEEDS_YOU_CHANGED, { projectId: "p9" });
await new Promise((r) => setTimeout(r, 20));
expect(calls).toBe(1);
await slot.emitRealtime(NEEDS_YOU_CHANGED, { projectId: "p1" });
await waitFor(() => expect(calls).toBe(2));
slot.lifecycle.unmount();
});

it("refetches the board page when the channel names its project", async () => {
const captured = await loadApp();
const panel = captured.navPanels[0]!;
let calls = 0;
const slot = renderSlot(panel, { subPath: "" }, {
rpc: {
stewardsBoard: () => {
calls += 1;
return {
projects: [{ projectId: "p1", name: "Acme" }],
board: { projectId: "p1", name: "Acme", paused: false, projectStewardThreadId: null, stages: [], digest: null, questions: [], withUser: [], needs: [], lessons: [], stewards: [], stuck: [], ended: [] },
};
},
},
} as never);
await waitFor(() => expect(calls).toBe(1));
// The handler only refetches once the board (and its project id) has rendered.
await waitFor(() => expect(slot.getByText("Acme")).toBeTruthy());
await slot.emitRealtime(NEEDS_YOU_CHANGED, { projectId: "p1" });
await waitFor(() => expect(calls).toBe(2));
await slot.emitRealtime(NEEDS_YOU_CHANGED, { projectId: "p2" });
await new Promise((r) => setTimeout(r, 20));
expect(calls).toBe(2);
slot.lifecycle.unmount();
});
});
Loading
Loading