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(inference): add registry test support helpers
Steven Enamakel73c4b903b667
diff --git a/crates/openhuman-core/src/inference/registry.rs b/crates/openhuman-core/src/inference/registry.rsindex b17b344ee5..0a3e19a01a 100644--- a/crates/openhuman-core/src/inference/registry.rs+++ b/crates/openhuman-core/src/inference/registry.rs@@ -100,7 +100,15 @@ pub fn unregister_chat_model(provider_id: &str) -> bool {/// The registered chat-model provider, if any.pub(crate) fn chat_model(provider_id: &str) -> Option<ChatModelEntry> {- CHAT_MODELS.get(provider_id)+ let registered = CHAT_MODELS.get(provider_id);+ // Unit tests model "a hosted provider is present" by default, as the old+ // built-in managed backend was; a test that wants the bare core asks for it+ // with `without_managed_provider`.+ #[cfg(test)]+ let registered = registered.or_else(|| {+ super::registry_test_support::default_managed_entry(provider_id)+ });+ registered}// ---------------------------------------------------------------------------diff --git a/crates/openhuman-core/src/inference/registry_test_support.rs b/crates/openhuman-core/src/inference/registry_test_support.rsindex 2c5f9295d4..25adffeabf 100644--- a/crates/openhuman-core/src/inference/registry_test_support.rs+++ b/crates/openhuman-core/src/inference/registry_test_support.rs@@ -79,3 +79,35 @@ impl Drop for FakeManaged {unregister_chat_model(PROVIDER_OPENHUMAN);}}++thread_local! {+ static BARE_CORE: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };+}++/// The managed provider every unit test sees unless it opts out: the fake,+/// answering for [`PROVIDER_OPENHUMAN`] only.+pub(crate) fn default_managed_entry(provider_id: &str) -> Option<ChatModelEntry> {+ if provider_id != PROVIDER_OPENHUMAN || BARE_CORE.with(std::cell::Cell::get) {+ return None;+ }+ Some(ChatModelEntry {+ build: Arc::new(build),+ probe: None,+ })+}++/// Guard that makes the current thread see a core with no managed chat-model+/// provider (the default registry state of a host that installed none).+pub(crate) struct BareCore;++/// Runs the rest of the test on a core with no managed chat-model provider.+pub(crate) fn without_managed_provider() -> BareCore {+ BARE_CORE.with(|flag| flag.set(true));+ BareCore+}++impl Drop for BareCore {+ fn drop(&mut self) {+ BARE_CORE.with(|flag| flag.set(false));+ }+}diff --git a/crates/openhuman-core/src/inference/registry_tests.rs b/crates/openhuman-core/src/inference/registry_tests.rsindex 9b995f2ff7..7cbc9a43a6 100644--- a/crates/openhuman-core/src/inference/registry_tests.rs+++ b/crates/openhuman-core/src/inference/registry_tests.rs@@ -41,6 +41,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();+ let _bare = crate::inference::registry_test_support::without_managed_provider();assert!(chat_model(PROVIDER_OPENHUMAN).is_none());assert!(embedding(PROVIDER_OPENHUMAN).is_none());assert!(catalog(PROVIDER_OPENHUMAN).is_none());@@ -169,6 +170,7 @@ fn a_registered_catalog_supplies_the_managed_limits_request() {#[test]fn selecting_the_managed_provider_with_nothing_registered_is_backend_unavailable() {let _guard = crate::inference::inference_test_guard();+ let _bare = crate::inference::registry_test_support::without_managed_provider();let _exclusive = crate::inference::provider::factory::test_provider_override::exclusive();let error = make_openhuman_backend_model_for_thread("chat",