use super::*;
#[tokio::test]
async fn disabled_returns_note_without_blocking() {
let tool = ClarificationTool::new(false, 3);
let result = tool
.execute(serde_json::json!({"question": "test?"}))
.await
.unwrap();
assert!(result["answer"].is_null());
assert!(result["note"].as_str().unwrap().contains("disabled"));
assert_eq!(tool.asked_count(), 0);
}
#[tokio::test]
async fn over_limit_returns_note_without_blocking() {
let tool = ClarificationTool::new(true, 0); let result = tool
.execute(serde_json::json!({"question": "test?"}))
.await
.unwrap();
assert!(result["answer"].is_null());
assert!(result["note"].as_str().unwrap().contains("limit reached"));
assert_eq!(tool.asked_count(), 0);
}
#[tokio::test]
async fn over_limit_after_exhausting_budget() {
let tool = ClarificationTool::new(true, 2);
tool.asked.store(2, Ordering::SeqCst);
let result = tool
.execute(serde_json::json!({"question": "one more?"}))
.await
.unwrap();
assert!(result["answer"].is_null());
assert!(result["note"].as_str().unwrap().contains("limit reached"));
assert_eq!(tool.asked_count(), 2);
}
#[tokio::test]
async fn missing_question_field_errors() {
let tool = ClarificationTool::new(true, 3);
let result = tool.execute(serde_json::json!({})).await;
assert!(result.is_err());
let msg = result.unwrap_err().to_string();
assert!(msg.contains("question"));
}
#[tokio::test]
async fn non_string_question_errors() {
let tool = ClarificationTool::new(true, 3);
let result = tool.execute(serde_json::json!({"question": 42})).await;
assert!(result.is_err());
}
#[test]
fn tool_name_and_description() {
let tool = ClarificationTool::new(true, 3);
assert_eq!(tool.name(), "ask_user");
assert!(!tool.description().is_empty());
}
#[test]
fn tool_schema_has_required_question() {
let tool = ClarificationTool::new(true, 3);
let schema = tool.schema();
assert_eq!(schema["type"], "object");
let required = schema["required"].as_array().unwrap();
assert!(required.iter().any(|v| v == "question"));
}
#[test]
fn tool_is_readonly_low_risk() {
let tool = ClarificationTool::new(true, 3);
assert!(tool.is_readonly());
assert!(!tool.is_destructive());
assert_eq!(tool.risk_level(), crate::safety::RiskLevel::Low);
}
#[test]
fn default_is_enabled_with_max_3() {
let tool = ClarificationTool::default();
assert_eq!(tool.asked_count(), 0);
}
#[tokio::test]
async fn tui_mode_returns_note_without_blocking() {
let tool = ClarificationTool::new(true, 3);
crate::output::set_tui_active(true);
let result = tool
.execute(serde_json::json!({"question": "test?"}))
.await
.unwrap();
crate::output::set_tui_active(false);
assert!(result["answer"].is_null());
assert!(result["note"].as_str().unwrap().contains("TUI mode"));
assert_eq!(tool.asked_count(), 0);
}