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
2 changes: 1 addition & 1 deletion plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ deployment: # where a merge is confirmed live (BB-53); omi
- Stewards are children of their parent steward, or of the project steward
when they have none, with parent notifications off (§4), so bb's thread tree
nests each under its parent. bb does not re-parent a live thread when its
parent ends: a child spawned under a goal that later ends stays under it
parent ends: a child spawned under an initiative that later ends stays under it
visually, even though the binding's `parentBindingId` moved up (`endBinding`).
The sidebar's own list (§21) derives the same nesting from each binding's
`parentKey`, one level deep, so the two views agree. Who reports to whom is in
Expand Down
34 changes: 17 additions & 17 deletions plugins/stewards/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,16 +368,16 @@ describe("playbooks", () => {
});

it("keys a phase on a label with `label:<name>`, keeping it out of the states (BB-248)", () => {
const withLabel = parsePlaybook(LINEAR_TICKETS.replace(" In Progress: { stage: build, stuck: 2d }", ' In Progress: { stage: build, stuck: 2d }\n "label:goal:awaiting-outcome": { stage: build, stuck: 120d }'), "linear-tickets");
const withLabel = parsePlaybook(LINEAR_TICKETS.replace(" In Progress: { stage: build, stuck: 2d }", ' In Progress: { stage: build, stuck: 2d }\n "label:initiative:awaiting-outcome": { stage: build, stuck: 120d }'), "linear-tickets");
if (!withLabel.ok) throw new Error(withLabel.error);
const p = withLabel.value;
expect(labelPhaseName("label:goal:awaiting-outcome")).toBe("goal:awaiting-outcome");
expect(labelPhaseName("label:initiative:awaiting-outcome")).toBe("initiative:awaiting-outcome");
expect(labelPhaseName("In Progress")).toBeNull();
expect(playbookLabels(p)).toEqual(["goal:awaiting-outcome"]);
expect(playbookStates(p)).not.toContain("label:goal:awaiting-outcome");
expect(playbookLabels(p)).toEqual(["initiative:awaiting-outcome"]);
expect(playbookStates(p)).not.toContain("label:initiative:awaiting-outcome");
expect(playbookStates(p)).toContain("In Progress");
// phaseOf still resolves the label key itself, for a binding's stored phase.
expect(phaseOf(p, "label:goal:awaiting-outcome")).toMatchObject({ name: "label:goal:awaiting-outcome", stage: "build" });
expect(phaseOf(p, "label:initiative:awaiting-outcome")).toMatchObject({ name: "label:initiative:awaiting-outcome", stage: "build" });
// A `label:` key with no name is refused; a state-only playbook has no label keys.
expect(parsePlaybook(LINEAR_TICKETS.replace(" In Progress: { stage: build, stuck: 2d }", ' In Progress: { stage: build, stuck: 2d }\n "label:": { stage: build }'), "linear-tickets")).toMatchObject({ ok: false });
const plain = parsePlaybook(LINEAR_TICKETS, "linear-tickets");
Expand Down Expand Up @@ -846,29 +846,29 @@ describe("project-level ticket watches (BB-246)", () => {
const file = (tickets: unknown) => parseProjectFile(JSON.stringify({ version: 1, tickets }));
const playbooks = () => {
const tickets = parsePlaybook(LINEAR_TICKETS, "linear-tickets");
const goals = parsePlaybook(LINEAR_TICKETS.replace("name: linear-tickets", "name: goals"), "goals");
const initiative = parsePlaybook(LINEAR_TICKETS.replace("name: linear-tickets", "name: initiative"), "initiative");
const prs = parsePlaybook(GITHUB_PRS, "github-prs");
if (!tickets.ok || !goals.ok || !prs.ok) throw new Error("playbook parse failed");
if (!tickets.ok || !initiative.ok || !prs.ok) throw new Error("playbook parse failed");
return new Map([
["linear-tickets", tickets.value],
["goals", goals.value],
["initiative", initiative.value],
["github-prs", prs.value],
]);
};

it("parses a tickets list, defaulting match, and refuses a bad shape", () => {
const parsed = file([{ match: { labels: ["docs"], title: "Docs: *" }, playbook: "goals" }, { playbook: "linear-tickets" }]);
const parsed = file([{ match: { labels: ["docs"], title: "Docs: *" }, playbook: "initiative" }, { playbook: "linear-tickets" }]);
if (!parsed.ok) throw new Error(parsed.error);
expect(parsed.value.tickets).toEqual([
{ match: { labels: ["docs"], title: "Docs: *" }, playbook: "goals" },
{ match: { labels: ["docs"], title: "Docs: *" }, playbook: "initiative" },
{ match: {}, playbook: "linear-tickets" },
]);
const empty = parseProjectFile(JSON.stringify({ version: 1 }));
if (!empty.ok) throw new Error(empty.error);
expect(empty.value.tickets).toEqual([]);
expect(file([{ match: { labels: [] }, playbook: "goals" }])).toMatchObject({ ok: false });
expect(file([{ match: { labels: [] }, playbook: "initiative" }])).toMatchObject({ ok: false });
expect(file([{ match: { labels: ["docs"] } }])).toMatchObject({ ok: false });
expect(file([{ match: { bogus: true }, playbook: "goals" }])).toMatchObject({ ok: false });
expect(file([{ match: { bogus: true }, playbook: "initiative" }])).toMatchObject({ ok: false });
// A near-miss key is still refused by the strict project file.
expect(parseProjectFile(JSON.stringify({ version: 1, ticket: [] }))).toMatchObject({ ok: false });
});
Expand All @@ -887,15 +887,15 @@ describe("project-level ticket watches (BB-246)", () => {
});

it("reports a ticket watch playbook that did not parse from the loader's error, once", () => {
const parsed = file([{ playbook: "goals" }]);
const parsed = file([{ playbook: "initiative" }]);
if (!parsed.ok) throw new Error(parsed.error);
const problems = ticketWatchProblems(parsed.value, new Map(), new Map([["goals", "stewards/playbooks/goals.md: the front matter is not YAML"]]));
expect(problems).toEqual([expect.stringMatching(/tickets\[0\].*"goals".*not YAML/u)]);
const problems = ticketWatchProblems(parsed.value, new Map(), new Map([["initiative", "stewards/playbooks/initiative.md: the front matter is not YAML"]]));
expect(problems).toEqual([expect.stringMatching(/tickets\[0\].*"initiative".*not YAML/u)]);
});

it("names a ticket watch by its playbook", () => {
const parsed = file([{ playbook: "goals" }]);
const parsed = file([{ playbook: "initiative" }]);
if (!parsed.ok) throw new Error(parsed.error);
expect(parsed.value.tickets.map((w) => ticketWatchId(w))).toEqual(["goals@ticket"]);
expect(parsed.value.tickets.map((w) => ticketWatchId(w))).toEqual(["initiative@ticket"]);
});
});
15 changes: 8 additions & 7 deletions plugins/stewards/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ export const playbookPath = (name: string) => `${STEWARDS_DIR}/playbooks/${name}
export const DEFAULT_LABEL = "bb-managed";

/**
* The label a goal ticket carries besides the adoption label, and the playbook
* that stewards it (BB-243). A ticket is a goal when it carries the label or
* runs under the playbook: the project steward's wake and digest read a goal's
* progress from the `**Met:**` comments, and the playbook name is known even
* before the first snapshot, so an unread history reads `unknown`, never `0`.
* The label an initiative ticket carries besides the adoption label, and the
* playbook that stewards it (BB-243). A ticket is an initiative when it
* carries the label or runs under the playbook: the project steward's wake and
* digest read an initiative's progress from the `**Met:**` comments, and the
* playbook name is known even before the first snapshot, so an unread history
* reads `unknown`, never `0`.
*/
export const GOAL_LABEL = "goal";
export const GOAL_PLAYBOOK = "goal";
export const INITIATIVE_LABEL = "initiative";
export const INITIATIVE_PLAYBOOK = "initiative";

/**
* Authors whose pull requests the dependency watch adopts under deps-prs
Expand Down
14 changes: 10 additions & 4 deletions plugins/stewards/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,14 @@ export interface GithubWriter {
* changes-requested review, where the owner's own pull request cannot.
*/
review(repo: string, number: number, event: "APPROVE" | "REQUEST_CHANGES" | "COMMENT", body: string): Promise<void>;
/** Squash-merge the pull request, with the given commit title and message; returns the merge commit sha when GitHub reports one. */
squashMerge(repo: string, number: number, title: string, body: string): Promise<{ sha: string | null }>;
/**
* Squash-merge the pull request, with the given commit title and message;
* returns the merge commit sha when GitHub reports one. `sha` is the head
* the caller judged: GitHub refuses with 409 "Head branch was modified"
* when the head moved, so an unattended merge never lands a push whose
* checks have not run (BB-257).
*/
squashMerge(repo: string, number: number, title: string, body: string, sha?: string | null): Promise<{ sha: string | null }>;
/**
* A pull request's title and body, for the squash merge commit (BB-193).
* Null when GitHub has no readable title, or when the read fails; the caller
Expand Down Expand Up @@ -156,8 +162,8 @@ export function createGhWriter(token: TokenReader = createGhTokenReader(), doFet
async review(repo, number, event, body) {
await request("POST", `/repos/${repo}/pulls/${number}/reviews`, { event, body });
},
async squashMerge(repo, number, title, body) {
const response = await request("PUT", `/repos/${repo}/pulls/${number}/merge`, { merge_method: "squash", commit_title: title, commit_message: body });
async squashMerge(repo, number, title, body, headSha) {
const response = await request("PUT", `/repos/${repo}/pulls/${number}/merge`, { merge_method: "squash", commit_title: title, commit_message: body, ...(headSha === undefined || headSha === null || headSha === "" ? {} : { sha: headSha }) });
const merged = (await response.json().catch(() => null)) as { sha?: unknown } | null;
const sha = merged?.sha;
return { sha: typeof sha === "string" && sha !== "" ? sha : null };
Expand Down
44 changes: 22 additions & 22 deletions plugins/stewards/reconcile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const reviews = (() => {
const ctx = { own: new Set(["thr_s", "thr_w"]), stewardThreadId: "thr_s", approved: false, cursor: "2026-10-01T12:00:00Z", workerInFlight: false };
const actionable = (cs: Array<{ text: string; actionable: boolean }>) => cs.filter((c) => c.actionable).map((c) => c.text);

const LABEL_PHASE = '\n "label:goal:awaiting-outcome": { stage: build, stuck: 120d }';
const LABEL_PHASE = '\n "label:initiative:awaiting-outcome": { stage: build, stuck: 120d }';
const labelledTickets = (() => {
const p = parsePlaybook(LINEAR_TICKETS.replace(" In Progress: { stage: build, stuck: 2d }", ` In Progress: { stage: build, stuck: 2d }${LABEL_PHASE}`), "linear-tickets");
if (!p.ok) throw new Error(p.error);
Expand All @@ -34,23 +34,23 @@ const labelledGithubIssues = (() => {

describe("phaseAndStage keys a phase on a present label (BB-248)", () => {
it("selects a matching label phase ahead of the state, on Linear", () => {
expect(phaseAndStage(labelledTickets, "In Progress", ["bb-managed", "goal:awaiting-outcome"])).toEqual({ phase: "label:goal:awaiting-outcome", stage: "build" });
expect(phaseAndStage(labelledTickets, "In Progress", ["bb-managed", "initiative:awaiting-outcome"])).toEqual({ phase: "label:initiative:awaiting-outcome", stage: "build" });
// The label match ignores case.
expect(phaseAndStage(labelledTickets, "In Progress", ["Goal:Awaiting-Outcome"])).toEqual({ phase: "label:goal:awaiting-outcome", stage: "build" });
expect(phaseAndStage(labelledTickets, "In Progress", ["Initiative:Awaiting-Outcome"])).toEqual({ phase: "label:initiative:awaiting-outcome", stage: "build" });
// No such label, or no labels at all: the state decides, as today.
expect(phaseAndStage(labelledTickets, "In Progress", ["bb-managed"])).toEqual({ phase: "In Progress", stage: "build" });
expect(phaseAndStage(labelledTickets, "In Progress")).toEqual({ phase: "In Progress", stage: "build" });
});

it("selects it on a GitHub entity too, over the synthesised status state", () => {
expect(phaseAndStage(labelledGithubIssues, "status:in-progress", ["bb-managed", "goal:awaiting-outcome"])).toEqual({ phase: "label:goal:awaiting-outcome", stage: "build" });
expect(phaseAndStage(labelledGithubIssues, "status:in-progress", ["bb-managed", "initiative:awaiting-outcome"])).toEqual({ phase: "label:initiative:awaiting-outcome", stage: "build" });
// A present status label is still a state, and decides when no label phase matches.
expect(phaseAndStage(labelledGithubIssues, "status:in-progress", ["bb-managed", "status:in-progress"])).toEqual({ phase: "status:in-progress", stage: "build" });
});

it("resolves the stored label phase for stuckDue", () => {
expect(phaseAndStage(labelledTickets, "In Progress", ["goal:awaiting-outcome"]).phase).toBe("label:goal:awaiting-outcome");
expect(stuckDue({ advancedAt: 1_000, createdAt: 0, phase: "label:goal:awaiting-outcome" }, labelledTickets, [], 1_000 + 120 * 86_400_000)).toBe(120 * 86_400_000);
expect(phaseAndStage(labelledTickets, "In Progress", ["initiative:awaiting-outcome"]).phase).toBe("label:initiative:awaiting-outcome");
expect(stuckDue({ advancedAt: 1_000, createdAt: 0, phase: "label:initiative:awaiting-outcome" }, labelledTickets, [], 1_000 + 120 * 86_400_000)).toBe(120 * 86_400_000);
});
});

Expand Down Expand Up @@ -503,29 +503,29 @@ describe("lifecycle", () => {
});
});

// BB-243: a goal is a ticket routed to the `goal` playbook. All three endings
// (reached, superseded, retired) are the goal closing; a child's merge is not
// one, so the binding carries on. The fixture is a fake goal, never the pilot's.
describe("goal endings (BB-243)", () => {
const goal = (() => {
const p = parsePlaybook(GITHUB_ISSUES.replace("name: github-issues", "name: goal").replace("approval: project", "approval: user"), "goal");
// BB-243: an initiative is a ticket routed to the `initiative` playbook. All three endings
// (reached, superseded, retired) are the initiative closing; a child's merge is not
// one, so the binding carries on. The fixture is a fake initiative, never the pilot's.
describe("initiative endings (BB-243)", () => {
const initiative = (() => {
const p = parsePlaybook(GITHUB_ISSUES.replace("name: github-issues", "name: initiative").replace("approval: project", "approval: user"), "initiative");
if (!p.ok) throw new Error(p.error);
return p.value;
})();
const open = { kind: "ticket" as const, endedAt: null, endReason: null, manualDetach: false, ending: null };

it("ends the binding when the goal is reached, superseded or retired, and never on a child merge", () => {
it("ends the binding when the initiative is reached, superseded or retired, and never on a child merge", () => {
// Reached: every criterion met, the owner closes it as completed.
expect(lifecycle(open, goal, issue({ state: "closed (completed)" }), "bb-managed").kind).toBe("terminal");
expect(lifecycle(open, initiative, issue({ state: "closed (completed)" }), "bb-managed").kind).toBe("terminal");
// Retired: the owner closes it as not planned.
expect(lifecycle(open, goal, issue({ state: "closed (not planned)" }), "bb-managed").kind).toBe("terminal");
// Superseded: a successor is filed and this goal is closed with a Revision comment.
const superseded = issue({ state: "closed", comments: [comment({ id: "r1", author: "Jane", body: "**Revision:** superseded by Goal: file the 2027 claim." })] });
expect(lifecycle(open, goal, superseded, "bb-managed").kind).toBe("terminal");
// A child merging does not close the goal, so the binding carries on.
expect(lifecycle(open, goal, issue({ state: "status:in-progress" }), "bb-managed").kind).toBe("continue");
// An ended goal stays ended while it is closed, whatever an earlier digest said.
expect(lifecycle({ ...open, endedAt: 1, endReason: "terminal" }, goal, issue({ state: "closed" }), "bb-managed").kind).toBe("stay-ended");
expect(lifecycle(open, initiative, issue({ state: "closed (not planned)" }), "bb-managed").kind).toBe("terminal");
// Superseded: a successor is filed and this initiative is closed with a Revision comment.
const superseded = issue({ state: "closed", comments: [comment({ id: "r1", author: "Jane", body: "**Revision:** superseded by Initiative: file the 2027 claim." })] });
expect(lifecycle(open, initiative, superseded, "bb-managed").kind).toBe("terminal");
// A child merging does not close the initiative, so the binding carries on.
expect(lifecycle(open, initiative, issue({ state: "status:in-progress" }), "bb-managed").kind).toBe("continue");
// An ended initiative stays ended while it is closed, whatever an earlier digest said.
expect(lifecycle({ ...open, endedAt: 1, endReason: "terminal" }, initiative, issue({ state: "closed" }), "bb-managed").kind).toBe("stay-ended");
});
});

Expand Down
Loading
Loading