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

推荐订阅源

博客园 - 司徒正美
T
The Blog of Author Tim Ferriss
F
Fortinet All Blogs
Martin Fowler
Martin Fowler
罗磊的独立博客
The GitHub Blog
The GitHub Blog
L
LangChain Blog
A
About on SuperTechFans
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
DataBreaches.Net
宝玉的分享
宝玉的分享
U
Unit 42
阮一峰的网络日志
阮一峰的网络日志
Last Week in AI
Last Week in AI
N
Netflix TechBlog - Medium
The Cloudflare Blog
Microsoft Azure Blog
Microsoft Azure Blog
H
Help Net Security
美团技术团队
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
爱范儿
爱范儿
酷 壳 – CoolShell
酷 壳 – CoolShell
MongoDB | Blog
MongoDB | Blog

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(discord): record gateway transport activity · opencla...
steipete · 2026-04-25 · via Recent Commits to openclaw:main

@@ -1,4 +1,6 @@

1+

import { EventEmitter } from "node:events";

12

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

3+

import { DISCORD_GATEWAY_TRANSPORT_ACTIVITY_EVENT } from "./gateway-handle.js";

2435

const { baseConnectSpy, GatewayIntents, GatewayPlugin } = vi.hoisted(() => {

46

const baseConnectSpy = vi.fn<(resume: boolean) => void>();

@@ -14,12 +16,30 @@ const { baseConnectSpy, GatewayIntents, GatewayPlugin } = vi.hoisted(() => {

1416

GuildMembers: 1 << 7,

1517

} as const;

161819+

class TestEmitter {

20+

private readonly listenersByEvent = new Map<string, Array<(value: unknown) => void>>();

21+22+

on(event: string, listener: (value: unknown) => void) {

23+

const listeners = this.listenersByEvent.get(event) ?? [];

24+

listeners.push(listener);

25+

this.listenersByEvent.set(event, listeners);

26+

}

27+28+

emit(event: string, value: unknown) {

29+

for (const listener of this.listenersByEvent.get(event) ?? []) {

30+

listener(value);

31+

}

32+

}

33+

}

34+1735

class GatewayPlugin {

1836

options: unknown;

1937

gatewayInfo: unknown;

38+

emitter = new TestEmitter();

2039

heartbeatInterval: ReturnType<typeof setInterval> | undefined = undefined;

2140

firstHeartbeatTimeout: ReturnType<typeof setTimeout> | undefined = undefined;

2241

isConnecting: boolean = false;

42+

ws?: unknown;

23432444

constructor(options?: unknown) {

2545

this.options = options;

@@ -64,14 +84,17 @@ describe("SafeGatewayPlugin.connect()", () => {

6484

baseConnectSpy.mockClear();

6585

});

668667-

function createPlugin() {

87+

function createPlugin(

88+

testing?: NonNullable<Parameters<typeof createDiscordGatewayPlugin>[0]["__testing"]>,

89+

) {

6890

return createDiscordGatewayPlugin({

6991

discordConfig: {},

7092

runtime: {

7193

log: vi.fn(),

7294

error: vi.fn(),

7395

exit: vi.fn(),

7496

},

97+

...(testing ? { __testing: testing } : {}),

7598

});

7699

}

77100

@@ -112,4 +135,58 @@ describe("SafeGatewayPlugin.connect()", () => {

112135

clearTimeout(staleTimeout);

113136

}

114137

});

138+139+

it("emits transport activity for current gateway socket messages", () => {

140+

const socket = new EventEmitter() as EventEmitter & { binaryType?: string };

141+

const plugin = createPlugin({

142+

webSocketCtor: function WebSocketCtor() {

143+

return socket;

144+

} as unknown as NonNullable<

145+

Parameters<typeof createDiscordGatewayPlugin>[0]["__testing"]

146+

>["webSocketCtor"],

147+

});

148+

const activitySpy = vi.fn();

149+

(

150+

plugin as unknown as {

151+

emitter: { on: (event: string, listener: (value: unknown) => void) => void };

152+

}

153+

).emitter.on(DISCORD_GATEWAY_TRANSPORT_ACTIVITY_EVENT, activitySpy);

154+155+

const createdSocket = (

156+

plugin as unknown as { createWebSocket: (url: string) => typeof socket }

157+

).createWebSocket("wss://gateway.discord.gg");

158+

(plugin as unknown as { ws: unknown }).ws = createdSocket;

159+160+

createdSocket.emit("message", Buffer.from("{}"));

161+162+

expect(activitySpy).toHaveBeenCalledWith({ at: expect.any(Number) });

163+

});

164+165+

it("ignores messages from stale gateway sockets", () => {

166+

const staleSocket = new EventEmitter() as EventEmitter & { binaryType?: string };

167+

const currentSocket = new EventEmitter();

168+

const plugin = createPlugin({

169+

webSocketCtor: function WebSocketCtor() {

170+

return staleSocket;

171+

} as unknown as NonNullable<

172+

Parameters<typeof createDiscordGatewayPlugin>[0]["__testing"]

173+

>["webSocketCtor"],

174+

});

175+

const activitySpy = vi.fn();

176+

(

177+

plugin as unknown as {

178+

emitter: { on: (event: string, listener: (value: unknown) => void) => void };

179+

}

180+

).emitter.on(DISCORD_GATEWAY_TRANSPORT_ACTIVITY_EVENT, activitySpy);

181+182+

const createdSocket = (

183+

plugin as unknown as { createWebSocket: (url: string) => typeof staleSocket }

184+

).createWebSocket("wss://gateway.discord.gg");

185+

expect(createdSocket).toBe(staleSocket);

186+

(plugin as unknown as { ws: unknown }).ws = currentSocket;

187+188+

staleSocket.emit("message", Buffer.from("{}"));

189+190+

expect(activitySpy).not.toHaveBeenCalled();

191+

});

115192

});