Skip to content

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

test: remove redundant tool registry approval e2e cases

Steven Enamakel682da8d828ee
diff --git a/tests/raw_coverage/tool_registry_approval_e2e.rs b/tests/raw_coverage/tool_registry_approval_e2e.rs
index 3d98712f23..c0a18ca8dc 100644
--- a/tests/raw_coverage/tool_registry_approval_e2e.rs
+++ b/tests/raw_coverage/tool_registry_approval_e2e.rs
@@ -395,308 +395,6 @@ enabled = true
harness.rpc_join.abort();
}
-#[tokio::test(flavor = "current_thread")]
-async fn tool_registry_entries_fall_back_on_current_thread_runtime() {
- let entries = registry_entries(&openhuman_core::core::runtime::DispatchCtx::host_default());
- assert!(entries
- .iter()
- .any(|entry| entry.tool_id == "tools.web_search"));
- assert!(entries
- .iter()
- .all(|entry| !entry.tool_id.starts_with("mcp-client::")));
-}
-
-#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
-async fn tool_registry_entries_include_connected_mcp_client_tools() {
- let tmp = tempdir().expect("tempdir");
- let config = Config {
- workspace_dir: tmp.path().to_path_buf(),
- ..Config::default()
- };
- let server = install_test_mcp_server(&config, &test_mcp_server()).await;
- openhuman_core::mcp::registry::ops::mcp_clients_set_enabled(
- &config,
- server.server_id.clone(),
- true,
- )
- .await
- .expect("enable test MCP server");
- let tools = connections::connect(&config, &server)
- .await
- .expect("connect test mcp server");
- assert_eq!(tools.first().map(|tool| tool.name.as_str()), Some("echo"));
-
- // A second workspace, so that scoping is what the assertions below actually
- // test. With one workspace open, `registry_entries()` and the config-scoped
- // form agree, and this case would keep passing if the forwarding regressed.
- let other_tmp = tempdir().expect("second tempdir");
- let other_config = Config {
- workspace_dir: other_tmp.path().to_path_buf(),
- ..Config::default()
- };
- let other_server = install_test_mcp_server(&other_config, &test_mcp_server()).await;
- openhuman_core::mcp::registry::ops::mcp_clients_set_enabled(
- &other_config,
- other_server.server_id.clone(),
- true,
- )
- .await
- .expect("enable second test MCP server");
- connections::connect(&other_config, &other_server)
- .await
- .expect("connect second test mcp server");
-
- // Config-scoped, not ambient: this case connects through
- // `host::for_config(&config)`, keyed by its own tempdir. `registry_entries()`
- // resolves through the process default instead, which returns a lone host
- // but `None` once another case in this binary has opened a second one — so
- // the ambient form reports nothing connected here purely because of who
- // else ran first.
- let entries = registry_entries_for_config(&config);
- let client_entry = entries
- .iter()
- .find(|entry| entry.tool_id == format!("mcp-client::{}::echo", server.server_id))
- .expect("connected mcp client entry");
- assert_eq!(client_entry.name, "echo");
- assert_eq!(client_entry.route["protocol"], json!("mcp-client"));
- assert_eq!(client_entry.route["server_id"], json!(server.server_id));
- assert!(client_entry.tags.iter().any(|tag| tag == "mcp_client"));
-
- // The other workspace's server must NOT leak in. This is the assertion that
- // fails if a config-scoped lookup falls back to the process default.
- assert!(
- !entries
- .iter()
- .any(|entry| entry.tool_id == format!("mcp-client::{}::echo", other_server.server_id)),
- "entries for one workspace must not include another workspace's server"
- );
-
- // Symmetrically, from the second workspace's side.
- let other_entries = registry_entries_for_config(&other_config);
- assert!(other_entries
- .iter()
- .any(|entry| entry.tool_id == format!("mcp-client::{}::echo", other_server.server_id)));
- assert!(!other_entries
- .iter()
- .any(|entry| entry.tool_id == format!("mcp-client::{}::echo", server.server_id)));
-
- // Config-scoped for the same reason as the lookup above: this connection
- // lives in the host keyed by `config`'s workspace, and the by-id form
- // resolves through the process default.
- assert!(connections::disconnect_for_config(&config, &server.server_id).await);
- assert!(connections::disconnect_for_config(&other_config, &other_server.server_id).await);
-}
-
-#[tokio::test]
-async fn tool_registry_diagnostics_reports_config_and_audit_store_failures() {
- let _lock = env_lock_async().await;
- let tmp = tempdir().expect("tempdir");
- let workspace_file = tmp.path().join("workspace-file");
- std::fs::write(&workspace_file, "not a directory").expect("workspace sentinel");
- let _workspace_guard = EnvVarGuard::set_to_path("OPENHUMAN_WORKSPACE", &workspace_file);
-
- let err = openhuman_core::tools::registry::ops::diagnostics()
- .await
- .expect_err("workspace file should prevent config load");
- assert!(err.contains("failed to load config for tool registry diagnostics"));
-
- // The write audit lives in the TinyMCP module (605ca6e841), which picks its
- // storage provider once per process at load, so a broken workspace no
- // longer reaches it. Fail it at the module seam instead; storage failures
- // inside the audit are covered by tinymcp's `storage/failing.rs`.
- let mut broken_audit_config = Config {
- workspace_dir: workspace_file,
- ..Config::default()
- };
- broken_audit_config.modules.enabled = false;
- let diagnostics =
- openhuman_core::tools::registry::ops::diagnostics_for_config(&broken_audit_config).await;
- assert!(diagnostics.value.mcp_write_audit.enabled);
- assert_eq!(diagnostics.value.mcp_write_audit.recent_rows, None);
- assert!(diagnostics
- .value
- .mcp_write_audit
- .last_error
- .as_deref()
- .is_some_and(|error| error.contains("MCP module unavailable")));
-}
-
-#[tokio::test]
-async fn approval_schema_handlers_validate_params_and_surface_empty_gate_state() {
- let schemas = all_approval_controller_schemas();
- assert_eq!(
- schemas
- .iter()
- .map(|schema| schema.function)
- .collect::<Vec<_>>(),
- vec![
- "list_pending",
- "list_recent_decisions",
- "decide",
- "get_gate_state",
- "preauthorize_flow"
- ]
- );
- let unknown = openhuman_core::security::approval::schemas::schemas("missing");
- assert_eq!(unknown.namespace, "approval");
- assert_eq!(unknown.function, "unknown");
- assert_eq!(unknown.outputs[0].name, "error");
-
- let controllers = all_approval_registered_controllers();
- assert_eq!(controllers.len(), schemas.len());
-
- let list_handler = controllers
- .iter()
- .find(|controller| controller.schema.function == "list_pending")
- .expect("list pending controller")
- .handler;
- let list_value = list_handler(DispatchCtx::process_default(), Map::new())
- .await
- .expect("list pending value");
- assert!(list_value
- .get("result")
- .or(Some(&list_value))
- .and_then(Value::as_array)
- .is_some());
-
- let recent_handler = controllers
- .iter()
- .find(|controller| controller.schema.function == "list_recent_decisions")
- .expect("recent decisions controller")
- .handler;
- let mut invalid_limit = Map::new();
- invalid_limit.insert("limit".to_string(), json!("ten"));
- assert!(
- recent_handler(DispatchCtx::process_default(), invalid_limit)
- .await
- .expect_err("string limit")
- .contains("expected unsigned integer")
- );
- for invalid in [json!(true), json!([]), json!({ "limit": 10 })] {
- let mut invalid_limit = Map::new();
- invalid_limit.insert("limit".to_string(), invalid);
- assert!(
- recent_handler(DispatchCtx::process_default(), invalid_limit)
- .await
- .expect_err("non-numeric limit")
- .contains("expected unsigned integer")
- );
- }
- let mut negative_limit = Map::new();
- negative_limit.insert("limit".to_string(), json!(-1));
- assert!(
- recent_handler(DispatchCtx::process_default(), negative_limit)
- .await
- .expect_err("negative limit")
- .contains("expected unsigned integer")
- );
- let mut null_limit = Map::new();
- null_limit.insert("limit".to_string(), Value::Null);
- let recent_value = recent_handler(DispatchCtx::process_default(), null_limit)
- .await
- .expect("null limit should use default");
- assert!(recent_value
- .get("result")
- .or(Some(&recent_value))
- .and_then(Value::as_array)
- .is_some());
-
- let decide_handler = controllers
- .iter()
- .find(|controller| controller.schema.function == "decide")
- .expect("decide controller")
- .handler;
- assert!(decide_handler(DispatchCtx::process_default(), Map::new())
- .await
- .expect_err("missing request id")
- .contains("missing required param 'request_id'"));
- let mut numeric_request = Map::new();
- numeric_request.insert("request_id".to_string(), json!(42));
- numeric_request.insert("decision".to_string(), json!("deny"));
- assert!(
- decide_handler(DispatchCtx::process_default(), numeric_request)
- .await
- .expect_err("numeric request id")
- .contains("expected string")
- );
- for invalid in [
- Value::Null,
- json!(false),
- json!([]),
- json!({ "id": "missing" }),
- ] {
- let mut invalid_request = Map::new();
- invalid_request.insert("request_id".to_string(), invalid);
- invalid_request.insert("decision".to_string(), json!("deny"));
- assert!(
- decide_handler(DispatchCtx::process_default(), invalid_request)
- .await
- .expect_err("non-string request id")
- .contains("expected string")
- );
- }
- let mut numeric_decision = Map::new();
- numeric_decision.insert("request_id".to_string(), json!("missing"));
- numeric_decision.insert("decision".to_string(), json!(42));
- assert!(
- decide_handler(DispatchCtx::process_default(), numeric_decision)
- .await
- .expect_err("numeric decision")
- .contains("expected string")
- );
- let mut invalid_decision = Map::new();
- invalid_decision.insert("request_id".to_string(), json!("missing"));
- invalid_decision.insert("decision".to_string(), json!("maybe"));
- assert!(
- decide_handler(DispatchCtx::process_default(), invalid_decision)
- .await
- .expect_err("invalid decision")
- .contains("approve_once|approve_always_for_tool|approve_always_for_flow|deny")
- );
-
- let preauthorize_handler = controllers
- .iter()
- .find(|controller| controller.schema.function == "preauthorize_flow")
- .expect("preauthorize flow controller")
- .handler;
- assert!(
- preauthorize_handler(DispatchCtx::process_default(), Map::new())
- .await
- .expect_err("missing flow id")
- .contains("missing required param 'flow_id'")
- );
- let mut missing_tools = Map::new();
- missing_tools.insert("flow_id".to_string(), json!("flow-1"));
- assert!(
- preauthorize_handler(DispatchCtx::process_default(), missing_tools)
- .await
- .expect_err("missing tool names")
- .contains("missing required param 'tool_names'")
- );
- let mut non_array_tools = Map::new();
- non_array_tools.insert("flow_id".to_string(), json!("flow-1"));
- non_array_tools.insert("tool_names".to_string(), json!("slack_post"));
- assert!(
- preauthorize_handler(DispatchCtx::process_default(), non_array_tools)
- .await
- .expect_err("non-array tool names")
- .contains("expected array of strings")
- );
- let mut mixed_tools = Map::new();
- mixed_tools.insert("flow_id".to_string(), json!("flow-1"));
- mixed_tools.insert("tool_names".to_string(), json!(["ok", 42]));
- assert!(
- preauthorize_handler(DispatchCtx::process_default(), mixed_tools)
- .await
- .expect_err("non-string tool name entry")
- .contains("expected string")
- );
- // Success-path behavior (gate-absent tolerance, idempotent grants, audit
- // rows) is pinned by the unit tests in `approval::rpc`/`approval::store`;
- // asserting it here would be order-dependent on whether a sibling test
- // already installed the process-global gate.
-}
-
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn approval_rpc_decision_paths_persist_always_allow_and_recent_audit() {
let _lock = env_lock_async().await;