From f956d0993cc9a3bec1ab1a6878fe373cf8f4f0cc Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 6 May 2026 07:56:29 +0100 Subject: [PATCH] test: avoid discord native command cold load --- .../native-command.think-autocomplete.test.ts | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/extensions/discord/src/monitor/native-command.think-autocomplete.test.ts b/extensions/discord/src/monitor/native-command.think-autocomplete.test.ts index 9ff2d784fdf..5b13be497b5 100644 --- a/extensions/discord/src/monitor/native-command.think-autocomplete.test.ts +++ b/extensions/discord/src/monitor/native-command.think-autocomplete.test.ts @@ -127,7 +127,7 @@ const STORE_PATH = path.join( const SESSION_KEY = "agent:main:main"; let findCommandByNativeName: typeof import("openclaw/plugin-sdk/command-auth").findCommandByNativeName; let resolveCommandArgChoices: typeof import("openclaw/plugin-sdk/command-auth").resolveCommandArgChoices; -let resolveDiscordNativeChoiceContext: typeof import("./native-command-ui.js").resolveDiscordNativeChoiceContext; +let resolveDiscordNativeChoiceContext: typeof import("./native-command-model-picker-ui.js").resolveDiscordNativeChoiceContext; function installProviderThinkingRegistryForTest(): void { const registry = createEmptyPluginRegistry(); @@ -165,10 +165,9 @@ function installProviderThinkingRegistryForTest(): void { } async function loadDiscordThinkAutocompleteModulesForTest() { - vi.resetModules(); installProviderThinkingRegistryForTest(); const commandAuth = await import("openclaw/plugin-sdk/command-auth"); - const nativeCommandUi = await import("./native-command-ui.js"); + const nativeCommandUi = await import("./native-command-model-picker-ui.js"); return { findCommandByNativeName: commandAuth.findCommandByNativeName, resolveCommandArgChoices: commandAuth.resolveCommandArgChoices, @@ -265,12 +264,14 @@ describe("discord native /think autocomplete", () => { channel: { id: "D1", type: ChannelType.DM }, user: { id: "U1" }, guild: undefined, - client: {}, + client: { fetchChannel: async () => ({ id: "D1", type: ChannelType.DM }) }, } as unknown as AutocompleteInteraction & { respond: (choices: Array<{ name: string; value: string }>) => Promise; }; - const command = findCommandByNativeName("think", "discord"); + const command = findCommandByNativeName("think", "discord", { + includeBundledChannelFallback: false, + }); expect(command).toBeTruthy(); const levelArg = command?.args?.find((entry) => entry.name === "level"); expect(levelArg).toBeTruthy(); @@ -295,6 +296,7 @@ describe("discord native /think autocomplete", () => { cfg, provider: context?.provider, model: context?.model, + catalog: [], }); const values = choices.map((choice) => choice.value); expect(values).toContain("xhigh"); @@ -333,7 +335,7 @@ describe("discord native /think autocomplete", () => { channel: { id: "C1", type: ChannelType.GuildText }, user: { id: "U1" }, guild: { id: "G1" }, - client: {}, + client: { fetchChannel: async () => ({ id: "C1", type: ChannelType.GuildText }) }, } as unknown as AutocompleteInteraction & { respond: (choices: Array<{ name: string; value: string }>) => Promise; }; @@ -344,7 +346,9 @@ describe("discord native /think autocomplete", () => { accountId: "default", threadBindings: createNoopThreadBindingManager("default"), }); - const command = findCommandByNativeName("think", "discord"); + const command = findCommandByNativeName("think", "discord", { + includeBundledChannelFallback: false, + }); const levelArg = command?.args?.find((entry) => entry.name === "level"); expect(command).toBeTruthy(); expect(levelArg).toBeTruthy(); @@ -358,6 +362,7 @@ describe("discord native /think autocomplete", () => { cfg, provider: context?.provider, model: context?.model, + catalog: [], }); const values = choices.map((choice) => choice.value); expect(values).toContain("max"); @@ -381,7 +386,7 @@ describe("discord native /think autocomplete", () => { channel: { id: "C1", type: ChannelType.GuildText }, user: { id: "U1" }, guild: { id: "G1" }, - client: {}, + client: { fetchChannel: async () => ({ id: "C1", type: ChannelType.GuildText }) }, } as unknown as AutocompleteInteraction & { respond: (choices: Array<{ name: string; value: string }>) => Promise; }; @@ -396,7 +401,9 @@ describe("discord native /think autocomplete", () => { expect(context).toBeNull(); expect(ensureConfiguredBindingRouteReadyMock).toHaveBeenCalledTimes(1); - const command = findCommandByNativeName("think", "discord"); + const command = findCommandByNativeName("think", "discord", { + includeBundledChannelFallback: false, + }); const levelArg = command?.args?.find((entry) => entry.name === "level"); expect(command).toBeTruthy(); expect(levelArg).toBeTruthy(); @@ -409,6 +416,7 @@ describe("discord native /think autocomplete", () => { cfg, provider: context?.provider, model: context?.model, + catalog: [], }); const values = choices.map((choice) => choice.value); expect(values).not.toContain("xhigh");