Skip to content

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

refactor(composio): split client factory into its own module

Steven Enamakel091107fa1db4
diff --git a/crates/openhuman-core/src/integrations/composio/client.rs b/crates/openhuman-core/src/integrations/composio/client.rs
index 120cf051a1..f56bbc2a78 100644
--- a/crates/openhuman-core/src/integrations/composio/client.rs
+++ b/crates/openhuman-core/src/integrations/composio/client.rs
@@ -24,7 +24,10 @@ pub use direct::direct_list_connections;
#[cfg(test)]
pub(crate) use direct::direct_list_tools;
pub(crate) use factory::create_direct_client_for_api_key;
-pub use factory::{resolve_composio_route, ComposioRoute};
+pub use factory::{
+ register_composio_route_builder, resolve_composio_route, unregister_composio_route_builder,
+ ComposioRoute, ComposioRouteBuilder,
+};
pub(crate) use network::module_transport_with_proxy;
// Brought into this module's own namespace (private `use`, not `pub use`)
diff --git a/crates/openhuman-core/src/integrations/composio/client/factory.rs b/crates/openhuman-core/src/integrations/composio/client/factory.rs
index 22c5d76357..4d1efddcf6 100644
--- a/crates/openhuman-core/src/integrations/composio/client/factory.rs
+++ b/crates/openhuman-core/src/integrations/composio/client/factory.rs
@@ -202,3 +202,7 @@ pub fn resolve_composio_route(config: &crate::config::Config) -> anyhow::Result<
}
}
}
+
+#[cfg(test)]
+#[path = "factory_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/integrations/composio/client/factory_tests.rs b/crates/openhuman-core/src/integrations/composio/client/factory_tests.rs
new file mode 100644
index 0000000000..d1baf05ad3
--- /dev/null
+++ b/crates/openhuman-core/src/integrations/composio/client/factory_tests.rs
@@ -0,0 +1,54 @@
+use super::*;
+
+fn config_with_mode(mode: &str) -> crate::config::Config {
+ let mut config = crate::config::Config::default();
+ config.composio.mode = mode.to_string();
+ config
+}
+
+#[test]
+fn a_registered_route_builder_resolves_the_backend_mode() {
+ let config = config_with_mode("backend");
+ register_composio_route_builder("backend", |_| Ok(ComposioRoute::Backend));
+ let route = resolve_composio_route(&config);
+ unregister_composio_route_builder("backend");
+ assert_eq!(route.unwrap().mode(), COMPOSIO_MODE_BACKEND);
+}
+
+#[test]
+fn the_empty_mode_uses_the_backend_route_builder() {
+ let config = config_with_mode("");
+ register_composio_route_builder("backend", |_| Ok(ComposioRoute::Backend));
+ let route = resolve_composio_route(&config);
+ unregister_composio_route_builder("backend");
+ assert!(matches!(route, Ok(ComposioRoute::Backend)));
+}
+
+#[test]
+fn a_route_builder_error_is_returned_unchanged() {
+ let config = config_with_mode("backend");
+ register_composio_route_builder("backend", |_| anyhow::bail!("no hosted session"));
+ let route = resolve_composio_route(&config);
+ unregister_composio_route_builder("backend");
+ assert_eq!(route.err().unwrap().to_string(), "no hosted session");
+}
+
+#[test]
+fn without_a_route_builder_the_built_in_resolution_applies() {
+ assert!(resolve_composio_route(&config_with_mode("disabled")).is_err());
+ let unknown = resolve_composio_route(&config_with_mode("bogus"))
+ .err()
+ .unwrap()
+ .to_string();
+ assert!(unknown.contains("unknown composio mode"));
+}
+
+#[test]
+fn a_host_pinned_credential_wins_over_a_registered_builder() {
+ let mut config = config_with_mode("backend");
+ config.composio.host_credential = Some(crate::config::ComposioHostCredential::new("key"));
+ register_composio_route_builder("backend", |_| anyhow::bail!("must not run"));
+ let route = resolve_composio_route(&config);
+ unregister_composio_route_builder("backend");
+ assert!(matches!(route, Ok(ComposioRoute::Direct(_))));
+}