Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(core): add schema test support tests

Steven Enamakelb92fc5c09471
diff --git a/crates/openhuman-core/src/core/schema_test_support_tests.rs b/crates/openhuman-core/src/core/schema_test_support_tests.rs
new file mode 100644
index 0000000000..ca8da26eab
--- /dev/null
+++ b/crates/openhuman-core/src/core/schema_test_support_tests.rs
@@ -0,0 +1,85 @@
+use super::*;
+
+fn handler(_ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
+ panic!("the pure contract runner must never execute handlers");
+}
+
+fn other_handler(_ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {
+ panic!("the pure contract runner must never execute handlers");
+}
+
+fn fixture() -> (RegisteredController, ControllerParamContract) {
+ let controller = RegisteredController {
+ schema: ControllerSchema {
+ namespace: "fixture",
+ function: "read",
+ description: "Read a fixture.",
+ inputs: vec![crate::core::FieldSchema {
+ name: "id", ty: crate::core::TypeSchema::String,
+ comment: "Fixture identifier.", required: true,
+ }],
+ outputs: vec![],
+ },
+ handler,
+ };
+ let contract = ControllerParamContract {
+ method: "fixture.read", required: &["id"], handler,
+ examples: vec![serde_json::json!({"id":"example"})],
+ parse: |params| match params.get("id").and_then(Value::as_str) {
+ Some("example") => Ok(()),
+ _ => Err("fixture id must be example".into()),
+ },
+ };
+ (controller, contract)
+}
+
+#[test]
+fn explicit_example_reaches_pure_parser_without_executing_handler() {
+ let (controller, contract) = fixture();
+ verify_parameter_contracts(&[controller], &[contract]).unwrap();
+}
+
+#[test]
+fn contract_inventory_rejects_missing_extra_duplicate_and_empty_rows() {
+ let (controller, contract) = fixture();
+ assert!(verify_parameter_contracts(std::slice::from_ref(&controller), &[])
+ .unwrap_err().contains("missing contract"));
+ assert!(verify_parameter_contracts(&[], std::slice::from_ref(&contract))
+ .unwrap_err().contains("extra contract"));
+ assert!(verify_parameter_contracts(&[controller], &[contract.clone(), contract])
+ .unwrap_err().contains("duplicate contract"));
+ assert!(verify_parameter_contracts(&[], &[]).unwrap_err().contains("empty"));
+}
+
+#[test]
+fn contract_rejects_each_removed_or_optional_required_declaration() {
+ let (controller, contract) = fixture();
+ for remove in [true, false] {
+ let mut broken = controller.clone();
+ if remove { broken.schema.inputs.clear(); }
+ else { broken.schema.inputs[0].required = false; }
+ assert!(verify_parameter_contracts(&[broken], std::slice::from_ref(&contract))
+ .unwrap_err().contains("required inputs mismatch"));
+ }
+}
+
+#[test]
+fn callback_identity_and_explicit_example_failures_are_not_hidden() {
+ let (controller, contract) = fixture();
+ let mut broken = contract.clone();
+ broken.handler = other_handler;
+ assert!(verify_parameter_contracts(std::slice::from_ref(&controller), &[broken])
+ .unwrap_err().contains("handler identity"));
+ let mut broken = contract.clone();
+ broken.examples.clear();
+ assert!(verify_parameter_contracts(std::slice::from_ref(&controller), &[broken])
+ .unwrap_err().contains("no examples"));
+ let mut broken = contract.clone();
+ broken.examples = vec![serde_json::json!({"id":"wrong"})];
+ assert!(verify_parameter_contracts(std::slice::from_ref(&controller), &[broken])
+ .unwrap_err().contains("pure parser"));
+ let mut broken = contract;
+ broken.examples = vec![serde_json::json!({"id":7})];
+ assert!(verify_parameter_contracts(&[controller], &[broken])
+ .unwrap_err().contains("schema rejects example"));
+}