The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(tinyflows): cover cancellation of partial callback registration
Steven Enamakel6716c24ac0bb
diff --git a/crates/openhuman-core/src/modules/tinyflows.rs b/crates/openhuman-core/src/modules/tinyflows.rsindex 8c063e6041..fc91f42b1e 100644--- a/crates/openhuman-core/src/modules/tinyflows.rs+++ b/crates/openhuman-core/src/modules/tinyflows.rs@@ -200,7 +200,7 @@ mod imp {serve_pair_after_first(path, first, second, async {}).await}- async fn serve_pair_after_first<F>(+ pub(super) async fn serve_pair_after_first<F>(path: String,first: impl tinybus::service::Interface + 'static,second: impl tinybus::service::Interface + 'static,@@ -268,9 +268,10 @@ mod fixture;#[cfg(feature = "modules")]pub(crate) use imp::{- copilot_invoke_proxy, copilot_proxy, proxy, run_proxy, serve, serve_pair,- ServedObjectRegistration, unserve,+ copilot_invoke_proxy, copilot_proxy, proxy, run_proxy, serve, serve_pair, unserve,};+#[cfg(all(test, feature = "modules"))]+pub(crate) use imp::serve_pair_after_first;#[cfg(not(feature = "modules"))]mod imp {@@ -309,11 +310,19 @@ mod imp {Err("scheduled jobs are unavailable: this build has no module loader".to_string())}+ pub(crate) async fn serve_pair(+ _path: String,+ _first: impl tinybus::service::Interface + 'static,+ _second: impl tinybus::service::Interface + 'static,+ ) -> Result<ServedObjectRegistration, String> {+ Err("scheduled jobs are unavailable: this build has no module loader".to_string())+ }+pub(crate) fn unserve(_path: String) {}}#[cfg(not(feature = "modules"))]-pub(crate) use imp::{copilot_invoke_proxy, copilot_proxy, proxy, run_proxy, serve, unserve};+pub(crate) use imp::{copilot_invoke_proxy, copilot_proxy, proxy, run_proxy, serve, serve_pair, unserve};/// Whether the module can serve in this build and configuration (the switch/// is on and the loader exists). Does not load anything.diff --git a/crates/openhuman-core/src/modules/tinyflows_tests.rs b/crates/openhuman-core/src/modules/tinyflows_tests.rsindex c32bbce105..76635f92bd 100644--- a/crates/openhuman-core/src/modules/tinyflows_tests.rs+++ b/crates/openhuman-core/src/modules/tinyflows_tests.rs@@ -1,5 +1,64 @@use super::*;+#[cfg(feature = "modules")]+struct RegistrationProbe {+ dropped: std::sync::Arc<tokio::sync::Notify>,+ context: std::sync::Arc<()>,+}++#[cfg(feature = "modules")]+impl Drop for RegistrationProbe {+ fn drop(&mut self) {+ self.dropped.notify_one();+ }+}++#[cfg(feature = "modules")]+#[async_trait::async_trait]+impl tinybus::service::Interface for RegistrationProbe {+ fn name(&self) -> tinybus::InterfaceName {+ tinybus::InterfaceName::new("ai.tinyhumans.openhuman.TestRegistration")+ .expect("interface name")+ }++ fn members(&self) -> Vec<tinybus::MemberName> {+ vec![tinybus::MemberName::new("Ping").expect("member name")]+ }++ async fn call(+ &self,+ _member: &tinybus::MemberName,+ _args: serde_json::Value,+ ) -> tinybus::Result<serde_json::Value> {+ let _keep_callback_context_alive = &self.context;+ Ok(serde_json::Value::Null)+ }+}++#[cfg(feature = "modules")]+struct SecondRegistrationProbe;++#[cfg(feature = "modules")]+#[async_trait::async_trait]+impl tinybus::service::Interface for SecondRegistrationProbe {+ fn name(&self) -> tinybus::InterfaceName {+ tinybus::InterfaceName::new("ai.tinyhumans.openhuman.TestRegistrationSecond")+ .expect("interface name")+ }++ fn members(&self) -> Vec<tinybus::MemberName> {+ vec![tinybus::MemberName::new("Ping").expect("member name")]+ }++ async fn call(+ &self,+ _member: &tinybus::MemberName,+ _args: serde_json::Value,+ ) -> tinybus::Result<serde_json::Value> {+ Ok(serde_json::Value::Null)+ }+}+#[test]fn the_disabled_message_names_the_component_and_the_switch() {let message = disabled_message();@@ -87,3 +146,58 @@ async fn the_copilot_object_answers_tool_catalog_over_its_bus_contract() {assert_eq!(run_flow.permission, "Write");assert!(run_flow.external_effect);}++#[cfg(feature = "modules")]+#[tokio::test]+async fn cancelling_partial_callback_registration_unserves_and_releases_its_context() {+ use std::sync::Arc;++ let path = format!("/ai/tinyhumans/openhuman/TestRegistration/{}", uuid::Uuid::new_v4());+ let dropped = Arc::new(tokio::sync::Notify::new());+ let context = Arc::new(());+ let weak_context = Arc::downgrade(&context);+ let (registered_tx, registered_rx) = tokio::sync::oneshot::channel();+ let (continue_tx, continue_rx) = tokio::sync::oneshot::channel();+ let task_path = path.clone();+ let task_dropped = Arc::clone(&dropped);+ let task_context = Arc::clone(&context);+ let registration = tokio::spawn(async move {+ serve_pair_after_first(+ task_path,+ RegistrationProbe {+ dropped: task_dropped,+ context: task_context,+ },+ SecondRegistrationProbe,+ async move {+ let _ = registered_tx.send(());+ let _ = continue_rx.await;+ },+ )+ .await+ });+ registered_rx.await.expect("first interface is served");++ let connected = super::super::runtime::runtime()+ .await+ .expect("module runtime exists");+ let proxy = connected+ .connection()+ .proxy(+ HOST_BUS_NAME,+ &path,+ "ai.tinyhumans.openhuman.TestRegistration",+ )+ .expect("probe proxy");+ assert!(proxy.call::<_, (), serde_json::Value>("Ping", ()).await.is_ok());++ registration.abort();+ let cleanup = dropped.notified();+ let _ = continue_tx.send(());+ tokio::time::timeout(std::time::Duration::from_secs(5), cleanup)+ .await+ .expect("detached registration settles and unregisters its interface");+ drop(context);+ assert!(weak_context.upgrade().is_none(), "callback context is released");+ assert!(proxy.call::<_, (), serde_json::Value>("Ping", ()).await.is_err());+}