diff --git a/extensions/discord/src/monitor/gateway-plugin.test.ts b/extensions/discord/src/monitor/gateway-plugin.test.ts index ad4bac437e4..b0946278703 100644 --- a/extensions/discord/src/monitor/gateway-plugin.test.ts +++ b/extensions/discord/src/monitor/gateway-plugin.test.ts @@ -136,9 +136,10 @@ describe("SafeGatewayPlugin.connect()", () => { function createPlugin( testing?: NonNullable[0]["__testing"]>, + discordConfig: Parameters[0]["discordConfig"] = {}, ) { return createDiscordGatewayPlugin({ - discordConfig: {}, + discordConfig, runtime: { log: vi.fn(), error: vi.fn(), @@ -148,6 +149,56 @@ describe("SafeGatewayPlugin.connect()", () => { }); } + it("includes GuildVoiceStates when voice is enabled by default", () => { + expect(resolveDiscordGatewayIntents() & GatewayIntents.GuildVoiceStates).toBe( + GatewayIntents.GuildVoiceStates, + ); + }); + + it("omits GuildVoiceStates when voice is disabled", () => { + const intents = resolveDiscordGatewayIntents({ voiceEnabled: false }); + + expect(intents & GatewayIntents.GuildVoiceStates).toBe(0); + }); + + it("lets intents.voiceStates override voice enablement", () => { + const enabled = resolveDiscordGatewayIntents({ + intentsConfig: { voiceStates: true }, + voiceEnabled: false, + }); + const disabled = resolveDiscordGatewayIntents({ + intentsConfig: { voiceStates: false }, + voiceEnabled: true, + }); + + expect(enabled & GatewayIntents.GuildVoiceStates).toBe(GatewayIntents.GuildVoiceStates); + expect(disabled & GatewayIntents.GuildVoiceStates).toBe(0); + }); + + it("keeps the legacy intents-config argument shape working", () => { + const intents = resolveDiscordGatewayIntents({ presence: true, guildMembers: true }); + + expect(intents & GatewayIntents.GuildPresences).toBe(GatewayIntents.GuildPresences); + expect(intents & GatewayIntents.GuildMembers).toBe(GatewayIntents.GuildMembers); + }); + + it("resolves gateway metadata timeout from config, env, then default", () => { + expect(resolveDiscordGatewayInfoTimeoutMs({ configuredTimeoutMs: 45_000 })).toBe(45_000); + expect( + resolveDiscordGatewayInfoTimeoutMs({ + env: { OPENCLAW_DISCORD_GATEWAY_INFO_TIMEOUT_MS: "25000" }, + }), + ).toBe(25_000); + expect(resolveDiscordGatewayInfoTimeoutMs({ env: {} })).toBe(30_000); + }); + + it("omits voice states when Discord voice is disabled in account config", () => { + const plugin = createPlugin(undefined, { voice: { enabled: false } }); + const options = (plugin as unknown as { options?: { intents?: number } }).options; + + expect((options?.intents ?? 0) & GatewayIntents.GuildVoiceStates).toBe(0); + }); + it("clears stale heartbeatInterval before delegating to super when isConnecting=true", () => { const plugin = createPlugin();