Make CallTool.Result.isError optional (#11)

This commit is contained in:
Mattt 2025-03-14 06:24:46 -07:00 • committed by GitHub
commit a62e51a61c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -139,16 +139,16 @@ struct ToolTests {
#expect(params.arguments?["param2"] == .int(42))
}
@Test("CallTool result validation")
@Test("CallTool success result validation")
func testCallToolResult() throws {
let content = [
Tool.Content.text("Result 1"),
Tool.Content.text("Result 2"),
]
let result = CallTool.Result(content: content, isError: false)
let result = CallTool.Result(content: content)
#expect(result.content.count == 2)
#expect(result.isError == false)
#expect(result.isError == nil)
if case .text(let text) = result.content[0] {
#expect(text == "Result 1")
@ -157,6 +157,20 @@ struct ToolTests {
}
}
@Test("CallTool error result validation")
func testCallToolErrorResult() throws {
let errorContent = [Tool.Content.text("Error message")]
let errorResult = CallTool.Result(content: errorContent, isError: true)
#expect(errorResult.content.count == 1)
#expect(errorResult.isError == true)
if case .text(let text) = errorResult.content[0] {
#expect(text == "Error message")
} else {
#expect(Bool(false), "Expected error text content")
}
}
@Test("ToolListChanged notification name validation")
func testToolListChangedNotification() throws {
#expect(ToolListChangedNotification.name == "notifications/tools/list_changed")