sausage-plugin part 2: import! with typed clients (sausage_interface::client_rs), TCP endpoints with rpc.endpoint, examples

Part 1 fixes: complete stdout writes, buffered stdin, Rust type names
in schemas, enum variant docs, -32603 for serde errors in handlers,
crate docs and modules. End-to-end check of a generated consumer through
a fake core.
This commit is contained in:
2026-10-23 00:35:45 +01:00
parent ae1cb4cc99
commit 8d3c163992
42 changed files with 3020 additions and 856 deletions
+34 -4
View File
@@ -25,8 +25,12 @@ enum Choice {
Second,
}
struct Plugin;
#[rpc]
#[rpc(endpoints(control=Plugin))]
impl Plugin {
/// Return the same named object without a contract change.
fn identity(&self, p: Add) -> Result<Add> {
Ok(p)
}
/// Choose the first value.
fn choice(&self) -> Result<Choice> {
Ok(Choice::First)
@@ -45,6 +49,23 @@ impl Plugin {
#[test]
fn discovery_and_dispatch() {
let doc = Plugin.discover();
assert!(
doc["x-sausage-endpoints"]["control"]["methods"]
.as_array()
.unwrap()
.iter()
.any(|m| m["name"] == "add")
);
assert!(doc["components"]["schemas"].get("AddResult").is_none());
assert_eq!(
doc["methods"]
.as_array()
.unwrap()
.iter()
.find(|m| m["name"] == "identity")
.unwrap()["result"]["schema"]["$ref"],
"#/components/schemas/Add"
);
assert!(
doc["components"]["schemas"]["Defaulted"]
.get("required")
@@ -55,8 +76,8 @@ fn discovery_and_dispatch() {
json!(["value"])
);
assert_eq!(
doc["components"]["schemas"]["ChoiceResult"]["enum"],
json!(["First", "Second"])
doc["components"]["schemas"]["Choice"]["oneOf"][0]["description"],
json!("The first choice.")
);
let add = doc["methods"]
.as_array()
@@ -76,7 +97,16 @@ fn discovery_and_dispatch() {
.unwrap(),
5
);
assert!(sausage_plugin::block_on(Plugin.dispatch("add", json!({}), &Ctx::default())).is_err());
assert_eq!(
sausage_plugin::block_on(Plugin.dispatch("add", json!({}), &Ctx::default()))
.unwrap_err()
.code,
-32602
);
let internal: sausage_plugin::Error = sausage_plugin::serde_json::from_str::<i32>("bad")
.unwrap_err()
.into();
assert_eq!(internal.code, -32603);
}
#[sausage_plugin::test]
async fn missing_core_fails_without_wait() {