use prodigy::cook::execution::mapreduce::agent::types::AgentResult;
use std::time::Duration;
#[test]
fn test_agent_result_json_serialization() {
let result = AgentResult::success(
"test_item".to_string(),
Some("test output".to_string()),
Duration::from_secs(120),
);
let json_str =
serde_json::to_string(&result).expect("Failed to serialize AgentResult to JSON string");
println!("Serialized JSON string: {}", json_str);
let json_value =
serde_json::to_value(&result).expect("Failed to serialize AgentResult to JSON value");
println!("Serialized JSON value: {:?}", json_value);
let reserialize =
serde_json::to_string(&json_value).expect("Failed to re-serialize JSON value");
println!("Re-serialized: {}", reserialize);
serde_json::from_str::<serde_json::Value>(&reserialize)
.expect("Re-serialized JSON is not valid");
}
#[test]
fn test_agent_result_array_serialization() {
let results = vec![
AgentResult::success(
"item_0".to_string(),
Some("output 0".to_string()),
Duration::from_secs(120),
),
AgentResult::success(
"item_1".to_string(),
Some("output 1".to_string()),
Duration::from_secs(150),
),
];
let json_value =
serde_json::to_value(&results).expect("Failed to serialize array to JSON value");
let json_str = serde_json::to_string(&json_value).expect("Failed to serialize value to string");
println!("Array serialized: {}", json_str);
let parsed: serde_json::Value =
serde_json::from_str(&json_str).expect("Failed to parse serialized JSON");
println!("Parsed successfully: {:?}", parsed);
}