Skip to content

Commit 3b2eec8

Browse files
karthiknadigCopilot
andcommitted
test: prove dispatch recovery after invalid envelopes (Refs #532)
Exercise valid requests and notifications after rejection checks, proving handler wiring and exact ID/parameter preservation without adding errors. Covers previously unexecuted negative-test callbacks without changing production behavior or coverage budgets. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent bbdb481 commit 3b2eec8

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

‎crates/pet-jsonrpc/src/server.rs‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,30 @@ mod tests {
273273
})
274274
}
275275

276+
fn assert_valid_dispatch_after_invalid_input(
277+
handlers: &HandlersKeyedByMethodName<TestContext>,
278+
context: &TestContext,
279+
) {
280+
assert!(context.request.lock().unwrap().is_none());
281+
assert!(context.notification.lock().unwrap().is_none());
282+
let error_count = context.errors.lock().unwrap().len();
283+
handlers.handle_request(
284+
json!({"jsonrpc": "2.0", "id": "after-invalid", "method": "method", "params": [42]}),
285+
);
286+
assert_eq!(
287+
context.request.lock().unwrap().take(),
288+
Some((RequestId::String("after-invalid".into()), json!([42])))
289+
);
290+
assert!(context.notification.lock().unwrap().is_none());
291+
handlers.handle_request(json!({"jsonrpc": "2.0", "method": "method", "params": [7]}));
292+
assert_eq!(
293+
context.notification.lock().unwrap().take(),
294+
Some(json!([7]))
295+
);
296+
assert!(context.request.lock().unwrap().is_none());
297+
assert_eq!(context.errors.lock().unwrap().len(), error_count);
298+
}
299+
276300
fn supported_request_id_values() -> [Value; 10] {
277301
[
278302
json!("request-1"),
@@ -392,6 +416,7 @@ mod tests {
392416
context.errors.lock().unwrap().as_slice(),
393417
vec![(None, -32600, "Invalid JSONRPC request".to_string()); 6]
394418
);
419+
assert_valid_dispatch_after_invalid_input(&handlers, &context);
395420
}
396421

397422
#[test]
@@ -422,6 +447,7 @@ mod tests {
422447
context.errors.lock().unwrap().as_slice(),
423448
vec![(None, -32600, "Invalid JSONRPC request".to_string()); 6]
424449
);
450+
assert_valid_dispatch_after_invalid_input(&handlers, &context);
425451
}
426452

427453
#[test]
@@ -449,12 +475,21 @@ mod tests {
449475
"Invalid JSONRPC request".to_string()
450476
),
451477
(
452-
Some(id),
478+
Some(id.clone()),
453479
-32602,
454480
"JSONRPC params must be an object or array".to_string()
455481
)
456482
]
457483
);
484+
handlers.handle_request(
485+
json!({"jsonrpc": "2.0", "id": value, "method": "method", "params": [42]}),
486+
);
487+
assert_eq!(
488+
context.request.lock().unwrap().take(),
489+
Some((id, json!([42])))
490+
);
491+
assert!(context.notification.lock().unwrap().is_none());
492+
assert_eq!(context.errors.lock().unwrap().len(), 2);
458493
}
459494
}
460495

@@ -527,6 +562,7 @@ mod tests {
527562
(Some(2.into()), -32602)
528563
]
529564
);
565+
assert_valid_dispatch_after_invalid_input(&handlers, &context);
530566
}
531567

532568
#[test]

0 commit comments

Comments
 (0)