Skip to content

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

fix(tests): update test assertions for delegate and remember_preference tools

Steven Enamakel10cdc96c00bb
diff --git a/crates/openhuman-core/src/agent/tools/delegate_tests.rs b/crates/openhuman-core/src/agent/tools/delegate_tests.rs
index 9c21f35b50..6bbf5e9267 100644
--- a/crates/openhuman-core/src/agent/tools/delegate_tests.rs
+++ b/crates/openhuman-core/src/agent/tools/delegate_tests.rs
@@ -61,17 +61,10 @@ fn schema_lists_agent_names() {
}
#[tokio::test]
-async fn missing_agent_param() {
+async fn missing_required_params_are_rejected() {
let tool = DelegateTool::new(sample_agents(), test_security());
- let result = tool.execute(json!({"prompt": "test"})).await;
- assert!(result.is_err());
-}
-
-#[tokio::test]
-async fn missing_prompt_param() {
- let tool = DelegateTool::new(sample_agents(), test_security());
- let result = tool.execute(json!({"agent": "researcher"})).await;
- assert!(result.is_err());
+ assert!(tool.execute(json!({"prompt": "test"})).await.is_err());
+ assert!(tool.execute(json!({"agent": "researcher"})).await.is_err());
}
#[tokio::test]
@@ -87,25 +80,16 @@ async fn unknown_agent_returns_error() {
#[tokio::test]
async fn depth_limit_enforced() {
- let tool = DelegateTool::with_depth(sample_agents(), test_security(), 3);
- let result = tool
- .execute(json!({"agent": "researcher", "prompt": "test"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("depth limit"));
-}
-
-#[tokio::test]
-async fn depth_limit_per_agent() {
- // coder has max_depth=2, so depth=2 should be blocked
- let tool = DelegateTool::with_depth(sample_agents(), test_security(), 2);
- let result = tool
- .execute(json!({"agent": "coder", "prompt": "test"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("depth limit"));
+ // Global limit, then coder's own max_depth=2 blocking at depth 2.
+ for (agent, depth) in [("researcher", 3), ("coder", 2)] {
+ let tool = DelegateTool::with_depth(sample_agents(), test_security(), depth);
+ let result = tool
+ .execute(json!({"agent": agent, "prompt": "test"}))
+ .await
+ .unwrap();
+ assert!(result.is_error, "{agent}@{depth}");
+ assert!(result.output().contains("depth limit"), "{agent}@{depth}");
+ }
}
#[test]
@@ -119,25 +103,16 @@ fn empty_agents_schema() {
}
#[tokio::test]
-async fn blank_agent_rejected() {
- let tool = DelegateTool::new(sample_agents(), test_security());
- let result = tool
- .execute(json!({"agent": " ", "prompt": "test"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("must not be empty"));
-}
-
-#[tokio::test]
-async fn blank_prompt_rejected() {
+async fn blank_agent_or_prompt_rejected() {
let tool = DelegateTool::new(sample_agents(), test_security());
- let result = tool
- .execute(json!({"agent": "researcher", "prompt": " \t "}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("must not be empty"));
+ for args in [
+ json!({"agent": " ", "prompt": "test"}),
+ json!({"agent": "researcher", "prompt": " \t "}),
+ ] {
+ let result = tool.execute(args.clone()).await.unwrap();
+ assert!(result.is_error, "{args}");
+ assert!(result.output().contains("must not be empty"), "{args}");
+ }
}
#[tokio::test]
diff --git a/crates/openhuman-core/src/agent/tools/remember_preference_tests.rs b/crates/openhuman-core/src/agent/tools/remember_preference_tests.rs
index dde1202405..219a4d2157 100644
--- a/crates/openhuman-core/src/agent/tools/remember_preference_tests.rs
+++ b/crates/openhuman-core/src/agent/tools/remember_preference_tests.rs
@@ -119,79 +119,30 @@ fn schema_has_required_fields() {
#[tokio::test]
#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
the tool resolves the bound driver rather than being handed a memory handle"]
-async fn missing_class_returns_error() {
+async fn invalid_arguments_return_a_tool_error_naming_the_problem() {
+ let cases = [
+ (json!({"key": "timezone", "value": "IST"}), "class"),
+ (
+ json!({"class": "bogus", "key": "timezone", "value": "IST"}),
+ "invalid class",
+ ),
+ (json!({"class": "style", "value": "terse"}), "key"),
+ (
+ json!({"class": "style", "key": " ", "value": "terse"}),
+ "key cannot be empty",
+ ),
+ (
+ json!({"class": "style", "key": "my pref", "value": "terse"}),
+ "invalid characters",
+ ),
+ (json!({"class": "tooling", "key": "pkg_mgr"}), "value"),
+ ];
let tool = RememberPreferenceTool::new(test_security());
- let result = tool
- .execute(json!({"key": "timezone", "value": "IST"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("class"));
-}
-
-#[tokio::test]
-#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
-the tool resolves the bound driver rather than being handed a memory handle"]
-async fn invalid_class_returns_error() {
- let tool = RememberPreferenceTool::new(test_security());
- let result = tool
- .execute(json!({"class": "bogus", "key": "timezone", "value": "IST"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("invalid class"));
-}
-
-#[tokio::test]
-#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
-the tool resolves the bound driver rather than being handed a memory handle"]
-async fn missing_key_returns_error() {
- let tool = RememberPreferenceTool::new(test_security());
- let result = tool
- .execute(json!({"class": "style", "value": "terse"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("key"));
-}
-
-#[tokio::test]
-#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
-the tool resolves the bound driver rather than being handed a memory handle"]
-async fn empty_key_returns_error() {
- let tool = RememberPreferenceTool::new(test_security());
- let result = tool
- .execute(json!({"class": "style", "key": " ", "value": "terse"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("key cannot be empty"));
-}
-
-#[tokio::test]
-#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
-the tool resolves the bound driver rather than being handed a memory handle"]
-async fn key_with_spaces_returns_error() {
- let tool = RememberPreferenceTool::new(test_security());
- let result = tool
- .execute(json!({"class": "style", "key": "my pref", "value": "terse"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("invalid characters"));
-}
-
-#[tokio::test]
-#[ignore = "needs a built tinymemory module (OPENHUMAN_MODULE_PATH) and its own process: \
-the tool resolves the bound driver rather than being handed a memory handle"]
-async fn missing_value_returns_error() {
- let tool = RememberPreferenceTool::new(test_security());
- let result = tool
- .execute(json!({"class": "tooling", "key": "pkg_mgr"}))
- .await
- .unwrap();
- assert!(result.is_error);
- assert!(result.output().contains("value"));
+ for (args, expected) in cases {
+ let result = tool.execute(args.clone()).await.unwrap();
+ assert!(result.is_error, "{args}");
+ assert!(result.output().contains(expected), "{args}: {}", result.output());
+ }
}
// ── Successful upsert ───────────────────────────────────────────────────