mirror of https://github.com/openclaw/openclaw.git
fix(cli): harden message gateway_stop teardown
This commit is contained in:
parent
74ad924202
commit
bc1edeba33
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue