use super::*;
use pretty_assertions::assert_eq;
use serde_json::json;
fn v2_update(value: serde_json::Value) -> v2::ToolCallUpdate {
serde_json::from_value(value).unwrap()
}
#[test]
fn v2_tool_call_updates_start_then_change_their_v1_call() {
let mut calls = ToolCalls::default();
let cases = [
(
json!({"toolCallId": "a", "name": "mcp__rho__bash", "kind": "execute", "status": "pending",
"_meta": {"claudeCode": {"toolName": "mcp__rho__bash"}}}),
v1::SessionUpdate::ToolCall(
v1::ToolCall::new("a", "mcp__rho__bash")
.name("mcp__rho__bash".to_owned())
.kind(v1::ToolKind::Execute)
.status(v1::ToolCallStatus::Pending)
.meta(
json!({"claudeCode": {"toolName": "mcp__rho__bash"}})
.as_object()
.cloned(),
),
),
),
(
json!({"toolCallId": "a", "status": "paused", "content": null}),
v1::SessionUpdate::ToolCallUpdate(v1::ToolCallUpdate::new(
"a",
v1::ToolCallUpdateFields::new()
.status(v1::ToolCallStatus::InProgress)
.content(Vec::new()),
)),
),
(
json!({"toolCallId": "a", "status": "cancelled"}),
v1::SessionUpdate::ToolCallUpdate(v1::ToolCallUpdate::new(
"a",
v1::ToolCallUpdateFields::new().status(v1::ToolCallStatus::Failed),
)),
),
(
json!({"toolCallId": "b", "title": "Edit a.rs", "status": "completed", "content": [{
"type": "diff",
"changes": [{"operation": "modify", "path": "/work/a.rs"}],
"patch": {"format": "git_patch", "text": "@@ -1 +1 @@\n-old\n+new\n"}
}]}),
v1::SessionUpdate::ToolCall(
v1::ToolCall::new("b", "Edit a.rs")
.status(v1::ToolCallStatus::Completed)
.content(vec!["```diff\n@@ -1 +1 @@\n-old\n+new\n```".into()]),
),
),
];
for (update, expected) in cases {
assert_eq!(calls.v1(&v2_update(update.clone())), expected, "{update}");
}
}