Files
openclaw/apps/shared/OpenClawKit/Tests/OpenClawKitTests/ToolResultTextFormatterTests.swift
Mariano 9476dda9f6 iOS Chat: clean UI noise and format tool outputs (#22122)
Merged via /review-pr -> /prepare-pr -> /merge-pr.

Prepared head SHA: 34dd87b0c0
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Co-authored-by: mbelinky <132747814+mbelinky@users.noreply.github.com>
Reviewed-by: @mbelinky
2026-02-20 19:01:03 +00:00

55 lines
1.5 KiB
Swift

import Testing
@testable import OpenClawChatUI
@Suite("ToolResultTextFormatter")
struct ToolResultTextFormatterTests {
@Test func leavesPlainTextUntouched() {
let result = ToolResultTextFormatter.format(text: "All good", toolName: "nodes")
#expect(result == "All good")
}
@Test func summarizesNodesListJSON() {
let json = """
{
"ts": 1771610031380,
"nodes": [
{
"displayName": "iPhone 16 Pro Max",
"connected": true,
"platform": "ios"
}
]
}
"""
let result = ToolResultTextFormatter.format(text: json, toolName: "nodes")
#expect(result.contains("1 node found."))
#expect(result.contains("iPhone 16 Pro Max"))
#expect(result.contains("connected"))
}
@Test func summarizesErrorJSONAndDropsAgentPrefix() {
let json = """
{
"status": "error",
"tool": "nodes",
"error": "agent=main node=iPhone gateway=default action=invoke: pairing required"
}
"""
let result = ToolResultTextFormatter.format(text: json, toolName: "nodes")
#expect(result == "Error: pairing required")
}
@Test func suppressesUnknownStructuredPayload() {
let json = """
{
"foo": "bar"
}
"""
let result = ToolResultTextFormatter.format(text: json, toolName: "nodes")
#expect(result.isEmpty)
}
}