Skip to content

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

test(runtime): cover proactive message routing to web and saas profile

Steven Enamakel069cb39ab875
diff --git a/crates/openhuman-core/src/core/runtime/subscribers_tests.rs b/crates/openhuman-core/src/core/runtime/subscribers_tests.rs
index d9ea879b3f..6765b7b61d 100644
--- a/crates/openhuman-core/src/core/runtime/subscribers_tests.rs
+++ b/crates/openhuman-core/src/core/runtime/subscribers_tests.rs
@@ -218,6 +218,78 @@ fn proactive_message_reaches_web_on_channelless_core_boot() {
const TEST_NAME: &str =
"core::runtime::subscribers::tests::proactive_message_reaches_web_on_channelless_core_boot";
+ if std::env::var(CHILD).as_deref() == Ok("1") {
+ tokio::runtime::Builder::new_current_thread()
+ .enable_all()
+ .build()
+ .expect("test runtime")
+ .block_on(async {
+ crate::core::bus::init().await.expect("bus init");
+ let mut web_events = crate::web_chat::subscribe_web_channel_events();
+ let config = crate::config::Config::default();
+ assert!(config.channels_config.active_channel.is_none());
+
+ super::register_domain_subscribers(
+ std::env::temp_dir(),
+ config,
+ true,
+ crate::core::runtime::DomainSet::none(),
+ &crate::core::runtime::DispatchCtx::ambient(),
+ );
+
+ crate::core::bus::BUS.publish(
+ crate::core::events::DomainEvent::ProactiveMessageRequested {
+ source: "cron:test".into(),
+ message: "Your morning briefing is ready.".into(),
+ job_name: Some("morning-briefing".into()),
+ tenant: None,
+ },
+ );
+
+ let event = tokio::time::timeout(std::time::Duration::from_secs(2), async {
+ loop {
+ let event = web_events
+ .recv()
+ .await
+ .expect("web event stream should remain open");
+ if event.event == "proactive_message"
+ && event.full_response.as_deref()
+ == Some("Your morning briefing is ready.")
+ {
+ break event;
+ }
+ }
+ })
+ .await
+ .expect("proactive message should reach the web event stream");
+ assert_eq!(event.event, "proactive_message");
+ assert_eq!(
+ event.full_response.as_deref(),
+ Some("Your morning briefing is ready.")
+ );
+ });
+ return;
+ }
+
+ let output = std::process::Command::new(std::env::current_exe().expect("test executable"))
+ .args(["--exact", TEST_NAME, "--nocapture", "--test-threads=1"])
+ .env(CHILD, "1")
+ .output()
+ .expect("run isolated proactive subscriber boot test");
+ let stdout = String::from_utf8_lossy(&output.stdout);
+ let stderr = String::from_utf8_lossy(&output.stderr);
+ assert!(
+ output.status.success() && stdout.contains("1 passed"),
+ "isolated proactive subscriber boot test failed:\n{stdout}\n{stderr}"
+ );
+}
+
+#[test]
+fn proactive_message_is_scoped_to_originating_saas_profile() {
+ const CHILD: &str = "OPENHUMAN_PROACTIVE_SUBSCRIBER_TEST_CHILD";
+ const TEST_NAME: &str =
+ "core::runtime::subscribers::tests::proactive_message_is_scoped_to_originating_saas_profile";
+
if std::env::var(CHILD).as_deref() == Ok("1") {
tokio::runtime::Builder::new_current_thread()
.enable_all()