Skip to content

Commit 071db2c

Browse files
committed
fix(whatsapp): capture login outcome output
1 parent a1304c9 commit 071db2c

3 files changed

Lines changed: 15 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Docs: https://docs.openclaw.ai
6464
- Control UI/Talk: stop and clear failed realtime Talk sessions when dismissing runtime error banners, so the next Talk click starts a fresh session instead of only stopping the stale one. Thanks @vincentkoc.
6565
- Control UI/Talk: retry from a failed realtime Talk session on the next Talk click instead of requiring a separate stale-session stop click first. Thanks @vincentkoc.
6666
- Canvas host: preserve the Gateway TLS scheme in browser canvas host URLs and startup mount logs, so direct HTTPS gateways do not advertise insecure canvas links. Thanks @vincentkoc.
67+
- WhatsApp/login: route login success and failure messages through the injected runtime, so setup/onboarding surfaces capture all login output instead of only the QR. Thanks @vincentkoc.
6768
- Google Chat: create an isolated Google auth transport per auth client, so google-auth-library interceptor mutations do not accumulate across webhook verification and access-token clients. Thanks @vincentkoc.
6869
- Doctor/plugins: remove orphaned managed npm copies of bundled `@openclaw/*` plugins during `doctor --fix`, so stale package manifests cannot shadow the current bundled plugin config schema.
6970
- Control UI/performance: cap long-task and long-animation-frame diagnostics in the shared event log, so slow-render telemetry does not evict gateway/plugin events from the Debug and Overview views. Thanks @vincentkoc.

extensions/whatsapp/src/login.coverage.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ describe("loginWeb coverage", () => {
111111
expect(createWaSocketMock).toHaveBeenCalledTimes(2);
112112
const firstSock = await createWaSocketMock.mock.results[0]?.value;
113113
expect(firstSock.ws.close).toHaveBeenCalled();
114+
expect(runtime.log).toHaveBeenCalledWith(
115+
expect.stringContaining("Linked after restart; web session ready."),
116+
);
114117
vi.runAllTimers();
115118
const secondSock = await createWaSocketMock.mock.results[1]?.value;
116119
expect(secondSock.ws.close).toHaveBeenCalled();
@@ -150,9 +153,11 @@ describe("loginWeb coverage", () => {
150153
output: { statusCode: 401 },
151154
});
152155

153-
await expect(loginWeb(false, waitForWaConnectionMock as never)).rejects.toThrow(
156+
const runtime: RuntimeEnv = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
157+
await expect(loginWeb(false, waitForWaConnectionMock as never, runtime)).rejects.toThrow(
154158
/cache cleared/i,
155159
);
160+
expect(runtime.error).toHaveBeenCalledWith(expect.stringContaining("session is logged out"));
156161
expect(rmMock).toHaveBeenCalledWith(testState.authDir, {
157162
recursive: true,
158163
force: true,
@@ -161,9 +166,13 @@ describe("loginWeb coverage", () => {
161166

162167
it("formats and rethrows generic errors", async () => {
163168
waitForWaConnectionMock.mockRejectedValueOnce(new Error("boom"));
164-
await expect(loginWeb(false, waitForWaConnectionMock as never)).rejects.toThrow(
169+
const runtime: RuntimeEnv = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
170+
await expect(loginWeb(false, waitForWaConnectionMock as never, runtime)).rejects.toThrow(
165171
"formatted:Error: boom",
166172
);
173+
expect(runtime.error).toHaveBeenCalledWith(
174+
expect.stringContaining("WhatsApp Web connection ended before fully opening."),
175+
);
167176
expect(formatErrorMock).toHaveBeenCalled();
168177
});
169178
});

extensions/whatsapp/src/login.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export async function loginWeb(
5151
},
5252
});
5353
if (result.outcome === "connected") {
54-
console.log(
54+
runtime.log(
5555
success(
5656
result.restarted
5757
? "✅ Linked after restart; web session ready."
@@ -64,7 +64,7 @@ export async function loginWeb(
6464
}
6565

6666
if (result.outcome === "logged-out") {
67-
console.error(
67+
runtime.error(
6868
danger(
6969
`WhatsApp reported the session is logged out. Cleared cached web session; please rerun ${formatCliCommand("openclaw channels login")} and scan the QR again.`,
7070
),
@@ -74,7 +74,7 @@ export async function loginWeb(
7474
});
7575
}
7676

77-
console.error(danger(`WhatsApp Web connection ended before fully opening. ${result.message}`));
77+
runtime.error(danger(`WhatsApp Web connection ended before fully opening. ${result.message}`));
7878
throw new Error(result.message, { cause: result.error });
7979
} finally {
8080
// Let Baileys flush any final events before closing the socket.

0 commit comments

Comments
 (0)