惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

A
About on SuperTechFans
G
Google Developers Blog
L
LangChain Blog
aimingoo的专栏
aimingoo的专栏
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
云风的 BLOG
云风的 BLOG
小众软件
小众软件
月光博客
月光博客
Recent Announcements
Recent Announcements
人人都是产品经理
人人都是产品经理
P
Proofpoint News Feed
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
The Cloudflare Blog
博客园_首页
美团技术团队
大猫的无限游戏
大猫的无限游戏
B
Blog
IT之家
IT之家
Jina AI
Jina AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
C
Check Point Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
test: tighten tool call normalization assertions · opencl...
steipete · 2026-05-10 · via Recent Commits to openclaw:main

@@ -2,6 +2,50 @@ import type { AgentMessage } from "@mariozechner/pi-agent-core";

22

import { describe, expect, it } from "vitest";

33

import { sanitizeReplayToolCallIdsForStream } from "./attempt.tool-call-normalization.js";

445+

type AssistantMessage = Extract<AgentMessage, { role: "assistant" }>;

6+

type ToolResultMessage = Extract<AgentMessage, { role: "toolResult" }>;

7+8+

function requireAssistantMessage(message: AgentMessage | undefined): AssistantMessage {

9+

if (!message || message.role !== "assistant") {

10+

throw new Error(`expected assistant message, got ${message?.role ?? "missing"}`);

11+

}

12+

return message;

13+

}

14+15+

function requireToolResultMessage(message: AgentMessage | undefined): ToolResultMessage {

16+

if (!message || message.role !== "toolResult") {

17+

throw new Error(`expected toolResult message, got ${message?.role ?? "missing"}`);

18+

}

19+

return message;

20+

}

21+22+

function assistantToolUseSummaries(message: AgentMessage | undefined) {

23+

const assistant = requireAssistantMessage(message);

24+

return assistant.content.map((content) => {

25+

const record = content as unknown as Record<string, unknown>;

26+

if (record.type !== "toolUse") {

27+

throw new Error(`expected toolUse content, got ${String(record.type)}`);

28+

}

29+

return {

30+

type: record.type,

31+

id: record.id,

32+

name: record.name,

33+

};

34+

});

35+

}

36+37+

function toolResultSummary(message: AgentMessage | undefined) {

38+

const toolResult = requireToolResultMessage(message);

39+

const record = toolResult as unknown as Record<string, unknown>;

40+

return {

41+

role: toolResult.role,

42+

toolCallId: toolResult.toolCallId,

43+

toolUseId: record.toolUseId,

44+

toolName: toolResult.toolName,

45+

isError: toolResult.isError,

46+

};

47+

}

48+549

describe("sanitizeReplayToolCallIdsForStream", () => {

650

it("drops orphaned tool results after strict id sanitization", () => {

751

const messages: AgentMessage[] = [

@@ -47,18 +91,17 @@ describe("sanitizeReplayToolCallIdsForStream", () => {

4791

repairToolUseResultPairing: true,

4892

});

499350-

expect(out).toMatchObject([

51-

{

52-

role: "assistant",

53-

content: [{ type: "toolUse", id: "callfunctionav7cbkigmk7x1", name: "read" }],

54-

},

55-

{

56-

role: "toolResult",

57-

toolCallId: "callfunctionav7cbkigmk7x1",

58-

toolUseId: "callfunctionav7cbkigmk7x1",

59-

toolName: "read",

60-

},

94+

expect(out.map((message) => message.role)).toEqual(["assistant", "toolResult"]);

95+

expect(assistantToolUseSummaries(out[0])).toEqual([

96+

{ type: "toolUse", id: "callfunctionav7cbkigmk7x1", name: "read" },

6197

]);

98+

expect(toolResultSummary(out[1])).toEqual({

99+

role: "toolResult",

100+

toolCallId: "callfunctionav7cbkigmk7x1",

101+

toolUseId: "callfunctionav7cbkigmk7x1",

102+

toolName: "read",

103+

isError: false,

104+

});

62105

});

6310664107

it("synthesizes missing tool results after strict id sanitization", () => {

@@ -86,18 +129,22 @@ describe("sanitizeReplayToolCallIdsForStream", () => {

86129

});

8713088131

expect(out.map((message) => message.role)).toEqual(["assistant", "toolResult", "toolResult"]);

89-

expect((out[0] as Extract<AgentMessage, { role: "assistant" }>).content).toMatchObject([

132+

expect(assistantToolUseSummaries(out[0])).toEqual([

90133

{ type: "toolUse", id: "callfunctionav7cbkigmk7x1", name: "read" },

91134

{ type: "toolUse", id: "callmissing", name: "exec" },

92135

]);

93-

expect(out[1]).toMatchObject({

136+

expect(toolResultSummary(out[1])).toEqual({

94137

role: "toolResult",

95138

toolCallId: "callfunctionav7cbkigmk7x1",

96139

toolUseId: "callfunctionav7cbkigmk7x1",

140+

toolName: "read",

141+

isError: false,

97142

});

98-

expect(out[2]).toMatchObject({

143+

expect(toolResultSummary(out[2])).toEqual({

99144

role: "toolResult",

100145

toolCallId: "callmissing",

146+

toolUseId: undefined,

147+

toolName: "exec",

101148

isError: true,

102149

});

103150

});

@@ -114,10 +161,14 @@ describe("sanitizeReplayToolCallIdsForStream", () => {

114161

repairToolUseResultPairing: true,

115162

});

116163117-

expect(out).toMatchObject([

118-

{ role: "assistant" },

119-

{ role: "toolResult", toolCallId: "callmissing", isError: true },

120-

]);

164+

expect(out.map((message) => message.role)).toEqual(["assistant", "toolResult"]);

165+

expect(toolResultSummary(out[1])).toEqual({

166+

role: "toolResult",

167+

toolCallId: "callmissing",

168+

toolUseId: undefined,

169+

toolName: "exec",

170+

isError: true,

171+

});

121172

});

122173123174

it("keeps real tool results for aborted assistant spans", () => {

@@ -146,21 +197,17 @@ describe("sanitizeReplayToolCallIdsForStream", () => {

146197

repairToolUseResultPairing: true,

147198

});

148199149-

expect(out).toMatchObject([

150-

{

151-

role: "assistant",

152-

stopReason: "aborted",

153-

content: [{ type: "toolUse", id: "callfunctionav7cbkigmk7x1", name: "read" }],

154-

},

155-

{

156-

role: "toolResult",

157-

toolCallId: "callfunctionav7cbkigmk7x1",

158-

toolUseId: "callfunctionav7cbkigmk7x1",

159-

toolName: "read",

160-

},

161-

{

162-

role: "user",

163-

},

200+

expect(out.map((message) => message.role)).toEqual(["assistant", "toolResult", "user"]);

201+

expect(requireAssistantMessage(out[0]).stopReason).toBe("aborted");

202+

expect(assistantToolUseSummaries(out[0])).toEqual([

203+

{ type: "toolUse", id: "callfunctionav7cbkigmk7x1", name: "read" },

164204

]);

205+

expect(toolResultSummary(out[1])).toEqual({

206+

role: "toolResult",

207+

toolCallId: "callfunctionav7cbkigmk7x1",

208+

toolUseId: "callfunctionav7cbkigmk7x1",

209+

toolName: "read",

210+

isError: false,

211+

});

165212

});

166213

});