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

Function test_confirmation_flow_approve

core/src/hitl.rs:713–759  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

711
712 #[tokio::test]
713 async fn test_confirmation_flow_approve() {
714 let (event_tx, mut event_rx) = broadcast::channel(100);
715 let manager = ConfirmationManager::new(ConfirmationPolicy::enabled(), event_tx);
716
717 // Request confirmation
718 let rx = manager
719 .request_confirmation("tool-1", "bash", &serde_json::json!({"command": "ls"}))
720 .await;
721
722 // Check event was emitted
723 let event = event_rx.recv().await.unwrap();
724 match event {
725 AgentEvent::ConfirmationRequired {
726 tool_id,
727 tool_name,
728 timeout_ms,
729 ..
730 } => {
731 assert_eq!(tool_id, "tool-1");
732 assert_eq!(tool_name, "bash");
733 assert_eq!(timeout_ms, 30_000); // Default timeout
734 }
735 _ => panic!("Expected ConfirmationRequired event"),
736 }
737
738 // Approve the confirmation
739 let result = manager.confirm("tool-1", true, None).await;
740 assert!(result.is_ok());
741 assert!(result.unwrap());
742
743 // Check ConfirmationReceived event
744 let event = event_rx.recv().await.unwrap();
745 match event {
746 AgentEvent::ConfirmationReceived {
747 tool_id, approved, ..
748 } => {
749 assert_eq!(tool_id, "tool-1");
750 assert!(approved);
751 }
752 _ => panic!("Expected ConfirmationReceived event"),
753 }
754
755 // Check response
756 let response = rx.await.unwrap();
757 assert!(response.approved);
758 assert!(response.reason.is_none());
759 }
760
761 #[tokio::test]
762 async fn test_confirmation_flow_reject() {

Callers

nothing calls this directly

Calls 2

request_confirmationMethod · 0.45
confirmMethod · 0.45

Tested by

no test coverage detected