diff --git a/src/cli/program/message/helpers.test.ts b/src/cli/program/message/helpers.test.ts index e566605d0d1..35bb44815aa 100644 --- a/src/cli/program/message/helpers.test.ts +++ b/src/cli/program/message/helpers.test.ts @@ -121,6 +121,22 @@ describe("runMessageAction", () => { expect(exitMock).toHaveBeenCalledWith(0); }); + it("logs gateway_stop failure and preserves failure exit code when send fails", async () => { + hasHooksMock.mockReturnValueOnce(true); + messageCommandMock.mockRejectedValueOnce(new Error("send failed")); + runGatewayStopMock.mockRejectedValueOnce(new Error("hook failed")); + const fakeCommand = { help: vi.fn() } as never; + const { runMessageAction } = createMessageCliHelpers(fakeCommand, "discord"); + + await expect( + runMessageAction("send", { channel: "discord", target: "123", message: "hi" }), + ).rejects.toThrow("exit"); + + expect(errorMock).toHaveBeenNthCalledWith(1, "Error: send failed"); + expect(errorMock).toHaveBeenNthCalledWith(2, "gateway_stop hook failed: Error: hook failed"); + expect(exitMock).toHaveBeenCalledWith(1); + }); + it("does not call exit(0) when the action throws", async () => { messageCommandMock.mockRejectedValueOnce(new Error("boom")); const fakeCommand = { help: vi.fn() } as never;