docs: document session guard tests · openclaw/openclaw@dca200a
steipete
·
2026-06-05
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies OpenAI tool schema normalization remains stable across runtime paths. |
1 | 2 | import type { StreamFn } from "openclaw/plugin-sdk/agent-core"; |
2 | 3 | import { |
3 | 4 | createNativeOpenAIResponsesModel, |
@@ -56,6 +57,7 @@ describe("OpenAI transport schema normalization runtime contract", () => {
|
56 | 57 | }); |
57 | 58 | |
58 | 59 | it("passes prepared executable schemas through compaction-triggered Responses requests", () => { |
| 60 | +// Server-side compaction must not strip provider-prepared strict tool schemas. |
59 | 61 | const hooks = buildProviderToolCompatFamilyHooks("openai"); |
60 | 62 | const tools = hooks.normalizeToolSchemas({ |
61 | 63 | provider: "openai", |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies quota suspension persists lane state and auto-resumes safely. |
1 | 2 | import { afterEach, describe, expect, it, vi } from "vitest"; |
2 | 3 | import { DEFAULT_CRON_MAX_CONCURRENT_RUNS } from "../config/cron-limits.js"; |
3 | 4 | import type { OpenClawConfig } from "../config/types.openclaw.js"; |
@@ -24,6 +25,7 @@ vi.mock("./command/session.js", () => ({
|
24 | 25 | })); |
25 | 26 | |
26 | 27 | async function suspendLane(ttlMs: number, cfg: OpenClawConfig, laneId: CommandLane) { |
| 28 | +// All cases exercise the public suspendSession path with fixed failure metadata. |
27 | 29 | const { suspendSession } = await import("./session-suspension.js"); |
28 | 30 | await suspendSession({ |
29 | 31 | cfg, |
@@ -104,6 +106,7 @@ describe("session suspension", () => {
|
104 | 106 | }); |
105 | 107 | |
106 | 108 | it("clamps oversized suspension TTLs for timers and persisted resume time", async () => { |
| 109 | +// Persisted expectedResumeBy must match the clamped timer, not MAX_SAFE_INTEGER. |
107 | 110 | vi.useFakeTimers(); |
108 | 111 | vi.setSystemTime(1_000); |
109 | 112 | const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout"); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies session tool-result guard inserts, truncates, and repairs tool results. |
1 | 2 | import type { AgentMessage } from "openclaw/plugin-sdk/agent-core"; |
2 | 3 | import { SessionManager } from "openclaw/plugin-sdk/agent-sessions"; |
3 | 4 | import { describe, expect, it } from "vitest"; |
@@ -32,6 +33,7 @@ function appendAssistantToolCall(
|
32 | 33 | sm: SessionManager, |
33 | 34 | params: { id: string; name: string; withArguments?: boolean }, |
34 | 35 | ) { |
| 36 | +// Builds pending tool calls with optional missing arguments for repair cases. |
35 | 37 | const toolCall: { |
36 | 38 | type: "toolCall"; |
37 | 39 | id: string; |
@@ -61,6 +63,7 @@ function getPersistedMessages(sm: SessionManager): AgentMessage[] {
|
61 | 63 | } |
62 | 64 | |
63 | 65 | function expectPersistedRoles(sm: SessionManager, expectedRoles: AgentMessage["role"][]) { |
| 66 | +// Role-order assertions prove where synthetic toolResult messages were inserted. |
64 | 67 | const messages = getPersistedMessages(sm); |
65 | 68 | expect(messages.map((message) => message.role)).toEqual(expectedRoles); |
66 | 69 | return messages; |
@@ -387,9 +390,7 @@ describe("installSessionToolResultGuard", () => {
|
387 | 390 | ); |
388 | 391 | |
389 | 392 | const messages = expectPersistedRoles(sm, ["assistant", "assistant", "toolResult"]); |
390 | | -expect((messages[2] as { toolCallId?: string; isError?: boolean }).toolCallId).toBe( |
391 | | -"call_1", |
392 | | -); |
| 393 | +expect((messages[2] as { toolCallId?: string; isError?: boolean }).toolCallId).toBe("call_1"); |
393 | 394 | expect((messages[2] as { isError?: boolean }).isError).toBe(false); |
394 | 395 | expect(JSON.stringify(messages)).not.toContain("missing tool result"); |
395 | 396 | expect(guard.getPendingIds()).toStrictEqual(["call_2"]); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies persisted tool results are redacted/capped and can be transformed by hooks. |
1 | 2 | import fs from "node:fs"; |
2 | 3 | import os from "node:os"; |
3 | 4 | import path from "node:path"; |
@@ -17,6 +18,7 @@ const originalConfigPath = process.env.OPENCLAW_CONFIG_PATH;
|
17 | 18 | let tempDirs: string[] = []; |
18 | 19 | |
19 | 20 | function writeTempPlugin(params: { dir: string; id: string; body: string }): string { |
| 21 | +// Temp plugin manifests allow testing real hook loading without bundled plugins. |
20 | 22 | const pluginDir = path.join(params.dir, params.id); |
21 | 23 | fs.mkdirSync(pluginDir, { recursive: true }); |
22 | 24 | const file = path.join(pluginDir, `${params.id}.mjs`); |
@@ -99,6 +101,7 @@ function expectPersistedToolResultTextCapped(sm: ReturnType<typeof SessionManage
|
99 | 101 | } |
100 | 102 | |
101 | 103 | function expectPersistedToolResultDetailsCapped(sm: ReturnType<typeof SessionManager.inMemory>) { |
| 104 | +// Large details are summarized before persistence to keep transcript files bounded. |
102 | 105 | const toolResult = requirePersistedToolResult(sm); |
103 | 106 | const details = toolResult.details as Record<string, unknown>; |
104 | 107 | expect(details.persistedDetailsTruncated).toBe(true); |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies guarded session managers emit transcript update events with stable sequence ids. |
1 | 2 | import type { AgentMessage } from "openclaw/plugin-sdk/agent-core"; |
2 | 3 | import { SessionManager } from "openclaw/plugin-sdk/agent-sessions"; |
3 | 4 | import { afterEach, describe, expect, it, vi } from "vitest"; |
@@ -10,6 +11,7 @@ import { guardSessionManager } from "./session-tool-result-guard-wrapper.js";
|
10 | 11 | const listeners: Array<() => void> = []; |
11 | 12 | |
12 | 13 | afterEach(() => { |
| 14 | +// Remove all transcript listeners between tests to avoid duplicate broadcasts. |
13 | 15 | while (listeners.length > 0) { |
14 | 16 | listeners.pop()?.(); |
15 | 17 | } |
@@ -124,6 +126,7 @@ describe("guardSessionManager transcript updates", () => {
|
124 | 126 | }); |
125 | 127 | |
126 | 128 | it("caches real tool result sequence before final assistant messages", () => { |
| 129 | +// Tool results are persisted but not broadcast, so later visible messages must skip their seq. |
127 | 130 | const updates: SessionTranscriptUpdate[] = []; |
128 | 131 | listeners.push(onSessionTranscriptUpdate((update) => updates.push(update))); |
129 | 132 | |
|
| Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +// Verifies transcript repair preserves sessions_spawn attachments and ACP routing fields. |
1 | 2 | import type { AgentMessage } from "openclaw/plugin-sdk/agent-core"; |
2 | 3 | import { describe, it, expect } from "vitest"; |
3 | 4 | import { sanitizeToolCallInputs } from "./session-transcript-repair.js"; |
4 | 5 | import { castAgentMessage, castAgentMessages } from "./test-helpers/agent-message-fixtures.js"; |
5 | 6 | |
6 | 7 | function mkSessionsSpawnToolCall(content: string): AgentMessage { |
| 8 | +// sessions_spawn attachments are transcript-owned payloads, not redaction targets. |
7 | 9 | return castAgentMessage({ |
8 | 10 | role: "assistant", |
9 | 11 | content: [ |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。