Skip to content

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

test(proactive): cover web and external subscriber delivery

Steven Enamakel4b7b36a1f95b
diff --git a/crates/openhuman-core/src/channels/proactive_tests.rs b/crates/openhuman-core/src/channels/proactive_tests.rs
index 623dd5ca41..67bb510fa0 100644
--- a/crates/openhuman-core/src/channels/proactive_tests.rs
+++ b/crates/openhuman-core/src/channels/proactive_tests.rs
@@ -96,6 +96,26 @@ async fn routes_to_active_external_channel() {
assert_eq!(outbound_intent_count.load(Ordering::SeqCst), 1);
}
+#[tokio::test]
+async fn web_and_external_proactive_subscribers_deliver_each_destination_once() {
+ let send_count = Arc::new(AtomicUsize::new(0));
+ let ch: Arc<dyn Channel> = Arc::new(MockChannel::new("telegram", Arc::clone(&send_count)));
+ let map: HashMap<String, Arc<dyn Channel>> = [("telegram".into(), ch)].into();
+ let external = ProactiveMessageSubscriber::new(Arc::new(map), Some("telegram".into()));
+ let web = crate::web_chat::proactive::WebProactiveSubscriber;
+ let mut web_events = crate::web_chat::subscribe_web_channel_events();
+ let event = proactive_event();
+
+ web.handle(&event).await;
+ external.handle(&event).await;
+
+ let delivered = web_events.recv().await.expect("web event");
+ assert_eq!(delivered.event, "proactive_message");
+ assert_eq!(delivered.full_response.as_deref(), Some("Hello!"));
+ assert!(web_events.try_recv().is_err(), "web event must not be duplicated");
+ assert_eq!(send_count.load(Ordering::SeqCst), 1);
+}
+
#[tokio::test]
async fn skips_external_when_channel_has_no_proactive_target() {
// The active channel is the configured default, but it has no resolvable
diff --git a/crates/openhuman-core/src/web_chat/proactive.rs b/crates/openhuman-core/src/web_chat/proactive.rs
index b37481b0b5..873383df56 100644
--- a/crates/openhuman-core/src/web_chat/proactive.rs
+++ b/crates/openhuman-core/src/web_chat/proactive.rs
@@ -29,7 +29,7 @@ pub(crate) fn register_proactive_subscriber() {
});
}
-struct WebProactiveSubscriber;
+pub(crate) struct WebProactiveSubscriber;
#[async_trait]
impl EventHandler<DomainEvent> for WebProactiveSubscriber {