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
fix(modules): key the served test storage to the connector module
M3gA-Mind1e1cafa84eff
diff --git a/crates/openhuman-core/src/integrations/composio/module_client.rs b/crates/openhuman-core/src/integrations/composio/module_client.rsindex 66350236d7..e1190f3470 100644--- a/crates/openhuman-core/src/integrations/composio/module_client.rs+++ b/crates/openhuman-core/src/integrations/composio/module_client.rs@@ -318,7 +318,7 @@ pub(crate) struct ModuleGuard {// next test may take the module. Without the module loader there are no// module calls to serve.#[cfg(feature = "modules")]- _storage: crate::modules::storage_host::test_module::TestModuleStorage,+ _storage: crate::modules::storage_host::backend_choice::TestModuleStorage,_lock: tokio::sync::MutexGuard<'static, ()>,}@@ -334,7 +334,7 @@ pub(crate) async fn module_guard() -> ModuleGuard {let lock = module_lock_guard().await;ModuleGuard {#[cfg(feature = "modules")]- _storage: crate::modules::storage_host::test_module::serve_test_module_storage(+ _storage: crate::modules::storage_host::backend_choice::serve_test_module_storage(crate::storage::test_support::memory_backend(),),_lock: lock,diff --git a/crates/openhuman-core/src/integrations/composio/tools/scope_gate_tests.rs b/crates/openhuman-core/src/integrations/composio/tools/scope_gate_tests.rsindex 10e4573188..c79514d282 100644--- a/crates/openhuman-core/src/integrations/composio/tools/scope_gate_tests.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/scope_gate_tests.rs@@ -247,7 +247,7 @@ async fn an_unreadable_preference_denies_at_every_gate() {.await.expect("the module stores the pref while storage is served");#[cfg(feature = "modules")]- crate::modules::storage_host::test_module::withdraw_test_module_storage();+ crate::modules::storage_host::backend_choice::withdraw_test_module_storage();#[cfg(not(feature = "modules"))]crate::storage::clear();diff --git a/crates/openhuman-core/src/modules/storage_host.rs b/crates/openhuman-core/src/modules/storage_host.rsindex 04718f6a49..03ec8a069c 100644--- a/crates/openhuman-core/src/modules/storage_host.rs+++ b/crates/openhuman-core/src/modules/storage_host.rs@@ -388,7 +388,8 @@ impl StorageHost {/// The module's binding for `scope`, built on first use and again when the/// installed backend changed. The host runs the declared schema here.async fn bind(&self, module: &str, scope: Scope) -> Result<Arc<Binding>, BindError> {- let backend = self.environment.backend().ok_or(BindError::NoBackend)?;+ let backend = backend_choice::for_module(module, &*self.environment)+ .ok_or(BindError::NoBackend)?;let key = (module.to_string(), scope.as_str().to_string());let mut bindings = self.bindings.lock().await;if let Some(existing) = bindings.get(&key) {@@ -576,9 +577,8 @@ pub(crate) fn current_module_scope(module_scope(tenant.profile.as_deref(), module_id)}-#[cfg(test)]-#[path = "storage_host_test_module.rs"]-pub(crate) mod test_module;+#[path = "storage_host_backend.rs"]+pub(crate) mod backend_choice;/// Production wiring: the broker's name owners, the installed backend, the/// host's scope rule and the compiled grants.@@ -607,10 +607,7 @@ impl Environment for Live {// one) wins. An embedder that did not gets the workspace default every// other store already opens for itself ([`crate::storage::local::backend_for`]),// so a module is not the one consumer left with no storage.- let installed = crate::storage::installed();- #[cfg(test)]- let installed = installed.or_else(test_module::test_module_storage);- installed.or_else(|| {+ crate::storage::installed().or_else(|| {let workspace = crate::core::runtime::DispatchCtx::ambient().resolved()?.workspace_dir()diff --git a/crates/openhuman-core/src/modules/storage_host_test_module.rs b/crates/openhuman-core/src/modules/storage_host_backend.rssimilarity index 64%rename from crates/openhuman-core/src/modules/storage_host_test_module.rsrename to crates/openhuman-core/src/modules/storage_host_backend.rsindex d158e7a22e..141e4ab941 100644--- a/crates/openhuman-core/src/modules/storage_host_test_module.rs+++ b/crates/openhuman-core/src/modules/storage_host_backend.rs@@ -1,11 +1,29 @@-//! Test-only storage for module calls while a unit test holds a module lock-//! (the connector module's `module_guard`). Kept out of the process storage-//! slot so it is never another concurrent test's storage (MAIN-57).+//! Which backend a module's storage binds to. Under `cfg(test)` a connector+//! module test serves its own storage here while it holds the module lock+//! (`module_guard`), kept out of the process storage slot so it is never+//! another concurrent test's storage (MAIN-57).use std::sync::Arc;use crate::storage::StorageBackend;+/// The backend `module`'s storage binds to: the host's, or under `cfg(test)`+/// the storage a connector-module test is serving.+pub(super) fn for_module(+ module: &str,+ environment: &dyn super::Environment,+) -> Option<Arc<dyn StorageBackend>> {+ #[cfg(test)]+ if module == super::super::connectors::MODULE_ID {+ if let Some(backend) = test_module_storage() {+ return Some(backend);+ }+ }+ let _ = module;+ environment.backend()+}++#[cfg(test)]/// Storage for module calls in unit tests that hold a module lock (the/// connector module's `module_guard`). A module call carries no workspace, so/// such a test needs a backend; this one is read only here, so it is never@@ -13,13 +31,15 @@ use crate::storage::StorageBackend;static TEST_MODULE_STORAGE: std::sync::Mutex<Option<Arc<dyn StorageBackend>>> =std::sync::Mutex::new(None);-pub(super) fn test_module_storage() -> Option<Arc<dyn StorageBackend>> {+#[cfg(test)]+fn test_module_storage() -> Option<Arc<dyn StorageBackend>> {TEST_MODULE_STORAGE.lock().unwrap_or_else(std::sync::PoisonError::into_inner).clone()}+#[cfg(test)]/// Serve `backend` to module calls until the returned guard drops. Hold the/// module's test lock for as long as it lives.pub(crate) fn serve_test_module_storage(backend: Arc<dyn StorageBackend>) -> TestModuleStorage {@@ -30,6 +50,7 @@ pub(crate) fn serve_test_module_storage(backend: Arc<dyn StorageBackend>) -> TesTestModuleStorage { previous }}+#[cfg(test)]/// Withdraw the backend module calls are served, as a storage outage would,/// while the guard from [`serve_test_module_storage`] is still held.pub(crate) fn withdraw_test_module_storage() {@@ -38,11 +59,13 @@ pub(crate) fn withdraw_test_module_storage() {.unwrap_or_else(std::sync::PoisonError::into_inner) = None;}+#[cfg(test)]/// Restores the previous test module storage on drop.pub(crate) struct TestModuleStorage {previous: Option<Arc<dyn StorageBackend>>,}+#[cfg(test)]impl Drop for TestModuleStorage {fn drop(&mut self) {*TEST_MODULE_STORAGEdiff --git a/scripts/ci/process-statics.json b/scripts/ci/process-statics.jsonindex 18d4fac65f..f223f01b7a 100644--- a/scripts/ci/process-statics.json+++ b/scripts/ci/process-statics.json@@ -400,7 +400,7 @@"verification": "modules/runtime_tests.rs: the_module_bus_is_a_singleton_and_serves_proxies"},{- "file": "crates/openhuman-core/src/modules/storage_host_test_module.rs",+ "file": "crates/openhuman-core/src/modules/storage_host_backend.rs","scope": "","name": "TEST_MODULE_STORAGE","type": "std::sync::Mutex<Option<Arc<dyn StorageBackend>>>",