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
47 changes: 47 additions & 0 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,53 @@ A **lesson** makes the answer a record and, for most of them, lands it.
closes the record, not the file. A boundary lesson is undone the same way
once the user has merged it.

## 21. The sidebar thread list

An opt-in replacement for bb's own sidebar list, registered through the
exclusive `experimental_threadList` slot (`plugins/stewards/app.tsx`). One tab
per project in the live view; in-flight efforts grouped by the steward
relationship; a collapsed Watches row for `ops`, Dependabot and Sentry
bindings; a collapsed Recently ended row; and the project steward demoted to
one small row at the bottom. Every row carries bb's own thread actions
context menu, so archive, pin, rename, split and delete still work.

**Grouping is the steward relationship, not the thread tree.** A worker
belongs to its binding through the plugin's `workers` table and a reviewer
through the worker the RPC names, so BB-23's removal of the parent link cannot
break it. The thread tree is used only for one-off threads, which have nothing
else, and as a fallback for a pre-BB-23 worker whose parent is its steward.
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 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
`thread-list/thread-list`". Registering the slot therefore makes the stewards
list active on every client that has not pinned a provider, and
`bb settings ui get sidebar.threadListProvider` on the dev server reads
`__automatic__`. **The guard was needed:** without it the list would win by
default. On load the plugin (`server.ts`, `pinSidebarThreadListProvider`)
reads the preference and, when it is unset or `__automatic__`, sets it to
`thread-list/thread-list`; an explicit value is left alone, and a failure is
logged, never thrown. `bb.onInstall` is not usable here — it does not run for
plugins baked into the `bb-server` image — so the pin is on load. BB-44 and
BB-45 are one landing; BB-44 must not land alone.

**The footer toggle (BB-45).** `app.tsx` registers a
`experimental_sidebarFooter` disclosure (`id: "sidebar"`, `icon:
"ShieldCheck"`): a switch that writes the same preference. On sets
`<pluginId>/sidebar`, the id BB-44 registers; off sets
`thread-list/thread-list`. It lists the preference when the disclosure opens
and, on an HTTP 409 revision conflict, re-lists and retries once with the
fresh revision. `__automatic__` (or a missing entry) reads as on, because it
means the stewards list is the effective provider until the pin makes the
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

- **Multi-repo projects only.** A bb project whose source is a single
Expand Down
39 changes: 39 additions & 0 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,45 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
put its own binding on hold for this, but only its parent or the project
steward lifts a hold.

## The sidebar thread list and its toggle

BB-44 registers a replacement for bb's own sidebar thread list through the
exclusive `experimental_threadList` slot: one tab per stewarded project,
in-flight efforts grouped by the steward relationship, and collapsed Watches
and Recently ended rows. BB-45 makes it switchable from where you are.

**The footer toggle.** A `ShieldCheck` icon in the sidebar footer (next to
Settings) opens a small panel above the footer row with a **Stewards
sidebar** switch and one line of help. On writes `sidebar.threadListProvider`
= `stewards/sidebar` (the list BB-44 registers); off writes it back to bb's
own `thread-list/thread-list`. The sidebar's list swaps without a reload. The
footer is host-rendered and stays in place under either list, so the icon is
reachable in both states. Hide it like any footer item through bb's footer
preferences (Settings → Appearance → Sidebar → footer items, or
`sidebar.hiddenFooterItems`).

**The Appearance page alternative.** The same choice is Settings → Appearance
→ Sidebar → the thread-list provider; the toggle is a shortcut to it, not a
second setting. Both write the one UI preference.

**The default-provider pin.** bb resolves an unset (`__automatic__`)
provider to the first installed thread list other than the bundled
`thread-list/thread-list` — the stewards list — so without a guard BB-44
would change everyone's sidebar the moment it landed. On load the plugin
reads the preference and, when it is unset or `__automatic__`, sets it to
`thread-list/thread-list`. An explicit value, including `stewards/sidebar`,
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.)

**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
reload. `bb settings ui get sidebar.threadListProvider` — a different client —
sees the value the toggle wrote, and bb tells the other clients the preference
changed. Each developer has their own server behind bb-gate, so in practice
the choice is per developer.

## Configuration

In the project's `.bb` (the multi-repo project repo), read from committed
Expand Down
104 changes: 103 additions & 1 deletion plugins/stewards/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// 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 { 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";

Expand Down Expand Up @@ -179,3 +179,105 @@ describe("the Stewards page's need links (BB-29)", () => {
slot.lifecycle.unmount();
});
});

// BB-45: the sidebar-footer disclosure writes the `sidebar.threadListProvider`
// UI preference, so the stewards list BB-44 registers can be turned on and off
// from the footer instead of Settings → Appearance.
describe("the sidebar-footer toggle (BB-45)", () => {
type UiPrefEntry = { value: string; revision: number };
type SetArgs = { key: string; value: string; expectedRevision: number };

/** A `uiPreferences.list()` answer with just the one preference the toggle reads. */
const listed = (entry: UiPrefEntry | null) => ({ preferences: entry === null ? {} : { "sidebar.threadListProvider": entry } }) as never;

const renderToggle = async (options: { entry: UiPrefEntry | null; set: (args: SetArgs) => Promise<unknown> }) => {
const captured = await loadApp();
const item = captured.experimentalSidebarFooterItems[0]!;
if (item.kind !== "disclosure") throw new Error("the sidebar footer item is not a disclosure");
const list = vi.fn(async () => listed(options.entry));
const set = vi.fn(options.set);
const slot = renderSlot({ component: item.component }, { dismiss: () => {} }, { pluginId: "stewards", sdk: { system: { uiPreferences: { list, set } } } as never });
return { slot, set };
};

const echo = async (args: SetArgs) => ({ key: args.key, value: args.value, revision: args.expectedRevision + 1 });

it("registers one footer disclosure under the Stewards sidebar label", async () => {
const captured = await loadApp();
expect(captured.experimentalSidebarFooterItems).toHaveLength(1);
expect(captured.experimentalSidebarFooterItems[0]).toMatchObject({ kind: "disclosure", id: "sidebar", label: "Stewards sidebar", icon: "ShieldCheck" });
});

it("shows the switch off for bb's list and on for the stewards list", async () => {
const off = await renderToggle({ entry: { value: "thread-list/thread-list", revision: 7 }, set: echo });
const offSwitch = await waitFor(() => off.slot.getByRole("switch", { name: "Stewards sidebar" }));
expect(offSwitch.getAttribute("aria-checked")).toBe("false");
off.slot.lifecycle.unmount();

const on = await renderToggle({ entry: { value: "stewards/sidebar", revision: 7 }, set: echo });
const onSwitch = await waitFor(() => on.slot.getByRole("switch", { name: "Stewards sidebar" }));
expect(onSwitch.getAttribute("aria-checked")).toBe("true");
on.slot.lifecycle.unmount();
});

it("reads an unpinned provider as on, the effective stewards list", async () => {
for (const entry of [null, { value: "__automatic__", revision: 0 }]) {
const { slot } = await renderToggle({ entry, set: echo });
const toggle = await waitFor(() => slot.getByRole("switch", { name: "Stewards sidebar" }));
expect(toggle.getAttribute("aria-checked")).toBe("true");
slot.lifecycle.unmount();
}
});

it("turns the stewards list on with the stewards list id and the listed revision", async () => {
const { slot, set } = await renderToggle({ entry: { value: "thread-list/thread-list", revision: 7 }, set: echo });
fireEvent.click(await waitFor(() => slot.getByRole("switch", { name: "Stewards sidebar" })));
await waitFor(() => expect(set).toHaveBeenCalledTimes(1));
expect(set.mock.calls[0]![0]).toEqual({ key: "sidebar.threadListProvider", value: "stewards/sidebar", expectedRevision: 7 });
await waitFor(() => expect(slot.getByRole("switch", { name: "Stewards sidebar" }).getAttribute("aria-checked")).toBe("true"));
slot.lifecycle.unmount();
});

it("turns the stewards list off by setting bb's own list", async () => {
const { slot, set } = await renderToggle({ entry: { value: "stewards/sidebar", revision: 3 }, set: echo });
fireEvent.click(await waitFor(() => slot.getByRole("switch", { name: "Stewards sidebar" })));
await waitFor(() => expect(set).toHaveBeenCalledTimes(1));
expect(set.mock.calls[0]![0]).toEqual({ key: "sidebar.threadListProvider", value: "thread-list/thread-list", expectedRevision: 3 });
await waitFor(() => expect(slot.getByRole("switch", { name: "Stewards sidebar" }).getAttribute("aria-checked")).toBe("false"));
slot.lifecycle.unmount();
});

it("re-lists and retries once when the set hits a revision conflict", async () => {
let sets = 0;
let lists = 0;
const captured = await loadApp();
const item = captured.experimentalSidebarFooterItems[0]!;
if (item.kind !== "disclosure") throw new Error("the sidebar footer item is not a disclosure");
const slot = renderSlot({ component: item.component }, { dismiss: () => {} }, {
pluginId: "stewards",
sdk: {
system: {
uiPreferences: {
list: async () => {
lists += 1;
return listed({ value: "thread-list/thread-list", revision: lists === 1 ? 7 : 9 });
},
set: async (args: SetArgs) => {
sets += 1;
if (sets === 1) throw Object.assign(new Error("revision conflict"), { status: 409 });
return { key: args.key, value: args.value, revision: args.expectedRevision + 1 };
},
},
},
} as never,
});
fireEvent.click(await waitFor(() => slot.getByRole("switch", { name: "Stewards sidebar" })));
await waitFor(() => expect(sets).toBe(2));
expect(slot.inspection.sdkCalls.filter((c) => c.method === "system.uiPreferences.set")).toEqual([
{ method: "system.uiPreferences.set", args: [{ key: "sidebar.threadListProvider", value: "stewards/sidebar", expectedRevision: 7 }] },
{ method: "system.uiPreferences.set", args: [{ key: "sidebar.threadListProvider", value: "stewards/sidebar", expectedRevision: 9 }] },
]);
expect(lists).toBe(2);
slot.lifecycle.unmount();
});
});
Loading
Loading