test: tighten fatal rejection assertions

This commit is contained in:
Peter Steinberger
2026-05-11 05:23:50 +01:00
parent 8e40d1336e
commit b92388b708
@@ -54,6 +54,16 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
process.emit("unhandledRejection", reason, Promise.resolve());
}
function expectConsoleLogWithMessage(
spy: ReturnType<typeof vi.spyOn>,
label: string,
message: string,
): void {
const call = spy.mock.calls.find((entry: unknown[]) => entry[0] === label);
expect(call?.[0]).toBe(label);
expect(String(call?.[1])).toContain(message);
}
function expectExitCodeFromUnhandled(
reason: unknown,
expected: number[],
@@ -88,9 +98,10 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
);
}
expect(consoleErrorSpy).toHaveBeenCalledWith(
expectConsoleLogWithMessage(
consoleErrorSpy,
"[openclaw] FATAL unhandled rejection:",
expect.stringContaining("Out of memory"),
"Out of memory",
);
});
});
@@ -124,9 +135,10 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
);
}
expect(consoleErrorSpy).toHaveBeenCalledWith(
expectConsoleLogWithMessage(
consoleErrorSpy,
"[openclaw] CONFIGURATION ERROR - requires fix:",
expect.stringContaining("Invalid config"),
"Invalid config",
);
});
});
@@ -167,9 +179,10 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
expectExitCodeFromUnhandled(transientErr, []);
}
expect(consoleWarnSpy).toHaveBeenCalledWith(
expectConsoleLogWithMessage(
consoleWarnSpy,
"[openclaw] Non-fatal unhandled rejection (continuing):",
expect.stringContaining("fetch failed"),
"fetch failed",
);
});
@@ -190,9 +203,10 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
expectExitCodeFromUnhandled(sqliteErr, []);
}
expect(consoleWarnSpy).toHaveBeenCalledWith(
expectConsoleLogWithMessage(
consoleWarnSpy,
"[openclaw] Non-fatal unhandled rejection (continuing):",
expect.stringContaining("unable to open database file"),
"unable to open database file",
);
});
@@ -200,9 +214,10 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
const genericErr = new Error("Something went wrong");
expectExitCodeFromUnhandled(genericErr, [1], "unhandled rejection");
expect(consoleErrorSpy).toHaveBeenCalledWith(
expectConsoleLogWithMessage(
consoleErrorSpy,
"[openclaw] Unhandled promise rejection:",
expect.stringContaining("Something went wrong"),
"Something went wrong",
);
});
@@ -222,9 +237,10 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
abortErr.name = "AbortError";
expectExitCodeFromUnhandled(abortErr, []);
expect(consoleWarnSpy).toHaveBeenCalledWith(
expectConsoleLogWithMessage(
consoleWarnSpy,
"[openclaw] Suppressed AbortError:",
expect.stringContaining("This operation was aborted"),
"This operation was aborted",
);
});
});