Tests: preserve plugin tool exports in mocks
This commit is contained in:
parent
3e2ad3f22d
commit
e8a7cea1d9
@ -7,9 +7,13 @@ const { resolvePluginToolsMock } = vi.hoisted(() => ({
|
|||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../plugins/tools.js", () => ({
|
vi.mock("../plugins/tools.js", async (importOriginal) => {
|
||||||
resolvePluginTools: resolvePluginToolsMock,
|
const mod = await importOriginal<typeof import("../plugins/tools.js")>();
|
||||||
}));
|
return {
|
||||||
|
...mod,
|
||||||
|
resolvePluginTools: resolvePluginToolsMock,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
import { createOpenClawTools } from "./openclaw-tools.js";
|
import { createOpenClawTools } from "./openclaw-tools.js";
|
||||||
|
|
||||||
|
|||||||
@ -8,9 +8,13 @@ import {
|
|||||||
import { withFetchPreconnect } from "../test-utils/fetch-mock.js";
|
import { withFetchPreconnect } from "../test-utils/fetch-mock.js";
|
||||||
import { createOpenClawTools } from "./openclaw-tools.js";
|
import { createOpenClawTools } from "./openclaw-tools.js";
|
||||||
|
|
||||||
vi.mock("../plugins/tools.js", () => ({
|
vi.mock("../plugins/tools.js", async (importOriginal) => {
|
||||||
resolvePluginTools: () => [],
|
const mod = await importOriginal<typeof import("../plugins/tools.js")>();
|
||||||
}));
|
return {
|
||||||
|
...mod,
|
||||||
|
resolvePluginTools: () => [],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
function asConfig(value: unknown): OpenClawConfig {
|
function asConfig(value: unknown): OpenClawConfig {
|
||||||
return value as OpenClawConfig;
|
return value as OpenClawConfig;
|
||||||
|
|||||||
@ -29,10 +29,14 @@ vi.mock("../infra/shell-env.js", async (importOriginal) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
vi.mock("../plugins/tools.js", () => ({
|
vi.mock("../plugins/tools.js", async (importOriginal) => {
|
||||||
resolvePluginTools: () => [],
|
const mod = await importOriginal<typeof import("../plugins/tools.js")>();
|
||||||
getPluginToolMeta: () => undefined,
|
return {
|
||||||
}));
|
...mod,
|
||||||
|
resolvePluginTools: () => [],
|
||||||
|
getPluginToolMeta: () => undefined,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
vi.mock("../infra/exec-approvals.js", async (importOriginal) => {
|
vi.mock("../infra/exec-approvals.js", async (importOriginal) => {
|
||||||
const mod = await importOriginal<typeof import("../infra/exec-approvals.js")>();
|
const mod = await importOriginal<typeof import("../infra/exec-approvals.js")>();
|
||||||
|
|||||||
@ -24,7 +24,11 @@ vi.mock("../tools/web-tools.js", () => ({
|
|||||||
createWebFetchTool: () => null,
|
createWebFetchTool: () => null,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../../plugins/tools.js", () => ({
|
vi.mock("../../plugins/tools.js", async (importOriginal) => {
|
||||||
resolvePluginTools: () => [],
|
const mod = await importOriginal<typeof import("../../plugins/tools.js")>();
|
||||||
getPluginToolMeta: () => undefined,
|
return {
|
||||||
}));
|
...mod,
|
||||||
|
resolvePluginTools: () => [],
|
||||||
|
getPluginToolMeta: () => undefined,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import * as cliRunnerModule from "../agents/cli-runner.js";
|
|||||||
import { FailoverError } from "../agents/failover-error.js";
|
import { FailoverError } from "../agents/failover-error.js";
|
||||||
import { loadModelCatalog } from "../agents/model-catalog.js";
|
import { loadModelCatalog } from "../agents/model-catalog.js";
|
||||||
import * as modelSelectionModule from "../agents/model-selection.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 { runEmbeddedPiAgent } from "../agents/pi-embedded.js";
|
||||||
import * as commandSecretGatewayModule from "../cli/command-secret-gateway.js";
|
import * as commandSecretGatewayModule from "../cli/command-secret-gateway.js";
|
||||||
import type { OpenClawConfig } from "../config/config.js";
|
import type { OpenClawConfig } from "../config/config.js";
|
||||||
@ -420,7 +421,7 @@ describe("agentCommand", () => {
|
|||||||
const store = path.join(home, "sessions.json");
|
const store = path.join(home, "sessions.json");
|
||||||
mockConfig(home, store);
|
mockConfig(home, store);
|
||||||
const onPreflightPassed = vi.fn();
|
const onPreflightPassed = vi.fn();
|
||||||
const clientTools = [
|
const clientTools: ClientToolDefinition[] = [
|
||||||
{
|
{
|
||||||
type: "function",
|
type: "function",
|
||||||
function: {
|
function: {
|
||||||
|
|||||||
@ -15,13 +15,17 @@ vi.mock("../../agents/agent-scope.js", () => ({
|
|||||||
|
|
||||||
const pluginToolMetaState = new Map<string, { pluginId: string; optional: boolean }>();
|
const pluginToolMetaState = new Map<string, { pluginId: string; optional: boolean }>();
|
||||||
|
|
||||||
vi.mock("../../plugins/tools.js", () => ({
|
vi.mock("../../plugins/tools.js", async (importOriginal) => {
|
||||||
resolvePluginTools: vi.fn(() => [
|
const mod = await importOriginal<typeof import("../../plugins/tools.js")>();
|
||||||
{ name: "voice_call", label: "voice_call", description: "Plugin calling tool" },
|
return {
|
||||||
{ name: "matrix_room", label: "matrix_room", description: "Matrix room helper" },
|
...mod,
|
||||||
]),
|
resolvePluginTools: vi.fn(() => [
|
||||||
getPluginToolMeta: vi.fn((tool: { name: string }) => pluginToolMetaState.get(tool.name)),
|
{ 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 }?];
|
type RespondCall = [boolean, unknown?, { code: number; message: string }?];
|
||||||
|
|
||||||
|
|||||||
@ -30,9 +30,13 @@ vi.mock("../plugins/config-state.js", () => ({
|
|||||||
isTestDefaultMemorySlotDisabled: disableDefaultMemorySlot,
|
isTestDefaultMemorySlotDisabled: disableDefaultMemorySlot,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../plugins/tools.js", () => ({
|
vi.mock("../plugins/tools.js", async (importOriginal) => {
|
||||||
getPluginToolMeta: noPluginToolMeta,
|
const mod = await importOriginal<typeof import("../plugins/tools.js")>();
|
||||||
}));
|
return {
|
||||||
|
...mod,
|
||||||
|
getPluginToolMeta: noPluginToolMeta,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
vi.mock("../agents/openclaw-tools.js", () => {
|
vi.mock("../agents/openclaw-tools.js", () => {
|
||||||
const tools = [
|
const tools = [
|
||||||
|
|||||||
@ -61,9 +61,13 @@ vi.mock("../plugins/config-state.js", () => ({
|
|||||||
isTestDefaultMemorySlotDisabled: () => false,
|
isTestDefaultMemorySlotDisabled: () => false,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
vi.mock("../plugins/tools.js", () => ({
|
vi.mock("../plugins/tools.js", async (importOriginal) => {
|
||||||
getPluginToolMeta: () => undefined,
|
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
|
// 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.
|
// routing/policy tests we only need a small set of tool names.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user