mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-21 20:38:55 +00:00
mcp: add protocol transcript tests for initialize, cancel, and batch (#3990)
This commit is contained in:
@@ -2112,3 +2112,28 @@ fn bridged_contact_sheet_keeps_the_times_asked_for() {
|
||||
let info = call_json(&mut s, "render_frame", json!({"times": [1.5, 0.25, 3], "inline": false}));
|
||||
assert_eq!(info["times"], json!([1.5, 0.25, 3.0]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stdio_batch_transcript() {
|
||||
let input = concat!(
|
||||
"{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"initialize\",\"params\":{\"protocolVersion\":\"2025-06-18\"}}\n",
|
||||
"{\"jsonrpc\":\"2.0\",\"method\":\"notifications/initialized\"}\n",
|
||||
"{\"jsonrpc\":\"2.0\",\"method\":\"notifications/cancelled\",\"params\":{\"requestId\":1,\"reason\":\"client\"}}\n",
|
||||
"[]\n",
|
||||
"[{\"jsonrpc\":\"2.0\",\"method\":\"notifications/cancelled\",\"params\":{\"requestId\":9}}]\n",
|
||||
"[{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"ping\"},{\"jsonrpc\":\"2.0\",\"method\":\"notifications/progress\"}]\n",
|
||||
"{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"ping\",\"params\":{}}\n"
|
||||
);
|
||||
let mut s = server();
|
||||
let mut out = Vec::new();
|
||||
s.serve(std::io::Cursor::new(input), &mut out).unwrap();
|
||||
|
||||
let replies: Vec<Value> = String::from_utf8(out).unwrap().lines().map(|l| serde_json::from_str(l).unwrap()).collect();
|
||||
assert_eq!(replies.len(), 4, "{replies:?}");
|
||||
assert_eq!(replies[0]["id"], 1);
|
||||
assert_eq!(replies[0]["result"]["serverInfo"]["name"], "effectcraft");
|
||||
assert_eq!(replies[1]["id"], Value::Null);
|
||||
assert_eq!(replies[1]["error"]["code"], -32600);
|
||||
assert_eq!(replies[2], json!([{"jsonrpc": "2.0", "id": 2, "result": {}}]));
|
||||
assert_eq!(replies[3], json!({"jsonrpc": "2.0", "id": 3, "result": {}}));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user