CI / UI Checks (pull_request) Successful in 14s
CI / Rust Checks (pull_request) Successful in 35m55s
CI / Rust Feature Validation (pull_request) Skipped
CI / Frontend E2E (pull_request) Skipped
CI / Community Image Smoke (pull_request) Skipped
CI / Required Checks (pull_request) Successful in 1s
CI / Deploy (pull_request) Skipped
104 lines
3.2 KiB
Rust
104 lines
3.2 KiB
Rust
//! Narrow HTTP helpers; all app/auth/catalog/upstream fixtures remain shared.
|
|
use super::*;
|
|
|
|
pub(super) async fn endpoint() -> Endpoint {
|
|
crank_test_support::postgres_schema_url_for_task("dispatch_owner", "t_e862066c").await;
|
|
Endpoint::started().await
|
|
}
|
|
|
|
pub(super) fn sdk(c: &CounterSet) -> [usize; 2] {
|
|
[c.sdk_dispatch_decoded(), c.sdk_dispatch_consumed()]
|
|
}
|
|
|
|
pub(super) fn payload(revision: &str, method: &str, id: Value) -> Value {
|
|
let mut message = json!({"jsonrpc":"2.0","id":id,"method":method});
|
|
if revision == MODERN_REVISION {
|
|
message["params"] = json!({"_meta":modern_meta()});
|
|
}
|
|
message
|
|
}
|
|
|
|
pub(super) fn request(
|
|
h: &Endpoint,
|
|
revision: &str,
|
|
session: Option<&str>,
|
|
accept: &str,
|
|
message: Value,
|
|
) -> reqwest::RequestBuilder {
|
|
h.request(revision, session, &h.key, accept, message)
|
|
.header("x-request-id", "dispatch-atdd")
|
|
.header(
|
|
"traceparent",
|
|
"00-11111111111111111111111111111111-2222222222222222-01",
|
|
)
|
|
}
|
|
|
|
pub(super) async fn body(response: reqwest::Response, sse: bool) -> Value {
|
|
assert_eq!(response.headers()["x-request-id"], "dispatch-atdd");
|
|
assert_eq!(
|
|
response.headers()["x-trace-id"],
|
|
"11111111111111111111111111111111"
|
|
);
|
|
assert!(
|
|
response.headers()["content-type"]
|
|
.to_str()
|
|
.unwrap()
|
|
.starts_with(if sse {
|
|
"text/event-stream"
|
|
} else {
|
|
"application/json"
|
|
})
|
|
);
|
|
let raw = tokio::time::timeout(std::time::Duration::from_secs(6), response.text())
|
|
.await
|
|
.unwrap()
|
|
.unwrap();
|
|
if sse {
|
|
let frames: Vec<Value> = raw
|
|
.lines()
|
|
.filter_map(|l| l.strip_prefix("data:"))
|
|
.map(|l| serde_json::from_str(l.trim()).unwrap())
|
|
.collect();
|
|
assert_eq!(frames.len(), 1, "one terminal SSE frame: {raw}");
|
|
frames.into_iter().next().unwrap()
|
|
} else {
|
|
serde_json::from_str(&raw).unwrap()
|
|
}
|
|
}
|
|
|
|
pub(super) async fn ack(response: reqwest::Response) {
|
|
assert_eq!(response.status(), 202);
|
|
assert!(response.headers().get("content-type").is_none());
|
|
assert!(response.headers().get("MCP-Session-Id").is_none());
|
|
assert!(response.bytes().await.unwrap().is_empty());
|
|
}
|
|
|
|
pub(super) async fn prepared(h: &Endpoint, revision: &str) -> Option<String> {
|
|
if revision == LEGACY_REVISION {
|
|
return h.session(revision).await;
|
|
}
|
|
let ops = h.sessions.snapshot();
|
|
let response = request(
|
|
h,
|
|
revision,
|
|
None,
|
|
"application/json",
|
|
payload(revision, "server/discover", json!(1)),
|
|
)
|
|
.send()
|
|
.await
|
|
.unwrap();
|
|
assert_eq!(response.status(), 200);
|
|
assert_eq!(response.headers()["MCP-Protocol-Version"], revision);
|
|
assert!(response.headers().get("MCP-Session-Id").is_none());
|
|
let wire = body(response, false).await;
|
|
assert_eq!(
|
|
wire["result"]["supportedVersions"],
|
|
json!([MODERN_REVISION, LEGACY_REVISION])
|
|
);
|
|
assert_eq!(wire["result"]["resultType"], "complete");
|
|
assert!(wire.get("error").is_none(), "{wire}");
|
|
assert_eq!(h.sessions.snapshot(), ops);
|
|
None
|
|
}
|