Skip to content

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

feat(core): add encryption methods to bound controller list

Steven Enamakel9c7de493e4b3
diff --git a/crates/openhuman-core/src/core/all_bound_controller_tests.rs b/crates/openhuman-core/src/core/all_bound_controller_tests.rs
index b9ec33d990..3e2e06f3cd 100644
--- a/crates/openhuman-core/src/core/all_bound_controller_tests.rs
+++ b/crates/openhuman-core/src/core/all_bound_controller_tests.rs
@@ -13,6 +13,7 @@ fn staged_bound_methods() -> Vec<&'static str> {
let mut methods = vec!["composio.execute"];
#[cfg(feature = "mcp")]
methods.push("mcp_clients.registry_get");
+ methods.extend(["encrypt.secret", "decrypt.secret"]);
methods.extend([
"socket.connect",
"socket.disconnect",
@@ -674,3 +675,6 @@ fn production_registry_binds_every_core_voice_controller_to_its_parser() {
}
#[path = "all_profiles_controller_tests.rs"]
mod profiles_controller_tests;
+
+#[path = "all_encryption_controller_tests.rs"]
+mod encryption_controller_tests;
diff --git a/crates/openhuman-core/src/core/all_encryption_controller_tests.rs b/crates/openhuman-core/src/core/all_encryption_controller_tests.rs
new file mode 100644
index 0000000000..7a4924f09d
--- /dev/null
+++ b/crates/openhuman-core/src/core/all_encryption_controller_tests.rs
@@ -0,0 +1,97 @@
+use super::*;
+
+#[test]
+fn raw_encryption_security_registry_matches_its_independent_contract() {
+ let entries: Vec<_> = registry()
+ .iter()
+ .filter(|row| {
+ matches!(
+ row.controller.schema.method_name().as_str(),
+ "encrypt.secret" | "decrypt.secret"
+ )
+ })
+ .collect();
+ let contracts = crate::security::encryption::encryption_parameter_contracts();
+
+ assert_eq!(entries.len(), 2, "complete raw encryption inventory");
+ assert_eq!(
+ entries
+ .iter()
+ .map(|row| row.controller.schema.method_name())
+ .collect::<Vec<_>>(),
+ ["encrypt.secret", "decrypt.secret"],
+ "encryption registration order is a wire contract"
+ );
+ assert!(entries.iter().all(|row| {
+ row.group == DomainGroup::Security
+ && ["encrypt", "decrypt"].contains(&row.controller.schema.namespace)
+ }));
+ assert!(internal_registry().iter().all(|row| {
+ !matches!(
+ row.controller.schema.method_name().as_str(),
+ "encrypt.secret" | "decrypt.secret"
+ )
+ }));
+ assert_eq!(
+ entries
+ .iter()
+ .map(|row| row.controller.rpc_method_name())
+ .collect::<Vec<_>>(),
+ ["openhuman.encrypt_secret", "openhuman.decrypt_secret"]
+ );
+
+ let entries = entries
+ .into_iter()
+ .map(|row| row.controller.clone())
+ .collect::<Vec<_>>();
+ verify_parameter_contracts(&entries, &contracts)
+ .expect("raw encryption entries use their declared schemas and runtime decoders");
+}
+
+#[test]
+fn bound_encryption_decoders_preserve_required_strings_and_ignore_extra_fields() {
+ use serde_json::json;
+
+ let entries = registry()
+ .iter()
+ .filter(|row| {
+ matches!(
+ row.controller.schema.method_name().as_str(),
+ "encrypt.secret" | "decrypt.secret"
+ )
+ })
+ .map(|row| row.controller.clone())
+ .collect::<Vec<_>>();
+
+ for (method, field) in [
+ ("encrypt.secret", "plaintext"),
+ ("decrypt.secret", "ciphertext"),
+ ] {
+ let entry = entries
+ .iter()
+ .find(|entry| entry.schema.method_name() == method)
+ .expect("raw encryption entry exists");
+ let mut params = Map::from_iter([(field.into(), json!("unchanged"))]);
+ params.insert("extra_scalar".into(), json!(true));
+ params.insert("extra_nested".into(), json!({"ignored":true}));
+ entry
+ .decode_params(params)
+ .unwrap_or_else(|error| panic!("{method} decoder rejected extra fields: {error}"));
+
+ assert_eq!(
+ entry.decode_params(Map::new()).unwrap_err(),
+ format!("missing required param '{field}'"),
+ "{method} missing-field error"
+ );
+ for value in [json!(null), json!(true), json!(42)] {
+ let params = Map::from_iter([(field.into(), value)]);
+ let error = entry
+ .decode_params(params)
+ .expect_err("non-string secret input is rejected");
+ assert!(
+ error.starts_with(&format!("invalid '{field}':")),
+ "{method} invalid-field prefix: {error}"
+ );
+ }
+ }
+}
diff --git a/crates/openhuman-core/src/security/encryption/mod.rs b/crates/openhuman-core/src/security/encryption/mod.rs
index f12c1e0dc0..dc597082b3 100644
--- a/crates/openhuman-core/src/security/encryption/mod.rs
+++ b/crates/openhuman-core/src/security/encryption/mod.rs
@@ -15,3 +15,6 @@ pub use schemas::{
all_controller_schemas as all_encryption_controller_schemas,
all_registered_controllers as all_encryption_registered_controllers,
};
+
+#[cfg(test)]
+pub(crate) use schemas::encryption_parameter_contracts;
diff --git a/crates/openhuman-core/src/security/encryption/schemas.rs b/crates/openhuman-core/src/security/encryption/schemas.rs
index 2c0acc76ff..125bde4501 100644
--- a/crates/openhuman-core/src/security/encryption/schemas.rs
+++ b/crates/openhuman-core/src/security/encryption/schemas.rs
@@ -23,6 +23,11 @@ pub fn all_registered_controllers() -> Vec<RegisteredController> {
]
}
+#[cfg(test)]
+pub(crate) fn encryption_parameter_contracts() -> Vec<crate::core::all::ControllerParamContract> {
+ tests::parameter_contracts()
+}
+
pub fn schemas(function: &str) -> ControllerSchema {
match function {
"encrypt_secret" => ControllerSchema {
diff --git a/crates/openhuman-core/src/security/encryption/schemas_tests.rs b/crates/openhuman-core/src/security/encryption/schemas_tests.rs
index 0581f192a5..a70f05e6eb 100644
--- a/crates/openhuman-core/src/security/encryption/schemas_tests.rs
+++ b/crates/openhuman-core/src/security/encryption/schemas_tests.rs
@@ -1,26 +1,43 @@
use super::*;
-use crate::core::all::{
- assert_schema_controller_parity, expect_schema_fields, expect_schema_identity,
-};
+use crate::core::all::ControllerParamContract;
#[test]
-fn encryption_schema_contracts_and_registration_are_preserved() {
- assert_eq!(all_controller_schemas().len(), 2);
- assert_eq!(all_registered_controllers().len(), 2);
- 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))]);
- }
+fn legacy_registered_handlers_keep_their_function_identity() {
+ let controllers = all_registered_controllers();
+ assert_eq!(controllers.len(), 2);
+ assert!(std::ptr::fn_addr_eq(
+ controllers[0].handler,
+ handle_encrypt_secret
+ ));
+ assert!(std::ptr::fn_addr_eq(
+ controllers[1].handler,
+ handle_decrypt_secret
+ ));
+}
+
+pub(super) fn parameter_contracts() -> Vec<ControllerParamContract> {
+ use serde_json::json;
+
+ vec![
+ ControllerParamContract {
+ method: "encrypt.secret",
+ required: &["plaintext"],
+ optional: &[],
+ examples: vec![
+ json!({"plaintext":""}),
+ json!({"plaintext":" keep whitespace "}),
+ ],
+ },
+ ControllerParamContract {
+ method: "decrypt.secret",
+ required: &["ciphertext"],
+ optional: &[],
+ examples: vec![
+ json!({"ciphertext":""}),
+ json!({"ciphertext":" keep whitespace "}),
+ ],
+ },
+ ]
}
#[test]