use super::*;
#[test]
fn traduce_las_actualizaciones_de_sesion() {
let chunk =
json!({ "update": { "sessionUpdate": "agent_message_chunk", "content": { "type": "text", "text": "hola" } } });
assert_eq!(update(&chunk), Some(AcpEvent::Text("hola".into())));
let tool = json!({ "update": { "sessionUpdate": "tool_call", "toolCallId": "t1", "title": "Leer a.rs", "status": "pending" } });
assert_eq!(
update(&tool),
Some(AcpEvent::ToolCall { id: "t1".into(), title: "Leer a.rs".into(), status: "pending".into() })
);
let done = json!({ "update": { "sessionUpdate": "tool_call_update", "toolCallId": "t1", "status": "completed",
"content": [{ "type": "content", "content": { "type": "text", "text": "ok" } }] } });
assert_eq!(
update(&done),
Some(AcpEvent::ToolUpdate { id: "t1".into(), status: "completed".into(), output: "ok".into(), title: None })
);
assert_eq!(update(&json!({ "update": { "sessionUpdate": "plan" } })), None);
let commands = json!({ "update": { "sessionUpdate": "available_commands_update", "availableCommands": [
{ "name": "/review", "description": "Revisa", "input": { "hint": "archivo" } }, { "name": "init" }, { "x": 1 }] } });
assert_eq!(
update(&commands),
Some(AcpEvent::Commands(vec![
AcpCommand { name: "review".into(), description: "Revisa".into(), hint: Some("archivo".into()) },
AcpCommand { name: "init".into(), description: String::new(), hint: None },
]))
);
let command = json!({ "update": { "sessionUpdate": "tool_call", "toolCallId": "t2", "title": "Terminal",
"rawInput": { "command": "cargo build" } } });
assert!(matches!(update(&command), Some(AcpEvent::ToolCall { title, .. }) if title == "cargo build"));
let renamed = json!({ "update": { "sessionUpdate": "tool_call_update", "toolCallId": "t2", "title": "Terminal",
"rawInput": { "command": "ls src" } } });
assert!(matches!(update(&renamed), Some(AcpEvent::ToolUpdate { title: Some(t), .. }) if t == "ls src"));
}