Skip to content

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

test(channel_runtime): cover released runtime callback scoping and send replay

Steven Enamakel0b20566e8102
diff --git a/crates/openhuman-core/src/modules/channel_runtime_tests.rs b/crates/openhuman-core/src/modules/channel_runtime_tests.rs
index e5a6bc9645..49f8847abb 100644
--- a/crates/openhuman-core/src/modules/channel_runtime_tests.rs
+++ b/crates/openhuman-core/src/modules/channel_runtime_tests.rs
@@ -88,3 +88,56 @@ async fn a_failed_cleanup_can_be_retried_without_aborting_pending_work() {
assert!(closing.lock().await.is_none());
join_cleanup(&closing, || tokio::spawn(async { Ok(()) })).await.unwrap();
}
+
+#[derive(Clone)]
+struct TransportFixture(Arc<std::sync::atomic::AtomicUsize>);
+
+#[allow(clippy::unused_async, reason = "TinyBus interfaces require async methods")]
+#[tinybus::interface(name = "ai.tinyhumans.tinychannels.ChannelsHost")]
+impl TransportFixture {
+ async fn dispatch_controller_backend(
+ &self,
+ request: tinychannels_bus::ChannelBackendRequest,
+ ) -> tinybus::Result<tinychannels_bus::ChannelBackendResult> {
+ use tinychannels_bus::module_progressive::{ProgressiveTransportRequest, ProgressiveTransportResult};
+ let tinychannels_bus::ChannelBackendRequest::ProgressiveTransport(request) = request else {
+ return Err(tinybus::Error::failed("unexpected fixture capability"));
+ };
+ let value = if let ProgressiveTransportRequest::Send { message, .. } = request {
+ assert!(message["idempotencyKey"].as_str().is_some());
+ self.0.fetch_add(1, Ordering::SeqCst);
+ serde_json::json!({"messageId":"fixture-message"})
+ } else { serde_json::Value::Null };
+ Ok(tinychannels_bus::ChannelBackendResult::ProgressiveTransport(ProgressiveTransportResult::Success(value)))
+ }
+}
+
+/// Run only against a separately built, byte-verified release artifact.
+#[tokio::test]
+#[ignore = "requires OPENHUMAN_CHANNELS_TEST_ARTIFACT pointing to the verified compiled module"]
+async fn released_runtime_scopes_callbacks_and_replays_one_final_send() {
+ use tinychannels_bus::module_progressive::{ProgressiveCommand, ProgressiveResult};
+ let artifact = std::env::var("OPENHUMAN_CHANNELS_TEST_ARTIFACT").expect("verified artifact path");
+ let mut config = crate::config::Config::default();
+ config.modules.allow_download = false;
+ config.modules.overrides = vec![crate::config::ModuleOverride { id: "tinychannels".into(), path: artifact }];
+ let first_sends = Arc::new(std::sync::atomic::AtomicUsize::new(0));
+ let second_sends = Arc::new(std::sync::atomic::AtomicUsize::new(0));
+ let first = ChannelRuntimeLease::open(ModuleClient::new(config.clone()), TransportFixture(first_sends.clone())).await.unwrap();
+ let second = ChannelRuntimeLease::open(ModuleClient::new(config), TransportFixture(second_sends.clone())).await.unwrap();
+ first.close().await.unwrap();
+ let opened: ProgressiveResult = second.object().call_confidential(methods::EXECUTE_PROGRESSIVE,
+ (ProgressiveCommand::Open { channel: "discord:fixture".into() },)).await.unwrap();
+ let ProgressiveResult::Opened { handle } = opened else { panic!("expected private handle"); };
+ for _ in 0..2 {
+ let completed: ProgressiveResult = second.object().call_confidential(methods::EXECUTE_PROGRESSIVE,
+ (ProgressiveCommand::Finish { handle: handle.clone(), text: "canonical final".into() },)).await.unwrap();
+ assert_eq!(completed, ProgressiveResult::Closed);
+ }
+ assert_eq!(first_sends.load(Ordering::SeqCst), 0);
+ assert_eq!(second_sends.load(Ordering::SeqCst), 1);
+ let callback_path = second.0.cleanup.callback.clone();
+ let connection = second.0.cleanup.connection.clone();
+ second.close().await.unwrap();
+ assert!(!connection.unserve(&callback_path).await, "adapter removed only after acknowledged stop");
+}