From ae99dde22bc013aac0f68ac0d035c7ffb460b2c8 Mon Sep 17 00:00:00 2001 From: Dylan Trotter Date: Wed, 18 Nov 2026 17:52:45 +0000 Subject: [PATCH] stewards: add the local source and an optional playbook to the contract (BB-361) --- plugins/github-watcher/source-contract.ts | 12 +++++-- plugins/linear/source-contract.ts | 12 +++++-- plugins/stewards/contract.test.ts | 40 ++++++++++++++++++++++- plugins/stewards/server.ts | 6 +++- plugins/stewards/source-contract.ts | 12 +++++-- 5 files changed, 74 insertions(+), 8 deletions(-) diff --git a/plugins/github-watcher/source-contract.ts b/plugins/github-watcher/source-contract.ts index 18018d7c..2cc72b59 100644 --- a/plugins/github-watcher/source-contract.ts +++ b/plugins/github-watcher/source-contract.ts @@ -20,7 +20,7 @@ import { z } from "zod"; export const STEWARDS_PLUGIN_ID = "stewards"; -export const sourceSchema = z.enum(["linear", "github"]); +export const sourceSchema = z.enum(["linear", "github", "local"]); export type Source = z.infer; /** A repository as GitHub spells it, `owner/name`, as a repo lease and a project's unit name. */ @@ -31,7 +31,7 @@ export const REPO_NAME = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u; * bb reserves the id `github` for its bundled plugin and refuses a path * install under it. */ -export const SOURCE_PLUGIN_IDS: Record = { linear: "linear", github: "github-watcher" }; +export const SOURCE_PLUGIN_IDS: Record = { linear: "linear", github: "github-watcher", local: "stewards" }; /** * A GitHub Deployment, as bb-gate-hooks forwards it on a `deployment` @@ -231,6 +231,14 @@ export const entitySnapshotSchema = z.object({ state: z.string(), /** Linear's state type (triage, backlog, unstarted, started, completed, canceled); null on GitHub. */ stateType: z.string().nullable(), + /** + * The playbook the entity names, when its source names one: the local + * source reads `ticket` or `initiative` off the ticket. Optional and + * additive -- linear and github omit it, and stewards routes those by the + * project's label and state rules. Absent means the source has no playbook + * of its own, not that it named the empty string. + */ + playbook: z.string().optional(), /** Linear: the team key. GitHub: "owner/repo". What a project lists and a lease hangs off. */ unit: z.string(), labels: z.array(z.string()), diff --git a/plugins/linear/source-contract.ts b/plugins/linear/source-contract.ts index 18018d7c..2cc72b59 100644 --- a/plugins/linear/source-contract.ts +++ b/plugins/linear/source-contract.ts @@ -20,7 +20,7 @@ import { z } from "zod"; export const STEWARDS_PLUGIN_ID = "stewards"; -export const sourceSchema = z.enum(["linear", "github"]); +export const sourceSchema = z.enum(["linear", "github", "local"]); export type Source = z.infer; /** A repository as GitHub spells it, `owner/name`, as a repo lease and a project's unit name. */ @@ -31,7 +31,7 @@ export const REPO_NAME = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u; * bb reserves the id `github` for its bundled plugin and refuses a path * install under it. */ -export const SOURCE_PLUGIN_IDS: Record = { linear: "linear", github: "github-watcher" }; +export const SOURCE_PLUGIN_IDS: Record = { linear: "linear", github: "github-watcher", local: "stewards" }; /** * A GitHub Deployment, as bb-gate-hooks forwards it on a `deployment` @@ -231,6 +231,14 @@ export const entitySnapshotSchema = z.object({ state: z.string(), /** Linear's state type (triage, backlog, unstarted, started, completed, canceled); null on GitHub. */ stateType: z.string().nullable(), + /** + * The playbook the entity names, when its source names one: the local + * source reads `ticket` or `initiative` off the ticket. Optional and + * additive -- linear and github omit it, and stewards routes those by the + * project's label and state rules. Absent means the source has no playbook + * of its own, not that it named the empty string. + */ + playbook: z.string().optional(), /** Linear: the team key. GitHub: "owner/repo". What a project lists and a lease hangs off. */ unit: z.string(), labels: z.array(z.string()), diff --git a/plugins/stewards/contract.test.ts b/plugins/stewards/contract.test.ts index 608b4c14..cf2181fa 100644 --- a/plugins/stewards/contract.test.ts +++ b/plugins/stewards/contract.test.ts @@ -2,7 +2,7 @@ import { existsSync, readFileSync } from "node:fs"; import { fileURLToPath } from "node:url"; import { describe, expect, it } from "vitest"; -import { isMissingPlugin, signatureLine, signedBy, snapshotPullSchema, sourceContract } from "./source-contract.js"; +import { SOURCE_PLUGIN_IDS, entitySnapshotSchema, isMissingPlugin, signatureLine, signedBy, snapshotPullSchema, sourceContract, sourceSchema } from "./source-contract.js"; const here = (p: string) => fileURLToPath(new URL(p, import.meta.url)); @@ -14,6 +14,44 @@ describe("source-contract.ts", () => { }); } + it("parses the local source, its plugin id and the optional playbook field (BB-361)", () => { + // A third source, served by stewards itself, joins the contract. + expect(sourceSchema.parse("local")).toBe("local"); + expect(SOURCE_PLUGIN_IDS.local).toBe("stewards"); + expect(SOURCE_PLUGIN_IDS).toEqual({ linear: "linear", github: "github-watcher", local: "stewards" }); + // The playbook is optional and additive: a source that names one carries + // it (the local source), and a source that has none omits it rather than + // sending a placeholder. + const snapshot = { + source: "local" as const, + kind: "issue" as const, + id: "LOCAL-1", + key: "LOCAL-1", + url: null, + title: "A local ticket", + state: "Ready", + stateType: null, + unit: "local", + labels: [], + author: null, + assignees: [], + priority: null, + estimate: null, + description: "The spec.", + createdAt: null, + updatedAt: null, + comments: [], + parent: null, + children: [], + linkedPulls: [], + pull: null, + viewer: null, + }; + expect(entitySnapshotSchema.parse({ ...snapshot, playbook: "initiative" })).toMatchObject({ source: "local", playbook: "initiative" }); + expect(entitySnapshotSchema.parse(snapshot).playbook).toBeUndefined(); + expect(entitySnapshotSchema.safeParse({ ...snapshot, playbook: 3 }).success).toBe(false); + }); + it("reads the last signature in a body", () => { expect(signedBy(`hello\n\n${signatureLine("thr_abc")}`)).toBe("thr_abc"); expect(signedBy(`> ${signatureLine("thr_old")}\n\nreply\n\n${signatureLine("thr_new")}`)).toBe("thr_new"); diff --git a/plugins/stewards/server.ts b/plugins/stewards/server.ts index 34948c1a..a0857bad 100644 --- a/plugins/stewards/server.ts +++ b/plugins/stewards/server.ts @@ -720,7 +720,7 @@ export const rpcContract = defineRpcContract({ linearTeams: z.array(z.string()), repos: z.array(z.string()), excludedRepos: z.array(z.string()), - playbooks: z.array(z.object({ kind: z.string(), name: z.string(), version: z.string().nullable(), source: z.enum(["linear", "github"]).nullable() })), + playbooks: z.array(z.object({ kind: z.string(), name: z.string(), version: z.string().nullable(), source: z.enum(["linear", "github", "local"]).nullable() })), problems: z.array(z.string()), nightly: z.object({ at: z.string(), timezone: z.string() }).nullable(), lastNight: z.string().nullable(), @@ -3871,6 +3871,10 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P // which it skips; stewards check says so. deployment: [...new Set(projects.flatMap((p) => deploymentTargets(p).map((t) => t.repo)))].sort(), }, + // The local source is stewards itself: it leases nothing on + // bb-gate-hooks, so its set is empty and the loop below never sends + // it. Present only so the Record covers every Source (BB-361). + local: { units: [], entities: [], dependabot: [], deployment: [] }, }; for (const source of ["linear", "github"] as const) { const body = JSON.stringify(sets[source]); diff --git a/plugins/stewards/source-contract.ts b/plugins/stewards/source-contract.ts index 18018d7c..2cc72b59 100644 --- a/plugins/stewards/source-contract.ts +++ b/plugins/stewards/source-contract.ts @@ -20,7 +20,7 @@ import { z } from "zod"; export const STEWARDS_PLUGIN_ID = "stewards"; -export const sourceSchema = z.enum(["linear", "github"]); +export const sourceSchema = z.enum(["linear", "github", "local"]); export type Source = z.infer; /** A repository as GitHub spells it, `owner/name`, as a repo lease and a project's unit name. */ @@ -31,7 +31,7 @@ export const REPO_NAME = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/u; * bb reserves the id `github` for its bundled plugin and refuses a path * install under it. */ -export const SOURCE_PLUGIN_IDS: Record = { linear: "linear", github: "github-watcher" }; +export const SOURCE_PLUGIN_IDS: Record = { linear: "linear", github: "github-watcher", local: "stewards" }; /** * A GitHub Deployment, as bb-gate-hooks forwards it on a `deployment` @@ -231,6 +231,14 @@ export const entitySnapshotSchema = z.object({ state: z.string(), /** Linear's state type (triage, backlog, unstarted, started, completed, canceled); null on GitHub. */ stateType: z.string().nullable(), + /** + * The playbook the entity names, when its source names one: the local + * source reads `ticket` or `initiative` off the ticket. Optional and + * additive -- linear and github omit it, and stewards routes those by the + * project's label and state rules. Absent means the source has no playbook + * of its own, not that it named the empty string. + */ + playbook: z.string().optional(), /** Linear: the team key. GitHub: "owner/repo". What a project lists and a lease hangs off. */ unit: z.string(), labels: z.array(z.string()),