Skip to content

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

test(core): cover optional parameter contract mismatches

Steven Enamakel05a9042dab19
diff --git a/crates/openhuman-core/src/core/all_bound_controller_tests.rs b/crates/openhuman-core/src/core/all_bound_controller_tests.rs
index 4a69e1d838..f25742e1c8 100644
--- a/crates/openhuman-core/src/core/all_bound_controller_tests.rs
+++ b/crates/openhuman-core/src/core/all_bound_controller_tests.rs
@@ -323,9 +323,11 @@ fn production_registry_binds_mcp_registry_get_to_its_declared_parser() {
"openhuman.mcp_clients_registry_get"
);
let contract = crate::mcp::registry::schemas::registry_get_parameter_contract();
- crate::core::all::verify_parameter_contracts(std::slice::from_ref(entry),
- std::slice::from_ref(&contract))
- .expect("raw MCP entry matches its independent contract and bound decoder");
+ crate::core::all::verify_parameter_contracts(
+ std::slice::from_ref(entry),
+ std::slice::from_ref(&contract),
+ )
+ .expect("raw MCP entry matches its independent contract and bound decoder");
assert!(entry.schema.inputs.iter().all(|field| field.required));
for remove in [true, false] {
@@ -374,9 +376,11 @@ fn production_registry_binds_computer_status_to_its_declared_parser() {
);
assert_eq!(entry.rpc_method_name(), "openhuman.modules_computer_status");
let contract = crate::modules::schemas::computer_status_parameter_contract();
- crate::core::all::verify_parameter_contracts(std::slice::from_ref(entry),
- std::slice::from_ref(&contract))
- .expect("raw Modules entry matches its independent contract and bound decoder");
+ crate::core::all::verify_parameter_contracts(
+ std::slice::from_ref(entry),
+ std::slice::from_ref(&contract),
+ )
+ .expect("raw Modules entry matches its independent contract and bound decoder");
// Runtime parsing intentionally keeps its permissive false default for
// non-boolean inputs; these maps are parser cases, not schema examples.
@@ -510,15 +514,25 @@ fn production_registry_binds_every_core_voice_controller_to_its_parser() {
"voice.live_settings_set",
"voice.live_test_provider",
];
- assert_eq!(entries.len(), expected_methods.len(), "complete core voice inventory");
+ assert_eq!(
+ entries.len(),
+ expected_methods.len(),
+ "complete core voice inventory"
+ );
assert!(grouped.iter().all(|row| row.group == DomainGroup::Voice));
assert_eq!(
- entries.iter().map(|entry| entry.schema.method_name()).collect::<Vec<_>>(),
+ entries
+ .iter()
+ .map(|entry| entry.schema.method_name())
+ .collect::<Vec<_>>(),
expected_methods,
"independent core voice inventory and registry order"
);
assert_eq!(
- contracts.iter().map(|contract| contract.method).collect::<Vec<_>>(),
+ contracts
+ .iter()
+ .map(|contract| contract.method)
+ .collect::<Vec<_>>(),
expected_methods,
"authored parameter fixtures cover the complete ordered voice inventory"
);
diff --git a/crates/openhuman-core/src/core/schema_test_support_tests.rs b/crates/openhuman-core/src/core/schema_test_support_tests.rs
index 05dfa1f653..c912be1d89 100644
--- a/crates/openhuman-core/src/core/schema_test_support_tests.rs
+++ b/crates/openhuman-core/src/core/schema_test_support_tests.rs
@@ -18,16 +18,24 @@ fn legacy_handler(_ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerF
fn fixture() -> (ControllerEntry, ControllerParamContract) {
let schema = ControllerSchema {
- namespace: "fixture",
- function: "read",
- description: "Read a fixture.",
- inputs: vec![crate::core::FieldSchema {
+ 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![],
+ },
+ crate::core::FieldSchema {
+ name: "label",
+ ty: crate::core::TypeSchema::String,
+ comment: "Optional fixture label.",
+ required: false,
+ },
+ ],
+ outputs: vec![],
};
let controller = ControllerEntry::bound(BoundRegisteredController::typed(
schema,
@@ -37,8 +45,11 @@ fn fixture() -> (ControllerEntry, ControllerParamContract) {
let contract = ControllerParamContract {
method: "fixture.read",
required: &["id"],
- optional: &[],
- examples: vec![serde_json::json!({"id":"example"})],
+ optional: &["label"],
+ examples: vec![
+ serde_json::json!({"id":"example"}),
+ serde_json::json!({"id":"example","label":"fixture"}),
+ ],
};
(controller, contract)
}
@@ -82,9 +93,35 @@ fn contract_rejects_each_removed_or_optional_required_declaration() {
} else {
broken.schema.inputs[0].required = false;
}
- assert!(verify_parameter_contracts(&[broken], std::slice::from_ref(&contract))
- .unwrap_err()
- .contains("required inputs mismatch"));
+ assert!(
+ verify_parameter_contracts(&[broken], std::slice::from_ref(&contract))
+ .unwrap_err()
+ .contains("required inputs mismatch")
+ );
+ }
+}
+
+#[test]
+fn contract_rejects_removed_or_required_optional_declarations() {
+ let (controller, contract) = fixture();
+ for remove in [true, false] {
+ let mut broken = controller.clone();
+ if remove {
+ broken.schema.inputs.retain(|field| field.name != "label");
+ } else {
+ broken
+ .schema
+ .inputs
+ .iter_mut()
+ .find(|field| field.name == "label")
+ .expect("independent optional field is present")
+ .required = true;
+ }
+ assert!(
+ verify_parameter_contracts(&[broken], std::slice::from_ref(&contract))
+ .unwrap_err()
+ .contains("optional inputs mismatch")
+ );
}
}
diff --git a/crates/openhuman-core/src/modules/schemas.rs b/crates/openhuman-core/src/modules/schemas.rs
index 846f41fd09..fc9df81a61 100644
--- a/crates/openhuman-core/src/modules/schemas.rs
+++ b/crates/openhuman-core/src/modules/schemas.rs
@@ -376,4 +376,3 @@ pub(crate) fn computer_status_parameter_contract() -> crate::core::all::Controll
],
}
}
-
diff --git a/crates/openhuman-core/src/voice/live/schemas_tests.rs b/crates/openhuman-core/src/voice/live/schemas_tests.rs
index 3b60815a1a..398c2494d9 100644
--- a/crates/openhuman-core/src/voice/live/schemas_tests.rs
+++ b/crates/openhuman-core/src/voice/live/schemas_tests.rs
@@ -40,7 +40,10 @@ fn live_legacy_catalog_keeps_private_handler_identities_and_schema_fixtures() {
}
let contracts = crate::voice::parameter_contracts();
- for contract in contracts.iter().filter(|contract| contract.method.contains(".live_")) {
+ for contract in contracts
+ .iter()
+ .filter(|contract| contract.method.contains(".live_"))
+ {
let controller = controllers
.iter()
.find(|controller| controller.schema.method_name() == contract.method)
diff --git a/crates/openhuman-core/src/voice/schemas_tests.rs b/crates/openhuman-core/src/voice/schemas_tests.rs
index d52db1476e..22479e307f 100644
--- a/crates/openhuman-core/src/voice/schemas_tests.rs
+++ b/crates/openhuman-core/src/voice/schemas_tests.rs
@@ -33,7 +33,10 @@ fn legacy_voice_catalog_keeps_its_handlers_and_schema_fixtures() {
}
let contracts = crate::voice::parameter_contracts();
- for contract in contracts.iter().filter(|contract| !contract.method.contains(".live_")) {
+ for contract in contracts
+ .iter()
+ .filter(|contract| !contract.method.contains(".live_"))
+ {
let controller = controllers
.iter()
.find(|controller| controller.schema.method_name() == contract.method)