Skip to content

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

test(channels): split the telegram runtime-command tests out of routes_tests

M3gA-Mind502e6f31ecd4
diff --git a/crates/openhuman-core/src/channels/routes_telegram_tests.rs b/crates/openhuman-core/src/channels/routes_telegram_tests.rs
new file mode 100644
index 0000000000..00afd58661
--- /dev/null
+++ b/crates/openhuman-core/src/channels/routes_telegram_tests.rs
@@ -0,0 +1,275 @@
+use super::*;
+
+#[tokio::test]
+async fn handle_runtime_command_telegram_status_replies_without_agent() {
+ let ctx = runtime_context(PathBuf::from("/tmp"));
+ let channel_impl = Arc::new(RecordingChannel::default());
+ let channel: Arc<dyn Channel> = channel_impl.clone();
+ let msg = inbound(
+ "1".into(),
+ "alice".into(),
+ "chat-remote".into(),
+ "/status".into(),
+ "telegram".into(),
+ Some("42".into()),
+ );
+
+ let handled = handle_runtime_command_if_needed(
+ &ctx,
+ &msg,
+ Some(&channel),
+ &conversation_history_key(&msg),
+ )
+ .await;
+ assert!(handled);
+
+ let sent = channel_impl.sent.lock().unwrap();
+ assert_eq!(sent.len(), 1);
+ assert!(
+ sent_text(&sent[0]).contains("**Status**"),
+ "status command returned unexpected reply: {:?}",
+ sent_text(&sent[0])
+ );
+ assert!(sent_text(&sent[0]).contains("Provider:"));
+}
+
+#[tokio::test]
+async fn handle_runtime_command_without_target_channel_still_consumes_command() {
+ let ctx = runtime_context(PathBuf::from("/tmp"));
+ let msg = inbound(
+ "1".into(),
+ "alice".into(),
+ "chat-remote".into(),
+ "/help".into(),
+ "telegram".into(),
+ None,
+ );
+
+ let handled =
+ handle_runtime_command_if_needed(&ctx, &msg, None, &conversation_history_key(&msg)).await;
+ assert!(handled);
+}
+
+#[tokio::test]
+async fn handle_runtime_command_telegram_help_replies_with_remote_command_list() {
+ let ctx = runtime_context(PathBuf::from("/tmp"));
+ let channel_impl = Arc::new(RecordingChannel::default());
+ let channel: Arc<dyn Channel> = channel_impl.clone();
+ let msg = inbound(
+ "1".into(),
+ "alice".into(),
+ "chat-remote".into(),
+ "/help".into(),
+ "telegram".into(),
+ Some("42".into()),
+ );
+
+ let handled = handle_runtime_command_if_needed(
+ &ctx,
+ &msg,
+ Some(&channel),
+ &conversation_history_key(&msg),
+ )
+ .await;
+ assert!(handled);
+
+ let sent = channel_impl.sent.lock().unwrap();
+ assert_eq!(sent.len(), 1);
+ assert!(sent_text(&sent[0]).contains("Remote control:"));
+ assert!(sent_text(&sent[0]).contains("`/status`"));
+ assert!(sent_text(&sent[0]).contains("`/sessions`"));
+ assert!(sent_text(&sent[0]).contains("`/new`"));
+ assert!(sent_text(&sent[0]).contains("Model routing: `/model`, `/models`"));
+}
+
+#[tokio::test]
+async fn handle_runtime_command_telegram_sessions_reports_empty_store() {
+ let tempdir = tempfile::tempdir().unwrap();
+ let ctx = runtime_context(tempdir.path().to_path_buf());
+ let channel_impl = Arc::new(RecordingChannel::default());
+ let channel: Arc<dyn Channel> = channel_impl.clone();
+ let msg = inbound(
+ "1".into(),
+ "alice".into(),
+ "chat-remote".into(),
+ "/sessions".into(),
+ "telegram".into(),
+ Some("42".into()),
+ );
+
+ let handled = handle_runtime_command_if_needed(
+ &ctx,
+ &msg,
+ Some(&channel),
+ &conversation_history_key(&msg),
+ )
+ .await;
+ assert!(handled);
+
+ let sent = channel_impl.sent.lock().unwrap();
+ assert_eq!(sent.len(), 1);
+ assert!(sent_text(&sent[0]).contains("No conversation threads yet. Send `/new` to create one."));
+ assert_eq!(sent[0].thread_id.as_deref(), Some("42"));
+}
+
+#[tokio::test]
+#[ignore = "the linked tinychannels-module is given no storage backend here, so /new fails to persist the chat binding (host storage is unavailable); needs a storage fixture"]
+async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
+ let tempdir = tempfile::tempdir().unwrap();
+ let ctx = runtime_context(tempdir.path().to_path_buf());
+ let channel_impl = Arc::new(RecordingChannel::default());
+ let channel: Arc<dyn Channel> = channel_impl.clone();
+ let sender_key = "telegram_alice_chat-remote";
+
+ ctx.conversation_histories.lock().unwrap().insert(
+ sender_key.to_string(),
+ vec![ChatMessage::user("old history")],
+ );
+
+ let new_msg = inbound(
+ "1".into(),
+ "alice".into(),
+ "chat-remote".into(),
+ "/new".into(),
+ "telegram".into(),
+ Some("42".into()),
+ );
+ assert!(
+ handle_runtime_command_if_needed(
+ &ctx,
+ &new_msg,
+ Some(&channel),
+ &conversation_history_key(&new_msg)
+ )
+ .await
+ );
+ assert!(ctx
+ .conversation_histories
+ .lock()
+ .unwrap()
+ .get(sender_key)
+ .is_none());
+
+ ctx.conversation_histories
+ .lock()
+ .unwrap()
+ .insert(sender_key.to_string(), vec![ChatMessage::user("after new")]);
+ set_route_selection(
+ &ctx,
+ sender_key,
+ ChannelRouteSelection {
+ provider: "anthropic".into(),
+ model: "claude-3".into(),
+ },
+ );
+
+ let subscriber = ChannelTurnStateSubscriber::new(tempdir.path().to_path_buf());
+ 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: tempdir.path().to_path_buf(),
+ })
+ .await;
+
+ let status_msg = inbound(
+ "3".into(),
+ "alice".into(),
+ "chat-remote".into(),
+ "/status".into(),
+ "telegram".into(),
+ Some("42".into()),
+ );
+ assert!(
+ handle_runtime_command_if_needed(
+ &ctx,
+ &status_msg,
+ Some(&channel),
+ &conversation_history_key(&status_msg)
+ )
+ .await
+ );
+
+ let sessions_msg = inbound(
+ "4".into(),
+ "alice".into(),
+ "chat-remote".into(),
+ "/sessions".into(),
+ "telegram".into(),
+ Some("42".into()),
+ );
+ assert!(
+ handle_runtime_command_if_needed(
+ &ctx,
+ &sessions_msg,
+ Some(&channel),
+ &conversation_history_key(&sessions_msg)
+ )
+ .await
+ );
+
+ let sent = channel_impl.sent.lock().unwrap();
+ assert_eq!(sent.len(), 3);
+ assert!(sent_text(&sent[0]).contains("Started new session"));
+ assert!(sent_text(&sent[0]).contains("In-memory channel history cleared for this chat."));
+
+ assert!(sent_text(&sent[1]).contains("**Status**"));
+ assert!(sent_text(&sent[1]).contains("Thread: `Telegram"));
+ assert!(sent_text(&sent[1]).contains("Provider: `anthropic`"));
+ assert!(sent_text(&sent[1]).contains("Model: `claude-3`"));
+ assert!(sent_text(&sent[1]).contains("In-memory turns: 1"));
+ assert!(sent_text(&sent[1]).contains("Turn: in progress"));
+
+ assert!(sent_text(&sent[2]).contains("**Recent sessions**"));
+ assert!(sent_text(&sent[2]).contains("→ `Telegram"));
+ assert!(sent
+ .iter()
+ .all(|message| message.thread_id.as_deref() == Some("42")));
+}
+
+#[tokio::test]
+async fn handle_runtime_command_telegram_new_reports_unavailable_storage() {
+ let tempdir = tempfile::tempdir().unwrap();
+ let ctx = runtime_context(tempdir.path().to_path_buf());
+ let channel_impl = Arc::new(RecordingChannel::default());
+ let channel: Arc<dyn Channel> = channel_impl.clone();
+ let sender_key = "telegram_alice_chat-remote";
+
+ ctx.conversation_histories.lock().unwrap().insert(
+ sender_key.to_string(),
+ vec![ChatMessage::user("old history")],
+ );
+
+ let msg = inbound(
+ "1".into(),
+ "alice".into(),
+ "chat-remote".into(),
+ "/new".into(),
+ "telegram".into(),
+ Some("42".into()),
+ );
+ assert!(
+ handle_runtime_command_if_needed(
+ &ctx,
+ &msg,
+ Some(&channel),
+ &conversation_history_key(&msg)
+ )
+ .await
+ );
+ let sent = channel_impl.sent.lock().unwrap();
+ assert_eq!(sent.len(), 1);
+ assert!(
+ sent_text(&sent[0]).contains("Created thread"),
+ "{}",
+ sent_text(&sent[0])
+ );
+ assert!(sent_text(&sent[0]).contains("failed to persist the chat binding"));
+ assert!(sent_text(&sent[0]).contains("host storage is unavailable"));
+ assert_eq!(sent[0].thread_id.as_deref(), Some("42"));
+}
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rs
index 74009d9586..9e06580779 100644
--- a/crates/openhuman-core/src/channels/routes_tests.rs
+++ b/crates/openhuman-core/src/channels/routes_tests.rs
@@ -500,276 +500,5 @@ async fn handle_runtime_command_set_model_clears_sender_history_and_persists_rou
assert!(sent_text(&sent[0]).contains("Model switched to `gpt-5-mini`"));
}
-#[tokio::test]
-async fn handle_runtime_command_telegram_status_replies_without_agent() {
- let ctx = runtime_context(PathBuf::from("/tmp"));
- let channel_impl = Arc::new(RecordingChannel::default());
- let channel: Arc<dyn Channel> = channel_impl.clone();
- let msg = inbound(
- "1".into(),
- "alice".into(),
- "chat-remote".into(),
- "/status".into(),
- "telegram".into(),
- Some("42".into()),
- );
-
- let handled = handle_runtime_command_if_needed(
- &ctx,
- &msg,
- Some(&channel),
- &conversation_history_key(&msg),
- )
- .await;
- assert!(handled);
-
- let sent = channel_impl.sent.lock().unwrap();
- assert_eq!(sent.len(), 1);
- assert!(
- sent_text(&sent[0]).contains("**Status**"),
- "status command returned unexpected reply: {:?}",
- sent_text(&sent[0])
- );
- assert!(sent_text(&sent[0]).contains("Provider:"));
-}
-
-#[tokio::test]
-async fn handle_runtime_command_without_target_channel_still_consumes_command() {
- let ctx = runtime_context(PathBuf::from("/tmp"));
- let msg = inbound(
- "1".into(),
- "alice".into(),
- "chat-remote".into(),
- "/help".into(),
- "telegram".into(),
- None,
- );
-
- let handled =
- handle_runtime_command_if_needed(&ctx, &msg, None, &conversation_history_key(&msg)).await;
- assert!(handled);
-}
-
-#[tokio::test]
-async fn handle_runtime_command_telegram_help_replies_with_remote_command_list() {
- let ctx = runtime_context(PathBuf::from("/tmp"));
- let channel_impl = Arc::new(RecordingChannel::default());
- let channel: Arc<dyn Channel> = channel_impl.clone();
- let msg = inbound(
- "1".into(),
- "alice".into(),
- "chat-remote".into(),
- "/help".into(),
- "telegram".into(),
- Some("42".into()),
- );
-
- let handled = handle_runtime_command_if_needed(
- &ctx,
- &msg,
- Some(&channel),
- &conversation_history_key(&msg),
- )
- .await;
- assert!(handled);
-
- let sent = channel_impl.sent.lock().unwrap();
- assert_eq!(sent.len(), 1);
- assert!(sent_text(&sent[0]).contains("Remote control:"));
- assert!(sent_text(&sent[0]).contains("`/status`"));
- assert!(sent_text(&sent[0]).contains("`/sessions`"));
- assert!(sent_text(&sent[0]).contains("`/new`"));
- assert!(sent_text(&sent[0]).contains("Model routing: `/model`, `/models`"));
-}
-
-#[tokio::test]
-async fn handle_runtime_command_telegram_sessions_reports_empty_store() {
- let tempdir = tempfile::tempdir().unwrap();
- let ctx = runtime_context(tempdir.path().to_path_buf());
- let channel_impl = Arc::new(RecordingChannel::default());
- let channel: Arc<dyn Channel> = channel_impl.clone();
- let msg = inbound(
- "1".into(),
- "alice".into(),
- "chat-remote".into(),
- "/sessions".into(),
- "telegram".into(),
- Some("42".into()),
- );
-
- let handled = handle_runtime_command_if_needed(
- &ctx,
- &msg,
- Some(&channel),
- &conversation_history_key(&msg),
- )
- .await;
- assert!(handled);
-
- let sent = channel_impl.sent.lock().unwrap();
- assert_eq!(sent.len(), 1);
- assert!(sent_text(&sent[0]).contains("No conversation threads yet. Send `/new` to create one."));
- assert_eq!(sent[0].thread_id.as_deref(), Some("42"));
-}
-
-#[tokio::test]
-#[ignore = "the linked tinychannels-module is given no storage backend here, so /new fails to persist the chat binding (host storage is unavailable); needs a storage fixture"]
-async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
- let tempdir = tempfile::tempdir().unwrap();
- let ctx = runtime_context(tempdir.path().to_path_buf());
- let channel_impl = Arc::new(RecordingChannel::default());
- let channel: Arc<dyn Channel> = channel_impl.clone();
- let sender_key = "telegram_alice_chat-remote";
-
- ctx.conversation_histories.lock().unwrap().insert(
- sender_key.to_string(),
- vec![ChatMessage::user("old history")],
- );
-
- let new_msg = inbound(
- "1".into(),
- "alice".into(),
- "chat-remote".into(),
- "/new".into(),
- "telegram".into(),
- Some("42".into()),
- );
- assert!(
- handle_runtime_command_if_needed(
- &ctx,
- &new_msg,
- Some(&channel),
- &conversation_history_key(&new_msg)
- )
- .await
- );
- assert!(ctx
- .conversation_histories
- .lock()
- .unwrap()
- .get(sender_key)
- .is_none());
-
- ctx.conversation_histories
- .lock()
- .unwrap()
- .insert(sender_key.to_string(), vec![ChatMessage::user("after new")]);
- set_route_selection(
- &ctx,
- sender_key,
- ChannelRouteSelection {
- provider: "anthropic".into(),
- model: "claude-3".into(),
- },
- );
-
- let subscriber = ChannelTurnStateSubscriber::new(tempdir.path().to_path_buf());
- 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: tempdir.path().to_path_buf(),
- })
- .await;
-
- let status_msg = inbound(
- "3".into(),
- "alice".into(),
- "chat-remote".into(),
- "/status".into(),
- "telegram".into(),
- Some("42".into()),
- );
- assert!(
- handle_runtime_command_if_needed(
- &ctx,
- &status_msg,
- Some(&channel),
- &conversation_history_key(&status_msg)
- )
- .await
- );
-
- let sessions_msg = inbound(
- "4".into(),
- "alice".into(),
- "chat-remote".into(),
- "/sessions".into(),
- "telegram".into(),
- Some("42".into()),
- );
- assert!(
- handle_runtime_command_if_needed(
- &ctx,
- &sessions_msg,
- Some(&channel),
- &conversation_history_key(&sessions_msg)
- )
- .await
- );
-
- let sent = channel_impl.sent.lock().unwrap();
- assert_eq!(sent.len(), 3);
- assert!(sent_text(&sent[0]).contains("Started new session"));
- assert!(sent_text(&sent[0]).contains("In-memory channel history cleared for this chat."));
-
- assert!(sent_text(&sent[1]).contains("**Status**"));
- assert!(sent_text(&sent[1]).contains("Thread: `Telegram"));
- assert!(sent_text(&sent[1]).contains("Provider: `anthropic`"));
- assert!(sent_text(&sent[1]).contains("Model: `claude-3`"));
- assert!(sent_text(&sent[1]).contains("In-memory turns: 1"));
- assert!(sent_text(&sent[1]).contains("Turn: in progress"));
-
- assert!(sent_text(&sent[2]).contains("**Recent sessions**"));
- assert!(sent_text(&sent[2]).contains("→ `Telegram"));
- assert!(sent
- .iter()
- .all(|message| message.thread_id.as_deref() == Some("42")));
-}
-
-#[tokio::test]
-async fn handle_runtime_command_telegram_new_reports_unavailable_storage() {
- let tempdir = tempfile::tempdir().unwrap();
- let ctx = runtime_context(tempdir.path().to_path_buf());
- let channel_impl = Arc::new(RecordingChannel::default());
- let channel: Arc<dyn Channel> = channel_impl.clone();
- let sender_key = "telegram_alice_chat-remote";
-
- ctx.conversation_histories.lock().unwrap().insert(
- sender_key.to_string(),
- vec![ChatMessage::user("old history")],
- );
-
- let msg = inbound(
- "1".into(),
- "alice".into(),
- "chat-remote".into(),
- "/new".into(),
- "telegram".into(),
- Some("42".into()),
- );
- assert!(
- handle_runtime_command_if_needed(
- &ctx,
- &msg,
- Some(&channel),
- &conversation_history_key(&msg)
- )
- .await
- );
- let sent = channel_impl.sent.lock().unwrap();
- assert_eq!(sent.len(), 1);
- assert!(
- sent_text(&sent[0]).contains("Created thread"),
- "{}",
- sent_text(&sent[0])
- );
- assert!(sent_text(&sent[0]).contains("failed to persist the chat binding"));
- assert!(sent_text(&sent[0]).contains("host storage is unavailable"));
- assert_eq!(sent[0].thread_id.as_deref(), Some("42"));
-}
+#[path = "routes_telegram_tests.rs"]
+mod routes_telegram_tests;
diff --git a/scripts/ci/check-openhuman-rust-layout.mjs b/scripts/ci/check-openhuman-rust-layout.mjs
index 846ba9838f..fadfc93a92 100644
--- a/scripts/ci/check-openhuman-rust-layout.mjs
+++ b/scripts/ci/check-openhuman-rust-layout.mjs
@@ -36,7 +36,7 @@ const LEGACY_LIMIT_ENTRIES = [
// their current sizes while follow-up work separates their test concerns.
// `core/` was pruned from the line limit by name until these pins; its
// oversized files are pinned at the size they had when enforcement began.
- ["crates/openhuman-core/src/core/all.rs", 1113],
+ ["crates/openhuman-core/src/core/all.rs", 1080],
["crates/openhuman-core/src/core/all_tests.rs", 1465],
["crates/openhuman-core/src/core/events.rs", 1649],
["crates/openhuman-core/src/core/events_tests.rs", 988],