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(channels): scope core context around linked runtime command tests
Steven Enamakele1a6cdfd7deb
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rsindex 0ecf5e6515..025cdc59b2 100644--- a/crates/openhuman-core/src/channels/routes_tests.rs+++ b/crates/openhuman-core/src/channels/routes_tests.rs@@ -121,71 +121,73 @@ async fn handle_linked_runtime_command(ctx.channels_by_name = linked.channels();ctx.module_objects = linked.module_objects();- let _core =- crate::channels::runtime::test_support::bind_test_core_context(ctx, linked.config());- let account_id = linked- .channels()- .keys()- .find(|name| tinychannels_bus::provider_id(name) == msg.channel)- .cloned()- .expect("linked runtime should expose the configured provider instance");- let prepared = crate::modules::channel_controller::prepare_inbound(- &crate::channels::context::module_client(ctx).await,- PrepareChannelInboundRequest {- source: ChannelInboundSource::Envelope {- envelope: tinychannels_bus::ChannelInboundEnvelope {- channel: tinychannels_bus::ChannelRef {- id: msg.channel.clone(),- account_id: Some(account_id),- },- message_id: msg.id.clone(),- reply_to_id: msg.reply_to_id.clone(),- conversation: tinychannels_bus::ConversationRef {- id: canonical_conversation_id- .unwrap_or(&msg.reply_target)- .to_owned(),- thread_id: msg.thread_ts.clone(),- topic_id: msg.topic_id.clone(),- ..Default::default()- },- sender: tinychannels_bus::SenderRef {- id: msg.sender.clone(),- name: msg.sender_name.clone(),+ let core = crate::channels::runtime::test_support::bind_test_core_context(ctx, linked.config());+ crate::core::runtime::CoreContext::scope(core, async {+ let account_id = linked+ .channels()+ .keys()+ .find(|name| tinychannels_bus::provider_id(name) == msg.channel)+ .cloned()+ .expect("linked runtime should expose the configured provider instance");+ let prepared = crate::modules::channel_controller::prepare_inbound(+ &crate::channels::context::module_client(ctx).await,+ PrepareChannelInboundRequest {+ source: ChannelInboundSource::Envelope {+ envelope: tinychannels_bus::ChannelInboundEnvelope {+ channel: tinychannels_bus::ChannelRef {+ id: msg.channel.clone(),+ account_id: Some(account_id),+ },+ message_id: msg.id.clone(),+ reply_to_id: msg.reply_to_id.clone(),+ conversation: tinychannels_bus::ConversationRef {+ id: canonical_conversation_id+ .unwrap_or(&msg.reply_target)+ .to_owned(),+ thread_id: msg.thread_ts.clone(),+ topic_id: msg.topic_id.clone(),+ ..Default::default()+ },+ sender: tinychannels_bus::SenderRef {+ id: msg.sender.clone(),+ name: msg.sender_name.clone(),+ ..Default::default()+ },+ timestamp_unix_ms: Some(msg.timestamp.saturating_mul(1000)),+ text: msg.content.clone(),+ parts: vec![tinychannels_bus::ContentPart::Text {+ text: msg.content.clone(),+ markdown_dialect: None,+ }],..Default::default()},- timestamp_unix_ms: Some(msg.timestamp.saturating_mul(1000)),- text: msg.content.clone(),- parts: vec![tinychannels_bus::ContentPart::Text {- text: msg.content.clone(),- markdown_dialect: None,- }],- ..Default::default()+ timestamp: msg.timestamp,},- timestamp: msg.timestamp,+ namespace: "main".into(),+ session_policy: Default::default(),+ preparation_mode: Default::default(),},- namespace: "main".into(),- session_policy: Default::default(),- preparation_mode: Default::default(),- },- )- .await- .expect("linked TinyChannels should prepare the command's trusted scope");- let session_key = prepared.session_key.clone();- let scope = RemoteSessionScope {- channel: prepared.envelope.channel,- conversation: prepared.envelope.conversation,- session_key: session_key.clone(),- };- handle_runtime_command_with_reset(- ctx,- &prepared.message,- target_channel,- &prepared.history_key,- Some(scope),- Some(session_key),- &prepared.message,- || async { Ok(()) },- )+ )+ .await+ .expect("linked TinyChannels should prepare the command's trusted scope");+ let session_key = prepared.session_key.clone();+ let scope = RemoteSessionScope {+ channel: prepared.envelope.channel,+ conversation: prepared.envelope.conversation,+ session_key: session_key.clone(),+ };+ handle_runtime_command_with_reset(+ ctx,+ &prepared.message,+ target_channel,+ &prepared.history_key,+ Some(scope),+ Some(session_key),+ &prepared.message,+ || async { Ok(()) },+ )+ .await+ }).await}diff --git a/crates/openhuman-core/src/channels/routes_tests_telegram.rs b/crates/openhuman-core/src/channels/routes_tests_telegram.rsindex 52a676ed93..139bb60dd9 100644--- a/crates/openhuman-core/src/channels/routes_tests_telegram.rs+++ b/crates/openhuman-core/src/channels/routes_tests_telegram.rs@@ -5,38 +5,36 @@ async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;let workspace = linked.config().workspace_dir.clone();let mut ctx = runtime_context(workspace.clone());- let core =- crate::channels::runtime::test_support::bind_test_core_context(&mut ctx, linked.config());- crate::core::runtime::CoreContext::scope(core, async {- let channel_state = Arc::new(TestChannel::new("recording"));- let channel = Arc::new(ChannelHandle::Test(Arc::clone(&channel_state)));- let sender_key = "telegram_alice_chat-remote";+ let channel_state = Arc::new(TestChannel::new("recording"));+ let channel = Arc::new(ChannelHandle::Test(Arc::clone(&channel_state)));+ let sender_key = "telegram_alice_chat-remote";- let new_msg = ChannelMessage {- reply_to_id: None,- id: "1".into(),- sender: "alice".into(),- reply_target: "chat-remote".into(),- content: "/new".into(),- channel: "telegram".into(),- timestamp: 0,- thread_ts: None,- topic_id: Some("42".into()),- sender_name: None,- };- assert!(- handle_linked_runtime_command(&mut ctx, &new_msg, Some(&channel), &linked, None).await- );- set_route_selection(- &ctx,- sender_key,- ChannelRouteSelection {- provider: "anthropic".into(),- model: "claude-3".into(),- },- );+ let new_msg = ChannelMessage {+ reply_to_id: None,+ id: "1".into(),+ sender: "alice".into(),+ reply_target: "chat-remote".into(),+ content: "/new".into(),+ channel: "telegram".into(),+ timestamp: 0,+ thread_ts: None,+ topic_id: Some("42".into()),+ sender_name: None,+ };+ assert!(handle_linked_runtime_command(&mut ctx, &new_msg, Some(&channel), &linked, None).await);+ set_route_selection(+ &ctx,+ sender_key,+ ChannelRouteSelection {+ provider: "anthropic".into(),+ model: "claude-3".into(),+ },+ );- let subscriber = ChannelTurnStateSubscriber::new(workspace.clone());+ let subscriber = ChannelTurnStateSubscriber::new(workspace.clone());+ let event_core =+ crate::channels::runtime::test_support::bind_test_core_context(&mut ctx, linked.config());+ crate::core::runtime::CoreContext::scope(event_core, async {subscriber.handle(&DomainEvent::ChannelMessageReceived {channel: "telegram".into(),@@ -49,66 +47,64 @@ async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {workspace_dir: workspace.clone(),}).await;+ })+ .await;- let status_msg = ChannelMessage {- reply_to_id: None,- id: "3".into(),- sender: "alice".into(),- reply_target: "chat-remote".into(),- content: "/status".into(),- channel: "telegram".into(),- timestamp: 0,- thread_ts: None,- topic_id: Some("42".into()),- sender_name: None,- };- assert!(- handle_linked_runtime_command(&mut ctx, &status_msg, Some(&channel), &linked, None)- .await- );+ let status_msg = ChannelMessage {+ reply_to_id: None,+ id: "3".into(),+ sender: "alice".into(),+ reply_target: "chat-remote".into(),+ content: "/status".into(),+ channel: "telegram".into(),+ timestamp: 0,+ thread_ts: None,+ topic_id: Some("42".into()),+ sender_name: None,+ };+ assert!(+ handle_linked_runtime_command(&mut ctx, &status_msg, Some(&channel), &linked, None).await+ );- let sessions_msg = ChannelMessage {- reply_to_id: None,- id: "4".into(),- sender: "alice".into(),- reply_target: "chat-remote".into(),- content: "/sessions".into(),- channel: "telegram".into(),- timestamp: 0,- thread_ts: None,- topic_id: Some("42".into()),- sender_name: None,- };- assert!(- handle_linked_runtime_command(&mut ctx, &sessions_msg, Some(&channel), &linked, None)- .await- );+ let sessions_msg = ChannelMessage {+ reply_to_id: None,+ id: "4".into(),+ sender: "alice".into(),+ reply_target: "chat-remote".into(),+ content: "/sessions".into(),+ channel: "telegram".into(),+ timestamp: 0,+ thread_ts: None,+ topic_id: Some("42".into()),+ sender_name: None,+ };+ assert!(+ handle_linked_runtime_command(&mut ctx, &sessions_msg, Some(&channel), &linked, None).await+ );- let sent = channel_state.sent.lock().unwrap();- assert_eq!(sent.len(), 3);- assert!(sent[0].content.contains("Started new session"));- assert!(sent[0]- .content- .contains("Durable conversation history reset for this chat."));+ let sent = channel_state.sent.lock().unwrap();+ assert_eq!(sent.len(), 3);+ assert!(sent[0].content.contains("Started new session"));+ assert!(sent[0]+ .content+ .contains("Durable conversation history reset for this chat."));- assert!(sent[1].content.contains("**Status**"));- assert!(sent[1].content.contains("Thread: `Telegram"));- assert!(sent[1].content.contains("Provider: `anthropic`"));- assert!(sent[1].content.contains("Model: `claude-3`"));- assert!(sent[1].content.contains("Session turns: 0"));- assert!(- sent[1].content.contains("Turn: in progress"),- "status should observe the received-event state in its host scope: {}",- sent[1].content- );+ assert!(sent[1].content.contains("**Status**"));+ assert!(sent[1].content.contains("Thread: `Telegram"));+ assert!(sent[1].content.contains("Provider: `anthropic`"));+ assert!(sent[1].content.contains("Model: `claude-3`"));+ assert!(sent[1].content.contains("Session turns: 0"));+ assert!(+ sent[1].content.contains("Turn: in progress"),+ "status should observe the received-event state in its host scope: {}",+ sent[1].content+ );- assert!(sent[2].content.contains("**Recent sessions**"));- assert!(sent[2].content.contains("→ `Telegram"));- assert!(sent- .iter()- .all(|message| message.topic_id.as_deref() == Some("42")));- })- .await;+ assert!(sent[2].content.contains("**Recent sessions**"));+ assert!(sent[2].content.contains("→ `Telegram"));+ assert!(sent+ .iter()+ .all(|message| message.topic_id.as_deref() == Some("42")));}#[tokio::test]