Skip to content

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

chore: files changed crates/openhuman-core/src/core/all.rs,crates/openhuman-core/src/core/all/valida

Steven Enamakelbdf2ff641d6c
diff --git a/crates/openhuman-core/src/core/all.rs b/crates/openhuman-core/src/core/all.rs
index 7162b3a90a..1ae9988127 100644
--- a/crates/openhuman-core/src/core/all.rs
+++ b/crates/openhuman-core/src/core/all.rs
@@ -50,6 +50,8 @@ impl RegisteredController {
pub use super::domain_group::DomainGroup;
mod components_gate;
+mod validate;
+use validate::validate_registry;
pub use components_gate::disabled_component_for_method;
/// A [`RegisteredController`] tagged with the [`DomainGroup`] it belongs to.
@@ -1192,69 +1194,6 @@ pub async fn try_invoke_registered_rpc(
Some(scoped.await)
}
-/// Validates the consistency of the controller registry.
-///
-/// The registry is the single source of truth: each [`RegisteredController`]
-/// carries its own schema, and [`all_controller_schemas`] derives the public
-/// list. No separate declaration can drift from handlers (Phase 2).
-///
-/// Ensures that:
-/// - There are no duplicate controllers or RPC methods.
-/// - Namespaces and functions are not empty.
-/// - Required input names are unique within a controller.
-fn validate_registry(registered: &[GroupedController]) -> Result<(), String> {
- use std::collections::{BTreeMap, BTreeSet};
-
- let mut errors: Vec<String> = Vec::new();
- let mut registered_keys = BTreeSet::new();
- let mut registered_rpc_methods = BTreeSet::new();
-
- for grouped in registered {
- let controller = &grouped.controller;
- let schema = &controller.schema;
- let key = format!("{}.{}", schema.namespace, schema.function);
- if !registered_keys.insert(key.clone()) {
- errors.push(format!("duplicate registered controller `{key}`"));
- }
-
- let rpc_method = controller.rpc_method_name();
- if !registered_rpc_methods.insert(rpc_method.clone()) {
- errors.push(format!("duplicate registered rpc method `{rpc_method}`"));
- }
-
- if schema.namespace.trim().is_empty() {
- errors.push(format!(
- "invalid registered controller `{key}`: namespace must not be empty"
- ));
- }
- if schema.function.trim().is_empty() {
- errors.push(format!(
- "invalid registered controller `{key}`: function must not be empty"
- ));
- }
-
- let mut required_inputs = BTreeSet::new();
- let mut required_dupes: BTreeMap<String, usize> = BTreeMap::new();
- for input in schema.inputs.iter().filter(|input| input.required) {
- if !required_inputs.insert(input.name.to_string()) {
- *required_dupes.entry(input.name.to_string()).or_default() += 1;
- }
- }
- for (name, _) in required_dupes {
- errors.push(format!(
- "duplicate required input `{name}` in `{}`",
- schema.method_name()
- ));
- }
- }
-
- if errors.is_empty() {
- Ok(())
- } else {
- Err(errors.join("; "))
- }
-}
-
#[derive(Debug, Clone)]
pub struct HttpMethodSchemaDefinition {
pub method: String,
diff --git a/crates/openhuman-core/src/core/all/validate.rs b/crates/openhuman-core/src/core/all/validate.rs
new file mode 100644
index 0000000000..ed7c1e34e7
--- /dev/null
+++ b/crates/openhuman-core/src/core/all/validate.rs
@@ -0,0 +1,66 @@
+//! Registry consistency validation.
+
+use super::GroupedController;
+
+/// Validates the consistency of the controller registry.
+///
+/// The registry is the single source of truth: each [`RegisteredController`]
+/// carries its own schema, and [`all_controller_schemas`] derives the public
+/// list. No separate declaration can drift from handlers (Phase 2).
+///
+/// Ensures that:
+/// - There are no duplicate controllers or RPC methods.
+/// - Namespaces and functions are not empty.
+/// - Required input names are unique within a controller.
+pub(super) fn validate_registry(registered: &[GroupedController]) -> Result<(), String> {
+ use std::collections::{BTreeMap, BTreeSet};
+
+ let mut errors: Vec<String> = Vec::new();
+ let mut registered_keys = BTreeSet::new();
+ let mut registered_rpc_methods = BTreeSet::new();
+
+ for grouped in registered {
+ let controller = &grouped.controller;
+ let schema = &controller.schema;
+ let key = format!("{}.{}", schema.namespace, schema.function);
+ if !registered_keys.insert(key.clone()) {
+ errors.push(format!("duplicate registered controller `{key}`"));
+ }
+
+ let rpc_method = controller.rpc_method_name();
+ if !registered_rpc_methods.insert(rpc_method.clone()) {
+ errors.push(format!("duplicate registered rpc method `{rpc_method}`"));
+ }
+
+ if schema.namespace.trim().is_empty() {
+ errors.push(format!(
+ "invalid registered controller `{key}`: namespace must not be empty"
+ ));
+ }
+ if schema.function.trim().is_empty() {
+ errors.push(format!(
+ "invalid registered controller `{key}`: function must not be empty"
+ ));
+ }
+
+ let mut required_inputs = BTreeSet::new();
+ let mut required_dupes: BTreeMap<String, usize> = BTreeMap::new();
+ for input in schema.inputs.iter().filter(|input| input.required) {
+ if !required_inputs.insert(input.name.to_string()) {
+ *required_dupes.entry(input.name.to_string()).or_default() += 1;
+ }
+ }
+ for (name, _) in required_dupes {
+ errors.push(format!(
+ "duplicate required input `{name}` in `{}`",
+ schema.method_name()
+ ));
+ }
+ }
+
+ if errors.is_empty() {
+ Ok(())
+ } else {
+ Err(errors.join("; "))
+ }
+}