Tests: preserve plugin tool exports in mocks

This commit is contained in:
Vincent Koc
2026-03-15 10:44:25 -07:00
parent 3e2ad3f22d
commit e8a7cea1d9
8 changed files with 57 additions and 28 deletions

View File

@@ -7,9 +7,13 @@ const { resolvePluginToolsMock } = vi.hoisted(() => ({
}),
}));
vi.mock("../plugins/tools.js", () => ({
resolvePluginTools: resolvePluginToolsMock,
}));
vi.mock("../plugins/tools.js", async (importOriginal) => {
const mod = await importOriginal<typeof import("../plugins/tools.js")>();
return {
...mod,
resolvePluginTools: resolvePluginToolsMock,
};
});
import { createOpenClawTools } from "./openclaw-tools.js";

View File

@@ -8,9 +8,13 @@ import {
import { withFetchPreconnect } from "../test-utils/fetch-mock.js";
import { createOpenClawTools } from "./openclaw-tools.js";
vi.mock("../plugins/tools.js", () => ({
resolvePluginTools: () => [],
}));
vi.mock("../plugins/tools.js", async (importOriginal) => {
const mod = await importOriginal<typeof import("../plugins/tools.js")>();
return {
...mod,
resolvePluginTools: () => [],
};
});
function asConfig(value: unknown): OpenClawConfig {
return value as OpenClawConfig;

View File

@@ -29,10 +29,14 @@ vi.mock("../infra/shell-env.js", async (importOriginal) => {
};
});
vi.mock("../plugins/tools.js", () => ({
resolvePluginTools: () => [],
getPluginToolMeta: () => undefined,
}));
vi.mock("../plugins/tools.js", async (importOriginal) => {
const mod = await importOriginal<typeof import("../plugins/tools.js")>();
return {
...mod,
resolvePluginTools: () => [],
getPluginToolMeta: () => undefined,
};
});
vi.mock("../infra/exec-approvals.js", async (importOriginal) => {
const mod = await importOriginal<typeof import("../infra/exec-approvals.js")>();

View File

@@ -24,7 +24,11 @@ vi.mock("../tools/web-tools.js", () => ({
createWebFetchTool: () => null,
}));
vi.mock("../../plugins/tools.js", () => ({
resolvePluginTools: () => [],
getPluginToolMeta: () => undefined,
}));
vi.mock("../../plugins/tools.js", async (importOriginal) => {
const mod = await importOriginal<typeof import("../../plugins/tools.js")>();
return {
...mod,
resolvePluginTools: () => [],
getPluginToolMeta: () => undefined,
};
});

View File

@@ -7,6 +7,7 @@ import * as cliRunnerModule from "../agents/cli-runner.js";
import { FailoverError } from "../agents/failover-error.js";
import { loadModelCatalog } from "../agents/model-catalog.js";
import * as modelSelectionModule from "../agents/model-selection.js";
import type { ClientToolDefinition } from "../agents/pi-embedded-runner/run/params.js";
import { runEmbeddedPiAgent } from "../agents/pi-embedded.js";
import * as commandSecretGatewayModule from "../cli/command-secret-gateway.js";
import type { OpenClawConfig } from "../config/config.js";
@@ -420,7 +421,7 @@ describe("agentCommand", () => {
const store = path.join(home, "sessions.json");
mockConfig(home, store);
const onPreflightPassed = vi.fn();
const clientTools = [
const clientTools: ClientToolDefinition[] = [
{
type: "function",
function: {

View File

@@ -15,13 +15,17 @@ vi.mock("../../agents/agent-scope.js", () => ({
const pluginToolMetaState = new Map<string, { pluginId: string; optional: boolean }>();
vi.mock("../../plugins/tools.js", () => ({
resolvePluginTools: vi.fn(() => [
{ name: "voice_call", label: "voice_call", description: "Plugin calling tool" },
{ name: "matrix_room", label: "matrix_room", description: "Matrix room helper" },
]),
getPluginToolMeta: vi.fn((tool: { name: string }) => pluginToolMetaState.get(tool.name)),
}));
vi.mock("../../plugins/tools.js", async (importOriginal) => {
const mod = await importOriginal<typeof import("../../plugins/tools.js")>();
return {
...mod,
resolvePluginTools: vi.fn(() => [
{ name: "voice_call", label: "voice_call", description: "Plugin calling tool" },
{ name: "matrix_room", label: "matrix_room", description: "Matrix room helper" },
]),
getPluginToolMeta: vi.fn((tool: { name: string }) => pluginToolMetaState.get(tool.name)),
};
});
type RespondCall = [boolean, unknown?, { code: number; message: string }?];

View File

@@ -30,9 +30,13 @@ vi.mock("../plugins/config-state.js", () => ({
isTestDefaultMemorySlotDisabled: disableDefaultMemorySlot,
}));
vi.mock("../plugins/tools.js", () => ({
getPluginToolMeta: noPluginToolMeta,
}));
vi.mock("../plugins/tools.js", async (importOriginal) => {
const mod = await importOriginal<typeof import("../plugins/tools.js")>();
return {
...mod,
getPluginToolMeta: noPluginToolMeta,
};
});
vi.mock("../agents/openclaw-tools.js", () => {
const tools = [

View File

@@ -61,9 +61,13 @@ vi.mock("../plugins/config-state.js", () => ({
isTestDefaultMemorySlotDisabled: () => false,
}));
vi.mock("../plugins/tools.js", () => ({
getPluginToolMeta: () => undefined,
}));
vi.mock("../plugins/tools.js", async (importOriginal) => {
const mod = await importOriginal<typeof import("../plugins/tools.js")>();
return {
...mod,
getPluginToolMeta: () => undefined,
};
});
// Perf: the real tool factory instantiates many tools per request; for these HTTP
// routing/policy tests we only need a small set of tool names.