docs: document tool guard tests · openclaw/openclaw@2d3b378
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Subagent spawn test helpers install mocked runtime seams so sessions_spawn |
| 2 | +// tests can exercise orchestration without real gateway/session-store effects. |
1 | 3 | import os from "node:os"; |
2 | 4 | import { normalizeOptionalString } from "@openclaw/normalization-core/string-coerce"; |
3 | 5 | import { expect, vi } from "vitest"; |
4 | 6 | import type { SubagentLifecycleHookRunner } from "../plugins/hooks.js"; |
5 | 7 | |
6 | | -// Test helpers for sessions_spawn. They install a mocked runtime barrel so |
7 | | -// spawn tests can exercise orchestration without touching the real gateway or |
8 | | -// session stores. |
9 | 8 | type MockFn = (...args: unknown[]) => unknown; |
10 | 9 | type MockImplementationTarget = { |
11 | 10 | mockImplementation: (implementation: (opts: { method?: string }) => Promise<unknown>) => unknown; |
@@ -197,8 +196,8 @@ export async function loadSubagentSpawnModuleForTest(params: {
|
197 | 196 | resetModules?: boolean; |
198 | 197 | }): Promise<SubagentSpawnModuleForTest> { |
199 | 198 | if (params.resetModules ?? true) { |
200 | | -// The helper rewires module imports with vi.doMock, so each test starts from |
201 | | -// a fresh module graph unless explicitly sharing mocks. |
| 199 | +// The helper rewires imports with vi.doMock, so each test starts from a |
| 200 | +// fresh module graph unless explicitly sharing mocks. |
202 | 201 | vi.resetModules(); |
203 | 202 | } |
204 | 203 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Tool allowlist guard tests cover fail-closed behavior when explicit |
| 2 | +// allowlists leave no callable tools for the selected runtime/model. |
1 | 3 | import { describe, expect, it } from "vitest"; |
2 | 4 | import { |
3 | 5 | buildEmptyExplicitToolAllowlistError, |
@@ -32,6 +34,8 @@ describe("tool allowlist guard", () => {
|
32 | 34 | }); |
33 | 35 | |
34 | 36 | it("allows inherited config allowlists when a run intentionally disables tools", () => { |
| 37 | +// Explicit runtime allowlists are command-time intent, while inherited |
| 38 | +// config allowlists should not block a deliberately text-only run. |
35 | 39 | expect( |
36 | 40 | buildEmptyExplicitToolAllowlistError({ |
37 | 41 | sources: [{ label: "tools.allow", entries: ["lobster", "llm-task"] }], |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Tool loop detection tests cover repeated-call hashing, ping-pong detection, |
| 2 | +// unknown-tool thresholds, and circuit-breaker escalation. |
1 | 3 | import { describe, expect, it } from "vitest"; |
2 | 4 | import type { ToolLoopDetectionConfig } from "../config/types.tools.js"; |
3 | 5 | import type { SessionState } from "../logging/diagnostic-session-state.js"; |
@@ -142,6 +144,8 @@ function recordSuccessfulPingPongCalls(params: {
|
142 | 144 | count: number; |
143 | 145 | textAtIndex: (toolName: "read" | "list", index: number) => string; |
144 | 146 | }) { |
| 147 | +// Alternating successful calls with unchanged output exercise the ping-pong |
| 148 | +// detector independently from same-tool repetition. |
145 | 149 | for (let i = 0; i < params.count; i += 1) { |
146 | 150 | if (i % 2 === 0) { |
147 | 151 | recordSuccessfulCall( |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// sessions_spawn tool tests cover model-visible schema gating, ACP/subagent |
| 2 | +// dispatch, and result details for spawned child sessions. |
1 | 3 | import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; |
2 | 4 | |
3 | 5 | const hoisted = vi.hoisted(() => { |
@@ -108,6 +110,8 @@ describe("sessions_spawn tool", () => {
|
108 | 110 | } |
109 | 111 | |
110 | 112 | it("hides ACP runtime affordances when no ACP backend is loaded", () => { |
| 113 | +// The tool schema is generated from live runtime availability; stale ACP |
| 114 | +// fields should not be advertised when no backend can handle them. |
111 | 115 | const tool = createSessionsSpawnTool(); |
112 | 116 | const schema = tool.parameters as { |
113 | 117 | properties?: { |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。