The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(core): consolidate bound wire contract tests
Steven Enamakel642ea4ed60cb
diff --git a/crates/openhuman-core/src/core/all_app_state_controller_tests.rs b/crates/openhuman-core/src/core/all_app_state_controller_tests.rsindex 80ee69dedc..4814d250ae 100644--- a/crates/openhuman-core/src/core/all_app_state_controller_tests.rs+++ b/crates/openhuman-core/src/core/all_app_state_controller_tests.rs@@ -1,56 +1,53 @@use super::*;-use crate::core::TypeSchema;#[test]fn raw_app_state_desktop_registry_matches_its_independent_contract() {+ let contract = super::registry_test_support::BoundFamilyWireContract {+ namespaces: &["app_state"],+ group: DomainGroup::Desktop,+ methods: &[+ ("app_state.snapshot", "openhuman.app_state_snapshot"),+ (+ "app_state.update_local_state",+ "openhuman.app_state_update_local_state",+ ),+ ],+ };+ super::registry_test_support::verify_family_contract(+ registry(),+ internal_registry(),+ &contract,+ &crate::desktop::app_state::app_state_parameter_contracts(),+ )+ .expect("raw AppState entries retain their ordered wire contracts");let entries: Vec<_> = registry().iter().filter(|row| row.controller.schema.namespace == "app_state").collect();- let methods = ["app_state.snapshot", "app_state.update_local_state"];- let contracts = crate::desktop::app_state::app_state_parameter_contracts();-+ let result = [("result", TypeSchema::Json, true)];assert_eq!(- entries.len(),- methods.len(),- "complete raw app_state inventory"+ crate::core::all::verify_wire_fields(&entries[0].controller.schema.inputs, &[]),+ Ok(()));assert_eq!(- entries- .iter()- .map(|row| row.controller.schema.method_name())- .collect::<Vec<_>>(),- methods,- "app_state registration order is a wire contract"+ crate::core::all::verify_wire_fields(&entries[0].controller.schema.outputs, &result),+ Ok(()));- assert!(entries.iter().all(|row| row.group == DomainGroup::Desktop));- assert!(internal_registry()- .iter()- .all(|row| row.controller.schema.namespace != "app_state"));assert_eq!(- entries- .iter()- .map(|row| row.controller.rpc_method_name())- .collect::<Vec<_>>(),- [- "openhuman.app_state_snapshot",- "openhuman.app_state_update_local_state"- ]+ crate::core::all::verify_wire_fields(+ &entries[1].controller.schema.inputs,+ &[+ ("encryptionKey", TypeSchema::Json, false),+ ("onboardingTasks", TypeSchema::Json, false),+ ("keyringConsent", TypeSchema::Json, false),+ ]+ ),+ Ok(())+ );+ assert_eq!(+ crate::core::all::verify_wire_fields(&entries[1].controller.schema.outputs, &result),+ Ok(()));- for entry in &entries {- let outputs = &entry.controller.schema.outputs;- assert_eq!(outputs.len(), 1);- assert_eq!(outputs[0].name, "result");- assert!(outputs[0].required);- assert!(matches!(&outputs[0].ty, TypeSchema::Json));- }-- let entries: Vec<_> = entries- .into_iter()- .map(|row| row.controller.clone())- .collect();- crate::core::all::verify_parameter_contracts(&entries, &contracts)- .expect("raw app_state entries use their declared schemas and runtime decoders");}#[test]diff --git a/crates/openhuman-core/src/core/all_approval_controller_tests.rs b/crates/openhuman-core/src/core/all_approval_controller_tests.rsindex d1bcf15bee..6a5c64fdb1 100644--- a/crates/openhuman-core/src/core/all_approval_controller_tests.rs+++ b/crates/openhuman-core/src/core/all_approval_controller_tests.rs@@ -1,13 +1,93 @@use super::*;-use crate::core::TypeSchema;use serde_json::json;#[test]fn raw_approval_security_registry_matches_its_independent_contract() {- let grouped: Vec<_> = registry()+ let contract = super::registry_test_support::BoundFamilyWireContract {+ namespaces: &["approval"],+ group: DomainGroup::Security,+ methods: &[+ ("approval.list_pending", "openhuman.approval_list_pending"),+ (+ "approval.list_recent_decisions",+ "openhuman.approval_list_recent_decisions",+ ),+ ("approval.decide", "openhuman.approval_decide"),+ (+ "approval.get_gate_state",+ "openhuman.approval_get_gate_state",+ ),+ (+ "approval.preauthorize_flow",+ "openhuman.approval_preauthorize_flow",+ ),+ ],+ };+ super::registry_test_support::verify_family_contract(+ registry(),+ internal_registry(),+ &contract,+ &crate::security::approval::approval_parameter_contracts(),+ )+ .expect("raw Approval entries retain their ordered wire contracts");+ let entries: Vec<_> = registry().iter().filter(|row| row.controller.schema.namespace == "approval").collect();+ use TypeSchema::{Array, Option, Ref, String, U64};+ let fields = [+ (+ vec![("agent_id", Option(Box::new(String)), false)],+ vec![("pending", Array(Box::new(Ref("PendingApproval"))), true)],+ ),+ (+ vec![("limit", Option(Box::new(U64)), false)],+ vec![(+ "decisions",+ Array(Box::new(Ref("ApprovalAuditEntry"))),+ true,+ )],+ ),+ (+ vec![+ ("request_id", String, true),+ ("decision", String, true),+ ("agent_id", Option(Box::new(String)), false),+ ],+ vec![("decided", Ref("PendingApproval"), true)],+ ),+ (vec![], vec![("state", Ref("ApprovalGateBootState"), true)]),+ (+ vec![+ ("flow_id", String, true),+ ("tool_names", Array(Box::new(String)), true),+ ],+ vec![("result", Ref("FlowPreauthorizationResult"), true)],+ ),+ ];+ for (row, (inputs, outputs)) in entries.iter().zip(fields) {+ assert_eq!(+ crate::core::all::verify_wire_fields(&row.controller.schema.inputs, &inputs),+ Ok(()),+ "{} inputs",+ row.controller.schema.method_name()+ );+ assert_eq!(+ crate::core::all::verify_wire_fields(&row.controller.schema.outputs, &outputs),+ Ok(()),+ "{} outputs",+ row.controller.schema.method_name()+ );+ }+}++#[test]+fn raw_approval_decoders_keep_permissive_and_strict_wire_behavior() {+ let entries: Vec<_> = registry()+ .iter()+ .filter(|row| row.controller.schema.namespace == "approval")+ .map(|row| row.controller.clone())+ .collect();let methods = ["approval.list_pending","approval.list_recent_decisions",@@ -15,133 +95,13 @@ fn raw_approval_security_registry_matches_its_independent_contract() {"approval.get_gate_state","approval.preauthorize_flow",];- let rpc_methods = [- "openhuman.approval_list_pending",- "openhuman.approval_list_recent_decisions",- "openhuman.approval_decide",- "openhuman.approval_get_gate_state",- "openhuman.approval_preauthorize_flow",- ];- let contracts = crate::security::approval::approval_parameter_contracts();-- assert_eq!(- grouped.len(),- methods.len(),- "complete raw approval inventory"- );assert_eq!(- grouped+ entries.iter()- .map(|row| row.controller.schema.method_name())+ .map(|entry| entry.schema.method_name()).collect::<Vec<_>>(),- methods,- "independent approval method inventory and order"+ methods);- assert!(grouped.iter().all(|row| row.group == DomainGroup::Security));- assert!(internal_registry()- .iter()- .all(|row| row.controller.schema.namespace != "approval"));- assert_eq!(- grouped- .iter()- .map(|row| row.controller.rpc_method_name())- .collect::<Vec<_>>(),- rpc_methods- );-- let entries: Vec<_> = grouped.iter().map(|row| row.controller.clone()).collect();- assert_eq!(- contracts.iter().map(|row| row.method).collect::<Vec<_>>(),- methods,- "independent fixtures enumerate every method in registration order"- );- crate::core::all::verify_parameter_contracts(&entries, &contracts)- .expect("raw approval entries use their declared schemas and runtime decoders");-- let schemas: Vec<_> = entries.iter().map(|entry| &entry.schema).collect();- for (schema, expected) in schemas.iter().zip([- ["agent_id"].as_slice(),- ["limit"].as_slice(),- ["request_id", "decision", "agent_id"].as_slice(),- [].as_slice(),- ["flow_id", "tool_names"].as_slice(),- ]) {- let actual: Vec<_> = schema.inputs.iter().map(|field| field.name).collect();- assert_eq!(- actual.as_slice(),- expected,- "{}.{} input order",- schema.namespace,- schema.function- );- }- assert_input(- schemas[0],- "agent_id",- false,- |ty| matches!(ty, TypeSchema::Option(inner) if matches!(inner.as_ref(), TypeSchema::String)),- );- assert_eq!(schemas[1].inputs.len(), 1);- assert_input(- schemas[1],- "limit",- false,- |ty| matches!(ty, TypeSchema::Option(inner) if matches!(inner.as_ref(), TypeSchema::U64)),- );- assert_eq!(schemas[2].inputs.len(), 3);- assert_input(schemas[2], "request_id", true, |ty| {- matches!(ty, TypeSchema::String)- });- assert_input(schemas[2], "decision", true, |ty| {- matches!(ty, TypeSchema::String)- });- assert_input(- schemas[2],- "agent_id",- false,- |ty| matches!(ty, TypeSchema::Option(inner) if matches!(inner.as_ref(), TypeSchema::String)),- );- assert!(schemas[3].inputs.is_empty());- assert_eq!(schemas[4].inputs.len(), 2);- assert_input(schemas[4], "flow_id", true, |ty| {- matches!(ty, TypeSchema::String)- });- assert_input(- schemas[4],- "tool_names",- true,- |ty| matches!(ty, TypeSchema::Array(inner) if matches!(inner.as_ref(), TypeSchema::String)),- );-- let outputs = [- ("pending", "PendingApproval", true),- ("decisions", "ApprovalAuditEntry", true),- ("decided", "PendingApproval", true),- ("state", "ApprovalGateBootState", true),- ("result", "FlowPreauthorizationResult", true),- ];- for (index, (schema, (name, reference, required))) in schemas.iter().zip(outputs).enumerate() {- assert_eq!(- schema.outputs.len(),- 1,- "{}.{} output count",- schema.namespace,- schema.function- );- let output = &schema.outputs[0];- assert_eq!(output.name, name);- assert_eq!(output.required, required);- if index < 2 {- assert!(matches!(- &output.ty,- TypeSchema::Array(inner)- if matches!(inner.as_ref(), TypeSchema::Ref(actual) if *actual == reference)- ));- } else {- assert!(matches!(&output.ty, TypeSchema::Ref(actual) if *actual == reference));- }- }-for (entry, extra) in entries.iter().zip([json!({"agent_id": " raw agent ", "unknown": {"nested": [1, null]}}),json!({"limit": 0, "unknown": true}),@@ -172,32 +132,3 @@ fn raw_approval_security_registry_matches_its_independent_contract() {])).expect_err("bound schema decoder enforces array item wire types");}--fn assert_input(- schema: &crate::core::ControllerSchema,- name: &str,- required: bool,- type_matches: impl FnOnce(&TypeSchema) -> bool,-) {- let field = schema- .inputs- .iter()- .find(|field| field.name == name)- .unwrap_or_else(|| {- panic!(- "{}.{} missing input {name}",- schema.namespace, schema.function- )- });- assert_eq!(- field.required, required,- "{}.{} {name}",- schema.namespace, schema.function- );- assert!(- type_matches(&field.ty),- "{}.{} input {name} has wrong type",- schema.namespace,- schema.function- );-}diff --git a/crates/openhuman-core/src/core/all_bound_controller_tests.rs b/crates/openhuman-core/src/core/all_bound_controller_tests.rsindex def1c176d9..3008a63036 100644--- a/crates/openhuman-core/src/core/all_bound_controller_tests.rs+++ b/crates/openhuman-core/src/core/all_bound_controller_tests.rs@@ -700,3 +700,9 @@ mod devices_controller_tests;#[path = "all_approval_controller_tests.rs"]mod approval_controller_tests;++#[path = "all_bound_registry_test_support.rs"]+mod registry_test_support;++#[path = "all_bound_registry_contract_tests.rs"]+mod registry_contract_tests;diff --git a/crates/openhuman-core/src/core/all_bound_registry_contract_tests.rs b/crates/openhuman-core/src/core/all_bound_registry_contract_tests.rsnew file mode 100644index 0000000000..06b6ac7299--- /dev/null+++ b/crates/openhuman-core/src/core/all_bound_registry_contract_tests.rs@@ -0,0 +1,99 @@+use super::registry_test_support::{verify_family_contract, BoundFamilyWireContract};+use super::*;++#[test]+fn family_verifier_rejects_group_visibility_and_inventory_mutations() {+ use crate::core::runtime::DispatchCtx;++ fn parse(params: Map<String, Value>) -> Result<String, String> {+ params+ .get("id")+ .and_then(Value::as_str)+ .map(str::to_owned)+ .ok_or_else(|| "missing id".into())+ }+ fn run(_ctx: DispatchCtx, _parsed: String) -> ControllerFuture {+ Box::pin(async { Ok(Value::Null) })+ }+ fn row(group: DomainGroup) -> GroupedController {+ GroupedController {+ group,+ controller: ControllerEntry::bound(BoundRegisteredController::typed(+ ControllerSchema {+ namespace: "fixture",+ function: "read",+ description: "Read one fixture.",+ inputs: vec![FieldSchema {+ name: "id",+ ty: TypeSchema::String,+ comment: "Fixture id.",+ required: true,+ }],+ outputs: vec![],+ },+ parse,+ run,+ )),+ }+ }++ let contract = BoundFamilyWireContract {+ namespaces: &["fixture"],+ group: DomainGroup::Platform,+ methods: &[("fixture.read", "openhuman.fixture_read")],+ };+ let fixtures = [ControllerParamContract {+ method: "fixture.read",+ required: &["id"],+ optional: &[],+ examples: vec![serde_json::json!({"id":"one"})],+ }];+ let good = row(DomainGroup::Platform);+ assert!(verify_family_contract(std::slice::from_ref(&good), &[], &contract, &fixtures).is_ok());+ assert!(+ verify_family_contract(&[row(DomainGroup::Security)], &[], &contract, &fixtures)+ .unwrap_err()+ .contains("wrong domain group")+ );+ assert!(verify_family_contract(+ std::slice::from_ref(&good),+ std::slice::from_ref(&good),+ &contract,+ &fixtures+ )+ .unwrap_err()+ .contains("internal registry"));++ for (methods, message) in [+ (+ &[("fixture.other", "openhuman.fixture_other")][..],+ "method inventory",+ ),+ (+ &[("fixture.read", "openhuman.fixture_other")][..],+ "RPC inventory",+ ),+ ] {+ let mutated = BoundFamilyWireContract {+ namespaces: &["fixture"],+ group: DomainGroup::Platform,+ methods,+ };+ assert!(+ verify_family_contract(std::slice::from_ref(&good), &[], &mutated, &fixtures)+ .unwrap_err()+ .contains(message)+ );+ }+ let wrong_fixture = [ControllerParamContract {+ method: "fixture.other",+ required: &["id"],+ optional: &[],+ examples: vec![serde_json::json!({"id":"one"})],+ }];+ assert!(+ verify_family_contract(std::slice::from_ref(&good), &[], &contract, &wrong_fixture)+ .unwrap_err()+ .contains("fixture inventory/order mismatch")+ );+}diff --git a/crates/openhuman-core/src/core/all_bound_registry_test_support.rs b/crates/openhuman-core/src/core/all_bound_registry_test_support.rsnew file mode 100644index 0000000000..c3a742ea3a--- /dev/null+++ b/crates/openhuman-core/src/core/all_bound_registry_test_support.rs@@ -0,0 +1,79 @@+use super::*;++pub(super) struct BoundFamilyWireContract<'a> {+ pub namespaces: &'a [&'a str],+ pub group: DomainGroup,+ pub methods: &'a [(&'a str, &'a str)],+}++pub(super) fn verify_family_contract(+ public: &[GroupedController],+ internal: &[GroupedController],+ contract: &BoundFamilyWireContract<'_>,+ fixtures: &[ControllerParamContract],+) -> Result<(), String> {+ use std::collections::BTreeSet;++ let namespaces: BTreeSet<_> = contract.namespaces.iter().copied().collect();+ if namespaces.is_empty() || namespaces.len() != contract.namespaces.len() {+ return Err("empty or duplicate namespace contract".into());+ }+ let rows: Vec<_> = public+ .iter()+ .filter(|row| namespaces.contains(row.controller.schema.namespace))+ .collect();+ if internal+ .iter()+ .any(|row| namespaces.contains(row.controller.schema.namespace))+ {+ return Err(format!(+ "{:?} leaked into the internal registry",+ contract.namespaces+ ));+ }+ if rows.is_empty() {+ return Err(format!("no public rows for {:?}", contract.namespaces));+ }+ if rows.iter().any(|row| row.group != contract.group) {+ return Err(format!(+ "{:?} registered under the wrong domain group",+ contract.namespaces+ ));+ }+ let actual_methods: Vec<_> = rows+ .iter()+ .map(|row| row.controller.schema.method_name())+ .collect();+ let expected_methods: Vec<_> = contract.methods.iter().map(|(method, _)| *method).collect();+ if actual_methods+ .iter()+ .map(String::as_str)+ .collect::<Vec<_>>()+ != expected_methods+ {+ return Err(format!(+ "{:?} method inventory/order mismatch: expected {expected_methods:?}, got {actual_methods:?}",+ contract.namespaces+ ));+ }+ let actual_rpc: Vec<_> = rows+ .iter()+ .map(|row| row.controller.rpc_method_name())+ .collect();+ let expected_rpc: Vec<_> = contract.methods.iter().map(|(_, rpc)| *rpc).collect();+ if actual_rpc.iter().map(String::as_str).collect::<Vec<_>>() != expected_rpc {+ return Err(format!(+ "{:?} RPC inventory/order mismatch: expected {expected_rpc:?}, got {actual_rpc:?}",+ contract.namespaces+ ));+ }+ let fixture_methods: Vec<_> = fixtures.iter().map(|fixture| fixture.method).collect();+ if fixture_methods != expected_methods {+ return Err(format!(+ "{:?} fixture inventory/order mismatch: expected {expected_methods:?}, got {fixture_methods:?}",+ contract.namespaces+ ));+ }+ let entries: Vec<_> = rows.into_iter().map(|row| row.controller.clone()).collect();+ crate::core::all::verify_parameter_contracts(&entries, fixtures)+}diff --git a/crates/openhuman-core/src/core/all_devices_controller_tests.rs b/crates/openhuman-core/src/core/all_devices_controller_tests.rsindex 0448c8082d..d76909699e 100644--- a/crates/openhuman-core/src/core/all_devices_controller_tests.rs+++ b/crates/openhuman-core/src/core/all_devices_controller_tests.rs@@ -1,115 +1,70 @@use super::*;-use crate::core::TypeSchema;#[test]fn raw_devices_security_registry_matches_its_independent_contract() {+ let contract = super::registry_test_support::BoundFamilyWireContract {+ namespaces: &["devices"],+ group: DomainGroup::Security,+ methods: &[+ ("devices.create_pairing", "openhuman.devices_create_pairing"),+ ("devices.list", "openhuman.devices_list"),+ ("devices.revoke", "openhuman.devices_revoke"),+ ],+ };+ super::registry_test_support::verify_family_contract(+ registry(),+ internal_registry(),+ &contract,+ &crate::security::devices::devices_parameter_contracts(),+ )+ .expect("raw Devices entries retain their ordered wire contracts");let entries: Vec<_> = registry().iter().filter(|row| row.controller.schema.namespace == "devices").collect();- let methods = ["devices.create_pairing", "devices.list", "devices.revoke"];- let contracts = crate::security::devices::devices_parameter_contracts();-+ use TypeSchema::{Array, Bool, Option, Ref, String};+ let create = &entries[0].controller.schema;assert_eq!(- entries.len(),- methods.len(),- "complete raw devices inventory"+ crate::core::all::verify_wire_fields(+ &create.inputs,+ &[("label", Option(Box::new(String)), false)]+ ),+ Ok(()));assert_eq!(- entries- .iter()- .map(|row| row.controller.schema.method_name())- .collect::<Vec<_>>(),- methods,- "device registration order is a wire contract"+ crate::core::all::verify_wire_fields(+ &create.outputs,+ &[+ ("channel_id", String, true),+ ("pairing_token", String, true),+ ("core_pubkey", String, true),+ ("rpc_url", Option(Box::new(String)), false),+ ("expires_at", String, true),+ ]+ ),+ Ok(()));- assert!(entries.iter().all(|row| row.group == DomainGroup::Security));- assert!(internal_registry()- .iter()- .all(|row| row.controller.schema.namespace != "devices"));assert_eq!(- entries- .iter()- .map(|row| row.controller.rpc_method_name())- .collect::<Vec<_>>(),- [- "openhuman.devices_create_pairing",- "openhuman.devices_list",- "openhuman.devices_revoke"- ]+ crate::core::all::verify_wire_fields(+ &entries[1].controller.schema.outputs,+ &[("devices", Array(Box::new(Ref("PairedDevice"))), true)]+ ),+ Ok(()));-- let create = &entries[0].controller.schema;- assert_eq!(create.inputs.len(), 1);- assert_eq!(create.inputs[0].name, "label");- assert!(!create.inputs[0].required);- assert!(matches!(- &create.inputs[0].ty,- TypeSchema::Option(inner) if matches!(inner.as_ref(), TypeSchema::String)- ));assert_eq!(- create- .outputs- .iter()- .map(|field| field.name)- .collect::<Vec<_>>(),- [- "channel_id",- "pairing_token",- "core_pubkey",- "rpc_url",- "expires_at"- ]+ crate::core::all::verify_wire_fields(+ &entries[2].controller.schema.inputs,+ &[("channel_id", String, true)]+ ),+ Ok(())+ );+ assert_eq!(+ crate::core::all::verify_wire_fields(+ &entries[2].controller.schema.outputs,+ &[("success", Bool, true)]+ ),+ Ok(()));- for name in ["channel_id", "pairing_token", "core_pubkey", "expires_at"] {- let field = create- .outputs- .iter()- .find(|field| field.name == name)- .expect("required pairing output is declared");- assert!(field.required, "{name} remains required");- assert!(- matches!(&field.ty, TypeSchema::String),- "{name} remains a string"- );- }- let rpc_url = create- .outputs- .iter()- .find(|field| field.name == "rpc_url")- .expect("optional RPC URL output is declared");- assert!(!rpc_url.required);- assert!(matches!(- &rpc_url.ty,- TypeSchema::Option(inner) if matches!(inner.as_ref(), TypeSchema::String)- ));-- let list = &entries[1].controller.schema;- assert!(list.inputs.is_empty());- assert_eq!(list.outputs.len(), 1);- assert_eq!(list.outputs[0].name, "devices");- assert!(list.outputs[0].required);- assert!(matches!(- &list.outputs[0].ty,- TypeSchema::Array(inner) if matches!(inner.as_ref(), TypeSchema::Ref("PairedDevice"))- ));-- let revoke = &entries[2].controller.schema;- assert_eq!(revoke.inputs.len(), 1);- assert_eq!(revoke.inputs[0].name, "channel_id");- assert!(revoke.inputs[0].required);- assert!(matches!(&revoke.inputs[0].ty, TypeSchema::String));- assert_eq!(revoke.outputs.len(), 1);- assert_eq!(revoke.outputs[0].name, "success");- assert!(revoke.outputs[0].required);- assert!(matches!(&revoke.outputs[0].ty, TypeSchema::Bool));-- let entries: Vec<_> = entries- .into_iter()- .map(|row| row.controller.clone())- .collect();- crate::core::all::verify_parameter_contracts(&entries, &contracts)- .expect("raw devices entries use their declared schemas and runtime decoders");}#[test]diff --git a/crates/openhuman-core/src/core/all_doctor_controller_tests.rs b/crates/openhuman-core/src/core/all_doctor_controller_tests.rsindex 904f7ad147..eb84f338a1 100644--- a/crates/openhuman-core/src/core/all_doctor_controller_tests.rs+++ b/crates/openhuman-core/src/core/all_doctor_controller_tests.rs@@ -1,57 +1,52 @@use super::*;-use crate::core::TypeSchema;#[test]fn raw_doctor_platform_registry_matches_its_independent_contract() {+ let contract = super::registry_test_support::BoundFamilyWireContract {+ namespaces: &["doctor"],+ group: DomainGroup::Platform,+ methods: &[+ ("doctor.report", "openhuman.doctor_report"),+ ("doctor.models", "openhuman.doctor_models"),+ ],+ };+ super::registry_test_support::verify_family_contract(+ registry(),+ internal_registry(),+ &contract,+ &crate::platform::doctor::doctor_parameter_contracts(),+ )+ .expect("raw Doctor entries retain their ordered wire contracts");let entries: Vec<_> = registry().iter().filter(|row| row.controller.schema.namespace == "doctor").collect();- let contracts = crate::platform::doctor::doctor_parameter_contracts();- let methods = ["doctor.report", "doctor.models"];-+ let use_cache = TypeSchema::Option(Box::new(TypeSchema::Bool));assert_eq!(- entries.len(),- methods.len(),- "complete raw Doctor inventory"+ crate::core::all::verify_wire_fields(&entries[0].controller.schema.inputs, &[]),+ Ok(()));assert_eq!(- entries- .iter()- .map(|row| row.controller.schema.method_name())- .collect::<Vec<_>>(),- methods,- "Doctor registration order is a wire contract"+ crate::core::all::verify_wire_fields(+ &entries[0].controller.schema.outputs,+ &[("report", TypeSchema::Ref("DoctorReport"), true)]+ ),+ Ok(()));- assert!(entries.iter().all(|row| row.group == DomainGroup::Platform));- assert!(internal_registry()- .iter()- .all(|row| row.controller.schema.namespace != "doctor"));assert_eq!(- entries- .iter()- .map(|row| row.controller.rpc_method_name())- .collect::<Vec<_>>(),- ["openhuman.doctor_report", "openhuman.doctor_models"]+ crate::core::all::verify_wire_fields(+ &entries[1].controller.schema.inputs,+ &[("use_cache", use_cache, false)]+ ),+ Ok(())+ );+ assert_eq!(+ crate::core::all::verify_wire_fields(+ &entries[1].controller.schema.outputs,+ &[("report", TypeSchema::Ref("ModelProbeReport"), true)]+ ),+ Ok(()));-- for (entry, output_type) in entries.iter().zip(["DoctorReport", "ModelProbeReport"]) {- let outputs = &entry.controller.schema.outputs;- assert_eq!(outputs.len(), 1);- assert_eq!(outputs[0].name, "report");- assert!(outputs[0].required);- assert!(matches!(- &outputs[0].ty,- TypeSchema::Ref(name) if *name == output_type- ));- }-- let entries: Vec<_> = entries- .into_iter()- .map(|row| row.controller.clone())- .collect();- crate::core::all::verify_parameter_contracts(&entries, &contracts)- .expect("raw Doctor entries use their declared schemas and runtime decoders");}#[test]diff --git a/crates/openhuman-core/src/core/all_encryption_controller_tests.rs b/crates/openhuman-core/src/core/all_encryption_controller_tests.rsindex ba7d8fef5c..3144ee0784 100644--- a/crates/openhuman-core/src/core/all_encryption_controller_tests.rs+++ b/crates/openhuman-core/src/core/all_encryption_controller_tests.rs@@ -2,42 +2,21 @@ use super::*;#[test]fn raw_encryption_security_registry_matches_its_independent_contract() {- let entries: Vec<_> = registry()- .iter()- .filter(|row| matches!(row.controller.schema.namespace, "encrypt" | "decrypt"))- .collect();- let contracts = crate::security::encryption::encryption_parameter_contracts();-- assert_eq!(entries.len(), 2, "complete raw encryption inventory");- assert_eq!(- entries- .iter()- .map(|row| row.controller.schema.method_name())- .collect::<Vec<_>>(),- ["encrypt.secret", "decrypt.secret"],- "encryption registration order is a wire contract"- );- assert!(entries.iter().all(|row| {- row.group == DomainGroup::Security- && ["encrypt", "decrypt"].contains(&row.controller.schema.namespace)- }));- assert!(internal_registry()- .iter()- .all(|row| !matches!(row.controller.schema.namespace, "encrypt" | "decrypt")));- assert_eq!(- entries- .iter()- .map(|row| row.controller.rpc_method_name())- .collect::<Vec<_>>(),- ["openhuman.encrypt_secret", "openhuman.decrypt_secret"]- );-- let entries = entries- .into_iter()- .map(|row| row.controller.clone())- .collect::<Vec<_>>();- verify_parameter_contracts(&entries, &contracts)- .expect("raw encryption entries use their declared schemas and runtime decoders");+ let contract = super::registry_test_support::BoundFamilyWireContract {+ namespaces: &["encrypt", "decrypt"],+ group: DomainGroup::Security,+ methods: &[+ ("encrypt.secret", "openhuman.encrypt_secret"),+ ("decrypt.secret", "openhuman.decrypt_secret"),+ ],+ };+ super::registry_test_support::verify_family_contract(+ registry(),+ internal_registry(),+ &contract,+ &crate::security::encryption::encryption_parameter_contracts(),+ )+ .expect("raw Encryption entries retain their ordered wire contracts");}#[test]diff --git a/crates/openhuman-core/src/core/all_profiles_controller_tests.rs b/crates/openhuman-core/src/core/all_profiles_controller_tests.rsindex bb8a6f7b2c..a58c08086b 100644--- a/crates/openhuman-core/src/core/all_profiles_controller_tests.rs+++ b/crates/openhuman-core/src/core/all_profiles_controller_tests.rs@@ -3,48 +3,32 @@ use crate::core::runtime::DispatchCtx;#[test]fn raw_profiles_operator_registry_matches_its_independent_contract() {- let entries: Vec<_> = registry()- .iter()- .filter(|row| row.controller.schema.namespace == "profiles")- .collect();- let contracts = crate::profiles::schemas::profile_parameter_contracts();- assert_eq!(entries.len(), 7, "complete raw Profiles inventory");- assert_eq!(- entries- .iter()- .map(|row| row.controller.schema.method_name())- .collect::<Vec<_>>(),- contracts- .iter()- .map(|contract| contract.method.to_owned())- .collect::<Vec<_>>(),- "Profiles registration order is a wire contract"- );- assert!(entries.iter().all(|row| row.group == DomainGroup::Operator));- assert!(internal_registry()- .iter()- .all(|row| row.controller.schema.namespace != "profiles"));- assert_eq!(- entries- .iter()- .map(|row| row.controller.rpc_method_name())- .collect::<Vec<_>>(),- [- "openhuman.profiles_provision",- "openhuman.profiles_deprovision",- "openhuman.profiles_list",- "openhuman.profiles_status",- "openhuman.profiles_set_credential",- "openhuman.profiles_clear_credential",- "openhuman.profiles_release",- ]- );- let entries = entries- .into_iter()- .map(|row| row.controller.clone())- .collect::<Vec<_>>();- verify_parameter_contracts(&entries, &contracts)- .expect("raw Profiles entries use their declared schemas and runtime decoders");+ let contract = super::registry_test_support::BoundFamilyWireContract {+ namespaces: &["profiles"],+ group: DomainGroup::Operator,+ methods: &[+ ("profiles.provision", "openhuman.profiles_provision"),+ ("profiles.deprovision", "openhuman.profiles_deprovision"),+ ("profiles.list", "openhuman.profiles_list"),+ ("profiles.status", "openhuman.profiles_status"),+ (+ "profiles.set_credential",+ "openhuman.profiles_set_credential",+ ),+ (+ "profiles.clear_credential",+ "openhuman.profiles_clear_credential",+ ),+ ("profiles.release", "openhuman.profiles_release"),+ ],+ };+ super::registry_test_support::verify_family_contract(+ registry(),+ internal_registry(),+ &contract,+ &crate::profiles::schemas::profile_parameter_contracts(),+ )+ .expect("raw Profiles entries retain their ordered wire contracts");}fn raw_profiles_entries() -> Vec<ControllerEntry> {diff --git a/crates/openhuman-core/src/core/schema_test_support.rs b/crates/openhuman-core/src/core/schema_test_support.rsindex 8f7054027f..60f8112137 100644--- a/crates/openhuman-core/src/core/schema_test_support.rs+++ b/crates/openhuman-core/src/core/schema_test_support.rs@@ -1,4 +1,5 @@use super::*;+use crate::core::{FieldSchema, TypeSchema};/// Independently authored wire fixtures checked against an actual bound/// registry entry. The runner validates examples with the production schema@@ -94,6 +95,40 @@ pub(crate) fn verify_parameter_schema(Ok(())}+pub(crate) fn verify_wire_fields(+ actual: &[FieldSchema],+ expected: &[(&'static str, TypeSchema, bool)],+) -> Result<(), String> {+ if actual.len() != expected.len() {+ return Err(format!(+ "wire field count mismatch: expected {}, got {}",+ expected.len(),+ actual.len()+ ));+ }+ for (index, (field, (name, ty, required))) in actual.iter().zip(expected).enumerate() {+ if field.name != *name {+ return Err(format!(+ "wire field {index} name mismatch: expected `{name}`, got `{}`",+ field.name+ ));+ }+ if field.ty != *ty {+ return Err(format!(+ "wire field `{name}` type mismatch: expected {ty:?}, got {:?}",+ field.ty+ ));+ }+ if field.required != *required {+ return Err(format!(+ "wire field `{name}` requiredness mismatch: expected {required}, got {}",+ field.required+ ));+ }+ }+ Ok(())+}+pub(crate) fn optional_input_contract(schema: &ControllerSchema,optional: &[&str],diff --git a/crates/openhuman-core/src/core/schema_test_support_tests.rs b/crates/openhuman-core/src/core/schema_test_support_tests.rsindex 5e5de8f5a5..fbab7c2261 100644--- a/crates/openhuman-core/src/core/schema_test_support_tests.rs+++ b/crates/openhuman-core/src/core/schema_test_support_tests.rs@@ -227,3 +227,76 @@ fn real_owner_namespaces_reject_each_controller_namespace_typo() {}}}++#[test]+fn wire_field_contract_pins_count_order_type_and_requiredness() {+ let field = crate::core::FieldSchema {+ name: "items",+ ty: crate::core::TypeSchema::Option(Box::new(crate::core::TypeSchema::Array(Box::new(+ crate::core::TypeSchema::Ref("WireItem"),+ )))),+ comment: "Items in wire order.",+ required: false,+ };+ let expected = [(+ "items",+ crate::core::TypeSchema::Option(Box::new(crate::core::TypeSchema::Array(Box::new(+ crate::core::TypeSchema::Ref("WireItem"),+ )))),+ false,+ )];+ assert_eq!(+ verify_wire_fields(std::slice::from_ref(&field), &expected),+ Ok(())+ );++ let wrong_name = [("renamed", expected[0].1.clone(), false)];+ assert!(+ verify_wire_fields(std::slice::from_ref(&field), &wrong_name)+ .unwrap_err()+ .contains("name mismatch")+ );+ assert!(verify_wire_fields(std::slice::from_ref(&field), &[])+ .unwrap_err()+ .contains("count mismatch"));+ let wrong_required = [("items", expected[0].1.clone(), true)];+ assert!(+ verify_wire_fields(std::slice::from_ref(&field), &wrong_required)+ .unwrap_err()+ .contains("requiredness mismatch")+ );+ let wrong_nested_type = [(+ "items",+ crate::core::TypeSchema::Option(Box::new(crate::core::TypeSchema::Array(Box::new(+ crate::core::TypeSchema::Ref("OtherWireItem"),+ )))),+ false,+ )];+ assert!(+ verify_wire_fields(std::slice::from_ref(&field), &wrong_nested_type)+ .unwrap_err()+ .contains("type mismatch")+ );++ let reversed = [+ crate::core::FieldSchema {+ name: "second",+ ty: crate::core::TypeSchema::Bool,+ comment: "Second.",+ required: true,+ },+ crate::core::FieldSchema {+ name: "first",+ ty: crate::core::TypeSchema::String,+ comment: "First.",+ required: true,+ },+ ];+ let ordered = [+ ("first", crate::core::TypeSchema::String, true),+ ("second", crate::core::TypeSchema::Bool, true),+ ];+ assert!(verify_wire_fields(&reversed, &ordered)+ .unwrap_err()+ .contains("name mismatch"));+}