Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(composio): withdraw the served module storage to simulate an outage

M3gA-Mind775bec566d7c
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.rs
index 0d2a9248bc..17eb25d409 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
@@ -222,13 +222,12 @@ async fn a_preference_still_in_the_legacy_file_gates_execution() {
/// read a stored preference, every gate that consults it denies.
///
/// The module caches its link to the host's storage on first use. Saving a
-/// preference while a backend is installed connects that link; removing the
+/// preference while a backend is served connects that link; withdrawing the
/// backend then makes the module's next preference read fail (`Unavailable`),
/// as a storage outage would.
///
-/// `module_guard` already holds the storage slot and installs a memory backend
-/// (restored on drop), so the test must not lock the slot a second time: the
-/// slot mutex is not reentrant and doing so deadlocks.
+/// `module_guard` serves module calls a memory backend (restored on drop);
+/// the test withdraws it rather than touching the process storage slot.
#[tokio::test]
async fn an_unreadable_preference_denies_at_every_gate() {
use crate::integrations::composio::module_client::module_guard;
@@ -246,7 +245,10 @@ async fn an_unreadable_preference_denies_at_every_gate() {
only(true, false, false),
)
.await
- .expect("the module stores the pref while storage is installed");
+ .expect("the module stores the pref while storage is served");
+ #[cfg(feature = "modules")]
+ crate::modules::storage_host::withdraw_test_module_storage();
+ #[cfg(not(feature = "modules"))]
crate::storage::clear();
let read =
diff --git a/crates/openhuman-core/src/modules/storage_host.rs b/crates/openhuman-core/src/modules/storage_host.rs
index d870c81f26..778aa6abf7 100644
--- a/crates/openhuman-core/src/modules/storage_host.rs
+++ b/crates/openhuman-core/src/modules/storage_host.rs
@@ -603,6 +603,15 @@ pub(crate) fn serve_test_module_storage(backend: Arc<dyn StorageBackend>) -> Tes
TestModuleStorage { previous }
}
+/// Withdraw the backend module calls are served, as a storage outage would,
+/// while the guard from [`serve_test_module_storage`] is still held.
+#[cfg(test)]
+pub(crate) fn withdraw_test_module_storage() {
+ *TEST_MODULE_STORAGE
+ .lock()
+ .unwrap_or_else(std::sync::PoisonError::into_inner) = None;
+}
+
/// Restores the previous test module storage on drop.
#[cfg(test)]
pub(crate) struct TestModuleStorage {