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): verify voice contracts against bound decoders
Steven Enamakelecbbb0a91206
diff --git a/crates/openhuman-core/src/core/all_bound_controller_tests.rs b/crates/openhuman-core/src/core/all_bound_controller_tests.rsindex 3e13e17cb9..e85402adca 100644--- a/crates/openhuman-core/src/core/all_bound_controller_tests.rs+++ b/crates/openhuman-core/src/core/all_bound_controller_tests.rs@@ -501,209 +501,48 @@ fn production_registry_binds_composio_execute_to_its_declared_parser() {#[cfg(feature = "voice")]#[test]fn production_registry_binds_every_core_voice_controller_to_its_parser() {- use serde_json::json;-- struct Contract {- method: &'static str,- required: &'static [&'static str],- optional: &'static [&'static str],- examples: Vec<Value>,- }-- let contracts = [- Contract {- method: "voice.status",- required: &[],- optional: &[],- examples: vec![json!({})],- },- Contract {- method: "voice.transcribe",- required: &["audio_path"],- optional: &["context", "skip_cleanup"],- examples: vec![- json!({"audio_path":"fixture.wav"}),- json!({"audio_path":"fixture.wav","context":"example","skip_cleanup":true}),- ],- },- Contract {- method: "voice.transcribe_bytes",- required: &["audio_bytes"],- optional: &["extension", "context", "skip_cleanup"],- examples: vec![- json!({"audio_bytes":[0,1]}),- json!({"audio_bytes":[0,1],"extension":"wav","context":"example","skip_cleanup":true}),- ],- },- Contract {- method: "voice.tts",- required: &["text"],- optional: &["output_path"],- examples: vec![- json!({"text":"Hello"}),- json!({"text":"Hello","output_path":"fixture.wav"}),- ],- },- Contract {- method: "voice.reply_synthesize",- required: &["text"],- optional: &["voice_id", "model_id", "output_format"],- examples: vec![- json!({"text":"Hello"}),- json!({"text":"Hello","voice_id":"fixture","model_id":"fixture","output_format":"mp3_44100"}),- ],- },- Contract {- method: "voice.stt_dispatch",- required: &["audio_base64"],- optional: &["provider", "model", "mime_type", "file_name", "language"],- examples: vec![- json!({"audio_base64":"AA=="}),- json!({"audio_base64":"AA==","provider":"cloud","model":"fixture","mime_type":"audio/wav","file_name":"fixture.wav","language":"en"}),- ],- },- Contract {- method: "voice.tts_dispatch",- required: &["text"],- optional: &["provider", "voice"],- examples: vec![- json!({"text":"Hello"}),- json!({"text":"Hello","provider":"cloud","voice":"fixture"}),- ],- },- Contract {- method: "voice.set_providers",- required: &[],- optional: &["stt_provider", "tts_provider", "stt_model", "tts_voice"],- examples: vec![- json!({}),- json!({"stt_provider":"cloud","tts_provider":"cloud","stt_model":"fixture","tts_voice":"fixture"}),- ],- },- Contract {- method: "voice.update_provider_settings",- required: &[],- optional: &["voice_providers", "stt_provider", "tts_provider"],- examples: vec![- json!({}),- json!({"voice_providers":[{"slug":"fixture-provider"}],"stt_provider":"cloud","tts_provider":"cloud"}),- ],- },- Contract {- method: "voice.list_models",- required: &["provider_id"],- optional: &["capability"],- examples: vec![- json!({"provider_id":"fixture"}),- json!({"provider_id":"fixture","capability":"stt"}),- ],- },- Contract {- method: "voice.test_provider",- required: &["workload", "provider"],- optional: &["validate_only", "api_key"],- examples: vec![- json!({"workload":"tts","provider":"cloud"}),- json!({"workload":"stt","provider":"cloud","validate_only":true,"api_key":"fixture-key"}),- ],- },- Contract {- method: "voice.live_providers",- required: &[],- optional: &[],- examples: vec![json!({})],- },- Contract {- method: "voice.live_settings_get",- required: &[],- optional: &[],- examples: vec![json!({})],- },- Contract {- method: "voice.live_settings_set",- required: &[],- optional: &["default_provider", "gemini", "sarvam", "elevenlabs"],- examples: vec![- json!({}),- json!({"default_provider":"gemini","gemini":{"model":"fixture","voice":null},"sarvam":{"language":"en"},"elevenlabs":{"voice_id":"fixture"}}),- ],- },- Contract {- method: "voice.live_test_provider",- required: &["provider"],- optional: &[],- examples: vec![json!({"provider":"gemini"})],- },- ];-- // Select raw production rows, before DomainSet, surface, or extension filtering.- let entries: Vec<_> = registry()+ // Discover the namespace from raw registries independently of the fixture+ // rows; surface/domain filters must not hide a missing binding.+ let grouped: Vec<_> = registry().iter().chain(internal_registry())- .filter_map(|grouped| {- grouped- .controller- .schema- .method_name()- .starts_with("voice.")- .then_some(&grouped.controller)- })+ .filter(|row| row.controller.schema.method_name().starts_with("voice.")).collect();+ let entries: Vec<_> = grouped.iter().map(|row| &row.controller).collect();+ let contracts = crate::voice::parameter_contracts();+ let expected_methods = [+ "voice.status",+ "voice.transcribe",+ "voice.transcribe_bytes",+ "voice.tts",+ "voice.reply_synthesize",+ "voice.stt_dispatch",+ "voice.tts_dispatch",+ "voice.set_providers",+ "voice.update_provider_settings",+ "voice.list_models",+ "voice.test_provider",+ "voice.live_providers",+ "voice.live_settings_get",+ "voice.live_settings_set",+ "voice.live_test_provider",+ ];+ assert_eq!(entries.len(), expected_methods.len(), "complete core voice inventory");+ assert!(grouped.iter().all(|row| row.group == DomainGroup::Voice));assert_eq!(- entries.len(),- contracts.len(),- "complete core voice inventory"+ entries.iter().map(|entry| entry.schema.method_name()).collect::<Vec<_>>(),+ expected_methods,+ "independent core voice inventory and registry order");- let methods: Vec<_> = entries- .iter()- .map(|entry| entry.schema.method_name())- .collect();assert_eq!(- methods,- contracts- .iter()- .map(|contract| contract.method)- .collect::<Vec<_>>(),- "independent core voice method inventory and registry order"+ contracts.iter().map(|contract| contract.method).collect::<Vec<_>>(),+ expected_methods,+ "authored parameter fixtures cover the complete ordered voice inventory");+ crate::core::all::verify_parameter_contracts(&entries, &contracts)+ .expect("raw voice entries use their declared schemas and runtime decoders");for (entry, contract) in entries.into_iter().zip(contracts) {- assert!(- entry.is_bound(),- "{} must have a production-bound parser",- contract.method- );- assert_eq!(- required_input_contract(&entry.schema, contract.required),- Ok(()),- "{} independent required-field contract",- contract.method- );- let optional: Vec<_> = entry- .schema- .inputs- .iter()- .filter(|input| !input.required)- .map(|input| input.name)- .collect();- assert_eq!(- optional, contract.optional,- "{} optional fields",- contract.method- );-- for example in &contract.examples {- let params = example- .as_object()- .expect("voice example is an object")- .clone();- validate_params(&entry.schema, ¶ms)- .expect("registered schema accepts voice example");- entry- .decode_params(params)- .expect("actual raw registry parser accepts voice example");- }-for &name in contract.required {for remove in [true, false] {let mut broken = entry.schema.clone();diff --git a/crates/openhuman-core/src/core/schema_test_support_tests.rs b/crates/openhuman-core/src/core/schema_test_support_tests.rsindex eb159eb5ca..ec9ae2b3b9 100644--- a/crates/openhuman-core/src/core/schema_test_support_tests.rs+++ b/crates/openhuman-core/src/core/schema_test_support_tests.rs@@ -1,17 +1,23 @@use super::*;use crate::core::runtime::DispatchCtx;-fn handler(_ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {- panic!("the pure contract runner must never execute handlers");+fn parse_fixture(params: Map<String, Value>) -> Result<(), String> {+ match params.get("id").and_then(Value::as_str) {+ Some("example") => Ok(()),+ _ => Err("fixture id must be example".into()),+ }}-fn other_handler(_ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {- panic!("this distinct handler must never be executed");+fn panic_runner(_ctx: DispatchCtx, _parsed: ()) -> ControllerFuture {+ panic!("the pure contract verifier must never execute a business runner");}-fn fixture() -> (RegisteredController, ControllerParamContract) {- let controller = RegisteredController {- schema: ControllerSchema {+fn legacy_handler(_ctx: DispatchCtx, _params: Map<String, Value>) -> ControllerFuture {+ panic!("legacy rejection must not execute a handler");+}++fn fixture() -> (ControllerEntry, ControllerParamContract) {+ let schema = ControllerSchema {namespace: "fixture",function: "read",description: "Read a fixture.",@@ -22,24 +28,23 @@ fn fixture() -> (RegisteredController, ControllerParamContract) {required: true,}],outputs: vec![],- },- handler,};+ let controller = ControllerEntry::bound(BoundRegisteredController::typed(+ schema,+ parse_fixture,+ panic_runner,+ ));let contract = ControllerParamContract {method: "fixture.read",required: &["id"],- handler,+ optional: &[],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() {+fn explicit_example_reaches_actual_bound_decoder_without_running_business_handler() {let (controller, contract) = fixture();verify_parameter_contracts(&[controller], &[contract]).unwrap();}@@ -77,25 +82,20 @@ 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")- );+ let broken = ControllerEntry {+ schema: broken.schema,+ ..broken+ };+ 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() {+fn missing_examples_and_actual_parser_rejection_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])@@ -107,7 +107,7 @@ fn callback_identity_and_explicit_example_failures_are_not_hidden() {assert!(verify_parameter_contracts(std::slice::from_ref(&controller), &[broken]).unwrap_err()- .contains("pure parser")+ .contains("bound decoder rejects example"));let mut broken = contract;broken.examples = vec![serde_json::json!({"id":7})];@@ -137,6 +137,29 @@ fn duplicate_controller_and_schema_identity_failures_are_rejected() {.contains("no description"));}+#[test]+fn legacy_entries_are_rejected_without_running_the_legacy_handler() {+ let (_, contract) = fixture();+ let legacy = ControllerEntry::legacy(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: legacy_handler,+ });+ assert!(verify_parameter_contracts(&[legacy], &[contract])+ .unwrap_err()+ .contains("registry entry is legacy"));+}+#[test]fn examples_must_be_objects_and_satisfy_schema_before_decoding() {let (controller, mut contract) = fixture();