mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 09:20:43 +00:00
fix(whatsapp): capture login outcome output
This commit is contained in:
@@ -111,6 +111,9 @@ describe("loginWeb coverage", () => {
|
||||
expect(createWaSocketMock).toHaveBeenCalledTimes(2);
|
||||
const firstSock = await createWaSocketMock.mock.results[0]?.value;
|
||||
expect(firstSock.ws.close).toHaveBeenCalled();
|
||||
expect(runtime.log).toHaveBeenCalledWith(
|
||||
expect.stringContaining("Linked after restart; web session ready."),
|
||||
);
|
||||
vi.runAllTimers();
|
||||
const secondSock = await createWaSocketMock.mock.results[1]?.value;
|
||||
expect(secondSock.ws.close).toHaveBeenCalled();
|
||||
@@ -150,9 +153,11 @@ describe("loginWeb coverage", () => {
|
||||
output: { statusCode: 401 },
|
||||
});
|
||||
|
||||
await expect(loginWeb(false, waitForWaConnectionMock as never)).rejects.toThrow(
|
||||
const runtime: RuntimeEnv = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
|
||||
await expect(loginWeb(false, waitForWaConnectionMock as never, runtime)).rejects.toThrow(
|
||||
/cache cleared/i,
|
||||
);
|
||||
expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("session is logged out"));
|
||||
expect(rmMock).toHaveBeenCalledWith(testState.authDir, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
@@ -161,9 +166,13 @@ describe("loginWeb coverage", () => {
|
||||
|
||||
it("formats and rethrows generic errors", async () => {
|
||||
waitForWaConnectionMock.mockRejectedValueOnce(new Error("boom"));
|
||||
await expect(loginWeb(false, waitForWaConnectionMock as never)).rejects.toThrow(
|
||||
const runtime: RuntimeEnv = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
|
||||
await expect(loginWeb(false, waitForWaConnectionMock as never, runtime)).rejects.toThrow(
|
||||
"formatted:Error: boom",
|
||||
);
|
||||
expect(runtime.error).toHaveBeenCalledWith(
|
||||
expect.stringContaining("WhatsApp Web connection ended before fully opening."),
|
||||
);
|
||||
expect(formatErrorMock).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -51,7 +51,7 @@ export async function loginWeb(
|
||||
},
|
||||
});
|
||||
if (result.outcome === "connected") {
|
||||
console.log(
|
||||
runtime.log(
|
||||
success(
|
||||
result.restarted
|
||||
? "✅ Linked after restart; web session ready."
|
||||
@@ -64,7 +64,7 @@ export async function loginWeb(
|
||||
}
|
||||
|
||||
if (result.outcome === "logged-out") {
|
||||
console.error(
|
||||
runtime.error(
|
||||
danger(
|
||||
`WhatsApp reported the session is logged out. Cleared cached web session; please rerun ${formatCliCommand("openclaw channels login")} and scan the QR again.`,
|
||||
),
|
||||
@@ -74,7 +74,7 @@ export async function loginWeb(
|
||||
});
|
||||
}
|
||||
|
||||
console.error(danger(`WhatsApp Web connection ended before fully opening. ${result.message}`));
|
||||
runtime.error(danger(`WhatsApp Web connection ended before fully opening. ${result.message}`));
|
||||
throw new Error(result.message, { cause: result.error });
|
||||
} finally {
|
||||
// Let Baileys flush any final events before closing the socket.
|
||||
|
||||
Reference in New Issue
Block a user