Skip to content

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

test(channels): track idempotent sends in proactive mock

Steven Enamakel9536116f30d4
diff --git a/crates/openhuman-core/src/channels/proactive_tests.rs b/crates/openhuman-core/src/channels/proactive_tests.rs
index 84946f932c..6891a3aa62 100644
--- a/crates/openhuman-core/src/channels/proactive_tests.rs
+++ b/crates/openhuman-core/src/channels/proactive_tests.rs
@@ -1,13 +1,12 @@
use super::*;
use crate::channels::traits::ChannelMessage;
use std::sync::atomic::{AtomicUsize, Ordering};
-use std::sync::Mutex;
use tokio::sync::mpsc;
struct MockChannel {
name: String,
send_count: Arc<AtomicUsize>,
- last_idempotency_key: Arc<Mutex<Option<String>>>,
+ outbound_intent_count: Arc<AtomicUsize>,
/// Configured proactive delivery target. `Some` ⇒ the channel can
/// receive recipient-less proactive sends; `None` ⇒ proactive routing
/// skips it (models Telegram, which has no stored default chat).
@@ -21,7 +20,7 @@ impl MockChannel {
Self {
name: name.to_string(),
send_count,
- last_idempotency_key: Arc::new(Mutex::new(None)),
+ outbound_intent_count: Arc::new(AtomicUsize::new(0)),
target: Some(name.to_string()),
}
}
@@ -31,7 +30,7 @@ impl MockChannel {
Self {
name: name.to_string(),
send_count,
- last_idempotency_key: Arc::new(Mutex::new(None)),
+ outbound_intent_count: Arc::new(AtomicUsize::new(0)),
target: None,
}
}
@@ -39,12 +38,12 @@ impl MockChannel {
fn with_recorder(
name: &str,
send_count: Arc<AtomicUsize>,
- last_idempotency_key: Arc<Mutex<Option<String>>>,
+ outbound_intent_count: Arc<AtomicUsize>,
) -> Self {
Self {
name: name.to_string(),
send_count,
- last_idempotency_key,
+ outbound_intent_count,
target: Some(name.to_string()),
}
}
@@ -58,14 +57,14 @@ impl Channel for MockChannel {
fn proactive_target(&self) -> Option<String> {
self.target.clone()
}
- async fn send(&self, message: &SendMessage) -> anyhow::Result<()> {
+ async fn send(&self, _message: &SendMessage) -> anyhow::Result<()> {
self.send_count.fetch_add(1, Ordering::SeqCst);
- *self
- .last_idempotency_key
- .lock()
- .unwrap_or_else(|e| e.into_inner()) = message.idempotency_key.clone();
Ok(())
}
+ async fn send_idempotent(&self, message: &SendMessage) -> anyhow::Result<()> {
+ self.outbound_intent_count.fetch_add(1, Ordering::SeqCst);
+ self.send(message).await
+ }
async fn listen(&self, _tx: mpsc::Sender<ChannelMessage>) -> anyhow::Result<()> {
Ok(())
}
@@ -89,11 +88,11 @@ async fn web_only_does_not_panic() {
#[tokio::test]
async fn routes_to_active_external_channel() {
let send_count = Arc::new(AtomicUsize::new(0));
- let last_idempotency_key = Arc::new(Mutex::new(None));
+ let outbound_intent_count = Arc::new(AtomicUsize::new(0));
let ch: Arc<dyn Channel> = Arc::new(MockChannel::with_recorder(
"telegram",
Arc::clone(&send_count),
- Arc::clone(&last_idempotency_key),
+ Arc::clone(&outbound_intent_count),
));
let map: HashMap<String, Arc<dyn Channel>> = [("telegram".into(), ch)].into();
let sub = ProactiveMessageSubscriber::new(Arc::new(map), Some("telegram".into()));
@@ -101,12 +100,7 @@ async fn routes_to_active_external_channel() {
sub.handle(&proactive_event()).await;
assert_eq!(send_count.load(Ordering::SeqCst), 1);
- assert!(last_idempotency_key
- .lock()
- .unwrap_or_else(|e| e.into_inner())
- .as_deref()
- .unwrap()
- .starts_with("legacy-send:telegram:"));
+ assert_eq!(outbound_intent_count.load(Ordering::SeqCst), 1);
}
#[tokio::test]