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(inference): add coverage for embedding host rpc and provider factory
Steven Enamakel2fad167368a7
diff --git a/crates/openhuman-core/src/inference/embedding_host/rpc_tests.rs b/crates/openhuman-core/src/inference/embedding_host/rpc_tests.rsindex 0ed49e910a..87db836064 100644--- a/crates/openhuman-core/src/inference/embedding_host/rpc_tests.rs+++ b/crates/openhuman-core/src/inference/embedding_host/rpc_tests.rs@@ -513,7 +513,8 @@ async fn conformant_custom_endpoint_verifies_and_sends_expected_request() {/// the missing session, not a local-only block). Also covers the rerouted/// `test_connection` construction line.#[tokio::test]-async fn test_connection_managed_without_session_reports_no_backend_session() {+async fn test_connection_managed_without_provider_reports_backend_unavailable() {+ let _guard = crate::inference::inference_test_guard_async().await;let tmp = TempDir::new().unwrap();let mut config = Config::default();config.config_path = tmp.path().join("config.toml");@@ -527,15 +528,16 @@ async fn test_connection_managed_without_session_reports_no_backend_session() {);let err = out.value["error"].as_str().unwrap_or_default();assert!(- err.contains("No backend session"),- "managed test with no session must report the backend-session error, got: {err}"+ err.contains(crate::core::observability::BACKEND_UNAVAILABLE_PREFIX),+ "managed test with no provider must report BACKEND_UNAVAILABLE, got: {err}");}/// Live `embed` (RPC) for managed also routes through the config-aware/// factory; with no session it surfaces the same backend-session error.#[tokio::test]-async fn embed_managed_without_session_errors_with_no_backend_session() {+async fn embed_managed_without_provider_errors_with_backend_unavailable() {+ let _guard = crate::inference::inference_test_guard_async().await;let tmp = TempDir::new().unwrap();let mut config = Config::default();config.config_path = tmp.path().join("config.toml");@@ -545,8 +547,8 @@ async fn embed_managed_without_session_errors_with_no_backend_session() {.await.expect_err("managed embed with no session must error");assert!(- err.contains("No backend session"),- "expected backend-session error, got: {err}"+ err.contains(crate::core::observability::BACKEND_UNAVAILABLE_PREFIX),+ "expected BACKEND_UNAVAILABLE, got: {err}");}diff --git a/crates/openhuman-core/src/inference/mod.rs b/crates/openhuman-core/src/inference/mod.rsindex fb62b23a13..6a71600274 100644--- a/crates/openhuman-core/src/inference/mod.rs+++ b/crates/openhuman-core/src/inference/mod.rs@@ -118,6 +118,9 @@ impl tinyinference_local::models::LocalModelConfig for crate::config::Config {}}+#[cfg(test)]+pub(crate) mod registry_test_support;+// Test helpers (re-exported for sibling test files that use inference_test_guard)#[cfg(test)]pub(crate) fn inference_test_guard() -> tokio::sync::MutexGuard<'static, ()> {diff --git a/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs b/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rsindex ef9a0d87fc..199659ed36 100644--- a/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs+++ b/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs@@ -262,6 +262,7 @@ fn resolves_to_managed_backend_for_default_config_but_not_for_local() {#[test]fn create_chat_model_routes_managed_backend_to_crate_native() {let _guard = crate::inference::inference_test_guard();+ let _managed = crate::inference::registry_test_support::FakeManaged::register();// No test-provider override installed → the managed short-circuit engages.let config = Config::default();let (model, _model_id) = create_chat_model_with_model_id_in(@@ -475,6 +476,7 @@ fn anthropic_auth_cloud_slug_in_text_mode_keeps_the_compat_client() {#[test]fn configured_openhuman_jwt_slug_routes_to_managed_chat_model() {let _guard = crate::inference::inference_test_guard();+ let _managed = crate::inference::registry_test_support::FakeManaged::register();let mut config = Config::default();config.cloud_providers.push(oh_entry("p_oh"));// A retired tier slug after the managed slug is a role alias: it runs on@@ -510,6 +512,7 @@ async fn openhuman_jwt_slug_discloses_pinned_model() {use std::time::Duration;let _guard = crate::inference::inference_test_guard_async().await;+ let _managed = crate::inference::registry_test_support::FakeManaged::register();crate::core::bus::init().await.expect("bus init");let mut rx = crate::core::bus::BUS.get().unwrap().receiver();@@ -649,6 +652,7 @@ async fn native_claude_turn_routes_disclose_pinned_models() {#[test]fn openhuman_jwt_slug_preserves_forced_text_mode() {let _guard = crate::inference::inference_test_guard();+ let _managed = crate::inference::registry_test_support::FakeManaged::register();let mut config = Config::default();config.cloud_providers.push(oh_entry("p_oh"));@@ -673,6 +677,7 @@ fn openhuman_jwt_slug_preserves_forced_text_mode() {#[test]fn openhuman_jwt_slug_without_model_preserves_managed_role_tier() {let _guard = crate::inference::inference_test_guard();+ let _managed = crate::inference::registry_test_support::FakeManaged::register();let mut config = Config::default();config.cloud_providers.push(oh_entry("p_oh"));diff --git a/crates/openhuman-core/src/inference/provider/factory_egress_fallback_tests.rs b/crates/openhuman-core/src/inference/provider/factory_egress_fallback_tests.rsindex d9063862cf..6a1cdd792c 100644--- a/crates/openhuman-core/src/inference/provider/factory_egress_fallback_tests.rs+++ b/crates/openhuman-core/src/inference/provider/factory_egress_fallback_tests.rs@@ -12,6 +12,8 @@ async fn create_chat_model_managed_emits_exactly_one_egress_realpath() {use crate::security::egress::{EgressDescriptor, EgressReason};use std::time::Duration;+ let _guard = crate::inference::inference_test_guard_async().await;+ let _managed = crate::inference::registry_test_support::FakeManaged::register();crate::core::bus::init().await.expect("bus init");let mut rx = crate::core::bus::BUS.get().unwrap().receiver();diff --git a/crates/openhuman-core/src/inference/provider/factory_managed_ledger_tests.rs b/crates/openhuman-core/src/inference/provider/factory_managed_ledger_tests.rsindex 9349b85e84..3566f799f7 100644--- a/crates/openhuman-core/src/inference/provider/factory_managed_ledger_tests.rs+++ b/crates/openhuman-core/src/inference/provider/factory_managed_ledger_tests.rs@@ -9,6 +9,7 @@ async fn managed_construction_ledger_collapses_repeat_disclosures() {use crate::core::events::DomainEvent;let _guard = crate::inference::inference_test_guard_async().await;+ let _managed = crate::inference::registry_test_support::FakeManaged::register();crate::core::bus::init().await.expect("bus init");let mut rx = crate::core::bus::BUS.get().unwrap().receiver();diff --git a/crates/openhuman-core/src/inference/registry_test_support.rs b/crates/openhuman-core/src/inference/registry_test_support.rsnew file mode 100644index 0000000000..2c5f9295d4--- /dev/null+++ b/crates/openhuman-core/src/inference/registry_test_support.rs@@ -0,0 +1,81 @@+//! Test support: a fake managed chat model registered under the managed+//! provider id, standing in for the hosted provider the core has no copy of.+//!+//! Registration is process-global, so callers hold+//! [`inference_test_guard`](crate::inference::inference_test_guard) (or its+//! async twin) for as long as the [`FakeManaged`] guard lives.++use std::sync::Arc;++use async_trait::async_trait;+use tinyinference_llm::model::{ChatModel, ModelProfile, ModelRequest, ModelResponse};++use super::registry::{+ register_chat_model, unregister_chat_model, ChatModelEntry, ChatModelRequest,+};+use crate::inference::provider::factory::PROVIDER_OPENHUMAN;++/// A chat model whose profile mirrors the managed provider's (`managed`, with+/// tool capabilities following `native_tool_calling`).+pub(crate) struct FakeManagedModel {+ profile: ModelProfile,+ /// The thread the request that built this model carried.+ pub(crate) thread_id: Option<String>,+}++#[async_trait]+impl ChatModel<()> for FakeManagedModel {+ fn profile(&self) -> Option<&ModelProfile> {+ Some(&self.profile)+ }++ async fn invoke(+ &self,+ _state: &(),+ _request: ModelRequest,+ ) -> tinyinference_llm::Result<ModelResponse> {+ Ok(ModelResponse::assistant("from the fake managed model"))+ }+}++fn build(request: &ChatModelRequest<'_>) -> anyhow::Result<(Arc<dyn ChatModel<()>>, String)> {+ let native = request.native_tool_calling;+ let model = FakeManagedModel {+ profile: ModelProfile {+ provider: Some("managed".to_string()),+ tool_calling: native,+ parallel_tool_calls: native,+ streaming_tool_chunks: native,+ streaming: true,+ ..ModelProfile::default()+ },+ thread_id: request.thread_id.map(str::to_string),+ };+ let resolved = request+ .model_override+ .unwrap_or(crate::config::MODEL_MANAGED_DEFAULT)+ .to_string();+ Ok((Arc::new(model), resolved))+}++/// Registers the fake for as long as the guard lives.+pub(crate) struct FakeManaged;++impl FakeManaged {+ pub(crate) fn register() -> Self {+ register_chat_model(+ PROVIDER_OPENHUMAN,+ ChatModelEntry {+ build: Arc::new(build),+ probe: None,+ },+ );+ Self+ }+}++impl Drop for FakeManaged {+ fn drop(&mut self) {+ unregister_chat_model(PROVIDER_OPENHUMAN);+ }+}diff --git a/crates/openhuman-core/src/inference/registry_tests.rs b/crates/openhuman-core/src/inference/registry_tests.rsindex 9e199d65a5..9b995f2ff7 100644--- a/crates/openhuman-core/src/inference/registry_tests.rs+++ b/crates/openhuman-core/src/inference/registry_tests.rs@@ -40,6 +40,7 @@ fn fake_entry(seen: Arc<Mutex<Vec<(String, Option<String>, Option<String>)>>>) -#[test]fn nothing_registered_resolves_no_provider() {+ let _guard = crate::inference::inference_test_guard();assert!(chat_model(PROVIDER_OPENHUMAN).is_none());assert!(embedding(PROVIDER_OPENHUMAN).is_none());assert!(catalog(PROVIDER_OPENHUMAN).is_none());@@ -77,7 +78,7 @@ async fn a_registered_chat_model_serves_the_managed_provider_for_a_thread() {seen[0],("chat".to_string(),- Some("hint:reasoning".to_string()),+ Some(crate::config::MODEL_MANAGED_DEFAULT.to_string()),Some("thread-1".to_string())));@@ -90,6 +91,7 @@ async fn a_registered_chat_model_serves_the_managed_provider_for_a_thread() {#[test]fn a_registered_embedding_factory_builds_the_managed_embedding_model() {+ let _guard = crate::inference::inference_test_guard();let calls = Arc::new(AtomicUsize::new(0));let counter = Arc::clone(&calls);register_embedding(PROVIDER_OPENHUMAN, move |request| {@@ -161,3 +163,30 @@ fn a_registered_catalog_supplies_the_managed_limits_request() {unregister_catalog(PROVIDER_OPENHUMAN);assert!(request.is_some());}++/// With nothing registered under the managed provider id, selecting it yields+/// the `BACKEND_UNAVAILABLE:` sentinel instead of a panic or a hosted model.+#[test]+fn selecting_the_managed_provider_with_nothing_registered_is_backend_unavailable() {+ let _guard = crate::inference::inference_test_guard();+ let _exclusive = crate::inference::provider::factory::test_provider_override::exclusive();+ let error = make_openhuman_backend_model_for_thread(+ "chat",+ &Config::default(),+ "any-model",+ true,+ None,+ &EgressLedger::none(),+ )+ .err()+ .expect("no managed provider is registered");+ assert!(+ error+ .to_string()+ .starts_with(crate::core::observability::BACKEND_UNAVAILABLE_PREFIX),+ "unexpected error: {error}"+ );+ let one_shot =+ create_chat_model_from_string("chat", PROVIDER_OPENHUMAN, &Config::default(), 0.5);+ assert!(one_shot.is_err());+}