use super::decode_cancelled_request_id; use serde_json::{Value, json}; #[test] fn rmcp_progress_cancel_decoder_preserves_exact_ids_and_ignores_other_fields() { for wire_id in [ "\"7\"", "7", "-7", "1.5", "1.0", "-0.0", "18446744073709551615", "\"\"", "\"line\\nbreak\"", ] { let id: Value = serde_json::from_str(wire_id).unwrap(); let params = json!({ "requestId": id, "reason": 42, "_meta": [], "unknown": {"nested": [true]} }); let decoded = decode_cancelled_request_id(¶ms).unwrap(); assert_eq!(decoded.to_string(), wire_id); } let long_id = Value::String("x".repeat(1024)); assert_eq!( decode_cancelled_request_id(&json!({"requestId": long_id})), Some(long_id) ); assert_ne!( decode_cancelled_request_id(&json!({"requestId": "7"})), decode_cancelled_request_id(&json!({"requestId": 7})) ); } #[test] fn rmcp_progress_cancel_decoder_has_no_target_for_invalid_or_missing_ids() { for params in [ json!(null), json!(true), json!(7), json!("requestId"), json!([]), json!({}), json!({"requestId": null}), json!({"requestId": true}), json!({"requestId": []}), json!({"requestId": {}}), json!({"reason": "ignored", "_meta": []}), ] { assert_eq!(decode_cancelled_request_id(¶ms), None, "{params}"); } }