74 lines
2.5 KiB
Rust
74 lines
2.5 KiB
Rust
use std::time::Duration;
|
|
|
|
use crank_core::PlatformApiKeyScope;
|
|
use crank_registry::PublishRequest;
|
|
use serde_json::{Value, json};
|
|
use time::{OffsetDateTime, format_description::well_known::Rfc3339};
|
|
|
|
use super::common::{
|
|
agent_mcp_url, build_test_app, create_platform_api_key, initialize_session,
|
|
post_jsonrpc_response, publish_agent_for_operation, spawn_mcp_server, spawn_upstream_server,
|
|
test_operation, test_registry, test_workspace_id,
|
|
};
|
|
|
|
#[tokio::test]
|
|
async fn generic_jsonrpc_errors_carry_the_same_safe_response_ids() {
|
|
let registry = test_registry().await;
|
|
let upstream_base_url = spawn_upstream_server().await;
|
|
let operation = test_operation(&upstream_base_url, "crm_error_identity");
|
|
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::parse("2026-03-26T10:00:00Z", &Rfc3339).unwrap(),
|
|
published_by: Some("alice"),
|
|
})
|
|
.await
|
|
.unwrap();
|
|
publish_agent_for_operation(®istry, &operation, "sales-error-identity").await;
|
|
let api_key = create_platform_api_key(
|
|
®istry,
|
|
"sales-error-identity",
|
|
"mcp-error-identity",
|
|
&[PlatformApiKeyScope::Read, PlatformApiKeyScope::Write],
|
|
)
|
|
.await;
|
|
let base_url = spawn_mcp_server(build_test_app(registry, Duration::ZERO, None)).await;
|
|
let client = reqwest::Client::new();
|
|
let mcp_url = agent_mcp_url(&base_url, "sales-error-identity");
|
|
let session = initialize_session(&client, &mcp_url, &api_key).await;
|
|
|
|
let response = post_jsonrpc_response(
|
|
&client,
|
|
&mcp_url,
|
|
&api_key,
|
|
Some(&session),
|
|
Some("jsonrpc-error-request"),
|
|
json!({
|
|
"jsonrpc": "2.0",
|
|
"id": 91,
|
|
"method": "unsupported/method",
|
|
"params": {}
|
|
}),
|
|
)
|
|
.await;
|
|
let request_id = response.headers()["x-request-id"]
|
|
.to_str()
|
|
.unwrap()
|
|
.to_owned();
|
|
let trace_id = response.headers()["x-trace-id"]
|
|
.to_str()
|
|
.unwrap()
|
|
.to_owned();
|
|
let payload = response.json::<Value>().await.unwrap();
|
|
|
|
assert_eq!(request_id, "jsonrpc-error-request");
|
|
assert_eq!(payload["error"]["data"]["request_id"], request_id);
|
|
assert_eq!(payload["error"]["data"]["trace_id"], trace_id);
|
|
}
|