Skip to content

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

test(composio): make the report-before-redact ordering in 7a34a510a testable

oxoxDev6f2fdc7f18ab
diff --git a/crates/openhuman-core/src/integrations/composio/tools/list_connections.rs b/crates/openhuman-core/src/integrations/composio/tools/list_connections.rs
index 83518832dc..4f498735d3 100644
--- a/crates/openhuman-core/src/integrations/composio/tools/list_connections.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools/list_connections.rs
@@ -6,7 +6,7 @@ use async_trait::async_trait;
use serde_json::{json, Value};
use super::live_config::live_composio_config;
-use super::redact::{composio_secrets, redact_composio_outcome, redact_text};
+use super::redact::{redact_and_report, redact_composio_outcome};
use crate::config::Config;
use tinytools::{PermissionLevel, Tool, ToolCategory, ToolResult};
@@ -108,13 +108,8 @@ impl ComposioListConnectionsTool {
let rendered = format!(
"[composio-direct] composio_list_connections (direct) failed: {e:#}"
);
- let secrets = composio_secrets(&live_config);
- let rendered = if secrets.is_empty() {
- rendered
- } else {
- redact_text(&rendered, &secrets)
- };
- super::super::ops::report_composio_op_error("list_connections", &rendered);
+ let rendered =
+ redact_and_report(&live_config, "list_connections", &rendered);
anyhow::anyhow!("{rendered}")
}) {
Ok(resp) => resp,
diff --git a/crates/openhuman-core/src/integrations/composio/tools/redact.rs b/crates/openhuman-core/src/integrations/composio/tools/redact.rs
index 95515c0faf..5d2bfa69be 100644
--- a/crates/openhuman-core/src/integrations/composio/tools/redact.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools/redact.rs
@@ -92,6 +92,21 @@ pub(crate) fn redact_result(mut result: ToolResult, secrets: &[String]) -> ToolR
result
}
+/// Redact every Composio secret `config` resolves to from `rendered`, report
+/// the redacted copy via
+/// [`report_composio_op_error`](super::super::ops::report_composio_op_error),
+/// and return that same redacted copy for the caller's own error text.
+pub(crate) fn redact_and_report(config: &Config, operation: &str, rendered: &str) -> String {
+ let secrets = composio_secrets(config);
+ let redacted = if secrets.is_empty() {
+ rendered.to_string()
+ } else {
+ redact_text(rendered, &secrets)
+ };
+ super::super::ops::report_composio_op_error(operation, &redacted);
+ redacted
+}
+
/// Redact every Composio key `config` resolves to from a tool's result or
/// error before it reaches the model.
pub(crate) fn redact_composio_outcome(
diff --git a/crates/openhuman-core/src/integrations/composio/tools_redact_tests.rs b/crates/openhuman-core/src/integrations/composio/tools_redact_tests.rs
index 230250d38f..838443f8a3 100644
--- a/crates/openhuman-core/src/integrations/composio/tools_redact_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools_redact_tests.rs
@@ -3,6 +3,7 @@
use serde_json::json;
use crate::config::{Config, ComposioHostCredential};
+use crate::integrations::composio::tools::redact::redact_and_report;
use crate::integrations::composio::tools::redact_composio_outcome;
const SHORT_KEY: &str = "abcdefgh";
@@ -65,3 +66,19 @@ fn secret_used_as_a_json_object_key_is_redacted() {
assert!(!serialized.contains(LONG_KEY), "{serialized}");
assert!(serialized.contains("[REDACTED]"), "{serialized}");
}
+
+/// `redact_and_report` is the single call site that both reports a
+/// direct-mode error to observability and supplies the caller's returned
+/// error text — one redacted value serves both, so this return value is
+/// exactly what reaches `report_composio_op_error`.
+#[test]
+fn redact_and_report_returns_no_raw_secret() {
+ let config = config_with_overlapping_secrets();
+ let rendered = format!(
+ "[composio-direct] composio_list_connections (direct) failed: invalid credential {LONG_KEY}"
+ );
+ let redacted = redact_and_report(&config, "test_op", &rendered);
+ assert!(!redacted.contains(LONG_KEY), "{redacted}");
+ assert!(!redacted.contains(SHORT_KEY), "{redacted}");
+ assert!(redacted.contains("[REDACTED]"), "{redacted}");
+}