test: avoid discord native command cold load

This commit is contained in:
Peter Steinberger
2026-05-06 07:56:29 +01:00
parent e37607349b
commit f956d0993c

View File

@@ -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<void>;
};
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<void>;
};
@@ -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<void>;
};
@@ -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");