docs: document openclaw tool tests · openclaw/openclaw@b491058
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies OpenClaw-owned tool hooks preserve adjusted params and telemetry. |
1 | 2 | import type { AgentTool } from "openclaw/plugin-sdk/agent-core"; |
2 | 3 | import { |
3 | 4 | installOpenClawOwnedToolHooks, |
@@ -33,6 +34,7 @@ type ToolExecutionStartEvent = Parameters<typeof handleToolExecutionStart>[1];
|
33 | 34 | type ToolExecutionEndEvent = Parameters<typeof handleToolExecutionEnd>[1]; |
34 | 35 | |
35 | 36 | function createToolHandlerCtx(): ToolHandlerContext { |
| 37 | +// Minimal embedded-agent tool handler context used to drive start/end events. |
36 | 38 | return { |
37 | 39 | params: { |
38 | 40 | runId: "run-contract", |
@@ -92,6 +94,7 @@ function createToolExtensionContext(): ExtensionContext {
|
92 | 94 | async function waitForAfterToolCall(hooks: { |
93 | 95 | afterToolCall: { mock: { calls: unknown[][] } }; |
94 | 96 | }): Promise<[Record<string, unknown>, Record<string, unknown>]> { |
| 97 | +// after_tool_call fires asynchronously after the execution-end event is processed. |
95 | 98 | await vi.waitFor(() => { |
96 | 99 | expect(hooks.afterToolCall).toHaveBeenCalledTimes(1); |
97 | 100 | }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies agents_list reports only subagents visible to the requester. |
1 | 2 | import { describe, expect, it, vi } from "vitest"; |
2 | 3 | import { createPerSenderSessionConfig } from "./test-helpers/session-config.js"; |
3 | 4 | import { createAgentsListTool } from "./tools/agents-list-tool.js"; |
@@ -19,6 +20,7 @@ describe("agents_list", () => {
|
19 | 20 | type AgentConfig = NonNullable<NonNullable<typeof configOverride.agents>["list"]>[number]; |
20 | 21 | |
21 | 22 | function setConfigWithAgentList(agentList: AgentConfig[]) { |
| 23 | +// Each test gets a fresh per-sender session config plus its agent list. |
22 | 24 | configOverride = { |
23 | 25 | session: createPerSenderSessionConfig(), |
24 | 26 | agents: { |
@@ -34,6 +36,7 @@ describe("agents_list", () => {
|
34 | 36 | } |
35 | 37 | |
36 | 38 | function readAgentList(result: unknown) { |
| 39 | +// Tool results expose the machine-readable agent list in details. |
37 | 40 | return (result as { details?: { agents?: Array<{ id: string; configured?: boolean }> } }) |
38 | 41 | .details?.agents; |
39 | 42 | } |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies OpenClaw plugin tools are resolved with browser/runtime context. |
1 | 2 | import { afterEach, describe, expect, it, vi } from "vitest"; |
2 | 3 | import type { OpenClawConfig } from "../config/config.js"; |
3 | 4 | import { resetConfigRuntimeState, setRuntimeConfigSnapshot } from "../config/config.js"; |
@@ -13,6 +14,7 @@ vi.mock("../plugins/tools.js", () => ({
|
13 | 14 | })); |
14 | 15 | |
15 | 16 | function firstResolvePluginToolsParams(): Record<string, unknown> { |
| 17 | +// Captures the plugin runtime contract passed from OpenClaw tool resolution. |
16 | 18 | const call = hoisted.resolvePluginTools.mock.calls[0]; |
17 | 19 | if (!call) { |
18 | 20 | throw new Error("Expected plugin tool resolution"); |
@@ -224,6 +226,7 @@ describe("createOpenClawTools browser plugin integration", () => {
|
224 | 226 | }); |
225 | 227 | |
226 | 228 | it("does not pass a stale active snapshot as plugin runtime config for a resolved run config", () => { |
| 229 | +// Resolved run config must win over any process-global runtime snapshot. |
227 | 230 | const staleSourceConfig = { |
228 | 231 | plugins: { |
229 | 232 | allow: ["old-plugin"], |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies node camera/photo tool payloads, media URLs, and vision gating. |
1 | 2 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 3 | import { |
3 | 4 | readFileUtf8AndCleanup, |
@@ -47,6 +48,7 @@ function unexpectedGatewayMethod(method: unknown): never {
|
47 | 48 | } |
48 | 49 | |
49 | 50 | function getNodesTool(options?: { modelHasVision?: boolean; allowMediaInvokeCommands?: boolean }) { |
| 51 | +// Tests vary only model vision capability and media invoke permission. |
50 | 52 | return createNodesTool({ |
51 | 53 | ...(options?.modelHasVision !== undefined ? { modelHasVision: options.modelHasVision } : {}), |
52 | 54 | ...(options?.allowMediaInvokeCommands !== undefined |
@@ -80,6 +82,7 @@ function expectInvokeParams(
|
80 | 82 | params?: Record<string, unknown>; |
81 | 83 | }, |
82 | 84 | ) { |
| 85 | +// Node command payloads are nested under the gateway node.invoke params object. |
83 | 86 | const record = requireRecord(invokeParams, "node.invoke params"); |
84 | 87 | expect(record.command).toBe(expected.command); |
85 | 88 | if (expected.nodeId !== undefined) { |
@@ -146,6 +149,7 @@ function setupNodeInvokeMock(params: {
|
146 | 149 | onInvoke?: (invokeParams: unknown) => GatewayMockResult | Promise<GatewayMockResult>; |
147 | 150 | invokePayload?: unknown; |
148 | 151 | }) { |
| 152 | +// Most camera tests need node.list followed by one node.invoke command. |
149 | 153 | callGateway.mockImplementation(async ({ method, params: invokeParams }: GatewayCall) => { |
150 | 154 | if (method === "node.list") { |
151 | 155 | return mockNodeList({ commands: params.commands, remoteIp: params.remoteIp }); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Shared registration assertions for optional media-generation OpenClaw tools. |
1 | 2 | import { describe, expect, it } from "vitest"; |
2 | 3 | import { collectPresentOpenClawTools } from "./openclaw-tools.registration.js"; |
3 | 4 | import { textResult, type AnyAgentTool } from "./tools/common.js"; |
4 | 5 | |
5 | 6 | function stubAgentTool(name: string): AnyAgentTool { |
| 7 | +// Registration tests only need a structurally valid tool. |
6 | 8 | return { |
7 | 9 | label: name, |
8 | 10 | name, |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies image-generation tool registration through the shared generation harness. |
1 | 2 | import { describeOpenClawGenerationToolRegistration } from "./openclaw-tools.generation.test-support.js"; |
2 | 3 | |
3 | 4 | describeOpenClawGenerationToolRegistration({ |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。