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

Function test_agent_permission_deny

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

Source from the content-addressed store, hash-verified

435
436#[tokio::test]
437async fn test_agent_permission_deny() {
438 let mock_client = Arc::new(MockLlmClient::new(vec![
439 // First response: tool call that will be denied
440 MockLlmClient::tool_call_response(
441 "tool-1",
442 "bash",
443 serde_json::json!({"command": "rm -rf /tmp/test"}),
444 ),
445 // Second response: LLM responds to the denial
446 MockLlmClient::text_response(
447 "I cannot execute that command due to permission restrictions.",
448 ),
449 ]));
450
451 let tool_executor = Arc::new(ToolExecutor::new("/tmp".to_string()));
452
453 // Create permission policy that denies rm commands
454 let permission_policy = PermissionPolicy::new().deny("bash(rm:*)");
455
456 let config = AgentConfig {
457 permission_checker: Some(Arc::new(permission_policy)),
458 ..Default::default()
459 };
460
461 let (tx, mut rx) = mpsc::channel(100);
462 let agent = AgentLoop::new(
463 mock_client.clone(),
464 tool_executor,
465 test_tool_context(),
466 config,
467 );
468 let result = agent.execute(&[], "Delete files", Some(tx)).await.unwrap();
469
470 // Check that we received a PermissionDenied event
471 let mut found_permission_denied = false;
472 while let Ok(event) = rx.try_recv() {
473 if let AgentEvent::PermissionDenied { tool_name, .. } = event {
474 assert_eq!(tool_name, "bash");
475 found_permission_denied = true;
476 }
477 }
478 assert!(
479 found_permission_denied,
480 "Should have received PermissionDenied event"
481 );
482
483 assert_eq!(result.tool_calls_count, 1);
484}
485
486#[tokio::test]
487async fn test_agent_permission_allow() {

Callers

nothing calls this directly

Calls 4

denyMethod · 0.80
test_tool_contextFunction · 0.70
cloneMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected