























@@ -54,6 +54,16 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
5454process.emit("unhandledRejection", reason, Promise.resolve());
5555}
565657+function expectConsoleLogWithMessage(
58+spy: ReturnType<typeof vi.spyOn>,
59+label: string,
60+message: string,
61+): void {
62+const call = spy.mock.calls.find((entry: unknown[]) => entry[0] === label);
63+expect(call?.[0]).toBe(label);
64+expect(String(call?.[1])).toContain(message);
65+}
66+5767function expectExitCodeFromUnhandled(
5868reason: unknown,
5969expected: number[],
@@ -88,9 +98,10 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
8898);
8999}
9010091-expect(consoleErrorSpy).toHaveBeenCalledWith(
101+expectConsoleLogWithMessage(
102+consoleErrorSpy,
92103"[openclaw] FATAL unhandled rejection:",
93-expect.stringContaining("Out of memory"),
104+"Out of memory",
94105);
95106});
96107});
@@ -124,9 +135,10 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
124135);
125136}
126137127-expect(consoleErrorSpy).toHaveBeenCalledWith(
138+expectConsoleLogWithMessage(
139+consoleErrorSpy,
128140"[openclaw] CONFIGURATION ERROR - requires fix:",
129-expect.stringContaining("Invalid config"),
141+"Invalid config",
130142);
131143});
132144});
@@ -167,9 +179,10 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
167179expectExitCodeFromUnhandled(transientErr, []);
168180}
169181170-expect(consoleWarnSpy).toHaveBeenCalledWith(
182+expectConsoleLogWithMessage(
183+consoleWarnSpy,
171184"[openclaw] Non-fatal unhandled rejection (continuing):",
172-expect.stringContaining("fetch failed"),
185+"fetch failed",
173186);
174187});
175188@@ -190,19 +203,21 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
190203expectExitCodeFromUnhandled(sqliteErr, []);
191204}
192205193-expect(consoleWarnSpy).toHaveBeenCalledWith(
206+expectConsoleLogWithMessage(
207+consoleWarnSpy,
194208"[openclaw] Non-fatal unhandled rejection (continuing):",
195-expect.stringContaining("unable to open database file"),
209+"unable to open database file",
196210);
197211});
198212199213it("exits on generic errors without code", () => {
200214const genericErr = new Error("Something went wrong");
201215202216expectExitCodeFromUnhandled(genericErr, [1], "unhandled rejection");
203-expect(consoleErrorSpy).toHaveBeenCalledWith(
217+expectConsoleLogWithMessage(
218+consoleErrorSpy,
204219"[openclaw] Unhandled promise rejection:",
205-expect.stringContaining("Something went wrong"),
220+"Something went wrong",
206221);
207222});
208223@@ -222,9 +237,10 @@ describe("installUnhandledRejectionHandler - fatal detection", () => {
222237abortErr.name = "AbortError";
223238224239expectExitCodeFromUnhandled(abortErr, []);
225-expect(consoleWarnSpy).toHaveBeenCalledWith(
240+expectConsoleLogWithMessage(
241+consoleWarnSpy,
226242"[openclaw] Suppressed AbortError:",
227-expect.stringContaining("This operation was aborted"),
243+"This operation was aborted",
228244);
229245});
230246});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。