#![allow(
unused_imports,
dead_code,
non_camel_case_types,
unused_variables,
clippy::all
)]
use prompty::model::ToolDispatchResult;
use prompty::model::context::{LoadContext, SaveContext};
#[test]
fn test_tool_dispatch_result_load_json() {
let json = r####"
{
"toolCallId": "call_abc123",
"name": "get_weather",
"result": {
"parts": [
{
"kind": "text",
"value": "72°F and sunny"
}
]
}
}
"####;
let ctx = LoadContext::default();
let result = ToolDispatchResult::from_json(json, &ctx);
assert!(
result.is_ok(),
"Failed to load from JSON: {:?}",
result.err()
);
let instance = result.unwrap();
assert_eq!(instance.tool_call_id, "call_abc123");
assert_eq!(instance.name, "get_weather");
}
#[test]
fn test_tool_dispatch_result_load_yaml() {
let yaml = r####"
toolCallId: call_abc123
name: get_weather
result:
parts:
- kind: text
value: 72°F and sunny
"####;
let ctx = LoadContext::default();
let result = ToolDispatchResult::from_yaml(yaml, &ctx);
assert!(
result.is_ok(),
"Failed to load from YAML: {:?}",
result.err()
);
let instance = result.unwrap();
assert_eq!(instance.tool_call_id, "call_abc123");
assert_eq!(instance.name, "get_weather");
}
#[test]
fn test_tool_dispatch_result_roundtrip() {
let json = r####"
{
"toolCallId": "call_abc123",
"name": "get_weather",
"result": {
"parts": [
{
"kind": "text",
"value": "72°F and sunny"
}
]
}
}
"####;
let load_ctx = LoadContext::default();
let result = ToolDispatchResult::from_json(json, &load_ctx);
assert!(result.is_ok(), "Failed to load: {:?}", result.err());
let instance = result.unwrap();
let save_ctx = SaveContext::default();
let json_output = instance.to_json(&save_ctx);
assert!(
json_output.is_ok(),
"Failed to serialize to JSON: {:?}",
json_output.err()
);
}