Skip to content

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

test(channels): move telegram route tests into a dedicated module

Steven Enamakel08a518f67ea9
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rs
index 09c2170eca..d2bd6ff735 100644
--- a/crates/openhuman-core/src/channels/routes_tests.rs
+++ b/crates/openhuman-core/src/channels/routes_tests.rs
@@ -655,170 +655,5 @@ async fn handle_runtime_command_telegram_sessions_reports_empty_store() {
assert_eq!(sent[0].thread_ts.as_deref(), Some("42"));
}
-#[tokio::test]
-async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
- let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
- let workspace = linked.config().workspace_dir.clone();
- let mut ctx = runtime_context(workspace.clone());
- let channel_state = Arc::new(TestChannel::new("recording"));
- let channel = Arc::new(ChannelHandle::Test(Arc::clone(&channel_state)));
- let sender_key = "telegram_alice_chat-remote";
-
- let new_msg = ChannelMessage {
- reply_to_id: None,
- topic_id: None,
- id: "1".into(),
- sender: "alice".into(),
- reply_target: "chat-remote".into(),
- content: "/new".into(),
- channel: "telegram".into(),
- timestamp: 0,
- thread_ts: Some("42".into()),
- sender_name: None,
- };
- assert!(handle_linked_runtime_command(&mut ctx, &new_msg, Some(&channel), &linked, None).await);
- set_route_selection(
- &ctx,
- sender_key,
- ChannelRouteSelection {
- provider: "anthropic".into(),
- model: "claude-3".into(),
- },
- );
-
- let subscriber = ChannelTurnStateSubscriber::with_config(Arc::new(linked.config().clone()));
- subscriber
- .handle(&DomainEvent::ChannelMessageReceived {
- channel: "telegram".into(),
- message_id: "2".into(),
- sender: "alice".into(),
- reply_target: "chat-remote".into(),
- content: "work".into(),
- thread_ts: Some("42".into()),
- inbound_envelope: None,
- workspace_dir: workspace.clone(),
- })
- .await;
-
- let status_msg = ChannelMessage {
- reply_to_id: None,
- topic_id: None,
- id: "3".into(),
- sender: "alice".into(),
- reply_target: "chat-remote".into(),
- content: "/status".into(),
- channel: "telegram".into(),
- timestamp: 0,
- thread_ts: Some("42".into()),
- sender_name: None,
- };
- assert!(
- handle_linked_runtime_command(&mut ctx, &status_msg, Some(&channel), &linked, None).await
- );
-
- let sessions_msg = ChannelMessage {
- reply_to_id: None,
- topic_id: None,
- id: "4".into(),
- sender: "alice".into(),
- reply_target: "chat-remote".into(),
- content: "/sessions".into(),
- channel: "telegram".into(),
- timestamp: 0,
- thread_ts: Some("42".into()),
- sender_name: None,
- };
- assert!(
- handle_linked_runtime_command(&mut ctx, &sessions_msg, Some(&channel), &linked, None).await
- );
-
- let sent = channel_state.sent.lock().unwrap();
- assert_eq!(sent.len(), 3);
- assert!(sent[0].content.contains("Started new session"));
- assert!(
- sent[0]
- .content
- .contains("Durable conversation history reset for this chat.")
- );
-
- assert!(sent[1].content.contains("**Status**"));
- assert!(sent[1].content.contains("Thread: `Telegram"));
- assert!(sent[1].content.contains("Provider: `anthropic`"));
- assert!(sent[1].content.contains("Model: `claude-3`"));
- assert!(sent[1].content.contains("Session turns: 0"));
- assert!(sent[1].content.contains("Turn: in progress"));
-
- assert!(sent[2].content.contains("**Recent sessions**"));
- assert!(sent[2].content.contains("→ `Telegram"));
- assert!(
- sent.iter()
- .all(|message| message.thread_ts.as_deref() == Some("42"))
- );
-}
-
-#[tokio::test]
-async fn handle_runtime_command_telegram_new_uses_module_storage() {
- let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
- let workspace = linked.config().workspace_dir.clone();
- let mut ctx = runtime_context(workspace);
- let channels = linked.channels();
- let channel = channels
- .iter()
- .find(|(name, _)| tinychannels_bus::provider_id(name) == "telegram")
- .map(|(_, channel)| Arc::clone(channel))
- .expect("linked runtime should expose its Telegram module handle");
- let msg = ChannelMessage {
- reply_to_id: None,
- topic_id: Some("42".into()),
- id: "100".into(),
- sender: "alice".into(),
- // This fixture supplies the same canonical conversation reference the
- // inbound module preparation boundary provides to command handling.
- reply_target: "-200:42".into(),
- content: "/new".into(),
- channel: "telegram".into(),
- timestamp: 0,
- thread_ts: Some("100".into()),
- sender_name: None,
- };
- assert!(
- handle_linked_runtime_command(&mut ctx, &msg, Some(&channel), &linked, Some("-200")).await
- );
- let topic_only_msg = ChannelMessage {
- id: "101".into(),
- thread_ts: None,
- ..msg.clone()
- };
- assert!(
- handle_linked_runtime_command(
- &mut ctx,
- &topic_only_msg,
- Some(&channel),
- &linked,
- Some("-200"),
- )
- .await
- );
- let sent = linked
- .provider_request_bodies("/bottoken/sendMessage")
- .await;
- assert_eq!(sent.len(), 2);
- assert_eq!(sent[0]["chat_id"], "-200");
- assert_eq!(sent[0]["message_thread_id"], "42");
- assert_eq!(sent[0]["reply_to_message_id"], 100);
- assert!(
- sent[0]["text"]
- .as_str()
- .unwrap()
- .contains("Started new session")
- );
- assert!(
- sent[0]["text"]
- .as_str()
- .unwrap()
- .contains("Durable conversation history reset")
- );
- assert_eq!(sent[1]["chat_id"], "-200");
- assert_eq!(sent[1]["message_thread_id"], "42");
- assert!(sent[1].get("reply_to_message_id").is_none());
-}
+#[path = "routes_tests_telegram.rs"]
+mod telegram;
diff --git a/crates/openhuman-core/src/channels/routes_tests_telegram.rs b/crates/openhuman-core/src/channels/routes_tests_telegram.rs
new file mode 100644
index 0000000000..844f7fc990
--- /dev/null
+++ b/crates/openhuman-core/src/channels/routes_tests_telegram.rs
@@ -0,0 +1,169 @@
+use super::*;
+
+#[tokio::test]
+async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
+ let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
+ let workspace = linked.config().workspace_dir.clone();
+ let mut ctx = runtime_context(workspace.clone());
+ let channel_state = Arc::new(TestChannel::new("recording"));
+ let channel = Arc::new(ChannelHandle::Test(Arc::clone(&channel_state)));
+ let sender_key = "telegram_alice_chat-remote";
+
+ let new_msg = ChannelMessage {
+ reply_to_id: None,
+ topic_id: None,
+ id: "1".into(),
+ sender: "alice".into(),
+ reply_target: "chat-remote".into(),
+ content: "/new".into(),
+ channel: "telegram".into(),
+ timestamp: 0,
+ thread_ts: Some("42".into()),
+ sender_name: None,
+ };
+ assert!(handle_linked_runtime_command(&mut ctx, &new_msg, Some(&channel), &linked, None).await);
+ set_route_selection(
+ &ctx,
+ sender_key,
+ ChannelRouteSelection {
+ provider: "anthropic".into(),
+ model: "claude-3".into(),
+ },
+ );
+
+ let subscriber = ChannelTurnStateSubscriber::with_config(Arc::new(linked.config().clone()));
+ subscriber
+ .handle(&DomainEvent::ChannelMessageReceived {
+ channel: "telegram".into(),
+ message_id: "2".into(),
+ sender: "alice".into(),
+ reply_target: "chat-remote".into(),
+ content: "work".into(),
+ thread_ts: Some("42".into()),
+ inbound_envelope: None,
+ workspace_dir: workspace.clone(),
+ })
+ .await;
+
+ let status_msg = ChannelMessage {
+ reply_to_id: None,
+ topic_id: None,
+ id: "3".into(),
+ sender: "alice".into(),
+ reply_target: "chat-remote".into(),
+ content: "/status".into(),
+ channel: "telegram".into(),
+ timestamp: 0,
+ thread_ts: Some("42".into()),
+ sender_name: None,
+ };
+ assert!(
+ handle_linked_runtime_command(&mut ctx, &status_msg, Some(&channel), &linked, None).await
+ );
+
+ let sessions_msg = ChannelMessage {
+ reply_to_id: None,
+ topic_id: None,
+ id: "4".into(),
+ sender: "alice".into(),
+ reply_target: "chat-remote".into(),
+ content: "/sessions".into(),
+ channel: "telegram".into(),
+ timestamp: 0,
+ thread_ts: Some("42".into()),
+ sender_name: None,
+ };
+ assert!(
+ handle_linked_runtime_command(&mut ctx, &sessions_msg, Some(&channel), &linked, None).await
+ );
+
+ let sent = channel_state.sent.lock().unwrap();
+ assert_eq!(sent.len(), 3);
+ assert!(sent[0].content.contains("Started new session"));
+ assert!(
+ sent[0]
+ .content
+ .contains("Durable conversation history reset for this chat.")
+ );
+
+ assert!(sent[1].content.contains("**Status**"));
+ assert!(sent[1].content.contains("Thread: `Telegram"));
+ assert!(sent[1].content.contains("Provider: `anthropic`"));
+ assert!(sent[1].content.contains("Model: `claude-3`"));
+ assert!(sent[1].content.contains("Session turns: 0"));
+ assert!(sent[1].content.contains("Turn: in progress"));
+
+ assert!(sent[2].content.contains("**Recent sessions**"));
+ assert!(sent[2].content.contains("→ `Telegram"));
+ assert!(
+ sent.iter()
+ .all(|message| message.thread_ts.as_deref() == Some("42"))
+ );
+}
+
+#[tokio::test]
+async fn handle_runtime_command_telegram_new_uses_module_storage() {
+ let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
+ let workspace = linked.config().workspace_dir.clone();
+ let mut ctx = runtime_context(workspace);
+ let channels = linked.channels();
+ let channel = channels
+ .iter()
+ .find(|(name, _)| tinychannels_bus::provider_id(name) == "telegram")
+ .map(|(_, channel)| Arc::clone(channel))
+ .expect("linked runtime should expose its Telegram module handle");
+ let msg = ChannelMessage {
+ reply_to_id: None,
+ topic_id: Some("42".into()),
+ id: "100".into(),
+ sender: "alice".into(),
+ // This fixture supplies the same canonical conversation reference the
+ // inbound module preparation boundary provides to command handling.
+ reply_target: "-200:42".into(),
+ content: "/new".into(),
+ channel: "telegram".into(),
+ timestamp: 0,
+ thread_ts: Some("100".into()),
+ sender_name: None,
+ };
+ assert!(
+ handle_linked_runtime_command(&mut ctx, &msg, Some(&channel), &linked, Some("-200")).await
+ );
+ let topic_only_msg = ChannelMessage {
+ id: "101".into(),
+ thread_ts: None,
+ ..msg.clone()
+ };
+ assert!(
+ handle_linked_runtime_command(
+ &mut ctx,
+ &topic_only_msg,
+ Some(&channel),
+ &linked,
+ Some("-200"),
+ )
+ .await
+ );
+ let sent = linked
+ .provider_request_bodies("/bottoken/sendMessage")
+ .await;
+ assert_eq!(sent.len(), 2);
+ assert_eq!(sent[0]["chat_id"], "-200");
+ assert_eq!(sent[0]["message_thread_id"], "42");
+ assert_eq!(sent[0]["reply_to_message_id"], 100);
+ assert!(
+ sent[0]["text"]
+ .as_str()
+ .unwrap()
+ .contains("Started new session")
+ );
+ assert!(
+ sent[0]["text"]
+ .as_str()
+ .unwrap()
+ .contains("Durable conversation history reset")
+ );
+ assert_eq!(sent[1]["chat_id"], "-200");
+ assert_eq!(sent[1]["message_thread_id"], "42");
+ assert!(sent[1].get("reply_to_message_id").is_none());
+}