Skip to content

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

test(core): consolidate schema tests into shared contract helpers

Steven Enamakel5c43e7bff5c3
diff --git a/crates/openhuman-core/src/desktop/app_state/schemas_tests.rs b/crates/openhuman-core/src/desktop/app_state/schemas_tests.rs
index ef6ad9af18..2285785722 100644
--- a/crates/openhuman-core/src/desktop/app_state/schemas_tests.rs
+++ b/crates/openhuman-core/src/desktop/app_state/schemas_tests.rs
@@ -1,62 +1,26 @@
use super::*;
+use crate::core::all::{assert_schema_controller_parity, expect_schema_identity};
#[test]
-fn all_schemas_returns_two() {
+fn app_state_schema_contracts_and_registration_are_preserved() {
assert_eq!(all_app_state_controller_schemas().len(), 2);
-}
-
-#[test]
-fn all_controllers_returns_two() {
- assert_eq!(all_app_state_registered_controllers().len(), 2);
-}
-
-#[test]
-fn snapshot_schema() {
+ assert_schema_controller_parity(
+ &all_app_state_controller_schemas(),
+ &all_app_state_registered_controllers(),
+ "snapshot",
+ );
let s = app_state_schemas("snapshot");
- assert_eq!(s.namespace, "app_state");
- assert_eq!(s.function, "snapshot");
+ expect_schema_identity(&s, "app_state", "snapshot");
assert!(s.inputs.is_empty());
assert!(!s.outputs.is_empty());
-}
-
-#[test]
-fn update_local_state_schema() {
let s = app_state_schemas("update_local_state");
- assert_eq!(s.namespace, "app_state");
- assert_eq!(s.function, "update_local_state");
+ expect_schema_identity(&s, "app_state", "update_local_state");
assert_eq!(s.inputs.len(), 3);
for input in &s.inputs {
assert!(!input.required, "input '{}' should be optional", input.name);
}
}
-#[test]
-fn schemas_and_controllers_match() {
- let s = all_app_state_controller_schemas();
- let c = all_app_state_registered_controllers();
- assert_eq!(s.len(), c.len());
- for (schema, ctrl) in s.iter().zip(c.iter()) {
- assert_eq!(schema.function, ctrl.schema.function);
- assert_eq!(schema.namespace, ctrl.schema.namespace);
- }
-}
-
-#[test]
-fn all_schemas_use_app_state_namespace() {
- for s in all_app_state_controller_schemas() {
- assert_eq!(s.namespace, "app_state");
- assert!(!s.description.is_empty());
- }
-}
-
-#[test]
-fn optional_json_helper() {
- let f = optional_json("key", "desc");
- assert_eq!(f.name, "key");
- assert!(!f.required);
- assert!(matches!(f.ty, TypeSchema::Json));
-}
-
#[test]
fn deserialize_update_local_state_params_empty() {
let params: UpdateLocalStateParams =
diff --git a/crates/openhuman-core/src/platform/update/schemas_tests.rs b/crates/openhuman-core/src/platform/update/schemas_tests.rs
index d406c7be62..230f2f677a 100644
--- a/crates/openhuman-core/src/platform/update/schemas_tests.rs
+++ b/crates/openhuman-core/src/platform/update/schemas_tests.rs
@@ -1,68 +1,26 @@
use super::*;
+use crate::core::all::{
+ assert_schema_controller_parity, expect_schema_fields, expect_schema_identity,
+};
#[test]
-fn all_schemas_returns_four() {
+fn update_schema_contracts_and_registration_are_preserved() {
assert_eq!(all_controller_schemas().len(), 4);
-}
-
-#[test]
-fn all_controllers_returns_four() {
assert_eq!(all_registered_controllers().len(), 4);
-}
-
-#[test]
-fn version_schema_has_no_inputs() {
- let s = schemas("version");
- assert_eq!(s.namespace, "update");
- assert_eq!(s.function, "version");
- assert!(s.inputs.is_empty());
- assert!(!s.outputs.is_empty());
-}
-
-#[test]
-fn run_schema_has_no_inputs() {
- let s = schemas("run");
- assert_eq!(s.namespace, "update");
- assert_eq!(s.function, "run");
- assert!(s.inputs.is_empty());
- assert!(!s.outputs.is_empty());
-}
-
-#[test]
-fn check_schema() {
- let s = schemas("check");
- assert_eq!(s.namespace, "update");
- assert_eq!(s.function, "check");
- assert!(s.inputs.is_empty());
- assert!(!s.outputs.is_empty());
-}
-
-#[test]
-fn apply_schema_requires_download_url_and_asset_name() {
- let s = schemas("apply");
- assert_eq!(s.function, "apply");
- let required: Vec<&str> = s
- .inputs
- .iter()
- .filter(|f| f.required)
- .map(|f| f.name)
- .collect();
- assert!(required.contains(&"download_url"));
- assert!(required.contains(&"asset_name"));
-}
-
-#[test]
-fn apply_schema_has_optional_staging_dir() {
- let s = schemas("apply");
- let staging = s.inputs.iter().find(|f| f.name == "staging_dir");
- assert!(staging.is_some_and(|f| !f.required));
-}
-
-#[test]
-fn schemas_and_controllers_match() {
- let s = all_controller_schemas();
- let c = all_registered_controllers();
- for (schema, ctrl) in s.iter().zip(c.iter()) {
- assert_eq!(schema.function, ctrl.schema.function);
+ assert_schema_controller_parity(
+ &all_controller_schemas(),
+ &all_registered_controllers(),
+ "version",
+ );
+ for function in ["version", "run", "check"] {
+ let schema = schemas(function);
+ expect_schema_identity(&schema, "update", function);
+ assert!(schema.inputs.is_empty());
+ assert!(!schema.outputs.is_empty());
}
+ let apply = schemas("apply");
+ expect_schema_identity(&apply, "update", "apply");
+ expect_schema_fields(&apply, &[("download_url", Some(true)), ("asset_name", Some(true)), ("staging_dir", Some(false))]);
+ let required: Vec<_> = apply.inputs.iter().filter(|field| field.required).map(|field| field.name).collect();
+ assert!(required.contains(&"download_url") && required.contains(&"asset_name"));
}
diff --git a/crates/openhuman-core/src/security/encryption/schemas_tests.rs b/crates/openhuman-core/src/security/encryption/schemas_tests.rs
index f8ceed53fa..0581f192a5 100644
--- a/crates/openhuman-core/src/security/encryption/schemas_tests.rs
+++ b/crates/openhuman-core/src/security/encryption/schemas_tests.rs
@@ -1,64 +1,39 @@
use super::*;
+use crate::core::all::{
+ assert_schema_controller_parity, expect_schema_fields, expect_schema_identity,
+};
#[test]
-fn all_schemas_returns_two() {
+fn encryption_schema_contracts_and_registration_are_preserved() {
assert_eq!(all_controller_schemas().len(), 2);
-}
-
-#[test]
-fn all_controllers_returns_two() {
assert_eq!(all_registered_controllers().len(), 2);
-}
-
-#[test]
-fn encrypt_schema_requires_plaintext() {
- let s = schemas("encrypt_secret");
- assert_eq!(s.namespace, "encrypt");
- assert_eq!(s.function, "secret");
- assert_eq!(s.inputs.len(), 1);
- assert!(s.inputs[0].required);
- assert_eq!(s.inputs[0].name, "plaintext");
-}
-
-#[test]
-fn decrypt_schema_requires_ciphertext() {
- let s = schemas("decrypt_secret");
- assert_eq!(s.namespace, "decrypt");
- assert_eq!(s.function, "secret");
- assert_eq!(s.inputs.len(), 1);
- assert!(s.inputs[0].required);
- assert_eq!(s.inputs[0].name, "ciphertext");
-}
-
-#[test]
-fn schemas_and_controllers_match() {
- let s = all_controller_schemas();
- let c = all_registered_controllers();
- assert_eq!(s.len(), c.len());
- for (schema, ctrl) in s.iter().zip(c.iter()) {
- assert_eq!(schema.function, ctrl.schema.function);
+ assert_schema_controller_parity(
+ &all_controller_schemas(),
+ &all_registered_controllers(),
+ "secret",
+ );
+ for (key, namespace, function, input) in [
+ ("encrypt_secret", "encrypt", "secret", "plaintext"),
+ ("decrypt_secret", "decrypt", "secret", "ciphertext"),
+ ] {
+ let schema = schemas(key);
+ expect_schema_identity(&schema, namespace, function);
+ assert_eq!(schema.inputs.len(), 1);
+ expect_schema_fields(&schema, &[(input, Some(true))]);
}
}
#[test]
-fn read_required_parses_string() {
+fn read_required_parses_values_and_preserves_error_categories() {
let mut m = Map::new();
m.insert("key".into(), Value::String("value".into()));
let result: String = read_required(&m, "key").unwrap();
assert_eq!(result, "value");
-}
-
-#[test]
-fn read_required_errors_on_missing_key() {
- let m = Map::new();
- let err = read_required::<String>(&m, "key").unwrap_err();
- assert!(err.contains("missing required param"));
-}
-
-#[test]
-fn read_required_errors_on_wrong_type() {
- let mut m = Map::new();
- m.insert("key".into(), Value::Bool(true));
- let err = read_required::<String>(&m, "key").unwrap_err();
- assert!(err.contains("invalid"));
+ assert!(read_required::<String>(&Map::new(), "key")
+ .unwrap_err()
+ .contains("missing required param"));
+ let wrong = Map::from_iter([("key".into(), Value::Bool(true))]);
+ assert!(read_required::<String>(&wrong, "key")
+ .unwrap_err()
+ .contains("invalid"));
}