Skip to content

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

test(dispatch): update inbound batch tests for new message types

Steven Enamakel40173bb45931
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/inbound_batch_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/inbound_batch_tests.rs
index 77cf608265..cd0703bc88 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/inbound_batch_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/inbound_batch_tests.rs
@@ -1,45 +1,52 @@
use super::*;
-use tinychannels_bus::{ChannelInboundEnvelope, ChannelRef, ConversationRef, SenderRef};
+use tinychannels_bus::{ChannelInboundEnvelope, ChannelMessage};
fn queued(seq: u64, id: &str, timestamp: u64, content: &str) -> QueuedInbound {
+ let msg = ChannelMessage {
+ reply_to_id: None,
+ topic_id: None,
+ id: id.to_string(),
+ sender: "alice".to_string(),
+ reply_target: format!("reply-{id}"),
+ content: content.to_string(),
+ channel: "telegram".to_string(),
+ timestamp,
+ thread_ts: Some(format!("thread-{id}")),
+ sender_name: None,
+ };
+ let envelope = ChannelInboundEnvelope {
+ message_id: id.to_string(),
+ text: content.to_string(),
+ parts: vec![ContentPart::Text {
+ text: content.to_string(),
+ markdown_dialect: None,
+ }],
+ ..Default::default()
+ };
QueuedInbound {
seq,
inbound: AdmittedInbound {
- msg: ChannelInboundEnvelope {
- message_id: id.to_string(),
- sender: SenderRef {
- id: "alice".to_string(),
- ..Default::default()
- },
- conversation: ConversationRef {
- id: format!("reply-{id}"),
- thread_id: Some(format!("thread-{id}")),
- ..Default::default()
- },
- text: content.to_string(),
- channel: ChannelRef {
- id: "telegram".to_string(),
- ..Default::default()
- },
- timestamp_unix_ms: Some(timestamp),
- ..Default::default()
- },
+ msg,
+ envelope,
history_key: "telegram_alice_reply".to_string(),
+ canonical_session_key: "main:telegram".to_string(),
+ session_key: "main:telegram".to_string(),
+ tenant: Default::default(),
+ native_target: None,
+ typed_envelope_input: false,
+ imported_history: Vec::new(),
+ legacy_history: None,
},
}
}
#[test]
fn single_message_passes_through_unchanged() {
- let one = queued(1, "m1", 5, " hello ");
- let merged = merge_channel_batch(vec![one.clone()]).unwrap();
- assert_eq!(merged.msg.text, " hello ");
- assert_eq!(merged.msg.message_id, "m1");
- assert_eq!(
- merged.msg.conversation.thread_id.as_deref(),
- Some("thread-m1")
- );
- assert_eq!(merged.history_key, one.inbound.history_key);
+ let merged = merge_channel_batch(vec![queued(1, "m1", 5, " hello ")]).unwrap();
+ assert_eq!(merged.msg.content, " hello ");
+ assert_eq!(merged.msg.id, "m1");
+ assert_eq!(merged.msg.thread_ts.as_deref(), Some("thread-m1"));
+ assert_eq!(merged.history_key, "telegram_alice_reply");
assert!(merge_channel_batch(Vec::new()).is_none());
}
@@ -51,43 +58,56 @@ fn merge_orders_by_timestamp_then_receive_order_and_uses_newest_as_base() {
queued(1, "m1", 10, "first"),
];
let merged = merge_channel_batch(batch).unwrap();
- assert_eq!(merged.msg.text, "first\nsecond\nthird");
- assert_eq!(merged.msg.message_id, "m3");
- assert_eq!(merged.msg.conversation.id, "reply-m3");
- assert_eq!(
- merged.msg.conversation.thread_id.as_deref(),
- Some("thread-m3")
- );
- assert_eq!(merged.msg.timestamp_unix_ms, Some(20));
+ assert_eq!(merged.msg.content, "first\nsecond\nthird");
+ assert_eq!(merged.envelope.text, "first\nsecond\nthird");
+ assert_eq!(merged.msg.id, "m3");
+ assert_eq!(merged.msg.reply_target, "reply-m3");
+ assert_eq!(merged.msg.thread_ts.as_deref(), Some("thread-m3"));
+ assert_eq!(merged.msg.timestamp, 20);
}
#[test]
-fn image_caption_then_text_keeps_marker_in_place_and_skips_blanks() {
- let batch = vec![
- queued(1, "m1", 1, "[IMAGE:/tmp/a.png]\nlook at this"),
+fn merged_typed_parts_keep_order_with_newline_separators() {
+ let merged = merge_channel_batch(vec![
+ queued(1, "m1", 1, "look"),
queued(2, "m2", 2, " "),
queued(3, "m3", 3, "what is it?"),
- ];
- let merged = merge_channel_batch(batch).unwrap();
- assert_eq!(
- merged.msg.text,
- "[IMAGE:/tmp/a.png]\nlook at this\nwhat is it?"
- );
+ ])
+ .unwrap();
+ assert_eq!(merged.msg.content, "look\nwhat is it?");
+ let texts: Vec<_> = merged
+ .envelope
+ .parts
+ .iter()
+ .filter_map(|part| match part {
+ ContentPart::Text { text, .. } => Some(text.as_str()),
+ _ => None,
+ })
+ .collect();
+ assert_eq!(texts, ["look", "\n", "what is it?"]);
}
#[test]
fn sender_name_is_the_last_one_present() {
let mut a = queued(1, "m1", 1, "a");
- a.inbound.msg.sender.name = Some("Alice A".into());
+ a.inbound.msg.sender_name = Some("Alice A".into());
let mut b = queued(2, "m2", 2, "b");
- b.inbound.msg.sender.name = Some("Alice B".into());
+ b.inbound.msg.sender_name = Some("Alice B".into());
let c = queued(3, "m3", 3, "c");
let merged = merge_channel_batch(vec![a, b, c]).unwrap();
- assert_eq!(merged.msg.sender.name.as_deref(), Some("Alice B"));
+ assert_eq!(merged.msg.sender_name.as_deref(), Some("Alice B"));
+}
+
+#[test]
+fn a_typed_message_marks_the_merged_batch_typed() {
+ let mut voice = queued(1, "m1", 1, "see attached");
+ voice.inbound.typed_envelope_input = true;
+ let merged = merge_channel_batch(vec![voice, queued(2, "m2", 2, "thanks")]).unwrap();
+ assert!(merged.typed_envelope_input);
}
#[test]
-fn item_traits_classify_media_commands_and_blanks() {
+fn item_traits_classify_media_commands_blanks_and_owned_state() {
let image = queued(1, "m1", 1, "[IMAGE:x] caption");
assert!(image.carries_media());
assert!(image.mergeable());
@@ -97,4 +117,16 @@ fn item_traits_classify_media_commands_and_blanks() {
assert_eq!(queued(1, "m", 1, "plain ✓").chars(), 7);
assert!(!queued(1, "m", 1, " /status").mergeable());
assert!(!queued(1, "m", 1, " \n ").mergeable());
+
+ let mut typed_media = queued(1, "m", 1, "see this");
+ typed_media.inbound.envelope.parts.push(ContentPart::Image {
+ media: Default::default(),
+ caption: None,
+ alt_text: None,
+ });
+ assert!(typed_media.carries_media(), "a typed image stretches the window");
+
+ let mut imported = queued(1, "m", 1, "hello");
+ imported.inbound.imported_history = vec![tinyagents_session::transcript::TranscriptMessage::user("old")];
+ assert!(!imported.mergeable(), "imported history belongs to one message");
}