Skip to content

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

test(schemas): consolidate schema unit tests into table-driven cases

Steven Enamakel4e33f4c129ee
diff --git a/crates/openhuman-core/src/flows/schemas_tests.rs b/crates/openhuman-core/src/flows/schemas_tests.rs
index 75f8c21645..838d74dd09 100644
--- a/crates/openhuman-core/src/flows/schemas_tests.rs
+++ b/crates/openhuman-core/src/flows/schemas_tests.rs
@@ -1,5 +1,8 @@
use super::*;
-use crate::core::all::{assert_schema_controller_parity, expect_schema_fields, expect_schema_identity, expect_schema_input_order, expect_schema_output_names, expect_schema_required_inputs};
+use crate::core::all::{
+ assert_schema_controller_parity, expect_schema_fields, expect_schema_identity,
+ expect_schema_input_order, expect_schema_output_names, expect_schema_required_inputs,
+};
use serde_json::json;
#[test]
@@ -18,11 +21,7 @@ fn flow_schema_wire_contracts_are_preserved() {
("resume", &["id", "thread_id"][..], &["approvals"][..]),
("list_runs", &[][..], &["limit"][..]),
("get_run", &["run_id"][..], &[][..]),
- (
- "build",
- &["mode"][..],
- &["thread_id", "request_id"][..],
- ),
+ ("build", &["mode"][..], &["thread_id", "request_id"][..]),
("build_cancel", &["thread_id"][..], &["request_id"][..]),
("discover", &[][..], &["thread_id", "request_id"][..]),
];
@@ -32,7 +31,10 @@ fn flow_schema_wire_contracts_are_preserved() {
expect_schema_required_inputs(&schema, required);
expect_schema_fields(
&schema,
- &optional.iter().map(|name| (*name, Some(false))).collect::<Vec<_>>(),
+ &optional
+ .iter()
+ .map(|name| (*name, Some(false)))
+ .collect::<Vec<_>>(),
);
}
let run = schemas("run");
@@ -202,53 +204,33 @@ fn read_required_errors_when_missing() {
assert!(err.contains("missing required param 'id'"));
}
-// ── R-m7: parse_draft_update_flow_id ─────────────────────────────────────
-
-#[test]
-fn parse_draft_update_flow_id_absent_leaves_link_untouched() {
- let params = Map::new();
- assert_eq!(parse_draft_update_flow_id(&params).unwrap(), None);
-}
-
-#[test]
-fn parse_draft_update_flow_id_null_is_an_explicit_unlink() {
- let mut params = Map::new();
- params.insert("flow_id".to_string(), Value::Null);
- assert_eq!(parse_draft_update_flow_id(&params).unwrap(), Some(None));
-}
-
-#[test]
-fn parse_draft_update_flow_id_string_links_to_that_flow() {
- let mut params = Map::new();
- params.insert("flow_id".to_string(), Value::String("flow-123".to_string()));
- assert_eq!(
- parse_draft_update_flow_id(&params).unwrap(),
- Some(Some("flow-123".to_string()))
- );
-}
-
-#[test]
-fn parse_draft_update_flow_id_empty_string_is_an_explicit_unlink() {
- let mut params = Map::new();
- params.insert("flow_id".to_string(), Value::String(" ".to_string()));
- assert_eq!(parse_draft_update_flow_id(&params).unwrap(), Some(None));
-}
-
-// Regression for R-m7: a number must be REJECTED, not silently coerced
-// into `Some(None)` (an explicit unlink) the way `Value::as_str()`
-// returning `None` on a type mismatch used to produce.
-#[test]
-fn parse_draft_update_flow_id_rejects_a_number() {
- let mut params = Map::new();
- params.insert("flow_id".to_string(), Value::from(42));
- let err = parse_draft_update_flow_id(&params).unwrap_err();
- assert!(err.contains("invalid 'flow_id'"), "{err}");
-}
-
+// R-m7: absent leaves the link untouched; null/blank explicitly unlink.
+// Invalid types must not silently become an explicit unlink.
#[test]
-fn parse_draft_update_flow_id_rejects_an_object() {
- let mut params = Map::new();
- params.insert("flow_id".to_string(), serde_json::json!({ "id": "flow-1" }));
- let err = parse_draft_update_flow_id(&params).unwrap_err();
- assert!(err.contains("invalid 'flow_id'"), "{err}");
+fn draft_update_flow_link_preserves_all_three_states_and_rejects_wrong_types() {
+ for (case, input, expected) in [
+ ("absent leaves link untouched", None, None),
+ ("null explicitly unlinks", Some(Value::Null), Some(None)),
+ (
+ "string links flow",
+ Some(json!("flow-123")),
+ Some(Some("flow-123".to_string())),
+ ),
+ ("blank explicitly unlinks", Some(json!(" ")), Some(None)),
+ ] {
+ let mut params = Map::new();
+ if let Some(input) = input {
+ params.insert("flow_id".into(), input);
+ }
+ assert_eq!(
+ parse_draft_update_flow_id(&params).unwrap(),
+ expected,
+ "{case}"
+ );
+ }
+ for (case, input) in [("number", json!(42)), ("object", json!({"id":"flow-1"}))] {
+ let params = Map::from_iter([("flow_id".into(), input)]);
+ let err = parse_draft_update_flow_id(&params).unwrap_err();
+ assert!(err.contains("invalid 'flow_id'"), "{case}: {err}");
+ }
}
diff --git a/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs b/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs
index c6088b48c2..ad2ac409b9 100644
--- a/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs
+++ b/crates/openhuman-core/src/inference/tokenjuice/schemas_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use crate::core::all::assert_schema_controller_parity;
+use crate::core::all::{assert_schema_controller_parity, expect_schema_fields};
use crate::core::runtime::DispatchCtx;
#[test]
@@ -29,26 +29,18 @@ fn compress_hint_carries_every_caller_supplied_field() {
p.insert("explicit".into(), Value::from("search"));
let hint = compress_hint_from_params(&p).expect("a well-formed hint must parse");
- assert_eq!(
- hint.source_tool.as_deref(),
- Some("grep"),
- "`tool_name` was the only field the old handler read"
- );
- assert_eq!(
- hint.mime.as_deref(),
- Some("text/html"),
- "`mime` must reach the router; it was dropped before #6088"
- );
- assert_eq!(
- hint.extension.as_deref(),
- Some("rs"),
- "`extension` must reach the router; it was dropped before #6088"
- );
- assert_eq!(
- hint.query.as_deref(),
- Some("needle"),
- "`query` must reach the router — the search compressor ranks by it"
- );
+ for (field, actual, expected) in [
+ ("tool_name", hint.source_tool.as_deref(), "grep"),
+ ("mime", hint.mime.as_deref(), "text/html"),
+ ("extension", hint.extension.as_deref(), "rs"),
+ ("query", hint.query.as_deref(), "needle"),
+ ] {
+ assert_eq!(
+ actual,
+ Some(expected),
+ "caller-supplied {field} must reach the router"
+ );
+ }
assert_eq!(
hint.explicit,
Some(ContentKind::Search),
@@ -100,38 +92,17 @@ fn compress_hint_accepts_the_documented_plain_text_spelling() {
#[test]
fn compress_schema_declares_all_five_hint_inputs() {
- let s = schemas("compress");
- for field in [
- "content",
- "tool_name",
- "mime",
- "extension",
- "query",
- "explicit",
- ] {
- assert!(
- s.inputs.iter().any(|f| f.name == field),
- "`compress` must declare `{field}`; a hint field the schema does not \
- name is one a caller cannot discover"
- );
- }
- assert!(
- s.inputs
- .iter()
- .find(|f| f.name == "content")
- .is_some_and(|f| f.required),
- "only `content` is required"
+ expect_schema_fields(
+ &schemas("compress"),
+ &[
+ ("content", Some(true)),
+ ("tool_name", Some(false)),
+ ("mime", Some(false)),
+ ("extension", Some(false)),
+ ("query", Some(false)),
+ ("explicit", Some(false)),
+ ],
);
- for optional in ["tool_name", "mime", "extension", "query", "explicit"] {
- assert!(
- !s.inputs
- .iter()
- .find(|f| f.name == optional)
- .unwrap()
- .required,
- "`{optional}` must stay optional"
- );
- }
}
/// `/schema` is what generators and model-facing tool definitions read. Declaring
diff --git a/crates/openhuman-core/src/integrations/composio/schemas_tests.rs b/crates/openhuman-core/src/integrations/composio/schemas_tests.rs
index 68ea292287..fdd063cf0b 100644
--- a/crates/openhuman-core/src/integrations/composio/schemas_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/schemas_tests.rs
@@ -96,14 +96,6 @@ fn read_required_and_non_empty_helpers_preserve_errors_and_trimming() {
assert_eq!(read_required_non_empty(&m, "toolkit").unwrap(), "gmail");
}
-#[test]
-fn read_optional_returns_none_on_missing_or_null() {
- let mut m = Map::new();
- assert_eq!(read_optional::<String>(&m, "k").unwrap(), None);
- m.insert("k".into(), Value::Null);
- assert_eq!(read_optional::<String>(&m, "k").unwrap(), None);
-}
-
#[test]
fn read_optional_helpers_preserve_typed_values_and_errors() {
let mut m = Map::new();
diff --git a/crates/openhuman-core/src/memory/schemas_tests.rs b/crates/openhuman-core/src/memory/schemas_tests.rs
index 275b5c4e3d..28b2748965 100644
--- a/crates/openhuman-core/src/memory/schemas_tests.rs
+++ b/crates/openhuman-core/src/memory/schemas_tests.rs
@@ -61,6 +61,7 @@ async fn call(config: &Config, function: &str, params: Value) -> Result<Value, S
handler(DispatchCtx::new(ctx.clone()), object(params)).await
})
.await
+ .map(|response| response.get("result").cloned().unwrap_or(response))
}
#[test]
@@ -71,8 +72,6 @@ fn every_spec_method_is_registered_with_its_exact_name() {
assert_eq!(all_controller_schemas().len(), SPEC_METHODS.len());
for controller in &controllers {
assert_eq!(controller.schema.namespace, "memory");
- assert!(!controller.schema.description.is_empty());
- assert!(!controller.schema.outputs.is_empty());
}
}
@@ -166,7 +165,6 @@ async fn memory_off_surfaces_the_memory_off_code() {
assert!(error.contains("MEMORY_OFF"), "{function}: {error}");
}
let engine = call(&config, "engine_get", json!({})).await.unwrap();
- let engine = engine.get("result").unwrap_or(&engine);
assert_eq!(engine["status"], "off");
}
@@ -183,37 +181,30 @@ async fn read_handlers_answer_over_a_bound_engine() {
)
.await
.unwrap();
- let learned = learned.get("result").unwrap_or(&learned).clone();
let id = learned["id"].as_str().expect("id").to_string();
let listed = call(&config, "items_list", json!({"limit": 5}))
.await
.unwrap();
- let listed = listed.get("result").unwrap_or(&listed);
assert_eq!(listed["items"].as_array().unwrap().len(), 1);
let recalled = call(&config, "recall", json!({"question": "oolong"}))
.await
.unwrap();
- let recalled = recalled.get("result").unwrap_or(&recalled);
assert!(!recalled["citations"].as_array().unwrap().is_empty());
let fetched = call(&config, "fetch", json!({"query": "oolong"}))
.await
.unwrap();
- let fetched = fetched.get("result").unwrap_or(&fetched);
assert_eq!(fetched["hits"].as_array().unwrap().len(), 1);
let engines = call(&config, "engines_list", json!({})).await.unwrap();
- let engines = engines.get("result").unwrap_or(&engines);
assert_eq!(engines["active"], "reference");
let engine = call(&config, "engine_get", json!({})).await.unwrap();
- let engine = engine.get("result").unwrap_or(&engine);
assert_eq!(engine["status"], "ok");
let forgotten = call(&config, "forget", json!({"ids": [id]})).await.unwrap();
- let forgotten = forgotten.get("result").unwrap_or(&forgotten);
assert_eq!(forgotten["forgotten"], 1);
call(&config, "learn", json!({"text": "Drinks tea"}))
@@ -222,12 +213,10 @@ async fn read_handlers_answer_over_a_bound_engine() {
let erased = call(&config, "erase_all", json!({"confirm": true}))
.await
.unwrap();
- let erased = erased.get("result").unwrap_or(&erased);
assert_eq!(erased["erased_scopes"], 1);
let listed = call(&config, "items_list", json!({"limit": 5}))
.await
.unwrap();
- let listed = listed.get("result").unwrap_or(&listed);
assert!(listed["items"].as_array().unwrap().is_empty());
}
@@ -243,7 +232,6 @@ async fn policy_handlers_validate_persist_and_report() {
)
.await
.unwrap();
- let policy = policy.get("result").unwrap_or(&policy);
assert_eq!(policy["log_conversations"], false);
assert_eq!(policy["recall"]["budget_tokens"], 900);
assert_eq!(policy["recall"]["team_limit"], 0);
@@ -256,9 +244,9 @@ async fn policy_handlers_validate_persist_and_report() {
assert!(bad.contains("INVALID_REQUEST"));
let got = call(&config, "policy_get", json!({})).await.unwrap();
- assert_eq!(got.get("result").unwrap_or(&got)["root"], "root");
+ assert_eq!(got["root"], "root");
let jobs = call(&config, "jobs_list", json!({})).await.unwrap();
- assert!(jobs.get("result").unwrap_or(&jobs)["pending"].is_array());
+ assert!(jobs["pending"].is_array());
}
#[tokio::test]
@@ -274,10 +262,9 @@ async fn lifecycle_handlers_answer_over_a_bound_engine() {
)
.await
.unwrap();
- assert_eq!(filed.get("result").unwrap_or(&filed)["source"], "notion");
+ assert_eq!(filed["source"], "notion");
let sources = call(&config, "brain_sources", json!({})).await.unwrap();
- let sources = sources.get("result").unwrap_or(&sources);
assert_eq!(sources["sources"][0]["source"], "notion");
let preview = call(
@@ -287,7 +274,6 @@ async fn lifecycle_handlers_answer_over_a_bound_engine() {
)
.await
.unwrap();
- let preview = preview.get("result").unwrap_or(&preview);
assert_eq!(preview["mode"], "turn");
assert!(preview["pack"]["markdown"]
.as_str()
@@ -295,13 +281,10 @@ async fn lifecycle_handlers_answer_over_a_bound_engine() {
.contains("9:30"));
let ran = call(&config, "jobs_run", json!({})).await.unwrap();
- assert_eq!(
- ran.get("result").unwrap_or(&ran)["runs"][0]["outcome"],
- "done"
- );
+ assert_eq!(ran["runs"][0]["outcome"], "done");
let agents = call(&config, "agents_list", json!({})).await.unwrap();
- assert!(agents.get("result").unwrap_or(&agents)["agents"].is_array());
+ assert!(agents["agents"].is_array());
}
#[tokio::test]
@@ -324,7 +307,6 @@ async fn engine_set_persists_the_selection_and_rejects_unknown_engines() {
)
.await
.unwrap();
- let view = view.get("result").unwrap_or(&view);
assert_eq!(view["engine"], "cortexdb");
assert_eq!(view["endpoint"], "https://cortex.example.test");
let saved = std::fs::read_to_string(&config.config_path).unwrap();
@@ -349,7 +331,6 @@ async fn source_handlers_add_remove_and_sync() {
)
.await
.unwrap();
- let added = added.get("result").unwrap_or(&added);
assert_eq!(added["source"]["kind"], "folder");
assert_eq!(added["source"]["label"], "Docs");
assert_eq!(added["source"]["status"], "idle");
@@ -366,12 +347,12 @@ async fn source_handlers_add_remove_and_sync() {
assert!(bad_kind.contains("INVALID_REQUEST"));
let none = call(&config, "sources_list", json!({})).await.unwrap();
- assert!(none.get("result").unwrap_or(&none)["sources"].is_array());
+ assert!(none["sources"].is_array());
let missing = call(&config, "sources_remove", json!({"id": "src-missing"}))
.await
.unwrap();
- assert_eq!(missing.get("result").unwrap_or(&missing)["removed"], false);
+ assert_eq!(missing["removed"], false);
let unknown_sync = {
bind_reference(&config);
@@ -387,13 +368,10 @@ async fn import_handlers_report_scan_and_refuse_without_consent() {
let tmp = tempfile::tempdir().unwrap();
let config = config_in(&tmp);
let scan = call(&config, "import_scan", json!({})).await.unwrap();
- assert_eq!(scan.get("result").unwrap_or(&scan)["found"], false);
+ assert_eq!(scan["found"], false);
let status = call(&config, "import_status", json!({})).await.unwrap();
- assert_eq!(
- status.get("result").unwrap_or(&status)["state"]["phase"],
- "idle"
- );
+ assert_eq!(status["state"]["phase"], "idle");
let refused = call(&config, "import_start", json!({"consent": false}))
.await
diff --git a/crates/openhuman-core/src/platform/doctor/schemas_tests.rs b/crates/openhuman-core/src/platform/doctor/schemas_tests.rs
index 912a75ed24..da6ccf1fc7 100644
--- a/crates/openhuman-core/src/platform/doctor/schemas_tests.rs
+++ b/crates/openhuman-core/src/platform/doctor/schemas_tests.rs
@@ -27,26 +27,22 @@ fn models_schema_has_optional_use_cache() {
}
#[test]
-fn read_optional_returns_none_for_missing() {
- let m = Map::new();
- let result: Option<bool> = read_optional(&m, "use_cache").unwrap();
- assert!(result.is_none());
-}
-
-#[test]
-fn read_optional_returns_none_for_null() {
- let mut m = Map::new();
- m.insert("use_cache".into(), Value::Null);
- let result: Option<bool> = read_optional(&m, "use_cache").unwrap();
- assert!(result.is_none());
-}
-
-#[test]
-fn read_optional_returns_some_for_value() {
- let mut m = Map::new();
- m.insert("use_cache".into(), Value::Bool(true));
- let result: Option<bool> = read_optional(&m, "use_cache").unwrap();
- assert_eq!(result, Some(true));
+fn optional_cache_flag_preserves_missing_null_and_boolean_values() {
+ for (case, input, expected) in [
+ ("missing", None, None),
+ ("null", Some(Value::Null), None),
+ ("boolean", Some(Value::Bool(true)), Some(true)),
+ ] {
+ let mut params = Map::new();
+ if let Some(input) = input {
+ params.insert("use_cache".into(), input);
+ }
+ assert_eq!(
+ read_optional::<bool>(&params, "use_cache").unwrap(),
+ expected,
+ "{case}"
+ );
+ }
}
#[test]
diff --git a/crates/openhuman-core/src/threads/schemas_tests.rs b/crates/openhuman-core/src/threads/schemas_tests.rs
index 4a2aeb26b2..58d83a3123 100644
--- a/crates/openhuman-core/src/threads/schemas_tests.rs
+++ b/crates/openhuman-core/src/threads/schemas_tests.rs
@@ -29,35 +29,25 @@ const ALL_FUNCTIONS: &[&str] = &[
];
#[test]
-fn all_controller_schemas_has_entry_per_function() {
- let names: Vec<_> = all_controller_schemas()
- .into_iter()
- .map(|s| s.function)
- .collect();
- assert_eq!(names.len(), ALL_FUNCTIONS.len());
- for expected in ALL_FUNCTIONS {
- assert!(names.contains(expected), "missing schema for {expected}");
- }
-}
-
-#[test]
-fn all_registered_controllers_has_handler_per_schema() {
- let controllers = all_registered_controllers();
- assert_eq!(controllers.len(), ALL_FUNCTIONS.len());
- let names: Vec<_> = controllers.iter().map(|c| c.schema.function).collect();
- for expected in ALL_FUNCTIONS {
- assert!(names.contains(expected), "missing handler for {expected}");
- }
-}
-
-#[test]
-fn every_schema_uses_threads_namespace() {
- for s in all_controller_schemas() {
- assert_eq!(
- s.namespace, "threads",
- "schema {} wrong namespace",
- s.function
- );
+fn schema_and_handler_catalogs_preserve_threads_wire_methods() {
+ for catalog in [
+ all_controller_schemas(),
+ all_registered_controllers()
+ .into_iter()
+ .map(|controller| controller.schema)
+ .collect(),
+ ] {
+ let names: Vec<_> = catalog
+ .iter()
+ .map(|schema| {
+ assert_eq!(schema.namespace, "threads", "{}", schema.function);
+ schema.function
+ })
+ .collect();
+ assert_eq!(names.len(), ALL_FUNCTIONS.len());
+ for expected in ALL_FUNCTIONS {
+ assert!(names.contains(expected), "missing method {expected}");
+ }
}
}