惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
D
Docker
J
Java Code Geeks
腾讯CDC
Blog — PlanetScale
Blog — PlanetScale
G
Google Developers Blog
M
MIT News - Artificial intelligence
L
LangChain Blog
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
博客园 - Franky
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
aimingoo的专栏
aimingoo的专栏
Last Week in AI
Last Week in AI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
N
Netflix TechBlog - Medium
B
Blog RSS Feed
Y
Y Combinator Blog
阮一峰的网络日志
阮一峰的网络日志
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(whatsapp): route login qr through runtime · openclaw/...
steipete · 2026-05-04 · via Recent Commits to openclaw:main

@@ -1,7 +1,9 @@

11

import { rmSync } from "node:fs";

22

import fs from "node:fs/promises";

3+

import type { RuntimeEnv } from "openclaw/plugin-sdk/runtime-env";

34

import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";

45

import { loginWeb } from "./login.js";

6+

import { renderQrTerminal } from "./qr-terminal.js";

57

import { createWaSocket, formatError, waitForWaConnection } from "./session.js";

6879

const rmMock = vi.spyOn(fs, "rm");

@@ -63,9 +65,14 @@ vi.mock("./session.js", async () => {

6365

};

6466

});

656768+

vi.mock("./qr-terminal.js", () => ({

69+

renderQrTerminal: vi.fn(async (qr: string) => `terminal:${qr}\n`),

70+

}));

71+6672

const createWaSocketMock = vi.mocked(createWaSocket);

6773

const waitForWaConnectionMock = vi.mocked(waitForWaConnection);

6874

const formatErrorMock = vi.mocked(formatError);

75+

const renderQrTerminalMock = vi.mocked(renderQrTerminal);

69767077

async function flushTasks() {

7178

await Promise.resolve();

@@ -94,7 +101,7 @@ describe("loginWeb coverage", () => {

94101

.mockRejectedValueOnce({ error: { output: { statusCode: 515 } } })

95102

.mockResolvedValueOnce(undefined);

9610397-

const runtime = { log: vi.fn(), error: vi.fn() } as never;

104+

const runtime: RuntimeEnv = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };

98105

const pendingLogin = loginWeb(false, waitForWaConnectionMock as never, runtime);

99106

await flushTasks();

100107

@@ -109,6 +116,35 @@ describe("loginWeb coverage", () => {

109116

expect(secondSock.ws.close).toHaveBeenCalled();

110117

});

111118119+

it("routes QR output through runtime for initial and restart sockets", async () => {

120+

waitForWaConnectionMock

121+

.mockRejectedValueOnce({ error: { output: { statusCode: 515 } } })

122+

.mockResolvedValueOnce(undefined);

123+124+

const runtime: RuntimeEnv = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };

125+

await loginWeb(false, waitForWaConnectionMock as never, runtime);

126+127+

expect(createWaSocketMock).toHaveBeenCalledTimes(2);

128+

expect(createWaSocketMock.mock.calls[0]?.[0]).toBe(false);

129+

const initialOpts = createWaSocketMock.mock.calls[0]?.[2] as

130+

| { onQr?: (qr: string) => void }

131+

| undefined;

132+

const restartOpts = createWaSocketMock.mock.calls[1]?.[2] as

133+

| { onQr?: (qr: string) => void }

134+

| undefined;

135+

expect(initialOpts?.onQr).toBe(restartOpts?.onQr);

136+137+

initialOpts?.onQr?.("initial-qr");

138+

restartOpts?.onQr?.("restart-qr");

139+

await flushTasks();

140+141+

expect(runtime.log).toHaveBeenCalledWith("Scan this QR in WhatsApp (Linked Devices):");

142+

expect(runtime.log).toHaveBeenCalledWith("terminal:initial-qr");

143+

expect(runtime.log).toHaveBeenCalledWith("terminal:restart-qr");

144+

expect(renderQrTerminalMock).toHaveBeenCalledWith("initial-qr", { small: true });

145+

expect(renderQrTerminalMock).toHaveBeenCalledWith("restart-qr", { small: true });

146+

});

147+112148

it("clears creds and throws when logged out", async () => {

113149

waitForWaConnectionMock.mockRejectedValueOnce({

114150

output: { statusCode: 401 },