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
refactor(composio): migrate direct client tests to new list_tools interface
Steven Enamakelf4a69ef6e7ac
diff --git a/crates/openhuman-core/src/integrations/composio/tools/direct/transport.rs b/crates/openhuman-core/src/integrations/composio/tools/direct/transport.rsindex b3bdaaea3a..4e350f4987 100644--- a/crates/openhuman-core/src/integrations/composio/tools/direct/transport.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/direct/transport.rs@@ -14,8 +14,8 @@ use tinyconnectors::client::{DirectRoute, Route, Transport};use tinyconnectors::Error as ConnectorError;use super::http_errors::response_error;-use crate::integrations::composio::types::{ComposioConnectionsResponse, ComposioToolsResponse};use super::types::DirectComposioClient;+use crate::integrations::composio::types::{ComposioConnectionsResponse, ComposioToolsResponse};/// Failure label per request path, matching the messages the host has always/// produced (and the `[composio-direct]` observability anchors match on).diff --git a/crates/openhuman-core/src/integrations/composio/tools/direct_tests_constructor_and_wire_types_tests.rs b/crates/openhuman-core/src/integrations/composio/tools/direct_tests_constructor_and_wire_types_tests.rsindex 10a2faab79..ea91be4703 100644--- a/crates/openhuman-core/src/integrations/composio/tools/direct_tests_constructor_and_wire_types_tests.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/direct_tests_constructor_and_wire_types_tests.rs@@ -28,8 +28,11 @@ async fn direct_client_does_not_forward_credentials_across_redirects() {)).await;- let tool = DirectComposioClient::new_with_v3_base("ck_secret_value", format!("{source}/tools"));- assert!(tool.list_tool_schemas_v3(&[], None).await.is_err());+ let tool = Arc::new(DirectComposioClient::new_with_v3_base(+ "ck_secret_value",+ source,+ ));+ assert!(tool.list_tools(&[], &[]).await.is_err());assert!(!redirected_request_seen.load(std::sync::atomic::Ordering::SeqCst));}@@ -60,112 +63,7 @@ fn composio_api_base_url_is_v3() {// ── list_tool_schemas_v3 query builder (direct-mode tags) ──────────────────-#[test]-fn build_list_tool_schemas_v3_query_always_includes_limit() {- let params = DirectComposioClient::build_list_tool_schemas_v3_query(&[], None);- assert_eq!(- params,- vec![- ("limit", "200".to_string()),- ("toolkit_versions", "latest".to_string()),- ]- );-}--#[test]-fn build_list_tool_schemas_v3_query_joins_toolkits_as_csv() {- let params = DirectComposioClient::build_list_tool_schemas_v3_query(&["github", "gmail"], None);- assert_eq!(- params,- vec![- ("limit", "200".to_string()),- ("toolkit_versions", "latest".to_string()),- ("toolkits", "github,gmail".to_string()),- ]- );-}--#[test]-fn build_list_tool_schemas_v3_query_emits_repeated_tags_params() {- // Composio v3 `/tools` takes tags as repeated `tags=` params- // (tags=stars&tags=repos), NOT comma-joined like the backend proxy.- // A Vec of duplicate ("tags", _) keys is exactly what reqwest's- // `.query(¶ms)` serializes into repeated query params.- let params = DirectComposioClient::build_list_tool_schemas_v3_query(- &["github"],- Some(&["stars", "repos"]),- );- assert_eq!(- params,- vec![- ("limit", "200".to_string()),- ("toolkit_versions", "latest".to_string()),- ("toolkits", "github".to_string()),- ("tags", "stars".to_string()),- ("tags", "repos".to_string()),- ]- );-}--#[test]-fn build_list_tool_schemas_v3_query_tags_without_toolkit_filter() {- let params =- DirectComposioClient::build_list_tool_schemas_v3_query(&[], Some(&["readOnlyHint"]));- assert_eq!(- params,- vec![- ("limit", "200".to_string()),- ("toolkit_versions", "latest".to_string()),- ("tags", "readOnlyHint".to_string()),- ]- );-}--#[test]-fn build_list_tool_schemas_v3_query_trims_and_drops_blank_entries() {- let params = DirectComposioClient::build_list_tool_schemas_v3_query(- &[" github ", " "],- Some(&[" stars ", "", " "]),- );- assert_eq!(- params,- vec![- ("limit", "200".to_string()),- ("toolkit_versions", "latest".to_string()),- ("toolkits", "github".to_string()),- ("tags", "stars".to_string()),- ]- );-}--#[test]-fn build_list_tool_schemas_v3_query_empty_tags_slice_is_no_filter() {- // `Some(&[])` and an all-blank slice must both behave like "no tags".- let empty = DirectComposioClient::build_list_tool_schemas_v3_query(&["gmail"], Some(&[]));- let blank = DirectComposioClient::build_list_tool_schemas_v3_query(&["gmail"], Some(&[" "]));- let expected = vec![- ("limit", "200".to_string()),- ("toolkit_versions", "latest".to_string()),- ("toolkits", "gmail".to_string()),- ];- assert_eq!(empty, expected);- assert_eq!(blank, expected);-}--#[test]-fn build_list_tool_schemas_v3_query_pins_toolkit_versions_latest() {- // #3932: without toolkit_versions, Composio v3 defaults to the pinned- // 00000000_00 snapshot, so any toolkit published after it (Outlook and- // every other post-launch toolkit) lists zero tools. `latest` keeps them- // visible.- let params = DirectComposioClient::build_list_tool_schemas_v3_query(&["outlook"], None);- assert!(- params.contains(&("toolkit_versions", "latest".to_string())),- "query must pin toolkit_versions=latest; got {params:?}"- );-}--// ── list_tool_schemas_v3 over HTTP (direct-mode tags reach the wire) ───────+// ── direct list_tools over HTTP (direct-mode tags reach the wire) ───────#[tokio::test]async fn list_tool_schemas_v3_sends_repeated_tags_to_v3_tools_endpoint() {@@ -196,11 +94,18 @@ async fn list_tool_schemas_v3_sends_repeated_tags_to_v3_tools_endpoint() {);let base = start_mock_backend(app).await;- let tool = DirectComposioClient::new_with_v3_base("ck_test_direct", base);+ let tool = Arc::new(DirectComposioClient::new_with_v3_base(+ "ck_test_direct",+ base,+ ));let items = tool- .list_tool_schemas_v3(&["github"], Some(&["stars", "repos"]))+ .list_tools(+ &["github".to_string()],+ &["stars".to_string(), "repos".to_string()],+ ).await- .expect("direct v3 /tools should succeed against the mock");+ .expect("direct v3 /tools should succeed against the mock")+ .tools;let query = captured.lock()@@ -226,8 +131,11 @@ async fn list_tool_schemas_v3_sends_repeated_tags_to_v3_tools_endpoint() {// And the v3 envelope reshapes back into schema items.assert_eq!(items.len(), 1);- assert_eq!(items[0].slug, "GITHUB_STAR_A_REPOSITORY");- assert_eq!(items[0].toolkit_slug.as_deref(), Some("github"));+ assert_eq!(items[0].function.name, "GITHUB_STAR_A_REPOSITORY");+ assert_eq!(+ items[0].function.description.as_deref(),+ Some("Star a repository")+ );}// ── execute_action over HTTP (correct v3 path/slug/body reach the wire) ────@@ -269,3 +177,62 @@ fn sanitize_error_message_replaces_newlines_with_spaces() {assert!(sanitized.contains("line1"));assert!(sanitized.contains("line2"));}++// ── failure messages stay byte-identical to the pre-module client ─────────++#[tokio::test]+async fn http_failures_keep_their_user_facing_messages() {+ use axum::{http::StatusCode, routing::get, Json, Router};+ let app = Router::new()+ .route(+ "/connected_accounts",+ get(|| async {+ (+ StatusCode::UNAUTHORIZED,+ Json(json!({"error": {"message": "Invalid API key"}})),+ )+ }),+ )+ .route(+ "/tools",+ get(|| async { (StatusCode::INTERNAL_SERVER_ERROR, "") }),+ );+ let tool = Arc::new(DirectComposioClient::new_with_v3_base(+ "ck_test_direct",+ start_mock_backend(app).await,+ ));++ let err = tool.list_connections().await.unwrap_err();+ assert_eq!(+ format!("{err:#}"),+ "Composio v3 connected_accounts failed: HTTP 401: Invalid API key"+ );+ let err = tool.list_tools(&[], &[]).await.unwrap_err();+ assert_eq!(+ format!("{err:#}"),+ "Composio v3 list_tool_schemas: HTTP 500"+ );+}++#[tokio::test]+async fn connections_come_back_without_route_lifted_identity() {+ use axum::{routing::get, Json, Router};+ let app = Router::new().route(+ "/connected_accounts",+ get(|| async {+ Json(json!({"items": [+ {"id": " ca_1 ", "toolkit": "gmail", "status": "ACTIVE", "email": "[email protected]"},+ {"id": " ", "toolkit": "slack", "status": "ACTIVE"}+ ]}))+ }),+ );+ let tool = Arc::new(DirectComposioClient::new_with_v3_base(+ "ck_test_direct",+ start_mock_backend(app).await,+ ));+ let connections = tool.list_connections().await.unwrap().connections;+ assert_eq!(connections.len(), 1, "blank id dropped");+ assert_eq!(connections[0].id, "ca_1");+ // Identity is the host's to enrich from cached profiles.+ assert!(connections[0].account_email.is_none());+}diff --git a/crates/openhuman-core/src/integrations/composio/tools/direct_tests_sanitization_and_connected_accounts_tests.rs b/crates/openhuman-core/src/integrations/composio/tools/direct_tests_sanitization_and_connected_accounts_tests.rsindex af8c8f7d1f..ca4b60c9ad 100644--- a/crates/openhuman-core/src/integrations/composio/tools/direct_tests_sanitization_and_connected_accounts_tests.rs+++ b/crates/openhuman-core/src/integrations/composio/tools/direct_tests_sanitization_and_connected_accounts_tests.rs@@ -39,142 +39,3 @@ fn sanitize_error_message_replaces_all_sensitive_variants() {"camelCase userId should be redacted");}--// ── composio_auth_config enabled detection ────────────────────────────────--// ── map_v3_tools_to_actions: item without slug falls back to name ─────────--// ── category ──────────────────────────────────────────────────────────────--// ── v3 /connected_accounts shape parsing ───────────────────────────-//-// Two upstream shapes covered:-// 1. `toolkit` as a plain string slug (older payloads)-// 2. `toolkit` as a nested `{ slug, ... }` object (newer payloads,-// mirroring the `de_string_or_object` drift handled by `types.rs`)-// Plus an `appName` fallback for payloads that omit `toolkit` entirely.--#[test]-fn connected_account_toolkit_slug_from_string() {- let raw: ComposioConnectedAccount = serde_json::from_value(json!({- "id": "ca_1",- "status": "ACTIVE",- "toolkit": "gmail",- "created_at": "2026-05-15T00:00:00Z"- }))- .unwrap();- assert_eq!(raw.id, "ca_1");- assert_eq!(raw.status.as_deref(), Some("ACTIVE"));- assert_eq!(raw.toolkit_slug().as_deref(), Some("gmail"));- assert_eq!(raw.created_at.as_deref(), Some("2026-05-15T00:00:00Z"));-}--#[test]-fn connected_account_toolkit_slug_from_nested_object() {- let raw: ComposioConnectedAccount = serde_json::from_value(json!({- "id": "ca_2",- "status": "INITIATED",- "toolkit": {"slug": "slack", "logo": "https://example.test/slack.png"}- }))- .unwrap();- assert_eq!(raw.toolkit_slug().as_deref(), Some("slack"));-}--#[test]-fn connected_account_toolkit_slug_fallback_to_app_name() {- let raw: ComposioConnectedAccount = serde_json::from_value(json!({- "id": "ca_3",- "status": "ACTIVE",- "appName": "notion"- }))- .unwrap();- assert_eq!(raw.toolkit_slug().as_deref(), Some("notion"));-}--#[test]-fn connected_account_toolkit_slug_returns_none_when_unrecognized() {- let raw: ComposioConnectedAccount = serde_json::from_value(json!({- "id": "ca_4",- "status": "PENDING",- "toolkit": {"unrelated": 42}- }))- .unwrap();- assert!(raw.toolkit_slug().is_none());-}--#[test]-fn connected_account_tolerates_missing_fields() {- // All optional fields absent — the row must still parse so a- // malformed Composio response doesn't blow up `list_connections`.- let raw: ComposioConnectedAccount = serde_json::from_value(json!({"id": "ca_5"})).unwrap();- assert_eq!(raw.id, "ca_5");- assert!(raw.status.is_none());- assert!(raw.toolkit_slug().is_none());- assert!(raw.created_at.is_none());-}--#[test]-fn connected_account_accepts_camelcase_created_at() {- // Tolerate both `created_at` (canonical) and `createdAt` (drift).- let raw: ComposioConnectedAccount = serde_json::from_value(json!({- "id": "ca_6",- "createdAt": "2026-05-15T00:00:00Z"- }))- .unwrap();- assert_eq!(raw.created_at.as_deref(), Some("2026-05-15T00:00:00Z"));-}--// ── API key trimming (issue #2323) ────────────────────────-//-// Composio v3 rejects API keys with leading/trailing whitespace as-// "Invalid API key format" (Sentry TAURI-RUST-D3). The constructor must-// strip surrounding whitespace defensively, but MUST preserve internal-// whitespace so legitimate keys containing spaces are not corrupted.--#[test]-fn direct_client_trims_surrounding_whitespace_in_api_key() {- let tool = DirectComposioClient::new(" key123 ");- assert_eq!(tool.api_key, "key123");-}--#[test]-fn direct_client_trims_trailing_newline_in_api_key() {- // The real-world Sentry case: secret store payloads frequently carry a- // trailing newline (clipboard paste, file read). It must be stripped.- let tool = DirectComposioClient::new("key123\n");- assert_eq!(tool.api_key, "key123");-}--#[test]-fn direct_client_preserves_internal_whitespace_in_api_key() {- // Pins the trim-scope: a future refactor must NOT widen this to- // `replace(' ', "")` or similar — only surrounding whitespace is stripped.- let tool = DirectComposioClient::new("k1 k2");- assert_eq!(tool.api_key, "k1 k2");-}--#[test]-fn direct_client_accepts_empty_api_key_without_panic() {- let tool = DirectComposioClient::new("");- assert_eq!(tool.api_key, "");-}--#[test]-fn is_loopback_http_url_accepts_real_loopback_hosts() {- assert!(is_loopback_http_url("http://127.0.0.1:8080/api/v3/tools"));- assert!(is_loopback_http_url("http://localhost:3000/"));- assert!(is_loopback_http_url("http://[::1]:9000/tools"));-}--#[test]-fn is_loopback_http_url_rejects_userinfo_smuggling_and_non_loopback() {- // Prefix-matching would have accepted these; host parsing rejects them.- assert!(!is_loopback_http_url(- "http://127.0.0.1:[email protected]/api/v3/tools"- ));- assert!(!is_loopback_http_url("http://localhost:[email protected]/"));- assert!(!is_loopback_http_url("http://evil.com:8080/"));- // HTTPS and unparseable inputs are not loopback-HTTP.- assert!(!is_loopback_http_url("https://127.0.0.1:8080/"));- assert!(!is_loopback_http_url("not a url"));-}