The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(dispatch): add progressive flow tests reusing native media helpers
Steven Enamakelc2b5815fd87f
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media.rsindex 333be279e5..6cff6c072d 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media.rs@@ -554,4 +554,4 @@ mod tests;#[cfg(test)]#[path = "native_media_flow_tests.rs"]-mod flow_tests;+pub(in crate::channels::runtime::dispatch::processor) mod flow_tests;diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media_flow_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media_flow_tests.rsindex 445c807285..259736a98e 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media_flow_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/native_media_flow_tests.rs@@ -13,7 +13,7 @@ const THREAD: &str = "telegram:telegram:conversation-42";/// A valid 1x1 PNG: the module checks image bytes against their declared type.const PNG: &[u8] = &[0x89, 0x50, 0x4e, 0x47, 0xd, 0xa, 0x1a, 0xa, 0x0, 0x0, 0x0, 0xd, 0x49, 0x48, 0x44, 0x52, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x1, 0x8, 0x6, 0x0, 0x0, 0x0, 0x1f, 0x15, 0xc4, 0x89, 0x0, 0x0, 0x0, 0xb, 0x49, 0x44, 0x41, 0x54, 0x78, 0x9c, 0x63, 0x60, 0x0, 0x2, 0x0, 0x0, 0x5, 0x0, 0x1, 0x7a, 0x5e, 0xab, 0x3f, 0x0, 0x0, 0x0, 0x0, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82];-fn envelope(parts: Vec<ContentPart>) -> ChannelInboundEnvelope {+pub(in crate::channels::runtime::dispatch::processor) fn envelope(parts: Vec<ContentPart>) -> ChannelInboundEnvelope {ChannelInboundEnvelope {channel: ChannelRef {id: "telegram".into(),@@ -30,7 +30,7 @@ fn envelope(parts: Vec<ContentPart>) -> ChannelInboundEnvelope {}}-fn runtime_context(+pub(in crate::channels::runtime::dispatch::processor) fn runtime_context(objects: Arc<HashMap<String, ModuleObjectClient>>,) -> ChannelRuntimeContext {let model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rsindex e3b7e3ee49..5b7edd3453 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive.rs@@ -309,3 +309,7 @@ pub(crate) fn output_event(progress: AgentProgress) -> Option<ChannelOutputEvent#[cfg(test)]#[path = "progressive_tests.rs"]mod tests;++#[cfg(test)]+#[path = "progressive_flow_tests.rs"]+mod flow_tests;diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive_flow_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive_flow_tests.rsnew file mode 100644index 0000000000..7171d14196--- /dev/null+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/progressive_flow_tests.rs@@ -0,0 +1,144 @@+//! Progressive output against the linked TinyChannels module and a mocked+//! Telegram endpoint: target resolution, opening, feeding and finishing.++use super::native_media::flow_tests::{envelope, runtime_context};+use super::*;+use crate::channels::runtime::test_support::linked_telegram_runtime;+use tinychannels_bus::module_progressive::ProgressiveResult;++#[tokio::test]+async fn native_target_resolves_only_a_configured_account_of_the_envelope_provider() {+ let linked = linked_telegram_runtime().await;+ let ctx = runtime_context(linked.module_objects());++ let configured = native_target(&ctx, &envelope(Vec::new())).unwrap();+ assert!(configured.is_some(), "the telegram account is configured");++ let mut wrong_provider = envelope(Vec::new());+ wrong_provider.channel.account_id = Some("slack:work".into());+ let err = native_target(&ctx, &wrong_provider).err().expect("provider mismatch");+ assert!(err.to_string().contains("no configured account identity"), "{err}");++ let mut no_account = envelope(Vec::new());+ no_account.channel.account_id = None;+ assert!(native_target(&ctx, &no_account).is_err());++ let mut unconfigured = envelope(Vec::new());+ unconfigured.channel.account_id = Some("telegram:other".into());+ let err = native_target(&ctx, &unconfigured).err().expect("unknown account");+ assert!(err.to_string().contains("not configured"), "{err}");+}++#[tokio::test]+async fn progress_is_streamed_and_the_final_reply_is_delivered_to_the_provider() {+ let linked = linked_telegram_runtime().await;+ let ctx = runtime_context(linked.module_objects());+ let target = native_target(&ctx, &envelope(Vec::new())).unwrap().unwrap();+ let reply = Some(target.open("turn-progress-1").await.expect("module opens the turn"));++ let (tx, rx) = mpsc::channel(8);+ let worker = spawn_native_progress(rx, reply.clone().unwrap());+ tx.send(AgentProgress::TextDelta {+ delta: "working on it".into(),+ iteration: 1,+ })+ .await+ .unwrap();+ // Events with no channel projection are skipped, not fed.+ tx.send(AgentProgress::TextDelta {+ delta: "more".into(),+ iteration: 1,+ })+ .await+ .unwrap();+ drop(tx);+ worker.await.unwrap();++ assert!(finish_native_reply(&reply, "all done").await);+ let paths = linked.provider_request_paths().await;+ assert!(+ paths.iter().any(|p| p.ends_with("/sendMessage") || p.ends_with("/editMessageText")),+ "the provider received the output: {paths:?}"+ );+}++#[tokio::test]+async fn finishing_a_closed_reply_reports_failure_and_missing_replies_are_noops() {+ let linked = linked_telegram_runtime().await;+ let ctx = runtime_context(linked.module_objects());+ let target = native_target(&ctx, &envelope(Vec::new())).unwrap().unwrap();+ let reply = Some(target.open("turn-progress-2").await.unwrap());++ close_native_reply(&reply).await;+ assert!(!finish_native_reply(&reply, "too late").await);+ // Closing twice is tolerated.+ close_native_reply(&reply).await;++ assert!(!finish_native_reply(&None, "nobody listening").await);+ close_native_reply(&None).await;+}++#[tokio::test]+async fn a_failed_progress_update_closes_the_reply() {+ let linked = linked_telegram_runtime().await;+ let ctx = runtime_context(linked.module_objects());+ let target = native_target(&ctx, &envelope(Vec::new())).unwrap().unwrap();+ let reply = target.open("turn-progress-3").await.unwrap();+ reply.close().await.unwrap();++ let (tx, rx) = mpsc::channel(4);+ let worker = spawn_native_progress(rx, reply.clone());+ tx.send(AgentProgress::TextDelta {+ delta: "into a closed turn".into(),+ iteration: 1,+ })+ .await+ .unwrap();+ drop(tx);+ tokio::time::timeout(std::time::Duration::from_secs(5), worker)+ .await+ .expect("the worker stops after the first failed update")+ .unwrap();+}++#[test]+fn delivery_counts_report_outcomes_and_unsupported_parts() {+ use tinychannels_bus::channel::{+ ChannelSendError, ChannelSendOutcome, ContentPart, MessageReceipt, OutboundContentPart,+ SendErrorKind,+ };+ let ok = ChannelSendOutcome { receipt: MessageReceipt::default(), error: None };+ let failed = ChannelSendOutcome {+ receipt: MessageReceipt::default(),+ error: Some(ChannelSendError { kind: SendErrorKind::Transient, ..Default::default() }),+ };+ let unsupported = vec![OutboundContentPart::Content {+ part: ContentPart::Text { text: "x".into(), markdown_dialect: None },+ }];++ let single = ProgressiveResult::DeliveryOutcome { outcome: Box::new(ok.clone()) };+ assert_eq!(delivery_outcome_count(&single), 1);+ assert_eq!(delivery_unsupported_count(&single), 0);++ let many = ProgressiveResult::DeliveryOutcomes { outcomes: vec![ok.clone(), failed.clone()] };+ assert_eq!(delivery_outcome_count(&many), 2);+ assert!(!delivery_succeeded(&many));+ assert!(delivery_succeeded(&ProgressiveResult::DeliveryOutcomes { outcomes: vec![ok.clone()] }));+ assert!(!delivery_succeeded(&ProgressiveResult::DeliveryOutcome { outcome: Box::new(failed) }));++ let batch = ProgressiveResult::DeliveryBatch {+ outcomes: vec![ok],+ unsupported: unsupported.clone(),+ failure: None,+ hosted_accepted: false,+ };+ assert_eq!(delivery_outcome_count(&batch), 1);+ assert_eq!(delivery_unsupported_count(&batch), 1);+ assert!(!delivery_succeeded(&batch), "unsupported parts are not a complete delivery");++ let unsupported_only = ProgressiveResult::DeliveryUnsupported { parts: unsupported };+ assert_eq!(delivery_unsupported_count(&unsupported_only), 1);+ assert_eq!(delivery_outcome_count(&unsupported_only), 0);+ assert!(delivery_succeeded(&ProgressiveResult::DeliveryUnsupported { parts: Vec::new() }));+ assert!(delivery_succeeded(&ProgressiveResult::Updated));+}