Skip to content

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

fix(modules): grant TinyConnectors the v1 preferences its migration reads

M3gA-Mindfa49607b8a9b
diff --git a/crates/openhuman-core/src/integrations/composio/module_client.rs b/crates/openhuman-core/src/integrations/composio/module_client.rs
index 32e33b8b6b..4057d33100 100644
--- a/crates/openhuman-core/src/integrations/composio/module_client.rs
+++ b/crates/openhuman-core/src/integrations/composio/module_client.rs
@@ -311,13 +311,36 @@ pub async fn call_bare<Reply: serde::de::DeserializeOwned>(
#[cfg(test)]
pub(crate) static MODULE_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());
+/// The module lock, and the storage the module keeps its preferences in.
+#[cfg(test)]
+pub(crate) struct ModuleGuard {
+ // Fields drop in order: the previous storage slot comes back before the
+ // next test may take the module.
+ _storage: crate::storage::test_support::InstalledBackendGuard,
+ _directory: tempfile::TempDir,
+ _lock: tokio::sync::MutexGuard<'static, ()>,
+}
+
/// Take the module lock for the rest of the test.
+///
+/// The module refuses a preference call when the host serves no storage, and
+/// a module call carries no workspace for the host to fall back to, so the
+/// guard installs what a booted host has: a SQLite backend of its own,
+/// restored on drop.
#[cfg(test)]
-pub(crate) async fn module_guard() -> tokio::sync::MutexGuard<'static, ()> {
+pub(crate) async fn module_guard() -> ModuleGuard {
// Tests that take the module drive its backend mode against a local mock;
// give this thread the stand-in route a host would register.
super::test_backend_route::register();
- MODULE_LOCK.lock().await
+ let lock = MODULE_LOCK.lock().await;
+ let directory = tempfile::tempdir().unwrap();
+ let url = format!("sqlite:{}", directory.path().join("storage").display());
+ let backend = crate::storage::open(&url).await.unwrap();
+ ModuleGuard {
+ _storage: crate::storage::test_support::install_for_test(&url, backend),
+ _directory: directory,
+ _lock: lock,
+ }
}
#[cfg(test)]
diff --git a/crates/openhuman-core/src/modules/storage_grant_schemas.rs b/crates/openhuman-core/src/modules/storage_grant_schemas.rs
index 24a858697f..dc30c87115 100644
--- a/crates/openhuman-core/src/modules/storage_grant_schemas.rs
+++ b/crates/openhuman-core/src/modules/storage_grant_schemas.rs
@@ -22,6 +22,7 @@ use std::sync::Arc;
use super::storage_grants::StorageGrant;
use super::storage_queue_manifest::QueueManifest;
use crate::storage::schema::module_collections;
+use crate::storage::CollectionSpec;
/// One module's row: its registry id, the schema owner that declares its
/// storage, secret prefixes the schema cannot name, and the queue manifest the
@@ -135,7 +136,14 @@ pub(super) async fn migrate_imported(ctx: &crate::core::runtime::DispatchCtx, mo
pub(super) fn grant_for(module_id: &str) -> Option<StorageGrant> {
let row = ROWS.iter().find(|row| row.module == module_id)?;
let queues = row.queues.and_then(|source| source());
- let collections = module_collections(row.owner);
+ let mut collections = module_collections(row.owner);
+ // A module may also read collections it does not provision: TinyConnectors'
+ // migration reads its v1 preferences, which its storage needs list.
+ for name in read_collections(row.owner) {
+ if !collections.iter().any(|spec| spec.name == name) {
+ collections.push(CollectionSpec::new(name));
+ }
+ }
let secret_prefixes: Vec<String> = row.secrets.iter().map(|s| (*s).to_owned()).collect();
// Collection declarations are now the owner contracts' only published
// storage inventory. Stream/blob/secret grants remain explicit below
@@ -155,6 +163,13 @@ pub(super) fn grant_for(module_id: &str) -> Option<StorageGrant> {
})
}
+fn read_collections(owner: &str) -> Vec<String> {
+ match owner {
+ "connectors" => tinyconnectors_bus::storage::storage_needs().collections,
+ _ => Vec::new(),
+ }
+}
+
fn stream_prefixes(owner: &str) -> Vec<String> {
match owner {
"mcp" => vec![tinymcp_bus::storage::AUDIT_STREAM.to_owned()],
diff --git a/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs b/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs
index 43e99a1656..c93c73de3e 100644
--- a/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs
+++ b/crates/openhuman-core/src/modules/storage_grant_schemas_tests.rs
@@ -181,3 +181,23 @@ fn non_document_grants_match_the_owner_contracts_without_broad_prefixes() {
Err(Denied::Target)
);
}
+
+#[test]
+fn connectors_may_read_the_v1_preferences_its_migration_moves() {
+ let connectors = declared("tinyconnectors").unwrap();
+ for collection in [
+ tinyconnectors_bus::storage::PREFS_NAMESPACE,
+ tinyconnectors_bus::storage::MIGRATIONS_NAMESPACE,
+ tinyconnectors_bus::storage::LEGACY_PREFS_NAMESPACE,
+ ] {
+ assert!(
+ allowed(
+ &connectors,
+ Object::Documents,
+ "Get",
+ json!({"collection": collection, "id": "gmail"})
+ ),
+ "{collection} is not granted"
+ );
+ }
+}