From 59baaf3d15211fc008751a6a68eb2a8fe676300a Mon Sep 17 00:00:00 2001 From: Dylan Trotter Date: Sat, 24 Oct 2026 05:03:42 +0000 Subject: [PATCH 1/2] slack: default a conversation's thread to the personal project (BB-42) --- plugins/slack/README.md | 2 +- plugins/slack/server.test.ts | 38 +++++++++++++++++++++++++++++++++--- plugins/slack/server.ts | 10 +++++++--- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/plugins/slack/README.md b/plugins/slack/README.md index 7c302561..ed93da36 100644 --- a/plugins/slack/README.md +++ b/plugins/slack/README.md @@ -43,7 +43,7 @@ on the pod. | Setting | What it is | |---|---| | Slack sign-in token | Filled in by Sign in with Slack. A secret; do not edit or paste by hand. | -| Project | Which bb project a Slack conversation starts its thread in. Empty uses the first project on this server. | +| Project | Which bb project a Slack conversation starts its thread in. Empty uses the personal project, or the first project when this server has none. | **Sign out** forgets the token and reconnects the stream, so the service drops the identity bound to the old connection. diff --git a/plugins/slack/server.test.ts b/plugins/slack/server.test.ts index f0f3ac80..bb42d1de 100644 --- a/plugins/slack/server.test.ts +++ b/plugins/slack/server.test.ts @@ -180,7 +180,7 @@ describe("Slack plugin", () => { expect(await s.harness.callRpc("status")).toEqual({ signedIn: false, user: null, - project: { id: "prj-1", name: "Project One" }, + project: { id: "prj-2", name: "Personal" }, projects: PROJECTS, hooks: { configured: true, connected: true, state: "connected" }, }); @@ -254,7 +254,7 @@ describe("Slack plugin", () => { // The thread runs where the developer's newest environment runs: that // provider, with its inputs, on its machine; never the pod's own host. expect(spawns[0]![0]).toMatchObject({ - projectId: "prj-1", + projectId: "prj-2", environment: { type: "provider", environmentProviderId: "multi-repo-workspace", inputs: { repos: ["a"] }, machine: { type: "existing", hostId: "host_on" } }, }); expect(String((spawns[0]![0] as { prompt: string }).prompt)).toContain("session D0123:1712345678.901234"); @@ -314,7 +314,7 @@ describe("Slack plugin", () => { }); it("runs the thread in the project's checkout on its connected machine when it has no environment there", async () => { - const s = await live({ environments: [] }); + const s = await live({ project: "prj-1", environments: [] }); s.hooks.last().send(s.hooks.session()); await tick(); expect(s.harness.sdk.callsTo("threads.spawn")[0]![0]).toMatchObject({ @@ -364,6 +364,38 @@ describe("Slack plugin", () => { await s.stop(); }); + it("starts a conversation in the personal project when the setting is empty, even when it is not first", async () => { + const s = await live(); + expect(((await s.harness.callRpc("status")) as { project: { id: string } }).project.id).toBe("prj-2"); + s.hooks.last().send(s.hooks.session()); + await tick(); + expect((s.harness.sdk.callsTo("threads.spawn")[0]![0] as { projectId: string }).projectId).toBe("prj-2"); + await s.stop(); + }); + + it("falls back to the personal project when the setting names no project", async () => { + const s = await live({ project: "not-a-project" }); + expect(((await s.harness.callRpc("status")) as { project: { id: string } }).project.id).toBe("prj-2"); + s.hooks.last().send(s.hooks.session()); + await tick(); + expect((s.harness.sdk.callsTo("threads.spawn")[0]![0] as { projectId: string }).projectId).toBe("prj-2"); + await s.stop(); + }); + + it("falls back to the first standard project when the server has no personal one", async () => { + const s = await live({ + projects: [ + { id: "prj-1", name: "Project One", kind: "standard" }, + { id: "prj-3", name: "Project Two", kind: "standard" }, + ], + }); + expect(((await s.harness.callRpc("status")) as { project: { id: string } }).project.id).toBe("prj-1"); + s.hooks.last().send(s.hooks.session()); + await tick(); + expect((s.harness.sdk.callsTo("threads.spawn")[0]![0] as { projectId: string }).projectId).toBe("prj-1"); + await s.stop(); + }); + it("keeps the conversation's thread on a transient send error, and starts a new one only when it is gone", async () => { let sends = 0; const transient = await live({ diff --git a/plugins/slack/server.ts b/plugins/slack/server.ts index ef8f2a76..a362d68c 100644 --- a/plugins/slack/server.ts +++ b/plugins/slack/server.ts @@ -54,7 +54,7 @@ export function settingDescriptors(_env: Record) { project: { type: "string", label: "Project", - description: "Which bb project a Slack conversation starts its thread in. Leave empty to use the first project on this server.", + description: "Which bb project a Slack conversation starts its thread in. Leave empty to use the personal project, or the first project when this server has none.", }, } as const; } @@ -114,14 +114,18 @@ type Project = { id: string; name: string; kind: string }; /** The environment a spawned thread runs in: `threads.spawn`'s `environment`. */ type SpawnEnvironment = Parameters[0]["environment"]; -/** The project a Slack conversation goes to: the chosen one, else the first. */ +/** + * The project a Slack conversation goes to: the chosen one, else the personal + * project (the way a thread with no project starts in bb), and only when there + * is none the first standard project. + */ export function chooseProject(projects: Project[], chosen: string): Project | null { const named = chosen.trim(); if (named !== "") { const found = projects.find((p) => p.id === named || p.name.toLowerCase() === named.toLowerCase()); if (found !== undefined) return found; } - return projects.find((p) => p.kind === "standard") ?? projects[0] ?? null; + return projects.find((p) => p.kind === "personal") ?? projects.find((p) => p.kind === "standard") ?? projects[0] ?? null; } export function createSlackPlugin(deps: SlackPluginDeps): (bb: BbPluginApi) => Promise { From 6fb6fd6c2b4237597ae39a7aac5fa13622508f45 Mon Sep 17 00:00:00 2001 From: Dylan Trotter Date: Sat, 24 Oct 2026 05:06:06 +0000 Subject: [PATCH 2/2] slack: prove the project setting wins over the personal default (BB-42) --- plugins/slack/server.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/slack/server.test.ts b/plugins/slack/server.test.ts index bb42d1de..c8497778 100644 --- a/plugins/slack/server.test.ts +++ b/plugins/slack/server.test.ts @@ -356,11 +356,13 @@ describe("Slack plugin", () => { it("changes the project the next Slack conversation goes to", async () => { const s = await live(); - expect((await s.harness.callRpc("setProject", { projectId: "prj-2" })) as { ok: boolean }).toEqual({ ok: true }); - expect(((await s.harness.callRpc("status")) as { project: { id: string } }).project.id).toBe("prj-2"); + // prj-1 is the standard project; the empty setting would pick the personal + // prj-2, so this proves the setting wins over the default. + expect((await s.harness.callRpc("setProject", { projectId: "prj-1" })) as { ok: boolean }).toEqual({ ok: true }); + expect(((await s.harness.callRpc("status")) as { project: { id: string } }).project.id).toBe("prj-1"); s.hooks.last().send(s.hooks.session()); await tick(); - expect((s.harness.sdk.callsTo("threads.spawn")[0]![0] as { projectId: string }).projectId).toBe("prj-2"); + expect((s.harness.sdk.callsTo("threads.spawn")[0]![0] as { projectId: string }).projectId).toBe("prj-1"); await s.stop(); });