()
| 829 | |
| 830 | #[tokio::test] |
| 831 | async fn test_agent_hitl_confirmation_events() { |
| 832 | use crate::hitl::{ConfirmationManager, ConfirmationPolicy}; |
| 833 | use tokio::sync::broadcast; |
| 834 | |
| 835 | let mock_client = Arc::new(MockLlmClient::new(vec![ |
| 836 | MockLlmClient::tool_call_response( |
| 837 | "tool-1", |
| 838 | "bash", |
| 839 | serde_json::json!({"command": "echo test"}), |
| 840 | ), |
| 841 | MockLlmClient::text_response("Done!"), |
| 842 | ])); |
| 843 | |
| 844 | let tool_executor = Arc::new(ToolExecutor::new("/tmp".to_string())); |
| 845 | |
| 846 | // Create HITL confirmation manager |
| 847 | let (event_tx, mut event_rx) = broadcast::channel(100); |
| 848 | let hitl_policy = ConfirmationPolicy { |
| 849 | enabled: true, |
| 850 | default_timeout_ms: 5000, // Long enough timeout |
| 851 | ..Default::default() |
| 852 | }; |
| 853 | let confirmation_manager = Arc::new(ConfirmationManager::new(hitl_policy, event_tx)); |
| 854 | |
| 855 | let permission_policy = PermissionPolicy::new(); |
| 856 | |
| 857 | let config = AgentConfig { |
| 858 | permission_checker: Some(Arc::new(permission_policy)), |
| 859 | confirmation_manager: Some(confirmation_manager.clone()), |
| 860 | ..Default::default() |
| 861 | }; |
| 862 | |
| 863 | // Spawn task to approve and collect events |
| 864 | let cm_clone = confirmation_manager.clone(); |
| 865 | let event_handle = tokio::spawn(async move { |
| 866 | let mut events = Vec::new(); |
| 867 | // Wait for ConfirmationRequired event |
| 868 | while let Ok(event) = event_rx.recv().await { |
| 869 | events.push(event.clone()); |
| 870 | if let AgentEvent::ConfirmationRequired { tool_id, .. } = event { |
| 871 | // Approve it |
| 872 | cm_clone.confirm(&tool_id, true, None).await.ok(); |
| 873 | // Wait for ConfirmationReceived |
| 874 | if let Ok(recv_event) = event_rx.recv().await { |
| 875 | events.push(recv_event); |
| 876 | } |
| 877 | break; |
| 878 | } |
| 879 | } |
| 880 | events |
| 881 | }); |
| 882 | |
| 883 | let agent = AgentLoop::new(mock_client, tool_executor, test_tool_context(), config); |
| 884 | let _result = agent.execute(&[], "Echo", None).await.unwrap(); |
| 885 | |
| 886 | // Check events |
| 887 | let events = event_handle.await.unwrap(); |
| 888 | assert!( |
nothing calls this directly
no test coverage detected