Skip to content

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

test(core): add tests for controller extension registration

Steven Enamakela447fe0357da
diff --git a/crates/openhuman-core/src/core/all_tests.rs b/crates/openhuman-core/src/core/all_tests.rs
index cbc8fdb4a5..c254ca5e58 100644
--- a/crates/openhuman-core/src/core/all_tests.rs
+++ b/crates/openhuman-core/src/core/all_tests.rs
@@ -120,7 +120,6 @@ fn registered_controller_rpc_method_name() {
fn namespace_description_known_namespaces() {
assert!(namespace_description("memory").is_some());
assert!(namespace_description("memory_tree").is_some());
- assert!(namespace_description("billing").is_some());
assert!(namespace_description("config").is_some());
assert!(namespace_description("health").is_some());
assert!(namespace_description("subsystems").is_some());
@@ -1260,8 +1259,9 @@ fn carved_out_families_report_their_own_group() {
("cron", DomainGroup::Automation),
("composio", DomainGroup::Integrations),
("task_sources", DomainGroup::Integrations),
- ("billing", DomainGroup::Hosted),
- ("team", DomainGroup::Hosted),
+ // `billing` / `team` / `referral` / `announcements` (`Hosted`) are no
+ // longer built in: `openhuman-tinyhumans::hosted` registers them as an
+ // extension — see `registry_extension_*` below.
("dashboard", DomainGroup::Desktop),
("notification", DomainGroup::Desktop),
("sandbox", DomainGroup::Runtimes),
@@ -2536,3 +2536,109 @@ fn session_db_controllers_are_gone_and_run_ledger_survives() {
"the `session_db` namespace was removed and must not be registered, got: {namespaces:?}"
);
}
+
+// ── Controller extensions (crates above the core) ──────────────────────────
+
+fn ext_controller(namespace: &'static str, function: &'static str) -> RegisteredController {
+ fn handler(_params: Map<String, serde_json::Value>) -> ControllerFuture {
+ Box::pin(async { Ok(serde_json::json!({"ext": true})) })
+ }
+ RegisteredController {
+ schema: schema(namespace, function, vec![]),
+ handler,
+ }
+}
+
+/// An extension's controllers are first-class for every lookup: schema,
+/// dispatch, method routing, capability facts and the namespace description.
+#[tokio::test]
+async fn registry_extension_is_visible_to_every_lookup_and_dispatches() {
+ register_controller_extension(ControllerExtension {
+ group: DomainGroup::Hosted,
+ controllers: vec![ext_controller("ext_probe", "ping")],
+ namespaces: &[("ext_probe", "Registry extension probe.")],
+ })
+ .expect("register extension");
+
+ assert_eq!(
+ rpc_method_from_parts("ext_probe", "ping").as_deref(),
+ Some("openhuman.ext_probe_ping")
+ );
+ assert_eq!(capability_for_parts("ext_probe", "ping"), Some(None));
+ assert_eq!(capability_for_rpc_method("openhuman.ext_probe_ping"), Some(None));
+ assert!(schema_for_rpc_method("openhuman.ext_probe_ping").is_some());
+ assert!(all_controller_schemas()
+ .iter()
+ .any(|s| s.namespace == "ext_probe" && s.function == "ping"));
+ assert_eq!(
+ namespace_description("ext_probe"),
+ Some("Registry extension probe.")
+ );
+
+ let result = try_invoke_registered_rpc("openhuman.ext_probe_ping", Map::new())
+ .await
+ .expect("extension method is dispatchable")
+ .expect("handler succeeds");
+ assert_eq!(result, serde_json::json!({"ext": true}));
+}
+
+/// Re-registering the identical set is a no-op; a *colliding* set (a built-in
+/// method) is refused by the same drift guard the boot registry passes.
+#[test]
+fn registry_extension_is_idempotent_and_refuses_collisions() {
+ let ext = || ControllerExtension {
+ group: DomainGroup::Hosted,
+ controllers: vec![ext_controller("ext_idem", "once")],
+ namespaces: &[("ext_idem", "Idempotency probe.")],
+ };
+ register_controller_extension(ext()).expect("first registration");
+ register_controller_extension(ext()).expect("identical re-registration is a no-op");
+ let count = {
+ let view = registry_view();
+ view.iter()
+ .filter(|g| g.controller.schema.namespace == "ext_idem")
+ .count()
+ };
+ assert_eq!(count, 1, "no duplicate rows after re-registration");
+
+ // `memory.list_files`-style collision with a built-in: pick any built-in.
+ let builtin = registry()
+ .first()
+ .expect("built-in registry is non-empty")
+ .controller
+ .schema
+ .clone();
+ let err = register_controller_extension(ControllerExtension {
+ group: DomainGroup::Hosted,
+ controllers: vec![ext_controller(builtin.namespace, builtin.function)],
+ namespaces: &[],
+ })
+ .expect_err("shadowing a built-in method must be refused");
+ assert!(err.contains("duplicate"), "{err}");
+}
+
+/// The ambient `DomainSet` gates extension controllers through their group,
+/// exactly like built-ins: with `hosted: false` the method is unknown.
+#[tokio::test]
+async fn registry_extension_is_gated_by_its_domain_group() {
+ register_controller_extension(ControllerExtension {
+ group: DomainGroup::Hosted,
+ controllers: vec![ext_controller("ext_gate", "ping")],
+ namespaces: &[],
+ })
+ .expect("register extension");
+
+ let mut domains = DomainSet::full();
+ domains.hosted = false;
+ let ctx = CoreContext::for_test(domains, None, None);
+ let hidden = CoreContext::scope(ctx, async {
+ (
+ try_invoke_registered_rpc("openhuman.ext_gate_ping", Map::new())
+ .await
+ .is_none(),
+ schema_for_rpc_method("openhuman.ext_gate_ping").is_none(),
+ )
+ })
+ .await;
+ assert_eq!(hidden, (true, true), "hosted: false must hide the extension");
+}