Add approval mode selection
CI / Rust Checks (push) Successful in 5m35s
CI / UI Checks (push) Successful in 5s
CI / Deployment Manifests (push) Successful in 2s
CI / Frontend E2E (push) Successful in 3m28s
CI / Deploy (push) Successful in 1m38s

This commit is contained in:
github-ops
2026-06-27 07:55:38 +00:00
parent 2b2ff92146
commit 700a684257
15 changed files with 425 additions and 31 deletions
@@ -359,10 +359,12 @@ async fn tool_call_with_approval_policy_creates_pending_request() {
let mut operation = test_operation(&upstream_base_url, "crm_requires_human_approval");
operation.execution_config.approval_policy = Some(OperationApprovalPolicy {
required: true,
mode: OperationApprovalMode::Custom,
risk_level: OperationApprovalRiskLevel::Dangerous,
ttl_seconds: 300,
show_payload_preview: true,
payload_preview_mode: OperationApprovalPayloadPreviewMode::MaskedJson,
elicitation_message: None,
});
registry
.create_operation(&test_workspace_id(), &operation, Some("alice"))
@@ -445,3 +447,171 @@ async fn tool_call_with_approval_policy_creates_pending_request() {
"ada@example.com"
);
}
#[tokio::test]
async fn elicitation_approval_requires_client_capability() {
let registry = test_registry().await;
let upstream_base_url = spawn_upstream_server().await;
let mut operation = test_operation(&upstream_base_url, "crm_requires_elicitation");
operation.execution_config.approval_policy = Some(OperationApprovalPolicy {
required: true,
mode: OperationApprovalMode::Elicitation,
risk_level: OperationApprovalRiskLevel::Normal,
ttl_seconds: 300,
show_payload_preview: true,
payload_preview_mode: OperationApprovalPayloadPreviewMode::MaskedJson,
elicitation_message: Some("Подтвердите создание лида.".to_owned()),
});
registry
.create_operation(&test_workspace_id(), &operation, Some("alice"))
.await
.unwrap();
registry
.publish_operation(PublishRequest {
workspace_id: &test_workspace_id(),
operation_id: &operation.id,
version: 1,
published_at: &OffsetDateTime::now_utc(),
published_by: Some("alice"),
})
.await
.unwrap();
publish_agent_with_bindings(
&registry,
"sales-elicitation-no-capability",
vec![binding_for_operation(&operation)],
)
.await;
let api_key = create_platform_api_key(
&registry,
"sales-elicitation-no-capability",
"mcp-elicitation-no-capability",
&[PlatformApiKeyScope::Read, PlatformApiKeyScope::Write],
)
.await;
let base_url = spawn_mcp_server(build_test_app(
registry.clone(),
Duration::from_millis(0),
Some("https://crank.example.com".to_owned()),
))
.await;
let client = reqwest::Client::new();
let mcp_url = agent_mcp_url(&base_url, "sales-elicitation-no-capability");
let initialized_session = initialize_session(&client, &mcp_url, &api_key).await;
let tool_result = post_jsonrpc(
&client,
&mcp_url,
&api_key,
Some(&initialized_session),
json!({
"jsonrpc": "2.0",
"id": 7,
"method": "tools/call",
"params": {
"name": "crm_requires_elicitation",
"arguments": {
"email": "ada@example.com"
}
}
}),
)
.await;
assert_eq!(tool_result["result"]["isError"], true);
assert_eq!(
tool_result["result"]["structuredContent"]["error"]["code"],
"approval_elicitation_not_supported"
);
}
#[tokio::test]
async fn elicitation_approval_uses_session_capability_without_approval_key() {
let registry = test_registry().await;
let upstream_base_url = spawn_upstream_server().await;
let mut operation = test_operation(&upstream_base_url, "crm_requires_elicitation_supported");
operation.execution_config.approval_policy = Some(OperationApprovalPolicy {
required: true,
mode: OperationApprovalMode::Elicitation,
risk_level: OperationApprovalRiskLevel::Normal,
ttl_seconds: 300,
show_payload_preview: true,
payload_preview_mode: OperationApprovalPayloadPreviewMode::MaskedJson,
elicitation_message: Some("Подтвердите создание лида.".to_owned()),
});
registry
.create_operation(&test_workspace_id(), &operation, Some("alice"))
.await
.unwrap();
registry
.publish_operation(PublishRequest {
workspace_id: &test_workspace_id(),
operation_id: &operation.id,
version: 1,
published_at: &OffsetDateTime::now_utc(),
published_by: Some("alice"),
})
.await
.unwrap();
publish_agent_with_bindings(
&registry,
"sales-elicitation-supported",
vec![binding_for_operation(&operation)],
)
.await;
let api_key = create_platform_api_key(
&registry,
"sales-elicitation-supported",
"mcp-elicitation-supported",
&[PlatformApiKeyScope::Read, PlatformApiKeyScope::Write],
)
.await;
let base_url = spawn_mcp_server(build_test_app(
registry.clone(),
Duration::from_millis(0),
Some("https://crank.example.com".to_owned()),
))
.await;
let client = reqwest::Client::new();
let mcp_url = agent_mcp_url(&base_url, "sales-elicitation-supported");
let initialized_session = initialize_session_with_capabilities(
&client,
&mcp_url,
&api_key,
json!({ "elicitation": {} }),
)
.await;
let tool_result = post_jsonrpc(
&client,
&mcp_url,
&api_key,
Some(&initialized_session),
json!({
"jsonrpc": "2.0",
"id": 8,
"method": "tools/call",
"params": {
"name": "crm_requires_elicitation_supported",
"arguments": {
"email": "ada@example.com"
}
}
}),
)
.await;
assert_eq!(tool_result["result"]["isError"], false);
assert_eq!(
tool_result["result"]["structuredContent"]["status"],
"elicitation_required"
);
assert_eq!(
tool_result["result"]["structuredContent"]["message"],
"Подтвердите создание лида."
);
assert_eq!(
tool_result["result"]["structuredContent"]["payload_preview"]["email"],
"ada@example.com"
);
}