From c4b61c4463fa23eebeabf67d741cf5ecb8b077ef Mon Sep 17 00:00:00 2001 From: tlongwell-block <109685178+tlongwell-block@users.noreply.github.com> Date: Mon, 29 Sep 2025 02:47:46 +0000 Subject: [PATCH] test: add test for to_readable_string --- .../tests/tool_request_to_readable_string.rs | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 crates/goose/tests/tool_request_to_readable_string.rs diff --git a/crates/goose/tests/tool_request_to_readable_string.rs b/crates/goose/tests/tool_request_to_readable_string.rs new file mode 100644 index 0000000000..542239b3c0 --- /dev/null +++ b/crates/goose/tests/tool_request_to_readable_string.rs @@ -0,0 +1,34 @@ +use goose::conversation::message::ToolRequest; +use mcp_core::ToolCall; +use serde_json::json; + +// This test targets: ToolRequest::to_readable_string +// It verifies that a successful tool call renders a readable string with +// pretty-printed JSON arguments and includes the tool name. +#[test] +fn test_tool_request_to_readable_string_pretty_json() { + let tool_call = ToolCall::new( + "fetch_user", + json!({ + "id": 42, + "active": true, + "details": {"level": 3} + }), + ); + + let req = ToolRequest { + id: "req-1".to_string(), + tool_call: Ok(tool_call), + }; + + let readable = req.to_readable_string(); + + // Starts with the expected tool prefix + assert!(readable.starts_with("Tool: fetch_user, Args: {")); + + // Pretty JSON should contain newlines and formatted key/value pairs + assert!(readable.contains('\n')); + assert!(readable.contains("\"id\": 42")); + assert!(readable.contains("\"active\": true")); + assert!(readable.contains("\"details\": {")); +}