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
refactor(channels): update channel handle usage in tests and core
Steven Enamakel92b3a0e996a7
diff --git a/crates/openhuman-core/src/channels/bus.rs b/crates/openhuman-core/src/channels/bus.rsindex d9b3067c89..16d72e36a9 100644--- a/crates/openhuman-core/src/channels/bus.rs+++ b/crates/openhuman-core/src/channels/bus.rs@@ -17,4 +17,3 @@ mod inbound_thread_id_tests;#[cfg(test)]#[path = "bus_tests.rs"]mod tests;-diff --git a/crates/openhuman-core/src/channels/context.rs b/crates/openhuman-core/src/channels/context.rsindex 2636a2170c..3f358abc55 100644--- a/crates/openhuman-core/src/channels/context.rs+++ b/crates/openhuman-core/src/channels/context.rs@@ -16,7 +16,6 @@ pub(crate) use tinychannels_bus::{DEFAULT_CHANNEL_MAX_BACKOFF_SECS, MAX_CHANNEL_HISTORY,};-pub(crate) type TurnModelSourceCacheMap = Arc<Mutex<HashMap<String, TurnModelSource>>>;pub(crate) type RouteSelectionMap = Arc<Mutex<HashMap<String, ChannelRouteSelection>>>;diff --git a/crates/openhuman-core/src/channels/host/channel_events_tests.rs b/crates/openhuman-core/src/channels/host/channel_events_tests.rsindex 01ac239308..54a875b583 100644--- a/crates/openhuman-core/src/channels/host/channel_events_tests.rs+++ b/crates/openhuman-core/src/channels/host/channel_events_tests.rs@@ -1,20 +1,19 @@//! Tests for the channel approval-surface and turn-state subscribers.use super::*;+use crate::channels::runtime::{ChannelHandle, TestChannel};use std::path::Path;#[cfg(feature = "e2e-test-support")]use tempfile::tempdir;-use crate::channels::runtime::{ChannelHandle, TestChannel};fn recording(name: &str) -> (Arc<ChannelHandle>, Arc<TestChannel>) {let channel = Arc::new(TestChannel::new(name));- (- Arc::new(ChannelHandle::Test(Arc::clone(&channel))),- channel,- )+ (Arc::new(ChannelHandle::Test(Arc::clone(&channel))), channel)}-fn approval_subscriber(channels: &[(&str, Arc<ChannelHandle>)]) -> ChannelApprovalSurfaceSubscriber {+fn approval_subscriber(+ channels: &[(&str, Arc<ChannelHandle>)],+) -> ChannelApprovalSurfaceSubscriber {let map: HashMap<String, Arc<ChannelHandle>> = channels.iter().map(|(name, channel)| ((*name).to_owned(), Arc::clone(channel)))diff --git a/crates/openhuman-core/src/channels/proactive_tests.rs b/crates/openhuman-core/src/channels/proactive_tests.rsindex f002473012..53199fd7d2 100644--- a/crates/openhuman-core/src/channels/proactive_tests.rs+++ b/crates/openhuman-core/src/channels/proactive_tests.rs@@ -6,10 +6,7 @@ fn channel(name: &str, target: Option<&str>) -> (Arc<ChannelHandle>, Arc<TestChalet mut channel = TestChannel::new(name);channel.proactive_target = target.map(str::to_owned);let channel = Arc::new(channel);- (- Arc::new(ChannelHandle::Test(Arc::clone(&channel))),- channel,- )+ (Arc::new(ChannelHandle::Test(Arc::clone(&channel))), channel)}fn proactive_event() -> DomainEvent {diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/helpers_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/helpers_tests.rsindex aa878202d2..078dcd024d 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/helpers_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/helpers_tests.rs@@ -32,7 +32,9 @@ async fn canceled_waiter_closes_handle_returned_by_in_flight_typing_start() {Ok(())})}));- let channel = Arc::new(crate::channels::runtime::ChannelHandle::Test(Arc::new(test_channel)));+ let channel = Arc::new(crate::channels::runtime::ChannelHandle::Test(Arc::new(+ test_channel,+ )));let cancellation = tokio_util::sync::CancellationToken::new();let waiter = spawn_typing_task(&DispatchCtx::unbound(),@@ -82,7 +84,9 @@ async fn typing_task_runs_under_the_handed_context_not_the_active_one() {Ok(None)})}));- let channel = Arc::new(crate::channels::runtime::ChannelHandle::Test(Arc::new(test_channel)));+ let channel = Arc::new(crate::channels::runtime::ChannelHandle::Test(Arc::new(+ test_channel,+ )));let cancellation = tokio_util::sync::CancellationToken::new();// The caller's own scope is Ravi's; the typing task was handed Asha's.let (waiter_tx, waiter_rx) = oneshot::channel();diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rsindex 2a721e4b97..53fbd06f76 100644--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/dispatch_tests.rs@@ -145,7 +145,13 @@ async fn an_unbound_channel_still_runs_the_orchestrator() {assert_eq!(calls.load(Ordering::SeqCst), 1);assert_eq!(- channel.sent.lock().unwrap().iter().map(|message| message.content.clone()).collect::<Vec<_>>(),+ channel+ .sent+ .lock()+ .unwrap()+ .iter()+ .map(|message| message.content.clone())+ .collect::<Vec<_>>(),vec!["orchestrator answered".to_string()]);}@@ -341,7 +347,13 @@ async fn bound_channel_runs_its_host_agent() {};assert_eq!(- channel.sent.lock().unwrap().iter().map(|message| message.content.clone()).collect::<Vec<_>>(),+ channel+ .sent+ .lock()+ .unwrap()+ .iter()+ .map(|message| message.content.clone())+ .collect::<Vec<_>>(),vec!["teeny says hi".to_string()],"the host agent's reply goes back to the chat");diff --git a/crates/openhuman-core/src/channels/runtime/startup.rs b/crates/openhuman-core/src/channels/runtime/startup.rsindex 04d6536986..b00b2d0491 100644--- a/crates/openhuman-core/src/channels/runtime/startup.rs+++ b/crates/openhuman-core/src/channels/runtime/startup.rs@@ -41,16 +41,15 @@ pub(crate) struct TestChannel {dyn Fn(String,u64,- ) -> futures::future::BoxFuture<'static, anyhow::Result<Option<String>>>+ )+ -> futures::future::BoxFuture<'static, anyhow::Result<Option<String>>>+ Send+ Sync,>,>,pub(crate) end_typing_refresh: Option<std::sync::Arc<- dyn Fn(String) -> futures::future::BoxFuture<'static, anyhow::Result<()>>- + Send- + Sync,+ dyn Fn(String) -> futures::future::BoxFuture<'static, anyhow::Result<()>> + Send + Sync,>,>,}@@ -136,7 +135,9 @@ impl ChannelHandle {#[cfg(test)]Self::Test(channel) => {let _ = recipient;- channel.start_typing_calls.fetch_add(1, std::sync::atomic::Ordering::SeqCst);+ channel+ .start_typing_calls+ .fetch_add(1, std::sync::atomic::Ordering::SeqCst);Ok(())}}@@ -155,7 +156,9 @@ impl ChannelHandle {#[cfg(test)]Self::Test(channel) => {let _ = recipient;- channel.stop_typing_calls.fetch_add(1, std::sync::atomic::Ordering::SeqCst);+ channel+ .stop_typing_calls+ .fetch_add(1, std::sync::atomic::Ordering::SeqCst);Ok(())}}@@ -214,11 +217,15 @@ impl TestChannel {}async fn send(&self, message: &tinychannels_bus::SendMessage) -> anyhow::Result<()> {- self.send_count.fetch_add(1, std::sync::atomic::Ordering::SeqCst);+ self.send_count+ .fetch_add(1, std::sync::atomic::Ordering::SeqCst);if let Some(error) = &self.send_error {anyhow::bail!(error.clone());}- self.sent.lock().expect("test send lock").push(message.clone());+ self.sent+ .lock()+ .expect("test send lock")+ .push(message.clone());self.sent_messages.lock().awaitdiff --git a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rsindex de4fd60c9b..b42e184c08 100644--- a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs+++ b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs@@ -76,7 +76,6 @@ impl RecordingChannel {}),})}-}#[async_trait::async_trait]@@ -187,11 +186,15 @@ async fn native_progressive_transport_dispatches_typed_content_through_configurelet channels: HashMap<String, Arc<super::ChannelHandle>> = HashMap::from([(other_account.name().to_owned(),- Arc::new(super::ChannelHandle::test(super::TestChannel::new(other_account.name()))),+ Arc::new(super::ChannelHandle::test(super::TestChannel::new(+ other_account.name(),+ ))),),(selected_account.name().to_owned(),- Arc::new(super::ChannelHandle::test(super::TestChannel::new(selected_account.name()))),+ Arc::new(super::ChannelHandle::test(super::TestChannel::new(+ selected_account.name(),+ ))),),]);let progressive_channels: HashMap<String, Arc<dyn ProgressiveChannelTransport>> =@@ -304,11 +307,15 @@ async fn native_progressive_transport_rejects_unconfigured_account_without_provilet channels: HashMap<String, Arc<super::ChannelHandle>> = HashMap::from([("telegram:bot-a".into(),- Arc::new(super::ChannelHandle::test(super::TestChannel::new(first_account.name()))),+ Arc::new(super::ChannelHandle::test(super::TestChannel::new(+ first_account.name(),+ ))),),("telegram:bot-b".into(),- Arc::new(super::ChannelHandle::test(super::TestChannel::new(second_account.name()))),+ Arc::new(super::ChannelHandle::test(super::TestChannel::new(+ second_account.name(),+ ))),),]);let progressive_channels: HashMap<String, Arc<dyn ProgressiveChannelTransport>> =@@ -364,7 +371,12 @@ async fn native_progressive_output_event_is_acknowledged_by_optional_host_observlet observer = Arc::new(RecordingOutputObserver::default());let adapter = Arc::new(RecordingChannel::new("telegram:bot-b"));let (callback, _context) = callback_for_channels(- HashMap::from([("telegram:bot-b".into(), Arc::new(super::ChannelHandle::test(super::TestChannel::new("telegram:bot-b"))))]),+ HashMap::from([(+ "telegram:bot-b".into(),+ Arc::new(super::ChannelHandle::test(super::TestChannel::new(+ "telegram:bot-b",+ ))),+ )]),HashMap::from([("telegram:bot-b".into(),adapter.clone() as Arc<dyn ProgressiveChannelTransport>,@@ -440,7 +452,12 @@ fn output_event_request(async fn native_progressive_output_event_validates_scope_without_observer() {let adapter = Arc::new(RecordingChannel::new("telegram:bot-b"));let (callback, _context) = callback_for_channels(- HashMap::from([("telegram:bot-b".into(), Arc::new(super::ChannelHandle::test(super::TestChannel::new("telegram:bot-b"))))]),+ HashMap::from([(+ "telegram:bot-b".into(),+ Arc::new(super::ChannelHandle::test(super::TestChannel::new(+ "telegram:bot-b",+ ))),+ )]),HashMap::from([("telegram:bot-b".into(),adapter.clone() as Arc<dyn ProgressiveChannelTransport>,@@ -478,7 +495,12 @@ async fn native_progressive_output_event_validates_scope_before_observer() {let observer = Arc::new(RecordingOutputObserver::default());let adapter = Arc::new(RecordingChannel::new("telegram:bot-b"));let (callback, _) = callback_for_channels(- HashMap::from([("telegram:bot-b".into(), Arc::new(super::ChannelHandle::test(super::TestChannel::new("telegram:bot-b"))))]),+ HashMap::from([(+ "telegram:bot-b".into(),+ Arc::new(super::ChannelHandle::test(super::TestChannel::new(+ "telegram:bot-b",+ ))),+ )]),HashMap::from([("telegram:bot-b".into(),adapter as Arc<dyn ProgressiveChannelTransport>,@@ -503,7 +525,12 @@ async fn native_progressive_callbacks_stop_after_channel_session_cancellation()let observer = Arc::new(RecordingOutputObserver::default());let adapter = Arc::new(RecordingChannel::new("telegram:bot-b"));let (callback, _context) = callback_for_channels(- HashMap::from([("telegram:bot-b".into(), Arc::new(super::ChannelHandle::test(super::TestChannel::new("telegram:bot-b"))))]),+ HashMap::from([(+ "telegram:bot-b".into(),+ Arc::new(super::ChannelHandle::test(super::TestChannel::new(+ "telegram:bot-b",+ ))),+ )]),HashMap::from([("telegram:bot-b".into(),adapter as Arc<dyn ProgressiveChannelTransport>,@@ -527,7 +554,12 @@ async fn native_progressive_callbacks_stop_after_channel_session_cancellation()async fn native_progressive_callbacks_fail_closed_after_transport_owner_drops() {let adapter = Arc::new(RecordingChannel::new("telegram:bot-b"));let (callback, context) = callback_for_channels(- HashMap::from([("telegram:bot-b".into(), Arc::new(super::ChannelHandle::test(super::TestChannel::new("telegram:bot-b"))))]),+ HashMap::from([(+ "telegram:bot-b".into(),+ Arc::new(super::ChannelHandle::test(super::TestChannel::new(+ "telegram:bot-b",+ ))),+ )]),HashMap::from([("telegram:bot-b".into(),adapter.clone() as Arc<dyn ProgressiveChannelTransport>,diff --git a/crates/openhuman-core/src/channels/runtime/test_support.rs b/crates/openhuman-core/src/channels/runtime/test_support.rsindex 0c9848e595..1a70db46d7 100644--- a/crates/openhuman-core/src/channels/runtime/test_support.rs+++ b/crates/openhuman-core/src/channels/runtime/test_support.rs@@ -369,7 +369,9 @@ pub async fn run_dispatch_harness(options: DispatchHarnessOptions) -> DispatchHalet mut channels_by_name = HashMap::new();channels_by_name.insert(options.channel_name.clone(),- Arc::new(crate::channels::runtime::ChannelHandle::Test(Arc::clone(&state))),+ Arc::new(crate::channels::runtime::ChannelHandle::Test(Arc::clone(+ &state,+ ))),);let model: Arc<dyn ChatModel<()>> = Arc::new(HarnessModel);diff --git a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rsindex 4bc9aa1cda..db36f83250 100644--- a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs+++ b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs@@ -5,8 +5,9 @@ use super::super::runtime::test_support::{use super::super::runtime::{process_channel_message, run_message_dispatch_loop, RuntimeChannelMessage,};-use super::common::{HistoryCaptureModel, use_real_agent_handler, RecordingChannel, SlowModel};+use super::common::{use_real_agent_handler, HistoryCaptureModel, RecordingChannel, SlowModel};use crate::agent::bus::{mock_agent_run_turn, AgentTurnRequest, AgentTurnResponse};+use crate::channels::runtime::ChannelHandle;use crate::core::events::DomainEvent;use crate::inference::provider;use std::collections::HashMap;@@ -14,7 +15,6 @@ use std::sync::atomic::{AtomicUsize, Ordering};use std::sync::{Arc, Mutex};use std::time::Duration;use tinychannels_bus as traits;-use crate::channels::runtime::ChannelHandle;use tokio::sync::Barrier;#[tokio::test]@@ -54,7 +54,10 @@ async fn host_pipeline_sends_reaction_marker_with_inbound_thread_target() {assert_eq!(observation.sends.len(), 1, "one reaction is sent");assert_eq!(observation.sends[0].content, "[REACTION:👍]");- assert_eq!(observation.sends[0].thread_ts.as_deref(), Some("message-42"));+ assert_eq!(+ observation.sends[0].thread_ts.as_deref(),+ Some("message-42")+ );}#[tokio::test]@@ -255,9 +258,15 @@ async fn discord_host_pipeline_keeps_thread_histories_separate() {let calls = model_state.calls.lock().unwrap();assert_eq!(calls.len(), 2);- assert!(calls[0].iter().any(|(_, text)| text == "first thread message"));- assert!(calls[1].iter().any(|(_, text)| text == "second thread message"));- assert!(!calls[1].iter().any(|(_, text)| text == "first thread message"));+ assert!(calls[0]+ .iter()+ .any(|(_, text)| text == "first thread message"));+ assert!(calls[1]+ .iter()+ .any(|(_, text)| text == "second thread message"));+ assert!(!calls[1]+ .iter()+ .any(|(_, text)| text == "first thread message"));drop(calls);assert_eq!(channel_state.sent_messages.lock().await.len(), 2);}@@ -336,9 +345,15 @@ async fn discord_host_pipeline_keeps_thread_histories_separate() {let histories = observed_histories.lock().unwrap();assert_eq!(histories.len(), 2);- assert!(histories[0].iter().any(|text| text == "first thread message"));- assert!(histories[1].iter().any(|text| text == "second thread message"));- assert!(!histories[1].iter().any(|text| text == "first thread message"));+ assert!(histories[0]+ .iter()+ .any(|text| text == "first thread message"));+ assert!(histories[1]+ .iter()+ .any(|text| text == "second thread message"));+ assert!(!histories[1]+ .iter()+ .any(|text| text == "first thread message"));}#[tokio::test]diff --git a/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs b/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rsindex 6577ee7428..86653ce2ab 100644--- a/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs+++ b/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs@@ -4,16 +4,15 @@ use super::super::context::{};use super::super::runtime::process_channel_message;use super::common::{- IterativeToolModel, MockPriceTool, ModelCaptureModel, RecordingChannel,- ToolCallingModel,+ IterativeToolModel, MockPriceTool, ModelCaptureModel, RecordingChannel, ToolCallingModel,};+use crate::channels::runtime::ChannelHandle;use crate::channels::runtime::TestChannel;use crate::inference::provider;use std::collections::HashMap;use std::sync::atomic::Ordering;use std::sync::{Arc, Mutex};use tinychannels_bus as traits;-use crate::channels::runtime::ChannelHandle;use tinyinference_llm::model::ChatModel;#[tokio::test]diff --git a/crates/openhuman-core/src/cron/bus.rs b/crates/openhuman-core/src/cron/bus.rsindex 77f22fe31d..33fea9a559 100644--- a/crates/openhuman-core/src/cron/bus.rs+++ b/crates/openhuman-core/src/cron/bus.rs@@ -5,13 +5,13 @@//! of directly constructing channel instances. The [`CronDeliverySubscriber`]//! picks up those events and dispatches to the appropriate channel, keeping//! channel construction out of the scheduler.+use crate::channels::runtime::ChannelHandle;use crate::core::events::DomainEvent;use async_trait::async_trait;use std::collections::HashMap;use std::sync::Arc;use tinybus::EventHandler;use tinychannels_bus::SendMessage;-use crate::channels::runtime::ChannelHandle;/// Subscribes to `CronDeliveryRequested` events and dispatches/// the output to the named channel.