Skip to content

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

test(composio): cover legacy scope preference migration

Steven Enamakelfc41c74a9b10
diff --git a/crates/openhuman-core/src/integrations/composio/module_client.rs b/crates/openhuman-core/src/integrations/composio/module_client.rs
index ad8084c475..0f96492f2f 100644
--- a/crates/openhuman-core/src/integrations/composio/module_client.rs
+++ b/crates/openhuman-core/src/integrations/composio/module_client.rs
@@ -111,10 +111,12 @@ async fn prime_curated_catalogs(config: &crate::config::Config) {
/// without a module loader has no catalogs to read and answers `Ok`.
#[cfg(feature = "modules")]
pub async fn ensure_catalogs(config: &crate::config::Config) -> Result<(), String> {
- super::contract::curated::prime(config).await.map_err(|error| {
- tracing::debug!("[composio][curated] prime failed: {error}");
- error
- })
+ super::contract::curated::prime(config)
+ .await
+ .map_err(|error| {
+ tracing::debug!("[composio][curated] prime failed: {error}");
+ error
+ })
}
/// Without the module loader there is no catalog to read.
diff --git a/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs b/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs
index 67594f0453..4b0dd63069 100644
--- a/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs
@@ -182,3 +182,52 @@ async fn composio_execute_via_mock_propagates_backend_error() {
assert!(err.starts_with("[composio:error:"), "got: {err}");
assert!(err.contains("rate limited"), "got: {err}");
}
+
+#[tokio::test]
+async fn composio_list_tools_honours_a_preference_still_in_the_legacy_file() {
+ // A workspace upgraded from before the preference moved into the module
+ // still has `composio_user_scopes.json`. The module filters the listing by
+ // the preference it holds, so that file must be migrated before the call;
+ // otherwise its default (`write` on) outranks the user's stored `write=false`.
+ let _serialised = module_guard().await;
+ let app = Router::new().route(
+ "/agent-integrations/composio/tools",
+ get(|| async {
+ Json(json!({
+ "success": true,
+ "data": {"tools": [
+ {"type":"function","function":{"name":"GMAIL_FETCH_EMAILS"}},
+ {"type":"function","function":{"name":"GMAIL_SEND_EMAIL"}}
+ ]}
+ }))
+ }),
+ );
+ let base = start_mock_backend(app).await;
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_with_backend(&tmp, base);
+ let legacy = crate::integrations::composio::file_store::path(
+ &config,
+ crate::integrations::composio::file_store::USER_SCOPES_FILE,
+ );
+ std::fs::create_dir_all(legacy.parent().unwrap()).unwrap();
+ std::fs::write(
+ &legacy,
+ json!({"gmail": {"read": true, "write": false, "admin": false}}).to_string(),
+ )
+ .unwrap();
+
+ let outcome = composio_list_tools(&config, Some(vec!["gmail".into()]), None).await;
+ // The module's preference store is process-wide: put the default back
+ // before asserting so a failure cannot leak `write=false` into other tests.
+ let restored = save_user_scope_pref(&config, "gmail", Default::default()).await;
+ let outcome = outcome.unwrap();
+ restored.unwrap();
+
+ let names: Vec<&str> = outcome
+ .value
+ .tools
+ .iter()
+ .map(|tool| tool.function.name.as_str())
+ .collect();
+ assert_eq!(names, ["GMAIL_FETCH_EMAILS"]);
+}
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 f8160c8e78..b1cb069d91 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
@@ -144,3 +144,37 @@ fn the_slack_channel_invite_stays_admin_scoped() {
assert_eq!(invite.scope, ToolScope::Admin);
assert!(!UserScopePref::default().allows(invite.scope));
}
+
+#[tokio::test]
+async fn a_preference_still_in_the_legacy_file_gates_execution() {
+ // The execute gate asks the module (`ListVisibleTools`), which only knows
+ // rows already migrated out of the legacy workspace file.
+ use crate::integrations::composio::module_client::module_guard;
+ let _serialised = module_guard().await;
+ let tmp = tempfile::tempdir().unwrap();
+ let mut config = Config::default();
+ config.workspace_dir = tmp.path().join("workspace");
+ config.config_path = tmp.path().join("config.toml");
+ let legacy = crate::integrations::composio::file_store::path(
+ &config,
+ crate::integrations::composio::file_store::USER_SCOPES_FILE,
+ );
+ std::fs::create_dir_all(legacy.parent().unwrap()).unwrap();
+ std::fs::write(
+ &legacy,
+ serde_json::json!({"gmail": {"read": true, "write": false, "admin": false}}).to_string(),
+ )
+ .unwrap();
+
+ let decision = evaluate_tool_visibility(&config, "GMAIL_SEND_EMAIL").await;
+ let restored =
+ super::super::ops::save_user_scope_pref(&config, "gmail", Default::default()).await;
+ restored.unwrap();
+
+ assert!(matches!(
+ decision,
+ ToolDecision::BlockedByScope {
+ scope: ToolScope::Write
+ }
+ ));
+}