fix(cli): harden message gateway_stop teardown

This commit is contained in:
Gustavo Madeira Santana 2026-02-14 17:14:53 -05:00
parent 74ad924202
commit bc1edeba33
2 changed files with 19 additions and 1 deletions

View File

@ -107,6 +107,20 @@ describe("runMessageAction", () => {
expect(exitMock).toHaveBeenCalledWith(1);
});
it("logs gateway_stop failure and still exits with success code", async () => {
hasHooksMock.mockReturnValueOnce(true);
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).toHaveBeenCalledWith("gateway_stop hook failed: Error: hook failed");
expect(exitMock).toHaveBeenCalledWith(0);
});
it("does not call exit(0) when the action throws", async () => {
messageCommandMock.mockRejectedValueOnce(new Error("boom"));
const fakeCommand = { help: vi.fn() } as never;

View File

@ -28,7 +28,11 @@ async function runPluginStopHooks(): Promise<void> {
if (!hookRunner?.hasHooks("gateway_stop")) {
return;
}
await hookRunner.runGatewayStop({ reason: "cli message action complete" }, {});
try {
await hookRunner.runGatewayStop({ reason: "cli message action complete" }, {});
} catch (err) {
defaultRuntime.error(danger(`gateway_stop hook failed: ${String(err)}`));
}
}
export function createMessageCliHelpers(