





















@@ -0,0 +1,98 @@
1+import { beforeEach, describe, expect, it, vi } from "vitest";
2+import type { createOpenClawCodingTools } from "../../../agents/pi-tools.js";
3+import type { AnyAgentTool } from "../../../agents/tools/common.js";
4+5+const toolState = vi.hoisted(() => ({
6+tools: [] as AnyAgentTool[],
7+pluginIds: {} as Record<string, string | undefined>,
8+throwError: null as Error | null,
9+createTools: vi.fn<typeof createOpenClawCodingTools>(),
10+}));
11+12+vi.mock("../../../agents/pi-tools.js", () => ({
13+createOpenClawCodingTools: (options?: Parameters<typeof createOpenClawCodingTools>[0]) => {
14+toolState.createTools(options);
15+if (toolState.throwError) {
16+throw toolState.throwError;
17+}
18+return toolState.tools;
19+},
20+}));
21+22+vi.mock("../../../plugins/tools.js", () => ({
23+getPluginToolMeta: (tool: { name: string }) => {
24+const pluginId = toolState.pluginIds[tool.name];
25+return pluginId ? { pluginId, optional: false } : undefined;
26+},
27+}));
28+29+const { collectActiveToolSchemaProjectionWarnings } =
30+await import("./active-tool-schema-warnings.js");
31+32+function tool(name: string, parameters: unknown): AnyAgentTool {
33+return {
34+ name,
35+label: name,
36+description: name,
37+ parameters,
38+execute: async () => ({ text: "ok" }),
39+} as unknown as AnyAgentTool;
40+}
41+42+describe("active tool schema doctor warnings", () => {
43+beforeEach(() => {
44+toolState.tools = [];
45+toolState.pluginIds = {};
46+toolState.throwError = null;
47+toolState.createTools.mockClear();
48+});
49+50+it("warns with plugin ownership for active tools blocked by runtime projection", () => {
51+toolState.tools = [
52+tool("message", { type: "object", properties: {} }),
53+tool("dofbot_move_angles", { type: "array", items: { type: "number" } }),
54+];
55+toolState.pluginIds = { dofbot_move_angles: "dofbot" };
56+57+expect(
58+collectActiveToolSchemaProjectionWarnings({
59+cfg: {
60+plugins: {
61+entries: {
62+dofbot: { enabled: true },
63+},
64+},
65+},
66+env: { HOME: "/tmp/openclaw-test" },
67+}),
68+).toEqual([
69+'- agents.main: active tool "dofbot_move_angles" from plugin "dofbot" has unsupported runtime input schema (dofbot_move_angles.parameters.type must be "object"). OpenClaw will quarantine this tool at runtime; fix or disable the plugin, or remove the tool from active allowlists.',
70+]);
71+});
72+73+it("does not validate disabled plugin mode", () => {
74+toolState.tools = [tool("dofbot_move_angles", { type: "array", items: { type: "number" } })];
75+toolState.pluginIds = { dofbot_move_angles: "dofbot" };
76+77+expect(
78+collectActiveToolSchemaProjectionWarnings({
79+cfg: { plugins: { enabled: false } },
80+env: { HOME: "/tmp/openclaw-test" },
81+}),
82+).toEqual([]);
83+expect(toolState.createTools).not.toHaveBeenCalled();
84+});
85+86+it("reports toolset construction failures instead of crashing doctor", () => {
87+toolState.throwError = new Error("plugin startup failed");
88+89+expect(
90+collectActiveToolSchemaProjectionWarnings({
91+cfg: { plugins: { entries: { dofbot: { enabled: true } } } },
92+env: { HOME: "/tmp/openclaw-test" },
93+}),
94+).toEqual([
95+"- agents.main: active tool schema validation could not load the runtime tool set (plugin startup failed). Fix plugin loading errors before relying on assistant tool startup.",
96+]);
97+});
98+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。