()
| 694 | |
| 695 | #[tokio::test] |
| 696 | async fn test_agent_hitl_rejected() { |
| 697 | use crate::hitl::{ConfirmationManager, ConfirmationPolicy}; |
| 698 | use tokio::sync::broadcast; |
| 699 | |
| 700 | let mock_client = Arc::new(MockLlmClient::new(vec![ |
| 701 | MockLlmClient::tool_call_response( |
| 702 | "tool-1", |
| 703 | "bash", |
| 704 | serde_json::json!({"command": "rm -rf /"}), |
| 705 | ), |
| 706 | MockLlmClient::text_response("Understood, I won't do that."), |
| 707 | ])); |
| 708 | |
| 709 | let tool_executor = Arc::new(ToolExecutor::new("/tmp".to_string())); |
| 710 | |
| 711 | // Create HITL confirmation manager |
| 712 | let (event_tx, _event_rx) = broadcast::channel(100); |
| 713 | let hitl_policy = ConfirmationPolicy { |
| 714 | enabled: true, |
| 715 | ..Default::default() |
| 716 | }; |
| 717 | let confirmation_manager = Arc::new(ConfirmationManager::new(hitl_policy, event_tx)); |
| 718 | |
| 719 | // Permission policy returns Ask |
| 720 | let permission_policy = PermissionPolicy::new(); |
| 721 | |
| 722 | let config = AgentConfig { |
| 723 | permission_checker: Some(Arc::new(permission_policy)), |
| 724 | confirmation_manager: Some(confirmation_manager.clone()), |
| 725 | ..Default::default() |
| 726 | }; |
| 727 | |
| 728 | // Spawn a task to reject the confirmation |
| 729 | let cm_clone = confirmation_manager.clone(); |
| 730 | tokio::spawn(async move { |
| 731 | tokio::time::sleep(std::time::Duration::from_millis(50)).await; |
| 732 | cm_clone |
| 733 | .confirm("tool-1", false, Some("Too dangerous".to_string())) |
| 734 | .await |
| 735 | .ok(); |
| 736 | }); |
| 737 | |
| 738 | let agent = AgentLoop::new(mock_client, tool_executor, test_tool_context(), config); |
| 739 | let result = agent.execute(&[], "Delete everything", None).await.unwrap(); |
| 740 | |
| 741 | // LLM should respond to the rejection |
| 742 | assert_eq!(result.text, "Understood, I won't do that."); |
| 743 | } |
| 744 | |
| 745 | #[tokio::test] |
| 746 | async fn test_agent_hitl_timeout_reject() { |
nothing calls this directly
no test coverage detected