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
test(flows): move composio flow-gate tests to their own module
Steven Enamakel512d808e0a6c
diff --git a/crates/openhuman-core/src/flows/tinyflows/caps/ops_tool_results_and_credentials_tests.rs b/crates/openhuman-core/src/flows/tinyflows/caps/ops_tool_results_and_credentials_tests.rsindex 332c0c62eb..f6c4849313 100644--- a/crates/openhuman-core/src/flows/tinyflows/caps/ops_tool_results_and_credentials_tests.rs+++ b/crates/openhuman-core/src/flows/tinyflows/caps/ops_tool_results_and_credentials_tests.rs@@ -1,7 +1,4 @@use super::*;-use crate::integrations::composio::catalog::{- seed_live_catalog_cache, seed_live_catalog_cache_expired, ToolContract,-};// ── native `oh:` tool result handling ──────────────────────────────────@@ -70,260 +67,6 @@ fn native_tool_success_passes_through() {assert!(reject_failed_native_tool_result("oh:storage_upload_file", &result).is_ok());}-// ── reject_unsuccessful_composio_response (B6) ──────────────────────────--#[test]-fn reject_unsuccessful_composio_response_errors_on_provider_failure() {- // Live-observed shape: SLACK_SEND_MESSAGE 400s upstream but the- // Composio execute call itself still returns HTTP 200.- let resp = ComposioExecuteResponse {- data: json!({}),- successful: false,- error: Some("Invalid request data".to_string()),- cost_usd: 0.0,- markdown_formatted: None,- };- let err = reject_unsuccessful_composio_response("SLACK_SEND_MESSAGE", resp)- .expect_err("unsuccessful response must become an Err");- let msg = err.to_string();- assert!(msg.contains("SLACK_SEND_MESSAGE"), "message was: {msg}");- assert!(msg.contains("Invalid request data"), "message was: {msg}");-}--#[test]-fn reject_unsuccessful_composio_response_falls_back_when_error_field_is_empty() {- let resp = ComposioExecuteResponse {- data: json!({}),- successful: false,- error: None,- cost_usd: 0.0,- markdown_formatted: None,- };- let err = reject_unsuccessful_composio_response("GMAIL_SEND_EMAIL", resp)- .expect_err("unsuccessful response must become an Err");- let msg = err.to_string();- assert!(msg.contains("GMAIL_SEND_EMAIL"), "message was: {msg}");- assert!(- msg.contains("no error detail returned by the provider"),- "message was: {msg}"- );-}--#[test]-fn reject_unsuccessful_composio_response_passes_through_on_success() {- let resp = ComposioExecuteResponse {- data: json!({ "ts": "123.456" }),- successful: true,- error: None,- cost_usd: 0.002,- markdown_formatted: None,- };- let ok = reject_unsuccessful_composio_response("SLACK_SEND_MESSAGE", resp.clone())- .expect("successful response must remain Ok");- assert!(ok.successful);- assert_eq!(ok.data, resp.data);-}--// ── input_context (PR A) ────────────────────────────────────────────────--/// A `composio:<toolkit>:<connection_id>` ref parses to its id and that id-/// resolves to the SPECIFIC connected account (toolkit + display label) —-/// not the toolkit's default connection.-#[test]-fn connection_ref_resolves_to_the_chosen_account() {- let integrations = vec![integration(- "gmail",- true,- vec![- connection("conn_work", Some("[email protected]"), true),- connection("conn_home", Some("[email protected]"), false),- ],- )];-- let id = composio_connection_id("composio:gmail:conn_home")- .expect("well-formed composio connection_ref should parse");- assert_eq!(id, "conn_home");-- let (toolkit, label) =- resolve_account(&integrations, id).expect("id should resolve to a connected account");- assert_eq!(toolkit, "gmail");- // The non-default account was chosen — resolution is by id, not default.- assert_eq!(label, Some("[email protected]"));-- // An id the user does not hold resolves to nothing (best-effort log path).- assert!(resolve_account(&integrations, "conn_unknown").is_none());-}--/// A made-up toolkit that OpenHuman ships no static catalog for and the user-/// has NOT connected still rejects — even when the connected set is present-/// but simply doesn't contain it.-#[tokio::test]-async fn unknown_toolkit_still_rejects() {- use crate::integrations::composio::contract::catalog_for_toolkit;- let config = Config::default();- // Precondition: `flowstestkit` is genuinely uncatalogued, so the decision- // flows through the connected-set path (not the static curated path).- assert!(catalog_for_toolkit("flowstestkit").is_none());-- // No connected set at all → fail-closed reject.- assert!(- !flow_tool_allowed(- &crate::core::runtime::DispatchCtx::ambient(),- &config,- "FLOWSTESTKIT_DO_THING",- None- )- .await- );- // Connected set present but does not include this toolkit → reject.- assert!(- !flow_tool_allowed(- &crate::core::runtime::DispatchCtx::ambient(),- &config,- "FLOWSTESTKIT_DO_THING",- Some(&["gmail".to_string()])- )- .await- );- // A blank slug is always rejected.- assert!(- !flow_tool_allowed(- &crate::core::runtime::DispatchCtx::ambient(),- &config,- "",- Some(&["flowstestkit".to_string()])- )- .await- );-}--/// A real Composio toolkit OpenHuman ships no static catalog for now PASSES-/// once the user has an ACTIVE connection for it (the TODO(0.3) fix) AND-/// the slug is a genuine action in its LIVE catalog (systemic tool-contract-/// fix) — seeded here so the test never touches a live Composio backend.-/// The exact same slug rejects above without a connection.-#[tokio::test]-async fn connected_uncatalogued_toolkit_now_passes() {- use crate::integrations::composio::contract::catalog_for_toolkit;- assert!(catalog_for_toolkit("flowstestkit").is_none());-- let config = Config::default();- seed_live_catalog_cache(- "flowstestkit",- vec![ToolContract {- slug: "FLOWSTESTKIT_DO_THING".to_string(),- toolkit: "flowstestkit".to_string(),- description: None,- required_args: Vec::new(),- input_schema: None,- output_fields: Vec::new(),- output_schema: None,- primary_array_path: None,- is_curated: false,- }],- );-- assert!(- flow_tool_allowed(- &crate::core::runtime::DispatchCtx::ambient(),- &config,- "FLOWSTESTKIT_DO_THING",- Some(&["flowstestkit".to_string()])- )- .await- );- // Case-insensitive match on the toolkit slug.- assert!(- flow_tool_allowed(- &crate::core::runtime::DispatchCtx::ambient(),- &config,- "FLOWSTESTKIT_DO_THING",- Some(&["FlowsTestKit".to_string()])- )- .await- );-}--/// E-m8: an EXPIRED `LIVE_CATALOG_CACHE` entry must be treated as a cache-/// miss, not a permanent hit. Before the TTL fix, seeding the cache once-/// (as `connected_uncatalogued_toolkit_now_passes` does above) made a-/// slug pass forever, for the life of the process — a Composio action-/// added after the first fetch would stay invisible until restart. Here-/// the seeded entry is pre-expired, so `fetch_live_toolkit_catalog` must-/// re-fetch — which fails in this test (no live Composio backend) — and-/// `flow_tool_allowed` must fail CLOSED, unlike the fresh-seed case above-/// which passes.-#[tokio::test]-async fn expired_live_catalog_entry_is_treated_as_a_cache_miss() {- use crate::integrations::composio::contract::catalog_for_toolkit;- assert!(catalog_for_toolkit("flowsexpiredkit").is_none());-- let config = Config::default();- seed_live_catalog_cache_expired(- "flowsexpiredkit",- vec![ToolContract {- slug: "FLOWSEXPIREDKIT_DO_THING".to_string(),- toolkit: "flowsexpiredkit".to_string(),- description: None,- required_args: Vec::new(),- input_schema: None,- output_fields: Vec::new(),- output_schema: None,- primary_array_path: None,- is_curated: false,- }],- );-- assert!(- !flow_tool_allowed(- &crate::core::runtime::DispatchCtx::ambient(),- &config,- "FLOWSEXPIREDKIT_DO_THING",- Some(&["flowsexpiredkit".to_string()])- )- .await,- "an expired cache entry must be re-fetched (and, with no live backend in this test, \- fail closed) rather than served as a permanent hit"- );-}--/// A CONNECTED but uncatalogued toolkit still rejects a slug that shares-/// its prefix but isn't a genuine action in the LIVE catalog — the-/// systemic tool-contract fix's tightening: connection alone is no longer-/// sufficient, the slug itself must be real.-#[tokio::test]-async fn connected_uncatalogued_toolkit_rejects_a_hallucinated_slug() {- use crate::integrations::composio::contract::catalog_for_toolkit;- assert!(catalog_for_toolkit("flowstestkit").is_none());-- let config = Config::default();- seed_live_catalog_cache(- "flowstestkit",- vec![ToolContract {- slug: "FLOWSTESTKIT_DO_THING".to_string(),- toolkit: "flowstestkit".to_string(),- description: None,- required_args: Vec::new(),- input_schema: None,- output_fields: Vec::new(),- output_schema: None,- primary_array_path: None,- is_curated: false,- }],- );-- assert!(- !flow_tool_allowed(- &crate::core::runtime::DispatchCtx::ambient(),- &config,- "FLOWSTESTKIT_MADE_UP_ACTION",- Some(&["flowstestkit".to_string()])- )- .await,- "a hallucinated slug for a connected-but-uncurated toolkit must still reject"- );-}-/// A `http_cred:<name>` ref resolves to the stored bearer credential and/// injects `Authorization: Bearer <token>` onto the outbound request.#[test]diff --git a/crates/openhuman-core/src/integrations/composio/flow_gate_tests.rs b/crates/openhuman-core/src/integrations/composio/flow_gate_tests.rsnew file mode 100644index 0000000000..17350bba06--- /dev/null+++ b/crates/openhuman-core/src/integrations/composio/flow_gate_tests.rs@@ -0,0 +1,285 @@+use super::*;+use crate::agent::prompts::types::IntegrationConnection;+use crate::integrations::composio::catalog::{+ seed_live_catalog_cache, seed_live_catalog_cache_expired, ToolContract,+};+use crate::integrations::composio::{ComposioExecuteResponse, ConnectedIntegration};++fn integration(+ toolkit: &str,+ connected: bool,+ connections: Vec<IntegrationConnection>,+) -> ConnectedIntegration {+ ConnectedIntegration {+ toolkit: toolkit.to_string(),+ description: String::new(),+ tools: Vec::new(),+ gated_tools: Vec::new(),+ connected,+ connections,+ non_active_status: None,+ }+}++fn connection(id: &str, label: Option<&str>, is_default: bool) -> IntegrationConnection {+ IntegrationConnection {+ connection_id: id.to_string(),+ label: label.map(str::to_string),+ is_default,+ }+}++// ── reject_unsuccessful_composio_response (B6) ──────────────────────────++#[test]+fn reject_unsuccessful_composio_response_errors_on_provider_failure() {+ // Live-observed shape: SLACK_SEND_MESSAGE 400s upstream but the+ // Composio execute call itself still returns HTTP 200.+ let resp = ComposioExecuteResponse {+ data: json!({}),+ successful: false,+ error: Some("Invalid request data".to_string()),+ cost_usd: 0.0,+ markdown_formatted: None,+ };+ let err = reject_unsuccessful_composio_response("SLACK_SEND_MESSAGE", resp)+ .expect_err("unsuccessful response must become an Err");+ let msg = err.to_string();+ assert!(msg.contains("SLACK_SEND_MESSAGE"), "message was: {msg}");+ assert!(msg.contains("Invalid request data"), "message was: {msg}");+}++#[test]+fn reject_unsuccessful_composio_response_falls_back_when_error_field_is_empty() {+ let resp = ComposioExecuteResponse {+ data: json!({}),+ successful: false,+ error: None,+ cost_usd: 0.0,+ markdown_formatted: None,+ };+ let err = reject_unsuccessful_composio_response("GMAIL_SEND_EMAIL", resp)+ .expect_err("unsuccessful response must become an Err");+ let msg = err.to_string();+ assert!(msg.contains("GMAIL_SEND_EMAIL"), "message was: {msg}");+ assert!(+ msg.contains("no error detail returned by the provider"),+ "message was: {msg}"+ );+}++#[test]+fn reject_unsuccessful_composio_response_passes_through_on_success() {+ let resp = ComposioExecuteResponse {+ data: json!({ "ts": "123.456" }),+ successful: true,+ error: None,+ cost_usd: 0.002,+ markdown_formatted: None,+ };+ let ok = reject_unsuccessful_composio_response("SLACK_SEND_MESSAGE", resp.clone())+ .expect("successful response must remain Ok");+ assert!(ok.successful);+ assert_eq!(ok.data, resp.data);+}++// ── input_context (PR A) ────────────────────────────────────────────────++/// A `composio:<toolkit>:<connection_id>` ref parses to its id and that id+/// resolves to the SPECIFIC connected account (toolkit + display label) —+/// not the toolkit's default connection.+#[test]+fn connection_ref_resolves_to_the_chosen_account() {+ let integrations = vec![integration(+ "gmail",+ true,+ vec![+ connection("conn_work", Some("[email protected]"), true),+ connection("conn_home", Some("[email protected]"), false),+ ],+ )];++ let id = composio_connection_id("composio:gmail:conn_home")+ .expect("well-formed composio connection_ref should parse");+ assert_eq!(id, "conn_home");++ let (toolkit, label) =+ resolve_account(&integrations, id).expect("id should resolve to a connected account");+ assert_eq!(toolkit, "gmail");+ // The non-default account was chosen — resolution is by id, not default.+ assert_eq!(label, Some("[email protected]"));++ // An id the user does not hold resolves to nothing (best-effort log path).+ assert!(resolve_account(&integrations, "conn_unknown").is_none());+}++/// A made-up toolkit that OpenHuman ships no static catalog for and the user+/// has NOT connected still rejects — even when the connected set is present+/// but simply doesn't contain it.+#[tokio::test]+async fn unknown_toolkit_still_rejects() {+ use crate::integrations::composio::contract::catalog_for_toolkit;+ let config = Config::default();+ // Precondition: `flowstestkit` is genuinely uncatalogued, so the decision+ // flows through the connected-set path (not the static curated path).+ assert!(catalog_for_toolkit("flowstestkit").is_none());++ // No connected set at all → fail-closed reject.+ assert!(+ !flow_tool_allowed(+ &crate::core::runtime::DispatchCtx::ambient(),+ &config,+ "FLOWSTESTKIT_DO_THING",+ None+ )+ .await+ );+ // Connected set present but does not include this toolkit → reject.+ assert!(+ !flow_tool_allowed(+ &crate::core::runtime::DispatchCtx::ambient(),+ &config,+ "FLOWSTESTKIT_DO_THING",+ Some(&["gmail".to_string()])+ )+ .await+ );+ // A blank slug is always rejected.+ assert!(+ !flow_tool_allowed(+ &crate::core::runtime::DispatchCtx::ambient(),+ &config,+ "",+ Some(&["flowstestkit".to_string()])+ )+ .await+ );+}++/// A real Composio toolkit OpenHuman ships no static catalog for now PASSES+/// once the user has an ACTIVE connection for it (the TODO(0.3) fix) AND+/// the slug is a genuine action in its LIVE catalog (systemic tool-contract+/// fix) — seeded here so the test never touches a live Composio backend.+/// The exact same slug rejects above without a connection.+#[tokio::test]+async fn connected_uncatalogued_toolkit_now_passes() {+ use crate::integrations::composio::contract::catalog_for_toolkit;+ assert!(catalog_for_toolkit("flowstestkit").is_none());++ let config = Config::default();+ seed_live_catalog_cache(+ "flowstestkit",+ vec![ToolContract {+ slug: "FLOWSTESTKIT_DO_THING".to_string(),+ toolkit: "flowstestkit".to_string(),+ description: None,+ required_args: Vec::new(),+ input_schema: None,+ output_fields: Vec::new(),+ output_schema: None,+ primary_array_path: None,+ is_curated: false,+ }],+ );++ assert!(+ flow_tool_allowed(+ &crate::core::runtime::DispatchCtx::ambient(),+ &config,+ "FLOWSTESTKIT_DO_THING",+ Some(&["flowstestkit".to_string()])+ )+ .await+ );+ // Case-insensitive match on the toolkit slug.+ assert!(+ flow_tool_allowed(+ &crate::core::runtime::DispatchCtx::ambient(),+ &config,+ "FLOWSTESTKIT_DO_THING",+ Some(&["FlowsTestKit".to_string()])+ )+ .await+ );+}++/// E-m8: an EXPIRED `LIVE_CATALOG_CACHE` entry must be treated as a cache+/// miss, not a permanent hit. Before the TTL fix, seeding the cache once+/// (as `connected_uncatalogued_toolkit_now_passes` does above) made a+/// slug pass forever, for the life of the process — a Composio action+/// added after the first fetch would stay invisible until restart. Here+/// the seeded entry is pre-expired, so `fetch_live_toolkit_catalog` must+/// re-fetch — which fails in this test (no live Composio backend) — and+/// `flow_tool_allowed` must fail CLOSED, unlike the fresh-seed case above+/// which passes.+#[tokio::test]+async fn expired_live_catalog_entry_is_treated_as_a_cache_miss() {+ use crate::integrations::composio::contract::catalog_for_toolkit;+ assert!(catalog_for_toolkit("flowsexpiredkit").is_none());++ let config = Config::default();+ seed_live_catalog_cache_expired(+ "flowsexpiredkit",+ vec![ToolContract {+ slug: "FLOWSEXPIREDKIT_DO_THING".to_string(),+ toolkit: "flowsexpiredkit".to_string(),+ description: None,+ required_args: Vec::new(),+ input_schema: None,+ output_fields: Vec::new(),+ output_schema: None,+ primary_array_path: None,+ is_curated: false,+ }],+ );++ assert!(+ !flow_tool_allowed(+ &crate::core::runtime::DispatchCtx::ambient(),+ &config,+ "FLOWSEXPIREDKIT_DO_THING",+ Some(&["flowsexpiredkit".to_string()])+ )+ .await,+ "an expired cache entry must be re-fetched (and, with no live backend in this test, \+ fail closed) rather than served as a permanent hit"+ );+}++/// A CONNECTED but uncatalogued toolkit still rejects a slug that shares+/// its prefix but isn't a genuine action in the LIVE catalog — the+/// systemic tool-contract fix's tightening: connection alone is no longer+/// sufficient, the slug itself must be real.+#[tokio::test]+async fn connected_uncatalogued_toolkit_rejects_a_hallucinated_slug() {+ use crate::integrations::composio::contract::catalog_for_toolkit;+ assert!(catalog_for_toolkit("flowstestkit").is_none());++ let config = Config::default();+ seed_live_catalog_cache(+ "flowstestkit",+ vec![ToolContract {+ slug: "FLOWSTESTKIT_DO_THING".to_string(),+ toolkit: "flowstestkit".to_string(),+ description: None,+ required_args: Vec::new(),+ input_schema: None,+ output_fields: Vec::new(),+ output_schema: None,+ primary_array_path: None,+ is_curated: false,+ }],+ );++ assert!(+ !flow_tool_allowed(+ &crate::core::runtime::DispatchCtx::ambient(),+ &config,+ "FLOWSTESTKIT_MADE_UP_ACTION",+ Some(&["flowstestkit".to_string()])+ )+ .await,+ "a hallucinated slug for a connected-but-uncurated toolkit must still reject"+ );+}+