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

推荐订阅源

雷峰网
雷峰网
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
宝玉的分享
宝玉的分享
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
T
Tailwind CSS Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
博客园_首页
博客园 - 三生石上(FineUI控件)
博客园 - 叶小钗
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
量子位
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
美团技术团队
小众软件
小众软件
Jina AI
Jina AI
S
SegmentFault 最新的问题
博客园 - Franky
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

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): supervise gateway registration failures · o...
steipete · 2026-04-25 · via Recent Commits to openclaw:main

@@ -1,8 +1,9 @@

11

import type { Client, Plugin } from "@buape/carbon";

2-

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

2+

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

334-

const { registerVoiceClientSpy } = vi.hoisted(() => ({

4+

const { registerVoiceClientSpy, waitForDiscordGatewayPluginRegistrationMock } = vi.hoisted(() => ({

55

registerVoiceClientSpy: vi.fn(),

6+

waitForDiscordGatewayPluginRegistrationMock: vi.fn(),

67

}));

7889

vi.mock("@buape/carbon/voice", () => ({

@@ -51,6 +52,7 @@ vi.mock("./auto-presence.js", () => ({

51525253

vi.mock("./gateway-plugin.js", () => ({

5354

createDiscordGatewayPlugin: vi.fn(),

55+

waitForDiscordGatewayPluginRegistration: waitForDiscordGatewayPluginRegistrationMock,

5456

}));

55575658

vi.mock("./gateway-supervisor.js", () => ({

@@ -73,16 +75,50 @@ vi.mock("./presence.js", () => ({

7375

import { createDiscordMonitorClient } from "./provider.startup.js";

74767577

describe("createDiscordMonitorClient", () => {

76-

it("adds listener compat for legacy voice plugins", () => {

78+

beforeEach(() => {

7779

registerVoiceClientSpy.mockReset();

80+

waitForDiscordGatewayPluginRegistrationMock.mockReset().mockReturnValue(undefined);

81+

});

788283+

function createRuntime() {

84+

return {

85+

log: vi.fn(),

86+

error: vi.fn(),

87+

exit: vi.fn(),

88+

};

89+

}

90+91+

function createClientWithPlugins(

92+

_options: ConstructorParameters<typeof import("@buape/carbon").Client>[0],

93+

handlers: ConstructorParameters<typeof import("@buape/carbon").Client>[1],

94+

plugins: Plugin[] = [],

95+

) {

96+

const pluginRegistry = plugins.map((plugin) => ({ id: plugin.id, plugin }));

97+

return {

98+

listeners: [...(handlers.listeners ?? [])],

99+

plugins: pluginRegistry,

100+

getPlugin: (id: string) => pluginRegistry.find((entry) => entry.id === id)?.plugin,

101+

} as Client;

102+

}

103+104+

function createAutoPresenceController() {

105+

return {

106+

enabled: false,

107+

start: vi.fn(),

108+

stop: vi.fn(),

109+

refresh: vi.fn(),

110+

runNow: vi.fn(),

111+

};

112+

}

113+114+

it("adds listener compat for legacy voice plugins", async () => {

79115

const gatewayPlugin = {

80116

id: "gateway",

81117

registerClient: vi.fn(),

82118

registerRoutes: vi.fn(),

83119

} as Plugin;

8412085-

const result = createDiscordMonitorClient({

121+

const result = await createDiscordMonitorClient({

86122

accountId: "default",

87123

applicationId: "app-1",

88124

token: "token-1",

@@ -91,29 +127,11 @@ describe("createDiscordMonitorClient", () => {

91127

modals: [],

92128

voiceEnabled: true,

93129

discordConfig: {},

94-

runtime: {

95-

log: vi.fn(),

96-

error: vi.fn(),

97-

exit: vi.fn(),

98-

},

99-

createClient: (_options, handlers, plugins = []) => {

100-

const pluginRegistry = plugins.map((plugin) => ({ id: plugin.id, plugin }));

101-

return {

102-

listeners: [...(handlers.listeners ?? [])],

103-

plugins: pluginRegistry,

104-

getPlugin: (id: string) => pluginRegistry.find((entry) => entry.id === id)?.plugin,

105-

} as Client;

106-

},

130+

runtime: createRuntime(),

131+

createClient: createClientWithPlugins,

107132

createGatewayPlugin: () => gatewayPlugin as never,

108133

createGatewaySupervisor: () => ({ shutdown: vi.fn(), handleError: vi.fn() }) as never,

109-

createAutoPresenceController: () =>

110-

({

111-

enabled: false,

112-

start: vi.fn(),

113-

stop: vi.fn(),

114-

refresh: vi.fn(),

115-

runNow: vi.fn(),

116-

}) as never,

134+

createAutoPresenceController: () => createAutoPresenceController() as never,

117135

isDisallowedIntentsError: () => false,

118136

});

119137

@@ -122,4 +140,73 @@ describe("createDiscordMonitorClient", () => {

122140

expect.arrayContaining([expect.objectContaining({ type: "legacy-voice-listener" })]),

123141

);

124142

});

143+144+

it("waits for gateway registration before creating the supervisor", async () => {

145+

const gatewayPlugin = { id: "gateway" } as Plugin;

146+

let resolveRegistration: (() => void) | undefined;

147+

const registration = new Promise<void>((resolve) => {

148+

resolveRegistration = resolve;

149+

});

150+

waitForDiscordGatewayPluginRegistrationMock.mockReturnValue(registration);

151+

const gatewaySupervisor = { shutdown: vi.fn(), handleError: vi.fn() };

152+

const createGatewaySupervisor = vi.fn(() => gatewaySupervisor);

153+154+

const resultPromise = createDiscordMonitorClient({

155+

accountId: "default",

156+

applicationId: "app-1",

157+

token: "token-1",

158+

commands: [],

159+

components: [],

160+

modals: [],

161+

voiceEnabled: false,

162+

discordConfig: {},

163+

runtime: createRuntime(),

164+

createClient: createClientWithPlugins,

165+

createGatewayPlugin: () => gatewayPlugin as never,

166+

createGatewaySupervisor: createGatewaySupervisor as never,

167+

createAutoPresenceController: () => createAutoPresenceController() as never,

168+

isDisallowedIntentsError: () => false,

169+

});

170+

await Promise.resolve();

171+172+

expect(waitForDiscordGatewayPluginRegistrationMock).toHaveBeenCalledWith(gatewayPlugin);

173+

expect(createGatewaySupervisor).not.toHaveBeenCalled();

174+175+

resolveRegistration?.();

176+

const result = await resultPromise;

177+178+

expect(createGatewaySupervisor).toHaveBeenCalledTimes(1);

179+

expect(result.gatewaySupervisor).toBe(gatewaySupervisor);

180+

});

181+182+

it("propagates gateway registration failures before supervisor startup", async () => {

183+

const gatewayPlugin = { id: "gateway" } as Plugin;

184+

const createGatewaySupervisor = vi.fn();

185+

const createAutoPresenceControllerForTest = vi.fn(createAutoPresenceController);

186+

waitForDiscordGatewayPluginRegistrationMock.mockReturnValue(

187+

Promise.reject(new Error("gateway metadata denied")),

188+

);

189+190+

await expect(

191+

createDiscordMonitorClient({

192+

accountId: "default",

193+

applicationId: "app-1",

194+

token: "token-1",

195+

commands: [],

196+

components: [],

197+

modals: [],

198+

voiceEnabled: false,

199+

discordConfig: {},

200+

runtime: createRuntime(),

201+

createClient: createClientWithPlugins,

202+

createGatewayPlugin: () => gatewayPlugin as never,

203+

createGatewaySupervisor: createGatewaySupervisor as never,

204+

createAutoPresenceController: createAutoPresenceControllerForTest as never,

205+

isDisallowedIntentsError: () => false,

206+

}),

207+

).rejects.toThrow("gateway metadata denied");

208+209+

expect(createGatewaySupervisor).not.toHaveBeenCalled();

210+

expect(createAutoPresenceControllerForTest).not.toHaveBeenCalled();

211+

});

125212

});