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
feat(schemas): add parameter contract helpers for controller tests
Steven Enamakel90ac4e860dce
diff --git a/crates/openhuman-core/src/mcp/registry/mod.rs b/crates/openhuman-core/src/mcp/registry/mod.rsindex e52561b7fe..825074c033 100644--- a/crates/openhuman-core/src/mcp/registry/mod.rs+++ b/crates/openhuman-core/src/mcp/registry/mod.rs@@ -487,3 +487,6 @@ pub(crate) fn tools_safe_for_agent(mod stub;#[cfg(not(feature = "mcp"))]pub use stub::*;++#[cfg(test)]+pub(crate) use schemas::registry_get_parameter_contract;diff --git a/crates/openhuman-core/src/mcp/registry/schemas/handlers.rs b/crates/openhuman-core/src/mcp/registry/schemas/handlers.rsindex 45e40721dd..ab368a7ff2 100644--- a/crates/openhuman-core/src/mcp/registry/schemas/handlers.rs+++ b/crates/openhuman-core/src/mcp/registry/schemas/handlers.rs@@ -37,7 +37,7 @@ pub(super) fn handle_registry_get() -> ControllerFuture {Box::pin(async move {let config = ctx.load_config().await?;- let qualified_name = read_required::<String>(¶ms, "qualified_name")?;+ let qualified_name = parse_registry_get(¶ms)?;to_json(crate::mcp::registry::ops::mcp_clients_registry_get(&config, qualified_name).await?)})}@@ -204,3 +204,8 @@ pub(super) fn handle_registry_settings_set()})}+++pub(super) fn parse_registry_get(params: &Map<String, Value>) -> Result<String, String> {+ read_required(params, "qualified_name")+}diff --git a/crates/openhuman-core/src/mcp/registry/schemas/mod.rs b/crates/openhuman-core/src/mcp/registry/schemas/mod.rsindex 076f80a06f..55055c2a22 100644--- a/crates/openhuman-core/src/mcp/registry/schemas/mod.rs+++ b/crates/openhuman-core/src/mcp/registry/schemas/mod.rs@@ -19,3 +19,15 @@ pub use registry::{all_controller_schemas, all_registered_controllers, schemas};// had when `include!` spliced everything into one file.#[cfg(test)]use params::{read_optional_u32, read_required, type_name};+++#[cfg(test)]+pub(crate) fn registry_get_parameter_contract() -> crate::core::all::ControllerParamContract {+ crate::core::all::ControllerParamContract {+ method: "mcp_clients.registry_get",+ required: &["qualified_name"],+ handler: handlers::handle_registry_get,+ examples: vec![serde_json::json!({"qualified_name":"example/server"})],+ parse: |params| handlers::parse_registry_get(¶ms).map(drop),+ }+}diff --git a/crates/openhuman-core/src/modules/schemas.rs b/crates/openhuman-core/src/modules/schemas.rsindex ab629278a1..e47b7a25a9 100644--- a/crates/openhuman-core/src/modules/schemas.rs+++ b/crates/openhuman-core/src/modules/schemas.rs@@ -270,7 +270,7 @@ fn handle_browser_forget_sites(ctx: DispatchCtx, params: Map<String, Value>) ->fn handle_computer_status(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {- let load = params.get("load").and_then(Value::as_bool).unwrap_or(false);+ let load = computer_status_load(¶ms);let config = ctx.load_config().await?;crate::core::runtime::components::require_config(&config, "computer")?;controller_value(super::computer::status(&config, load).await)@@ -329,3 +329,19 @@ fn string_param(params: &Map<String, Value>, key: &str) -> Option<String> {#[cfg(test)]#[path = "schemas_tests.rs"]mod tests;+++fn computer_status_load(params: &Map<String, Value>) -> bool {+ params.get("load").and_then(Value::as_bool).unwrap_or(false)+}++#[cfg(test)]+pub(crate) fn computer_status_parameter_contract() -> crate::core::all::ControllerParamContract {+ crate::core::all::ControllerParamContract {+ method: "modules.computer_status",+ required: &[],+ handler: handle_computer_status,+ examples: vec![serde_json::json!({}),serde_json::json!({"load":false}),serde_json::json!({"load":true})],+ parse: |params| { let _ = computer_status_load(¶ms); Ok(()) },+ }+}diff --git a/crates/openhuman-core/src/voice/live/schema_parameter_contracts.rs b/crates/openhuman-core/src/voice/live/schema_parameter_contracts.rsnew file mode 100644index 0000000000..45d7e2f86c--- /dev/null+++ b/crates/openhuman-core/src/voice/live/schema_parameter_contracts.rs@@ -0,0 +1,33 @@+use super::*;+use crate::core::all::ControllerParamContract;+use serde_json::json;++fn decode<T: serde::de::DeserializeOwned>(params: Map<String, Value>) -> Result<(), String> {+ parse_params::<T>(params).map(drop)+}++fn ignored(_params: Map<String, Value>) -> Result<(), String> {+ Ok(())+}++pub(crate) fn contracts() -> Vec<ControllerParamContract> {+ vec![+ ControllerParamContract {+ method: "voice.live_providers", required: &[], handler: handle_live_providers,+ examples: vec![json!({})], parse: ignored,+ },+ ControllerParamContract {+ method: "voice.live_settings_get", required: &[], handler: handle_live_settings_get,+ examples: vec![json!({})], parse: ignored,+ },+ ControllerParamContract {+ method: "voice.live_settings_set", required: &[], handler: handle_live_settings_set,+ examples: vec![json!({}),json!({"default_provider":"gemini","gemini":{"model":"fixture","voice":null},"sarvam":{"language":"en"},"elevenlabs":{"voice_id":"fixture"}})],+ parse: decode::<LiveSettingsPatch>,+ },+ ControllerParamContract {+ method: "voice.live_test_provider", required: &["provider"], handler: handle_live_test_provider,+ examples: vec![json!({"provider":"gemini"})], parse: decode::<TestParams>,+ },+ ]+}diff --git a/crates/openhuman-core/src/voice/live/schemas.rs b/crates/openhuman-core/src/voice/live/schemas.rsindex 385ff181cc..60c734e96f 100644--- a/crates/openhuman-core/src/voice/live/schemas.rs+++ b/crates/openhuman-core/src/voice/live/schemas.rs@@ -133,8 +133,7 @@ fn handle_live_settings_get(ctx: DispatchCtx, _params: Map<String, Value>) -> Cofn handle_live_settings_set(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {- let patch: LiveSettingsPatch = serde_json::from_value(Value::Object(params))- .map_err(|e| format!("invalid params: {e}"))?;+ let patch = parse_params::<LiveSettingsPatch>(params)?;let mut config = ctx.load_config().await?;to_value(ops::live_settings_set(&mut config, patch).await?.value)})@@ -142,8 +141,7 @@ fn handle_live_settings_set(ctx: DispatchCtx, params: Map<String, Value>) -> Confn handle_live_test_provider(ctx: DispatchCtx, params: Map<String, Value>) -> ControllerFuture {Box::pin(async move {- let params: TestParams = serde_json::from_value(Value::Object(params))- .map_err(|e| format!("invalid params: {e}"))?;+ let params = parse_params::<TestParams>(params)?;let config = ctx.load_config().await?;to_value(ops::live_test_provider(&config, ¶ms.provider)@@ -186,3 +184,14 @@ pub fn live_controller_schemas() -> Vec<ControllerSchema> {#[cfg(test)]#[path = "schemas_tests.rs"]mod tests;+++fn parse_params<T: serde::de::DeserializeOwned>(params: Map<String, Value>) -> Result<T, String> {+ serde_json::from_value(Value::Object(params)).map_err(|e| format!("invalid params: {e}"))+}++#[cfg(test)]+#[path = "schema_parameter_contracts.rs"]+mod parameter_contracts;+#[cfg(test)]+pub(crate) use parameter_contracts::contracts as parameter_contracts;diff --git a/crates/openhuman-core/src/voice/mod.rs b/crates/openhuman-core/src/voice/mod.rsindex 63d0bca5ef..da33b05c17 100644--- a/crates/openhuman-core/src/voice/mod.rs+++ b/crates/openhuman-core/src/voice/mod.rs@@ -62,3 +62,6 @@ pub use types::{VoiceSpeechResult, VoiceStatus, VoiceTtsResult};mod stub;#[cfg(not(feature = "voice"))]pub use stub::*;++#[cfg(all(test, feature = "voice"))]+pub(crate) use schemas::parameter_contracts;diff --git a/crates/openhuman-core/src/voice/schemas/mod.rs b/crates/openhuman-core/src/voice/schemas/mod.rsindex fba276f63c..aa172e75c7 100644--- a/crates/openhuman-core/src/voice/schemas/mod.rs+++ b/crates/openhuman-core/src/voice/schemas/mod.rs@@ -15,6 +15,11 @@ mod helpers;mod params;mod registry;+#[cfg(test)]+mod parameter_contracts;+#[cfg(test)]+pub(crate) use parameter_contracts::contracts as parameter_contracts;+// Re-export the public API that callers outside this module use.pub use registry::{all_voice_controller_schemas, all_voice_registered_controllers, voice_schemas};@@ -22,7 +27,6 @@ pub use registry::{all_voice_controller_schemas, all_voice_registered_controller// Internal re-exports used by the test companion file.// ----------------------------------------------------------------------------#[cfg(test)]#[cfg(test)]use helpers::{deserialize_params, generate_silent_wav, to_json, validate_stt_provider, validate_tts_provider,diff --git a/crates/openhuman-core/src/voice/schemas/parameter_contracts.rs b/crates/openhuman-core/src/voice/schemas/parameter_contracts.rsnew file mode 100644index 0000000000..45a1455885--- /dev/null+++ b/crates/openhuman-core/src/voice/schemas/parameter_contracts.rs@@ -0,0 +1,76 @@+use super::handlers::*;+use super::params::*;+use crate::core::all::ControllerParamContract;+use serde::de::DeserializeOwned;+use serde_json::{json, Map, Value};++fn decode<T: DeserializeOwned>(params: Map<String, Value>) -> Result<(), String> {+ super::helpers::deserialize_params::<T>(params).map(drop)+}++fn ignored(_params: Map<String, Value>) -> Result<(), String> {+ Ok(())+}++/// Explicit parameter fixtures; decoder types match the named handlers.+/// Domain-specific defaults, values and errors remain in schemas_tests.rs.+pub(crate) fn contracts() -> Vec<ControllerParamContract> {+ let mut contracts = vec![+ ControllerParamContract {+ method: "voice.status", required: &[], handler: handle_voice_status,+ examples: vec![json!({})], parse: ignored,+ },+ ControllerParamContract {+ method: "voice.transcribe", required: &["audio_path"], handler: handle_voice_transcribe,+ examples: vec![json!({"audio_path":"fixture.wav"}), json!({"audio_path":"fixture.wav","context":"example","skip_cleanup":true})],+ parse: decode::<TranscribeParams>,+ },+ ControllerParamContract {+ method: "voice.transcribe_bytes", required: &["audio_bytes"], handler: handle_voice_transcribe_bytes,+ examples: vec![json!({"audio_bytes":[0,1]}), json!({"audio_bytes":[0,1],"extension":"wav","context":"example","skip_cleanup":true})],+ parse: decode::<TranscribeBytesParams>,+ },+ ControllerParamContract {+ method: "voice.tts", required: &["text"], handler: handle_voice_tts,+ examples: vec![json!({"text":"Hello"}), json!({"text":"Hello","output_path":"fixture.wav"})],+ parse: decode::<TtsParams>,+ },+ ControllerParamContract {+ method: "voice.reply_synthesize", required: &["text"], handler: handle_voice_reply_synthesize,+ examples: vec![json!({"text":"Hello"}), json!({"text":"Hello","voice_id":"fixture","model_id":"fixture","output_format":"mp3_44100"})],+ parse: decode::<ReplySynthesizeParams>,+ },+ ControllerParamContract {+ method: "voice.stt_dispatch", required: &["audio_base64"], handler: handle_voice_stt_dispatch,+ examples: vec![json!({"audio_base64":"AA=="}), json!({"audio_base64":"AA==","provider":"cloud","model":"fixture","mime_type":"audio/wav","file_name":"fixture.wav","language":"en"})],+ parse: decode::<SttDispatchParams>,+ },+ ControllerParamContract {+ method: "voice.tts_dispatch", required: &["text"], handler: handle_voice_tts_dispatch,+ examples: vec![json!({"text":"Hello"}), json!({"text":"Hello","provider":"cloud","voice":"fixture"})],+ parse: decode::<TtsDispatchParams>,+ },+ ControllerParamContract {+ method: "voice.set_providers", required: &[], handler: handle_voice_set_providers,+ examples: vec![json!({}), json!({"stt_provider":"cloud","tts_provider":"cloud","stt_model":"fixture","tts_voice":"fixture"})],+ parse: decode::<SetProvidersParams>,+ },+ ControllerParamContract {+ method: "voice.update_provider_settings", required: &[], handler: handle_voice_update_provider_settings,+ examples: vec![json!({}), json!({"voice_providers":[{"slug":"fixture-provider"}],"stt_provider":"cloud","tts_provider":"cloud"})],+ parse: decode::<VoiceUpdateProviderSettingsParams>,+ },+ ControllerParamContract {+ method: "voice.list_models", required: &["provider_id"], handler: handle_voice_list_models,+ examples: vec![json!({"provider_id":"fixture"}), json!({"provider_id":"fixture","capability":"stt"})],+ parse: decode::<VoiceListModelsParams>,+ },+ ControllerParamContract {+ method: "voice.test_provider", required: &["workload","provider"], handler: handle_voice_test_provider,+ examples: vec![json!({"workload":"tts","provider":"cloud"}), json!({"workload":"stt","provider":"cloud","validate_only":true,"api_key":"fixture-key"})],+ parse: decode::<VoiceTestProviderParams>,+ },+ ];+ contracts.extend(crate::voice::live::schemas::parameter_contracts());+ contracts+}