Skip to content

Commit 75d1d3f

Browse files
Brandon BennettBrandon Bennett
authored andcommitted
test(rmcp): add missing edge case tests from code review
Add tests identified during code review: - description stripping for primitive types - composition types (Option<String> with anyOf/oneOf/null) - cache correctness (Arc::ptr_eq for repeated calls) - schema_for_input rejecting array types (not just primitives) - schema_for_output accepting unit type ()
1 parent 8b5fe90 commit 75d1d3f

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

crates/rmcp/src/handler/server/common.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,45 @@ mod tests {
337337
assert!(!schema.contains_key("title"));
338338
}
339339

340+
#[test]
341+
fn test_schema_for_output_strips_description_for_primitive() {
342+
let schema = schema_for_output::<i32>().unwrap();
343+
assert!(!schema.contains_key("description"));
344+
}
345+
346+
#[test]
347+
fn test_schema_for_output_accepts_composition() {
348+
let result = schema_for_output::<Option<String>>();
349+
assert!(result.is_ok());
350+
let schema = result.unwrap();
351+
let schema_str = serde_json::to_string(&schema).unwrap();
352+
assert!(
353+
schema_str.contains("anyOf") || schema_str.contains("oneOf") || schema_str.contains("null"),
354+
"Expected composition schema for Option<String>, got: {schema_str}"
355+
);
356+
}
357+
358+
#[test]
359+
fn test_schema_for_output_caches_result() {
360+
let result1 = schema_for_output::<i32>();
361+
let result2 = schema_for_output::<i32>();
362+
assert!(result1.is_ok());
363+
assert!(result2.is_ok());
364+
assert!(Arc::ptr_eq(result1.as_ref().unwrap(), result2.as_ref().unwrap()));
365+
}
366+
367+
#[test]
368+
fn test_schema_for_input_rejects_array() {
369+
let result = schema_for_input::<Vec<i32>>();
370+
assert!(result.is_err());
371+
}
372+
373+
#[test]
374+
fn test_schema_for_output_accepts_unit() {
375+
let result = schema_for_output::<()>();
376+
assert!(result.is_ok());
377+
}
378+
340379
#[test]
341380
fn test_schema_for_output_accepts_object() {
342381
let result = schema_for_output::<TestObject>();

0 commit comments

Comments
 (0)