Skip to content

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

refactor(core): replace schema contract structs with assertion helpers

Steven Enamakel3b972715ac19
diff --git a/crates/openhuman-core/src/core/all.rs b/crates/openhuman-core/src/core/all.rs
index bc3abd74ee..d85a711ce2 100644
--- a/crates/openhuman-core/src/core/all.rs
+++ b/crates/openhuman-core/src/core/all.rs
@@ -1217,6 +1217,50 @@ pub(crate) struct ControllerSchemaContract {
pub outputs: Option<&'static [&'static str]>,
}
+#[cfg(test)]
+pub(crate) fn expect_schema_identity(schema: &ControllerSchema, namespace: &str, function: &str) {
+ assert_eq!(schema.namespace, namespace);
+ assert_eq!(schema.function, function);
+}
+
+#[cfg(test)]
+pub(crate) fn expect_schema_fields(schema: &ControllerSchema, fields: &[(&str, Option<bool>)]) {
+ for (name, required) in fields {
+ let field = schema
+ .inputs
+ .iter()
+ .find(|field| field.name == *name)
+ .unwrap_or_else(|| panic!("{}.{} is missing input `{name}`", schema.namespace, schema.function));
+ if let Some(required) = required {
+ assert_eq!(field.required, *required, "{}.{} input `{name}`", schema.namespace, schema.function);
+ }
+ }
+}
+
+#[cfg(test)]
+pub(crate) fn expect_schema_input_order(schema: &ControllerSchema, inputs: &[&str]) {
+ let actual: Vec<_> = schema.inputs.iter().map(|field| field.name).collect();
+ assert_eq!(actual, inputs, "{}.{} input order", schema.namespace, schema.function);
+}
+
+#[cfg(test)]
+pub(crate) fn expect_schema_output_names(schema: &ControllerSchema, outputs: &[&str]) {
+ let actual: Vec<_> = schema.outputs.iter().map(|field| field.name).collect();
+ assert_eq!(actual, outputs, "{}.{} output names", schema.namespace, schema.function);
+}
+
+#[cfg(test)]
+pub(crate) fn expect_schema_output_fields(schema: &ControllerSchema, outputs: &[&str]) {
+ for name in outputs {
+ assert!(
+ schema.outputs.iter().any(|field| field.name == *name),
+ "{}.{} is missing output `{name}`",
+ schema.namespace,
+ schema.function
+ );
+ }
+}
+
/// Check one controller against a fixed wire contract copied from its
/// independently asserted domain schema tests.
#[cfg(test)]
diff --git a/crates/openhuman-core/src/mcp/ui/schemas_tests.rs b/crates/openhuman-core/src/mcp/ui/schemas_tests.rs
index f13fed5d49..366d5dbdbe 100644
--- a/crates/openhuman-core/src/mcp/ui/schemas_tests.rs
+++ b/crates/openhuman-core/src/mcp/ui/schemas_tests.rs
@@ -1,33 +1,12 @@
use super::*;
-use crate::core::all::{
- assert_schema_contract, ControllerSchemaContract as Contract, SchemaFieldContract as Field,
-};
+use crate::core::all::{expect_schema_fields, expect_schema_identity};
use crate::core::runtime::DispatchCtx;
#[test]
fn mcp_ui_schema_contracts_are_preserved() {
- let contract = Contract {
- namespace: "mcp_ui",
- function: "tool_call",
- input_count: None,
- input_order: None,
- required_input_order: Some(&["server_id", "tool_name"]),
- inputs: &[
- Field {
- name: "server_id",
- required: Some(true),
- type_debug: None,
- },
- Field {
- name: "tool_name",
- required: Some(true),
- type_debug: None,
- },
- ],
- output_fields: &[],
- outputs: None,
- };
- assert_schema_contract(&schemas("tool_call"), &contract);
+ let schema = schemas("tool_call");
+ expect_schema_identity(&schema, "mcp_ui", "tool_call");
+ expect_schema_fields(&schema, &[("server_id", Some(true)), ("tool_name", Some(true))]);
}
async fn with_workspace<F: std::future::Future>(body: F) -> F::Output {
diff --git a/crates/openhuman-core/src/security/devices/schemas_tests.rs b/crates/openhuman-core/src/security/devices/schemas_tests.rs
index d08474d259..6b4981bec5 100644
--- a/crates/openhuman-core/src/security/devices/schemas_tests.rs
+++ b/crates/openhuman-core/src/security/devices/schemas_tests.rs
@@ -1,65 +1,35 @@
use super::*;
use crate::core::all::{
- assert_schema_contract, ControllerSchemaContract as Contract, SchemaFieldContract as Field,
+ expect_schema_fields, expect_schema_identity, expect_schema_input_order,
+ expect_schema_output_names, expect_schema_output_fields,
};
use serde_json::json;
#[test]
fn device_schema_wire_contracts_are_preserved() {
- let contracts = [
- Contract {
- namespace: "devices",
- function: "create_pairing",
- input_count: Some(1),
- input_order: Some(&["label"]),
- required_input_order: None,
- inputs: &[Field {
- name: "label",
- required: Some(false),
- type_debug: None,
- }],
- output_fields: &["channel_id", "pairing_token", "core_pubkey"],
- outputs: None,
- },
- Contract {
- namespace: "devices",
- function: "list",
- input_count: Some(0),
- input_order: None,
- required_input_order: None,
- inputs: &[],
- output_fields: &[],
- outputs: Some(&["devices"]),
- },
- Contract {
- namespace: "devices",
- function: "revoke",
- input_count: Some(1),
- input_order: Some(&["channel_id"]),
- required_input_order: None,
- inputs: &[Field {
- name: "channel_id",
- required: Some(true),
- type_debug: None,
- }],
- output_fields: &[],
- outputs: Some(&["success"]),
- },
- ];
+ let contracts = ["create_pairing", "list", "revoke"];
let names: Vec<_> = all_controller_schemas()
.into_iter()
.map(|schema| schema.function)
.collect();
- assert_eq!(
- names,
- contracts
- .iter()
- .map(|contract| contract.function)
- .collect::<Vec<_>>()
- );
- for contract in &contracts {
- assert_schema_contract(&schemas(contract.function), contract);
- }
+ assert_eq!(names, contracts);
+
+ let create = schemas("create_pairing");
+ expect_schema_identity(&create, "devices", "create_pairing");
+ expect_schema_input_order(&create, &["label"]);
+ expect_schema_fields(&create, &[("label", Some(false))]);
+ expect_schema_output_fields(&create, &["channel_id", "pairing_token", "core_pubkey"]);
+
+ let list = schemas("list");
+ expect_schema_identity(&list, "devices", "list");
+ assert!(list.inputs.is_empty());
+ expect_schema_output_names(&list, &["devices"]);
+
+ let revoke = schemas("revoke");
+ expect_schema_identity(&revoke, "devices", "revoke");
+ expect_schema_input_order(&revoke, &["channel_id"]);
+ expect_schema_fields(&revoke, &[("channel_id", Some(true))]);
+ expect_schema_output_names(&revoke, &["success"]);
}
#[test]
diff --git a/crates/openhuman-core/src/tools/schemas_tests.rs b/crates/openhuman-core/src/tools/schemas_tests.rs
index d96a922018..13f54e4e61 100644
--- a/crates/openhuman-core/src/tools/schemas_tests.rs
+++ b/crates/openhuman-core/src/tools/schemas_tests.rs
@@ -1,8 +1,6 @@
use super::*;
-use crate::core::all::{
- assert_schema_contract, ControllerSchemaContract as Contract, SchemaFieldContract as Field,
-};
+use crate::core::all::{expect_schema_fields, expect_schema_identity, expect_schema_output_fields};
use crate::tools::schemas::registry::tools_schemas;
use serde_json::{json, Map};
const BASE_CONTROLLERS: usize = 5;
@@ -32,81 +30,20 @@ fn apify_linkedin_scrape_controller_is_retired() {
#[test]
fn tools_schema_wire_contracts_are_preserved() {
- let contracts: &[(&str, &[Field], &[&str])] = &[
- (
- "composio_execute",
- &[Field {
- name: "action",
- required: Some(true),
- type_debug: None,
- }],
- &[],
- ),
- (
- "web_answer",
- &[
- Field {
- name: "query",
- required: Some(true),
- type_debug: None,
- },
- Field {
- name: "depth",
- required: None,
- type_debug: None,
- },
- ],
- &["citations"],
- ),
- (
- "web_contents",
- &[Field {
- name: "urls",
- required: Some(true),
- type_debug: None,
- }],
- &[],
- ),
- (
- "searxng_search",
- &[
- Field {
- name: "query",
- required: Some(true),
- type_debug: None,
- },
- Field {
- name: "max_results",
- required: None,
- type_debug: None,
- },
- ],
- &[],
- ),
- (
- "web_search",
- &[Field {
- name: "query",
- required: Some(true),
- type_debug: None,
- }],
- &["provider"],
- ),
+ let contracts: &[(&str, &[(&str, Option<bool>)])] = &[
+ ("composio_execute", &[("action", Some(true))]),
+ ("web_answer", &[("query", Some(true)), ("depth", None)]),
+ ("web_contents", &[("urls", Some(true))]),
+ ("searxng_search", &[("query", Some(true)), ("max_results", None)]),
+ ("web_search", &[("query", Some(true))]),
];
- for (function, inputs, outputs) in contracts {
- let contract = Contract {
- namespace: "tools",
- function: *function,
- input_count: None,
- input_order: None,
- required_input_order: None,
- inputs: *inputs,
- output_fields: *outputs,
- outputs: None,
- };
+ for (function, inputs) in contracts {
let schema = tools_schemas(&format!("tools_{function}"));
- assert_schema_contract(&schema, &contract);
+ expect_schema_identity(&schema, "tools", function);
+ expect_schema_fields(&schema, inputs);
}
+ expect_schema_output_fields(&tools_schemas("tools_web_answer"), &["citations"]);
+ expect_schema_output_fields(&tools_schemas("tools_web_search"), &["provider"]);
}
#[test]
diff --git a/crates/openhuman-core/src/web3/wallet/schemas_tests.rs b/crates/openhuman-core/src/web3/wallet/schemas_tests.rs
index 4dae6d6930..54548815b6 100644
--- a/crates/openhuman-core/src/web3/wallet/schemas_tests.rs
+++ b/crates/openhuman-core/src/web3/wallet/schemas_tests.rs
@@ -1,83 +1,33 @@
use super::*;
-use crate::core::all::{
- assert_schema_contract, ControllerSchemaContract as Contract, SchemaFieldContract as Field,
-};
+use crate::core::all::{expect_schema_fields, expect_schema_input_order};
#[test]
fn wallet_schema_wire_contracts_are_preserved() {
assert_eq!(all_wallet_controller_schemas().len(), 16);
assert_eq!(all_wallet_registered_controllers().len(), 16);
- let contracts: &[(&str, Option<&[&str]>, Option<usize>, &[Field])] = &[
- ("generate_mnemonic", Some(&["wordCount"][..]), None, &[]),
- (
- "validate_mnemonic",
- Some(&["phrase"][..]),
- None,
- &[Field {
- name: "phrase",
- required: Some(true),
- type_debug: None,
- }],
- ),
- ("derive_recovery_material", Some(&["phrase"][..]), None, &[]),
- (
- "tx_status",
- Some(&["chain", "hash", "evmNetwork"][..]),
- None,
- &[],
- ),
- ("status", None, Some(0), &[]),
- (
- "setup",
- None,
- Some(6),
- &[
- Field {
- name: "encryptedMnemonic",
- required: Some(true),
- type_debug: None,
- },
- Field {
- name: "force",
- required: Some(false),
- type_debug: None,
- },
- ],
- ),
- (
- "execute_prepared",
- Some(&["quoteId", "confirmed"][..]),
- None,
- &[],
- ),
- (
- "prepare_transfer",
- None,
- None,
- &[Field {
- name: "assetSymbol",
- required: Some(false),
- type_debug: None,
- }],
- ),
- ];
- for (function, input_order, input_count, inputs) in contracts {
- let contract = Contract {
- namespace: "wallet",
- function: *function,
- input_count: *input_count,
- input_order: *input_order,
- required_input_order: None,
- inputs: *inputs,
- output_fields: &[],
- outputs: None,
- };
- let schema = wallet_schemas(function);
- assert_ne!(schema.function, "unknown", "missing {}", contract.function);
- assert_schema_contract(&schema, &contract);
+ for (function, inputs) in [
+ ("generate_mnemonic", &["wordCount"][..]),
+ ("validate_mnemonic", &["phrase"][..]),
+ ("derive_recovery_material", &["phrase"][..]),
+ ("tx_status", &["chain", "hash", "evmNetwork"][..]),
+ ("execute_prepared", &["quoteId", "confirmed"][..]),
+ ] {
+ expect_schema_input_order(&wallet_schemas(function), inputs);
}
-
+ let status = wallet_schemas("status");
+ assert!(status.inputs.is_empty());
+ let setup = wallet_schemas("setup");
+ assert_eq!(setup.inputs.len(), 6);
+ expect_schema_fields(&setup, &[("encryptedMnemonic", Some(true)), ("force", Some(false))]);
+ expect_schema_fields(
+ &wallet_schemas("validate_mnemonic"),
+ &[("phrase", Some(true))],
+ );
+ expect_schema_fields(
+ &wallet_schemas("prepare_transfer"),
+ &[("assetSymbol", Some(false))],
+ );
for removed in ["prepare_swap", "prepare_contract_call"] {
assert_eq!(wallet_schemas(removed).function, "unknown");
}