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
refactor(tests): wrap tests in library context scopes
Steven Enamakel58173ed97b15
diff --git a/crates/openhuman-core/src/inference/provider/factory_crate_native_diagnostics_tests.rs b/crates/openhuman-core/src/inference/provider/factory_crate_native_diagnostics_tests.rsindex 143f35a947..eee49063d7 100644--- a/crates/openhuman-core/src/inference/provider/factory_crate_native_diagnostics_tests.rs+++ b/crates/openhuman-core/src/inference/provider/factory_crate_native_diagnostics_tests.rs@@ -5,7 +5,8 @@ use tinyinference_llm::providers::registry::openrouter_default_provider_options;#[test]fn crate_native_chat_model_factory_preserves_invalid_route_diagnostics() {let _guard = crate::inference::inference_test_guard();- let config = Config::default();+ super::with_library_test_context(|| {+ let config = Config::default();let unconfigured =create_chat_model_from_string_with_model_id("reasoning", "groq:llama3", &config, 0.7)@@ -36,10 +37,11 @@ fn crate_native_chat_model_factory_preserves_invalid_route_diagnostics() {.err().expect("incomplete BYOK must fail").to_string();- assert!(- byok.contains("BYOK_INCOMPLETE"),- "unexpected diagnostic: {byok}"- );+ assert!(+ byok.contains("BYOK_INCOMPLETE"),+ "unexpected diagnostic: {byok}"+ );+ });}/// Real-path smoke (privacy epic S2, #4436): driving the actual inference@@ -57,7 +59,10 @@ async fn from_string_external_provider_emits_egress_realpath() {let config = Config::default();// External provider → real chokepoint must emit BEFORE constructing.- let _ = create_test_chat_model_from_string("agentic", "openai:gpt-4o-mini", &config);+ super::with_library_test_context_async(|| async {+ let _ = create_test_chat_model_from_string("agentic", "openai:gpt-4o-mini", &config);+ })+ .await;// Bus is process-wide; drain past unrelated events until our descriptor lands.let found = tokio::time::timeout(std::time::Duration::from_secs(2), async {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 42be0a5d37..44955574e5 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@@ -23,12 +23,15 @@ async fn create_chat_model_managed_emits_exactly_one_egress_realpath() {let marker = "egress-managed-realpath-marker-v1";let mut config = Config::default();config.default_model = Some(marker.to_string());- let _ = create_chat_model_with_model_id_in(- &crate::core::runtime::DispatchCtx::ambient(),- "scratch",- &config,- 0.7,- );+ super::with_library_test_context_async(|| async {+ let _ = create_chat_model_with_model_id_in(+ &crate::core::runtime::DispatchCtx::ambient(),+ "scratch",+ &config,+ 0.7,+ );+ })+ .await;// Bound the drain with a unique sentinel published AFTER our construction.let sentinel = "egress-managed-sentinel-end";diff --git a/crates/openhuman-core/src/inference/provider/factory_tests.rs b/crates/openhuman-core/src/inference/provider/factory_tests.rsindex 2e2dd06bfd..9731a66cf6 100644--- a/crates/openhuman-core/src/inference/provider/factory_tests.rs+++ b/crates/openhuman-core/src/inference/provider/factory_tests.rs@@ -4,6 +4,24 @@ use crate::config::Config;use crate::security::credentials::AuthService;use tempfile::TempDir;+fn with_library_test_context<T>(f: impl FnOnce() -> T) -> T {+ let context = crate::core::runtime::CoreContext::for_test_with_host_kind(+ crate::core::types::HostKind::Library,+ crate::core::runtime::DomainSet::full(),+ None,+ );+ crate::core::runtime::CoreContext::sync_scope(context, f)+}++async fn with_library_test_context_async<F: std::future::Future>(f: impl FnOnce() -> F) -> F::Output {+ let context = crate::core::runtime::CoreContext::for_test_with_host_kind(+ crate::core::types::HostKind::Library,+ crate::core::runtime::DomainSet::full(),+ None,+ );+ crate::core::runtime::CoreContext::scope(context, f()).await+}+struct ManagedRouteFixtureModel;#[async_trait::async_trait]@@ -88,7 +106,9 @@ fn create_test_chat_model_from_string(provider: &str,config: &Config,) -> anyhow::Result<(Arc<dyn ChatModel<()>>, String)> {- create_chat_model_from_string_with_model_id(role, provider, config, 0.7)+ with_library_test_context(|| {+ create_chat_model_from_string_with_model_id(role, provider, config, 0.7)+ })}fn create_test_local_chat_model_from_string(diff --git a/crates/openhuman-core/src/inference/readiness_tests.rs b/crates/openhuman-core/src/inference/readiness_tests.rsindex f5b52b5406..aabcb9798b 100644--- a/crates/openhuman-core/src/inference/readiness_tests.rs+++ b/crates/openhuman-core/src/inference/readiness_tests.rs@@ -55,19 +55,23 @@ async fn cached_probe_serves_definitive_negative_results() {}),},);- let core = CoreContext::for_test_with_extensions(+ let core = CoreContext::for_test_with_host_kind_and_extensions(+ crate::core::types::HostKind::Library,DomainSet::full(),Some(config.workspace_dir.clone()),extensions,);let ctx = DispatchCtx::new(core);- let first = cached_probe(&ctx, "summarization", &config).await;- assert!(first- .unwrap_err()- .to_ascii_lowercase()- .contains("api key not configured for provider"));- assert_eq!(hit_count.load(Ordering::SeqCst), 1);- assert!(cached_probe(&ctx, "summarization", &config).await.is_err());- assert_eq!(hit_count.load(Ordering::SeqCst), 1);+ CoreContext::scope(ctx.resolved().expect("test context"), async {+ let first = cached_probe(&ctx, "summarization", &config).await;+ assert!(first+ .unwrap_err()+ .to_ascii_lowercase()+ .contains("api key not configured for provider"));+ assert_eq!(hit_count.load(Ordering::SeqCst), 1);+ assert!(cached_probe(&ctx, "summarization", &config).await.is_err());+ assert_eq!(hit_count.load(Ordering::SeqCst), 1);+ })+ .await;}diff --git a/crates/openhuman-core/src/inference/registry_tests.rs b/crates/openhuman-core/src/inference/registry_tests.rsindex 71f65395dc..a8e6b7a0ce 100644--- a/crates/openhuman-core/src/inference/registry_tests.rs+++ b/crates/openhuman-core/src/inference/registry_tests.rs@@ -84,8 +84,15 @@ async fn a_registered_chat_model_serves_the_managed_provider_for_a_thread() {Some("thread-1"),&EgressLedger::none(),);- let one_shot =- create_chat_model_from_string("chat", PROVIDER_OPENHUMAN, &Config::default(), 0.5);+ let library = crate::core::runtime::CoreContext::for_test_with_host_kind(+ crate::core::types::HostKind::Library,+ crate::core::runtime::DomainSet::full(),+ None,+ );+ let one_shot = crate::core::runtime::CoreContext::scope(library, async {+ create_chat_model_from_string("chat", PROVIDER_OPENHUMAN, &Config::default(), 0.5)+ })+ .await;unregister_chat_model(PROVIDER_OPENHUMAN);let (model, resolved) = built.expect("registered model builds");diff --git a/crates/openhuman-core/src/inference/turn_models_native_tests.rs b/crates/openhuman-core/src/inference/turn_models_native_tests.rsindex 0a0c40d0e4..448ab40493 100644--- a/crates/openhuman-core/src/inference/turn_models_native_tests.rs+++ b/crates/openhuman-core/src/inference/turn_models_native_tests.rs@@ -66,7 +66,7 @@ async fn native_budget_wrapping_keeps_owner_error_slots_for_primary_tiers_and_suNone,extensions,);- let ctx = DispatchCtx::new(context);+ let ctx = DispatchCtx::new(context.clone());let tmp = tempfile::tempdir().expect("isolated workspace");let config = Arc::new(managed_fixture_config(&tmp));let budget = ModelBudget {@@ -344,9 +344,12 @@ async fn injected_turn_without_profile_keeps_conservative_capabilities() {.host_overrides(Arc::new(overrides)),);let ctx = DispatchCtx::new(context);- let models = TurnModelSource::new_crate_native(&ctx, "chat", Arc::new(Default::default()))- .build("hint:chat", 0.2, None, None)- .expect("profileless host-injected model builds");+ let models = CoreContext::scope(context, async {+ TurnModelSource::new_crate_native(&ctx, "chat", Arc::new(Default::default()))+ .build("hint:chat", 0.2, None, None)+ .expect("profileless host-injected model builds")+ })+ .await;assert_eq!(models.provider_id(), "injected");assert!(!models.native_tools());