Skip to content

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

refactor(flows): extract mock tool preflight into helper

Steven Enamakel840bf4547bce
diff --git a/crates/openhuman-core/src/flows/builder_host.rs b/crates/openhuman-core/src/flows/builder_host.rs
index fd772c9cbd..96723e8b99 100644
--- a/crates/openhuman-core/src/flows/builder_host.rs
+++ b/crates/openhuman-core/src/flows/builder_host.rs
@@ -247,12 +247,7 @@ impl FlowsHost {
async fn preflight_tool(&self, slug: String, args: Value) -> Result<Value, String> {
let config = Arc::clone(&self.config);
self.in_context(async move {
- if let Some(backend) = crate::flows::caps_host::tools::backend_for(&slug) {
- backend
- .preflight(&config, &slug, &args)
- .await
- .map_err(|error| error.to_string())?;
- }
+ preflight_mock_tool(&config, &slug, &args).await?;
// The module discards this acknowledgement and returns only its
// deterministic MockTools result. Never invoke the real backend.
Ok(Value::Null)
@@ -261,6 +256,16 @@ impl FlowsHost {
}
}
+async fn preflight_mock_tool(config: &Config, slug: &str, args: &Value) -> Result<(), String> {
+ if let Some(backend) = crate::flows::caps_host::tools::backend_for(slug) {
+ backend
+ .preflight(config, slug, args)
+ .await
+ .map_err(|error| error.to_string())?;
+ }
+ Ok(())
+}
+
fn required<T: DeserializeOwned>(value: &Value, key: &str) -> Result<T, String> {
optional_field(value, key)?.ok_or_else(|| format!("missing `{key}`"))
}
@@ -355,4 +360,8 @@ pub(crate) async fn register(
})
}
+#[cfg(test)]
+#[path = "builder_host_tests.rs"]
+mod tests;
+
use super::ops;
diff --git a/crates/openhuman-core/src/flows/builder_host_tests.rs b/crates/openhuman-core/src/flows/builder_host_tests.rs
new file mode 100644
index 0000000000..9701b3af7a
--- /dev/null
+++ b/crates/openhuman-core/src/flows/builder_host_tests.rs
@@ -0,0 +1,55 @@
+use super::*;
+
+use serde_json::json;
+
+fn required_args_contract() -> crate::integrations::composio::catalog::ToolContract {
+ crate::integrations::composio::catalog::ToolContract {
+ slug: "PREFLIGHTCAPSHOST_SEND_EMAIL".into(),
+ toolkit: "preflightcapshost".into(),
+ description: None,
+ required_args: vec!["to".into()],
+ input_schema: None,
+ output_fields: Vec::new(),
+ output_schema: None,
+ primary_array_path: None,
+ is_curated: false,
+ }
+}
+
+#[tokio::test]
+async fn mock_tool_preflight_rejects_missing_required_args_without_invoking_backend() {
+ crate::integrations::composio::catalog::seed_live_catalog_cache(
+ "preflightcapshost",
+ vec![required_args_contract()],
+ );
+ let config = Config::default();
+
+ let error = preflight_mock_tool(
+ &config,
+ "PREFLIGHTCAPSHOST_SEND_EMAIL",
+ &json!({"to": null}),
+ )
+ .await
+ .expect_err("mock calls must not accept unwired required arguments");
+ assert!(error.contains("`to`"), "{error}");
+}
+
+#[tokio::test]
+async fn mock_tool_preflight_accepts_wired_composio_and_native_arguments() {
+ crate::integrations::composio::catalog::seed_live_catalog_cache(
+ "preflightcapshost",
+ vec![required_args_contract()],
+ );
+ let config = Config::default();
+
+ preflight_mock_tool(
+ &config,
+ "PREFLIGHTCAPSHOST_SEND_EMAIL",
+ &json!({"to": "[email protected]"}),
+ )
+ .await
+ .unwrap();
+ preflight_mock_tool(&config, "oh:web_search", &json!({}))
+ .await
+ .unwrap();
+}