Skip to content

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

test(tests): update approval schema parsing and validation tests

Steven Enamakel454f6b68b21e
diff --git a/crates/openhuman-core/src/core/all_approval_controller_tests.rs b/crates/openhuman-core/src/core/all_approval_controller_tests.rs
index c4cd4f2bed..b5000f7787 100644
--- a/crates/openhuman-core/src/core/all_approval_controller_tests.rs
+++ b/crates/openhuman-core/src/core/all_approval_controller_tests.rs
@@ -24,7 +24,11 @@ fn raw_approval_security_registry_matches_its_independent_contract() {
];
let contracts = crate::security::approval::approval_parameter_contracts();
- assert_eq!(grouped.len(), methods.len(), "complete raw approval inventory");
+ assert_eq!(
+ grouped.len(),
+ methods.len(),
+ "complete raw approval inventory"
+ );
assert_eq!(
grouped
.iter()
@@ -45,10 +49,7 @@ fn raw_approval_security_registry_matches_its_independent_contract() {
rpc_methods
);
- let entries: Vec<_> = grouped
- .iter()
- .map(|row| row.controller.clone())
- .collect();
+ let entries: Vec<_> = grouped.iter().map(|row| row.controller.clone()).collect();
assert_eq!(
contracts.iter().map(|row| row.method).collect::<Vec<_>>(),
methods,
@@ -66,7 +67,11 @@ fn raw_approval_security_registry_matches_its_independent_contract() {
["flow_id", "tool_names"].as_slice(),
]) {
assert_eq!(
- schema.inputs.iter().map(|field| field.name).collect::<Vec<_>>(),
+ schema
+ .inputs
+ .iter()
+ .map(|field| field.name)
+ .collect::<Vec<_>>(),
expected,
"{}.{} input order",
schema.namespace,
@@ -80,21 +85,36 @@ fn raw_approval_security_registry_matches_its_independent_contract() {
|ty| matches!(ty, TypeSchema::Option(inner) if matches!(inner.as_ref(), TypeSchema::String)),
);
assert_eq!(schemas[1].inputs.len(), 1);
- assert_input(schemas[1], "limit", false, |ty| {
- matches!(ty, TypeSchema::Option(inner) if matches!(inner.as_ref(), TypeSchema::U64))
- });
+ assert_input(
+ schemas[1],
+ "limit",
+ false,
+ |ty| matches!(ty, TypeSchema::Option(inner) if matches!(inner.as_ref(), TypeSchema::U64)),
+ );
assert_eq!(schemas[2].inputs.len(), 3);
- assert_input(schemas[2], "request_id", true, |ty| matches!(ty, TypeSchema::String));
- assert_input(schemas[2], "decision", true, |ty| matches!(ty, TypeSchema::String));
- assert_input(schemas[2], "agent_id", false, |ty| {
- matches!(ty, TypeSchema::Option(inner) if matches!(inner.as_ref(), TypeSchema::String))
+ assert_input(schemas[2], "request_id", true, |ty| {
+ matches!(ty, TypeSchema::String)
+ });
+ assert_input(schemas[2], "decision", true, |ty| {
+ matches!(ty, TypeSchema::String)
});
+ assert_input(
+ schemas[2],
+ "agent_id",
+ false,
+ |ty| matches!(ty, TypeSchema::Option(inner) if matches!(inner.as_ref(), TypeSchema::String)),
+ );
assert!(schemas[3].inputs.is_empty());
assert_eq!(schemas[4].inputs.len(), 2);
- assert_input(schemas[4], "flow_id", true, |ty| matches!(ty, TypeSchema::String));
- assert_input(schemas[4], "tool_names", true, |ty| {
- matches!(ty, TypeSchema::Array(inner) if matches!(inner.as_ref(), TypeSchema::String))
+ assert_input(schemas[4], "flow_id", true, |ty| {
+ matches!(ty, TypeSchema::String)
});
+ assert_input(
+ schemas[4],
+ "tool_names",
+ true,
+ |ty| matches!(ty, TypeSchema::Array(inner) if matches!(inner.as_ref(), TypeSchema::String)),
+ );
let outputs = [
("pending", "PendingApproval", true),
@@ -104,7 +124,13 @@ fn raw_approval_security_registry_matches_its_independent_contract() {
("result", "FlowPreauthorizationResult", true),
];
for (schema, (name, reference, required)) in schemas.iter().zip(outputs) {
- assert_eq!(schema.outputs.len(), 1, "{}.{} output count", schema.namespace, schema.function);
+ assert_eq!(
+ schema.outputs.len(),
+ 1,
+ "{}.{} output count",
+ schema.namespace,
+ schema.function
+ );
let output = &schema.outputs[0];
assert_eq!(output.name, name);
assert_eq!(output.required, required);
@@ -152,8 +178,17 @@ fn assert_input(
.inputs
.iter()
.find(|field| field.name == name)
- .unwrap_or_else(|| panic!("{}.{} missing input {name}", schema.namespace, schema.function));
- assert_eq!(field.required, required, "{}.{} {name}", schema.namespace, schema.function);
+ .unwrap_or_else(|| {
+ panic!(
+ "{}.{} missing input {name}",
+ schema.namespace, schema.function
+ )
+ });
+ assert_eq!(
+ field.required, required,
+ "{}.{} {name}",
+ schema.namespace, schema.function
+ );
assert!(
type_matches(&field.ty),
"{}.{} input {name} has wrong type",
diff --git a/crates/openhuman-core/src/security/approval/schemas.rs b/crates/openhuman-core/src/security/approval/schemas.rs
index a22b889ca5..83a11d42cd 100644
--- a/crates/openhuman-core/src/security/approval/schemas.rs
+++ b/crates/openhuman-core/src/security/approval/schemas.rs
@@ -261,24 +261,24 @@ fn parse_decide(
fn parse_preauthorize_flow(params: Map<String, Value>) -> Result<(String, Vec<String>), String> {
let flow_id = read_required_string(&params, "flow_id")?;
let tool_names = match params.get("tool_names") {
- Some(Value::Array(items)) => items
- .iter()
- .map(|v| match v {
- Value::String(s) => Ok(s.clone()),
- other => Err(format!(
- "invalid 'tool_names' entry: expected string, got {}",
- type_name(other)
- )),
- })
- .collect::<Result<Vec<String>, String>>()?,
- Some(other) => {
- return Err(format!(
- "invalid 'tool_names': expected array of strings, got {}",
+ Some(Value::Array(items)) => items
+ .iter()
+ .map(|v| match v {
+ Value::String(s) => Ok(s.clone()),
+ other => Err(format!(
+ "invalid 'tool_names' entry: expected string, got {}",
type_name(other)
- ))
- }
- None => return Err("missing required param 'tool_names'".to_string()),
- };
+ )),
+ })
+ .collect::<Result<Vec<String>, String>>()?,
+ Some(other) => {
+ return Err(format!(
+ "invalid 'tool_names': expected array of strings, got {}",
+ type_name(other)
+ ))
+ }
+ None => return Err("missing required param 'tool_names'".to_string()),
+ };
Ok((flow_id, tool_names))
}
diff --git a/crates/openhuman-core/src/security/approval/schemas_tests.rs b/crates/openhuman-core/src/security/approval/schemas_tests.rs
index 9d48e42168..53f9f37256 100644
--- a/crates/openhuman-core/src/security/approval/schemas_tests.rs
+++ b/crates/openhuman-core/src/security/approval/schemas_tests.rs
@@ -1,5 +1,7 @@
use super::*;
-use crate::core::all::{assert_schema_controller_parity, ControllerHandler, ControllerParamContract};
+use crate::core::all::{
+ assert_schema_controller_parity, ControllerHandler, ControllerParamContract,
+};
use serde_json::json;
#[test]
@@ -37,7 +39,12 @@ pub(super) fn parameter_contracts() -> Vec<ControllerParamContract> {
method: "approval.list_recent_decisions",
required: &[],
optional: &["limit"],
- examples: vec![json!({}), json!({"limit": null}), json!({"limit": 0}), json!({"limit": 500})],
+ examples: vec![
+ json!({}),
+ json!({"limit": null}),
+ json!({"limit": 0}),
+ json!({"limit": 500}),
+ ],
},
ControllerParamContract {
method: "approval.decide",
@@ -93,9 +100,11 @@ fn list_pending_parser_trims_optional_agent_and_ignores_extras() {
}
for value in [json!(false), json!(0), json!([]), json!({})] {
assert_eq!(
- parse_list_pending(Map::from_iter([("agent_id".into(), value.clone())]))
- .unwrap_err(),
- format!("invalid 'agent_id': expected string, got {}", value_kind(&value))
+ parse_list_pending(Map::from_iter([("agent_id".into(), value.clone())])).unwrap_err(),
+ format!(
+ "invalid 'agent_id': expected string, got {}",
+ value_kind(&value)
+ )
);
}
}
@@ -109,15 +118,13 @@ fn recent_decisions_parser_keeps_optional_unsigned_limit_semantics() {
);
for limit in [0, 1, u64::MAX] {
assert_eq!(
- parse_list_recent_decisions(Map::from_iter([("limit".into(), json!(limit))]))
- .unwrap(),
+ parse_list_recent_decisions(Map::from_iter([("limit".into(), json!(limit))])).unwrap(),
Some(limit)
);
}
for value in [json!(-1), json!(1.5)] {
assert_eq!(
- parse_list_recent_decisions(Map::from_iter([("limit".into(), value)]))
- .unwrap_err(),
+ parse_list_recent_decisions(Map::from_iter([("limit".into(), value)])).unwrap_err(),
"invalid 'limit': expected unsigned integer"
);
}
@@ -128,8 +135,7 @@ fn recent_decisions_parser_keeps_optional_unsigned_limit_semantics() {
(json!({}), "object"),
] {
assert_eq!(
- parse_list_recent_decisions(Map::from_iter([("limit".into(), value)]))
- .unwrap_err(),
+ parse_list_recent_decisions(Map::from_iter([("limit".into(), value)])).unwrap_err(),
format!("invalid 'limit': expected unsigned integer, got {kind}")
);
}
@@ -220,23 +226,21 @@ fn preauthorize_parser_preserves_flow_and_tool_strings_without_normalizing() {
]))
.unwrap();
assert_eq!(flow, " flow raw ");
- assert_eq!(
- tools,
- vec![
- String::new(),
- " tool ".to_owned(),
- "tool".to_owned(),
- "tool".to_owned()
- ]
- );
assert_eq!(
- parse_preauthorize_flow(Map::from_iter([("flow_id".into(), json!("flow"))]))
- .unwrap_err(),
+ tools,
+ vec![
+ String::new(),
+ " tool ".to_owned(),
+ "tool".to_owned(),
+ "tool".to_owned()
+ ]
+ );
+ assert_eq!(
+ parse_preauthorize_flow(Map::from_iter([("flow_id".into(), json!("flow"))])).unwrap_err(),
"missing required param 'tool_names'"
);
assert_eq!(
- parse_preauthorize_flow(Map::from_iter([("tool_names".into(), json!([]))]))
- .unwrap_err(),
+ parse_preauthorize_flow(Map::from_iter([("tool_names".into(), json!([]))])).unwrap_err(),
"missing required param 'flow_id'"
);
for value in [json!(null), json!(true), json!("tools"), json!({})] {