MCPcopy Create free account
hub / github.com/AI45Lab/Code / test_agent_hitl_approved

Function test_agent_hitl_approved

core/src/agent/tests.rs:647–693  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

645
646#[tokio::test]
647async fn test_agent_hitl_approved() {
648 use crate::hitl::{ConfirmationManager, ConfirmationPolicy};
649 use tokio::sync::broadcast;
650
651 let mock_client = Arc::new(MockLlmClient::new(vec![
652 MockLlmClient::tool_call_response(
653 "tool-1",
654 "bash",
655 serde_json::json!({"command": "echo hello"}),
656 ),
657 MockLlmClient::text_response("Command executed!"),
658 ]));
659
660 let tool_executor = Arc::new(ToolExecutor::new("/tmp".to_string()));
661
662 // Create HITL confirmation manager with policy enabled
663 let (event_tx, _event_rx) = broadcast::channel(100);
664 let hitl_policy = ConfirmationPolicy {
665 enabled: true,
666 ..Default::default()
667 };
668 let confirmation_manager = Arc::new(ConfirmationManager::new(hitl_policy, event_tx));
669
670 // Create permission policy that returns Ask for bash
671 let permission_policy = PermissionPolicy::new(); // Default is Ask
672
673 let config = AgentConfig {
674 permission_checker: Some(Arc::new(permission_policy)),
675 confirmation_manager: Some(confirmation_manager.clone()),
676 ..Default::default()
677 };
678
679 // Spawn a task to approve the confirmation
680 let cm_clone = confirmation_manager.clone();
681 tokio::spawn(async move {
682 // Wait a bit for the confirmation request to be created
683 tokio::time::sleep(std::time::Duration::from_millis(50)).await;
684 // Approve it
685 cm_clone.confirm("tool-1", true, None).await.ok();
686 });
687
688 let agent = AgentLoop::new(mock_client, tool_executor, test_tool_context(), config);
689 let result = agent.execute(&[], "Run echo", None).await.unwrap();
690
691 assert_eq!(result.text, "Command executed!");
692 assert_eq!(result.tool_calls_count, 1);
693}
694
695#[tokio::test]
696async fn test_agent_hitl_rejected() {

Callers

nothing calls this directly

Calls 4

test_tool_contextFunction · 0.70
cloneMethod · 0.45
confirmMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected