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

推荐订阅源

Martin Fowler
Martin Fowler
J
Java Code Geeks
博客园 - 【当耐特】
宝玉的分享
宝玉的分享
腾讯CDC
D
DataBreaches.Net
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
V
V2EX
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
Jina AI
Jina AI
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
U
Unit 42
B
Blog
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium

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(clickclack): skip malformed websocket frames · opencl...
vincentkoc · 2026-05-14 · via Recent Commits to openclaw:main

@@ -0,0 +1,142 @@

1+

import { EventEmitter } from "node:events";

2+

import type { ChannelGatewayContext } from "openclaw/plugin-sdk/channel-contract";

3+

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

4+

import type { ResolvedClickClackAccount } from "./types.js";

5+6+

class FakeSocket extends EventEmitter {

7+

close = vi.fn(() => {

8+

this.emit("close");

9+

});

10+

}

11+12+

const mocks = vi.hoisted(() => ({

13+

client: {

14+

me: vi.fn(),

15+

events: vi.fn(),

16+

websocket: vi.fn(),

17+

channelMessages: vi.fn(),

18+

directMessages: vi.fn(),

19+

thread: vi.fn(),

20+

},

21+

handleClickClackInbound: vi.fn(),

22+

resolveWorkspaceId: vi.fn(),

23+

}));

24+25+

vi.mock("./http-client.js", () => ({

26+

createClickClackClient: vi.fn(() => mocks.client),

27+

}));

28+29+

vi.mock("./inbound.js", () => ({

30+

handleClickClackInbound: mocks.handleClickClackInbound,

31+

}));

32+33+

vi.mock("./resolve.js", () => ({

34+

resolveWorkspaceId: mocks.resolveWorkspaceId,

35+

}));

36+37+

import { startClickClackGatewayAccount } from "./gateway.js";

38+39+

function createGatewayContext(

40+

abortSignal: AbortSignal,

41+

): ChannelGatewayContext<ResolvedClickClackAccount> {

42+

const setStatus = vi.fn();

43+

const log = { warn: vi.fn(), info: vi.fn(), error: vi.fn(), debug: vi.fn() };

44+

return {

45+

cfg: {

46+

channels: {

47+

clickclack: {

48+

baseUrl: "https://clickclack.example",

49+

token: "test-token",

50+

workspace: "main",

51+

reconnectMs: 1,

52+

},

53+

},

54+

} as ChannelGatewayContext<ResolvedClickClackAccount>["cfg"],

55+

accountId: "default",

56+

account: {} as ResolvedClickClackAccount,

57+

runtime: {} as ChannelGatewayContext<ResolvedClickClackAccount>["runtime"],

58+

abortSignal,

59+

log,

60+

getStatus: () =>

61+

({ accountId: "default" }) as ReturnType<

62+

ChannelGatewayContext<ResolvedClickClackAccount>["getStatus"]

63+

>,

64+

setStatus,

65+

};

66+

}

67+68+

describe("ClickClack gateway", () => {

69+

beforeEach(() => {

70+

vi.clearAllMocks();

71+

mocks.client.me.mockResolvedValue({

72+

id: "bot-user",

73+

display_name: "Bot",

74+

handle: "bot",

75+

avatar_url: "",

76+

created_at: "2026-01-01T00:00:00.000Z",

77+

});

78+

mocks.client.events.mockResolvedValue([]);

79+

mocks.resolveWorkspaceId.mockResolvedValue("workspace-1");

80+

mocks.client.channelMessages.mockResolvedValue([

81+

{

82+

id: "msg-1",

83+

workspace_id: "workspace-1",

84+

channel_id: "chan-1",

85+

author_id: "human-1",

86+

thread_root_id: "msg-1",

87+

body: "hello",

88+

body_format: "markdown",

89+

created_at: "2026-01-01T00:00:00.000Z",

90+

author: {

91+

id: "human-1",

92+

kind: "human",

93+

display_name: "Human",

94+

handle: "human",

95+

avatar_url: "",

96+

created_at: "2026-01-01T00:00:00.000Z",

97+

},

98+

},

99+

]);

100+

});

101+102+

it("skips malformed websocket frames without stopping the monitor", async () => {

103+

const socket = new FakeSocket();

104+

mocks.client.websocket.mockReturnValue(socket);

105+

const abort = new AbortController();

106+

const ctx = createGatewayContext(abort.signal);

107+

let runError: unknown;

108+

const run = startClickClackGatewayAccount(ctx).catch((error: unknown) => {

109+

runError = error;

110+

});

111+112+

await vi.waitFor(() => expect(mocks.client.websocket).toHaveBeenCalledTimes(1));

113+114+

socket.emit("message", Buffer.from("{not json"));

115+

await new Promise((resolve) => setImmediate(resolve));

116+

expect(runError).toBeUndefined();

117+

expect(ctx.log?.warn).toHaveBeenCalledWith(

118+

"[default] skipped malformed ClickClack websocket event",

119+

);

120+121+

socket.emit(

122+

"message",

123+

Buffer.from(

124+

JSON.stringify({

125+

id: "evt-1",

126+

cursor: "cursor-1",

127+

type: "message.created",

128+

workspace_id: "workspace-1",

129+

channel_id: "chan-1",

130+

seq: 2,

131+

created_at: "2026-01-01T00:00:00.000Z",

132+

payload: { message_id: "msg-1", author_id: "human-1" },

133+

}),

134+

),

135+

);

136+137+

await vi.waitFor(() => expect(mocks.handleClickClackInbound).toHaveBeenCalledTimes(1));

138+

abort.abort();

139+

await run;

140+

expect(runError).toBeUndefined();

141+

});

142+

});