




























@@ -136,9 +136,10 @@ describe("SafeGatewayPlugin.connect()", () => {
136136137137function createPlugin(
138138testing?: NonNullable<Parameters<typeof createDiscordGatewayPlugin>[0]["__testing"]>,
139+discordConfig: Parameters<typeof createDiscordGatewayPlugin>[0]["discordConfig"] = {},
139140) {
140141return createDiscordGatewayPlugin({
141-discordConfig: {},
142+ discordConfig,
142143runtime: {
143144log: vi.fn(),
144145error: vi.fn(),
@@ -148,6 +149,56 @@ describe("SafeGatewayPlugin.connect()", () => {
148149});
149150}
150151152+it("includes GuildVoiceStates when voice is enabled by default", () => {
153+expect(resolveDiscordGatewayIntents() & GatewayIntents.GuildVoiceStates).toBe(
154+GatewayIntents.GuildVoiceStates,
155+);
156+});
157+158+it("omits GuildVoiceStates when voice is disabled", () => {
159+const intents = resolveDiscordGatewayIntents({ voiceEnabled: false });
160+161+expect(intents & GatewayIntents.GuildVoiceStates).toBe(0);
162+});
163+164+it("lets intents.voiceStates override voice enablement", () => {
165+const enabled = resolveDiscordGatewayIntents({
166+intentsConfig: { voiceStates: true },
167+voiceEnabled: false,
168+});
169+const disabled = resolveDiscordGatewayIntents({
170+intentsConfig: { voiceStates: false },
171+voiceEnabled: true,
172+});
173+174+expect(enabled & GatewayIntents.GuildVoiceStates).toBe(GatewayIntents.GuildVoiceStates);
175+expect(disabled & GatewayIntents.GuildVoiceStates).toBe(0);
176+});
177+178+it("keeps the legacy intents-config argument shape working", () => {
179+const intents = resolveDiscordGatewayIntents({ presence: true, guildMembers: true });
180+181+expect(intents & GatewayIntents.GuildPresences).toBe(GatewayIntents.GuildPresences);
182+expect(intents & GatewayIntents.GuildMembers).toBe(GatewayIntents.GuildMembers);
183+});
184+185+it("resolves gateway metadata timeout from config, env, then default", () => {
186+expect(resolveDiscordGatewayInfoTimeoutMs({ configuredTimeoutMs: 45_000 })).toBe(45_000);
187+expect(
188+resolveDiscordGatewayInfoTimeoutMs({
189+env: { OPENCLAW_DISCORD_GATEWAY_INFO_TIMEOUT_MS: "25000" },
190+}),
191+).toBe(25_000);
192+expect(resolveDiscordGatewayInfoTimeoutMs({ env: {} })).toBe(30_000);
193+});
194+195+it("omits voice states when Discord voice is disabled in account config", () => {
196+const plugin = createPlugin(undefined, { voice: { enabled: false } });
197+const options = (plugin as unknown as { options?: { intents?: number } }).options;
198+199+expect((options?.intents ?? 0) & GatewayIntents.GuildVoiceStates).toBe(0);
200+});
201+151202it("clears stale heartbeatInterval before delegating to super when isConnecting=true", () => {
152203const plugin = createPlugin();
153204此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。