Skip to content

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

test(cron): cover channel bridge routing and fail-closed paths

Steven Enamakel921f43f4ffda
diff --git a/crates/openhuman-core/src/cron/channel_bridge_tests.rs b/crates/openhuman-core/src/cron/channel_bridge_tests.rs
index e922a269ab..e0d87fa48a 100644
--- a/crates/openhuman-core/src/cron/channel_bridge_tests.rs
+++ b/crates/openhuman-core/src/cron/channel_bridge_tests.rs
@@ -32,3 +32,83 @@ fn conversation_ref_rejects_unknown_kind_claims() {
};
assert!(conversation_ref(&identity).is_err());
}
+
+fn session(provider: &str, account: Option<&str>, conversation: &str) -> tinyflows_bus::schedule::ChannelSessionIdentity {
+ tinyflows_bus::schedule::ChannelSessionIdentity {
+ tenant_key: "t".into(),
+ agent_id: "orchestrator".into(),
+ session_key: "s".into(),
+ provider: provider.into(),
+ account_id: account.map(str::to_owned),
+ conversation: ChannelConversationIdentity {
+ kind: "dm".into(),
+ id: conversation.into(),
+ scope_id: None,
+ parent_id: None,
+ thread_id: None,
+ topic_id: None,
+ },
+ }
+}
+
+#[tokio::test]
+async fn sends_and_announces_fail_closed_without_a_running_runtime() {
+ clear_channel_bridge();
+ let id = session("telegram", Some("telegram"), "42");
+ assert_eq!(
+ send_to_channel("telegram", &id, "42", "hi", "k").await.unwrap_err(),
+ "channel runtime is not running"
+ );
+ assert_eq!(
+ announce_to_channel("telegram", "42", None, "hi", "k").await.unwrap_err(),
+ "channel runtime is not running"
+ );
+}
+
+#[tokio::test]
+async fn send_rejects_identities_that_do_not_match_the_trusted_route() {
+ let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
+ let objects = linked.module_objects();
+ let account = objects
+ .keys()
+ .find(|k| tinychannels_bus::provider_id(k) == "telegram")
+ .unwrap()
+ .clone();
+ register_channel_bridge(objects);
+
+ let mismatch = send_to_channel("telegram", &session("slack", Some(&account), "42"), "42", "x", "k").await;
+ assert_eq!(mismatch.unwrap_err(), "channel origin provider does not match the captured session");
+
+ let no_account = send_to_channel("telegram", &session("telegram", None, "42"), "42", "x", "k").await;
+ assert_eq!(no_account.unwrap_err(), "channel origin has no configured account identity");
+
+ let foreign_account =
+ send_to_channel("telegram", &session("telegram", Some("slack:team"), "42"), "42", "x", "k").await;
+ assert_eq!(foreign_account.unwrap_err(), "channel origin has no configured account identity");
+
+ let other_room = send_to_channel("telegram", &session("telegram", Some(&account), "42"), "99", "x", "k").await;
+ assert_eq!(
+ other_room.unwrap_err(),
+ "channel origin recipient does not match the captured conversation"
+ );
+
+ let missing = send_to_channel("telegram", &session("telegram", Some("telegram:ghost"), "42"), "42", "x", "k").await;
+ assert_eq!(missing.unwrap_err(), "configured channel module is unavailable");
+
+ let mut bad_kind = session("telegram", Some(&account), "42");
+ bad_kind.conversation.kind = "invented".into();
+ let invalid = send_to_channel("telegram", &bad_kind, "42", "x", "k").await;
+ assert_eq!(invalid.unwrap_err(), "channel origin conversation kind is invalid");
+
+ let unconfigured = announce_to_channel("discord", "42", Some("thread"), "x", "k").await;
+ assert_eq!(unconfigured.unwrap_err(), "channel discord is not configured");
+
+ let ok = send_to_channel("telegram", &session("telegram", Some(&account), "42"), "42", "sent", "k-ok").await;
+ clear_channel_bridge();
+ ok.expect("a matching identity is delivered through the module");
+ assert!(linked
+ .provider_request_paths()
+ .await
+ .iter()
+ .any(|p| p.ends_with("/sendMessage")));
+}