fix(discord): align gateway metadata timeout tests

This commit is contained in:
Peter Steinberger
2026-04-28 20:34:18 +01:00
parent 0608c1015b
commit 06a0cd88fb

View File

@@ -136,9 +136,10 @@ describe("SafeGatewayPlugin.connect()", () => {
function createPlugin(
testing?: NonNullable<Parameters<typeof createDiscordGatewayPlugin>[0]["__testing"]>,
discordConfig: Parameters<typeof createDiscordGatewayPlugin>[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();