diff --git a/apps/cli/src/__tests__/command-output/thread-tell.test.ts b/apps/cli/src/__tests__/command-output/thread-tell.test.ts index 637ff5efdb..7df74ce6ba 100644 --- a/apps/cli/src/__tests__/command-output/thread-tell.test.ts +++ b/apps/cli/src/__tests__/command-output/thread-tell.test.ts @@ -156,6 +156,40 @@ describe("bb thread tell command output", () => { }, ); + it.each([404, 503, "transport"] as const)( + "bb thread send preserves the send error when the hint lookup fails with %s", + async (failure) => { + stubServerApi({ + "v1.threads.:id.$get": async () => { + if (failure === "transport") { + throw new Error("Thread lookup connection closed"); + } + return new Response( + JSON.stringify({ message: "Thread lookup failed" }), + { status: failure, headers: { "Content-Type": "application/json" } }, + ); + }, + "v1.threads.:id.send.$post": async () => + new Response( + JSON.stringify({ + code: "thread_environment_unavailable", + message: "Thread environment is unavailable", + details: { reason: "destroyed", environmentStatus: "destroyed" }, + }), + { status: 409, headers: { "Content-Type": "application/json" } }, + ), + }); + + await expect( + runCommand(["thread", "send", "thread-gone", "hello"], register), + ).rejects.toThrow("process.exit:1"); + + expect( + vi.mocked(console.error).mock.calls.map((call) => String(call[0])), + ).toEqual(["Error: HTTP 409: Thread environment is unavailable"]); + }, + ); + it("bb thread tell names the plugin a message is waiting on", async () => { const post = vi.fn(async () => ({ ok: true,