Keep -32602 and existing validation order; tell callers to send the object itself. Cover host routing, stdout fast paths, SDK calls and generated dispatch. Card: SAU-317
This commit is contained in:
@@ -116,6 +116,53 @@ fn discovery_and_dispatch() {
|
||||
.into();
|
||||
assert_eq!(internal.code, -32603);
|
||||
}
|
||||
#[sausage_plugin::test]
|
||||
async fn params_must_be_objects() {
|
||||
for (params, kind) in [
|
||||
(json!("{\"a\":2,\"b\":3}"), "a string"),
|
||||
(json!([]), "an array"),
|
||||
(json!(42), "a number"),
|
||||
(json!(null), "null"),
|
||||
(json!(true), "a boolean"),
|
||||
] {
|
||||
let message = format!(
|
||||
"params must be a JSON object, got {kind}. Send the object itself, not a JSON-encoded string."
|
||||
);
|
||||
let outgoing = sausage_plugin::call("plugin.add", params.clone())
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert_eq!(outgoing.code, -32602);
|
||||
assert_eq!(outgoing.message, message);
|
||||
for method in ["add", "choice", "unknown"] {
|
||||
let incoming = Plugin
|
||||
.dispatch(method, params.clone(), &Ctx::default())
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert_eq!(incoming.code, -32602);
|
||||
assert_eq!(incoming.message, message);
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
Plugin
|
||||
.dispatch("add", json!({"a":2,"b":3}), &Ctx::default())
|
||||
.await
|
||||
.unwrap(),
|
||||
5
|
||||
);
|
||||
assert_eq!(
|
||||
Plugin
|
||||
.dispatch("defaults", json!({}), &Ctx::default())
|
||||
.await
|
||||
.unwrap(),
|
||||
json!({"value":""})
|
||||
);
|
||||
// An object reaches transport validation rather than the params rejection.
|
||||
let outgoing = sausage_plugin::call("plugin.add", json!({"a":2,"b":3}))
|
||||
.await
|
||||
.unwrap_err();
|
||||
assert!(outgoing.message.contains("no core transport"));
|
||||
}
|
||||
|
||||
#[sausage_plugin::test]
|
||||
async fn missing_core_fails_without_wait() {
|
||||
assert!(
|
||||
|
||||
Reference in New Issue
Block a user