Skip to content

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

test(channels): update test harnesses for linked runtime commands

Steven Enamakel3d1f265582eb
diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rs
index 71f0cf9724..298b69d687 100644
--- a/crates/openhuman-core/src/channels/routes_tests.rs
+++ b/crates/openhuman-core/src/channels/routes_tests.rs
@@ -68,6 +68,50 @@ pub(super) fn runtime_context(workspace_dir: PathBuf) -> ChannelRuntimeContext {
}
}
+async fn handle_linked_runtime_command(
+ ctx: &mut ChannelRuntimeContext,
+ msg: &ChannelMessage,
+ target_channel: Option<&Arc<ChannelHandle>>,
+ linked: &crate::channels::runtime::test_support::LinkedTelegramRuntime,
+) -> bool {
+ use tinychannels_bus::module_inbound::{ChannelInboundSource, PrepareChannelInboundRequest};
+ use tinychannels_bus::module_remote::RemoteSessionScope;
+
+ ctx.channels_by_name = linked.channels();
+ let _core = crate::channels::runtime::test_support::bind_test_core_context(ctx);
+ let prepared = crate::modules::channel_controller::prepare_inbound(
+ &crate::channels::context::module_client(ctx).await,
+ PrepareChannelInboundRequest {
+ source: ChannelInboundSource::Legacy {
+ message: msg.clone(),
+ envelope: None,
+ },
+ 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,
+ msg,
+ target_channel,
+ &prepared.history_key,
+ Some(scope),
+ Some(session_key),
+ &prepared.message,
+ || async { Ok(()) },
+ )
+ .await
+}
+
#[cfg(feature = "modules")]
async fn module_route_help_response(
workspace_dir: &Path,
@@ -412,8 +456,8 @@ async fn failed_history_reset_does_not_apply_requested_route() {
#[tokio::test]
async fn handle_runtime_command_telegram_status_replies_without_agent() {
- let _linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
- let ctx = runtime_context(PathBuf::from("/tmp"));
+ let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
+ let mut ctx = runtime_context(PathBuf::from("/tmp"));
let channel_state = Arc::new(TestChannel::new("recording"));
let channel = Arc::new(ChannelHandle::Test(Arc::clone(&channel_state)));
let msg = ChannelMessage {
@@ -429,13 +473,7 @@ async fn handle_runtime_command_telegram_status_replies_without_agent() {
sender_name: None,
};
- let handled = handle_runtime_command_if_needed(
- &ctx,
- &msg,
- Some(&channel),
- &conversation_history_key(&msg),
- )
- .await;
+ let handled = handle_linked_runtime_command(&mut ctx, &msg, Some(&channel), &linked).await;
assert!(handled);
let sent = channel_state.sent.lock().unwrap();
@@ -450,8 +488,8 @@ async fn handle_runtime_command_telegram_status_replies_without_agent() {
#[tokio::test]
async fn handle_runtime_command_without_target_channel_still_consumes_command() {
- let _linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
- let ctx = runtime_context(PathBuf::from("/tmp"));
+ let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
+ let mut ctx = runtime_context(PathBuf::from("/tmp"));
let msg = ChannelMessage {
reply_to_id: None,
topic_id: None,
@@ -465,15 +503,14 @@ async fn handle_runtime_command_without_target_channel_still_consumes_command()
sender_name: None,
};
- let handled =
- handle_runtime_command_if_needed(&ctx, &msg, None, &conversation_history_key(&msg)).await;
+ let handled = handle_linked_runtime_command(&mut ctx, &msg, None, &linked).await;
assert!(handled);
}
#[tokio::test]
async fn handle_runtime_command_telegram_help_replies_with_remote_command_list() {
- let _linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
- let ctx = runtime_context(PathBuf::from("/tmp"));
+ let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
+ let mut ctx = runtime_context(PathBuf::from("/tmp"));
let channel_state = Arc::new(TestChannel::new("recording"));
let channel = Arc::new(ChannelHandle::Test(Arc::clone(&channel_state)));
let msg = ChannelMessage {
@@ -489,13 +526,7 @@ async fn handle_runtime_command_telegram_help_replies_with_remote_command_list()
sender_name: None,
};
- let handled = handle_runtime_command_if_needed(
- &ctx,
- &msg,
- Some(&channel),
- &conversation_history_key(&msg),
- )
- .await;
+ let handled = handle_linked_runtime_command(&mut ctx, &msg, Some(&channel), &linked).await;
assert!(handled);
let sent = channel_state.sent.lock().unwrap();
@@ -511,9 +542,9 @@ async fn handle_runtime_command_telegram_help_replies_with_remote_command_list()
#[tokio::test]
async fn handle_runtime_command_telegram_sessions_reports_empty_store() {
- let _linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
+ let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
let tempdir = tempfile::tempdir().unwrap();
- let ctx = runtime_context(tempdir.path().to_path_buf());
+ let mut ctx = runtime_context(tempdir.path().to_path_buf());
let channel_state = Arc::new(TestChannel::new("recording"));
let channel = Arc::new(ChannelHandle::Test(Arc::clone(&channel_state)));
let msg = ChannelMessage {
@@ -529,13 +560,7 @@ async fn handle_runtime_command_telegram_sessions_reports_empty_store() {
sender_name: None,
};
- let handled = handle_runtime_command_if_needed(
- &ctx,
- &msg,
- Some(&channel),
- &conversation_history_key(&msg),
- )
- .await;
+ let handled = handle_linked_runtime_command(&mut ctx, &msg, Some(&channel), &linked).await;
assert!(handled);
let sent = channel_state.sent.lock().unwrap();
@@ -548,9 +573,9 @@ async fn handle_runtime_command_telegram_sessions_reports_empty_store() {
#[tokio::test]
async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
- let _linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
+ let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
let tempdir = tempfile::tempdir().unwrap();
- let ctx = runtime_context(tempdir.path().to_path_buf());
+ let mut ctx = runtime_context(tempdir.path().to_path_buf());
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";
@@ -567,15 +592,7 @@ async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
thread_ts: Some("42".into()),
sender_name: None,
};
- assert!(
- handle_runtime_command_if_needed(
- &ctx,
- &new_msg,
- Some(&channel),
- &conversation_history_key(&new_msg)
- )
- .await
- );
+ assert!(handle_linked_runtime_command(&mut ctx, &new_msg, Some(&channel), &linked).await);
set_route_selection(
&ctx,
sender_key,
@@ -611,15 +628,7 @@ async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
thread_ts: Some("42".into()),
sender_name: None,
};
- assert!(
- handle_runtime_command_if_needed(
- &ctx,
- &status_msg,
- Some(&channel),
- &conversation_history_key(&status_msg)
- )
- .await
- );
+ assert!(handle_linked_runtime_command(&mut ctx, &status_msg, Some(&channel), &linked).await);
let sessions_msg = ChannelMessage {
reply_to_id: None,
@@ -633,15 +642,7 @@ async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
thread_ts: Some("42".into()),
sender_name: None,
};
- assert!(
- handle_runtime_command_if_needed(
- &ctx,
- &sessions_msg,
- Some(&channel),
- &conversation_history_key(&sessions_msg)
- )
- .await
- );
+ assert!(handle_linked_runtime_command(&mut ctx, &sessions_msg, Some(&channel), &linked).await);
let sent = channel_state.sent.lock().unwrap();
assert_eq!(sent.len(), 3);
@@ -666,9 +667,9 @@ async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {
#[tokio::test]
async fn handle_runtime_command_telegram_new_uses_module_storage() {
- let _linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
+ let linked = crate::channels::runtime::test_support::linked_telegram_runtime().await;
let tempdir = tempfile::tempdir().unwrap();
- let ctx = runtime_context(tempdir.path().to_path_buf());
+ let mut ctx = runtime_context(tempdir.path().to_path_buf());
let channel_state = Arc::new(TestChannel::new("recording"));
let channel = Arc::new(ChannelHandle::Test(Arc::clone(&channel_state)));
let msg = ChannelMessage {
@@ -683,15 +684,7 @@ async fn handle_runtime_command_telegram_new_uses_module_storage() {
thread_ts: Some("42".into()),
sender_name: None,
};
- assert!(
- handle_runtime_command_if_needed(
- &ctx,
- &msg,
- Some(&channel),
- &conversation_history_key(&msg)
- )
- .await
- );
+ assert!(handle_linked_runtime_command(&mut ctx, &msg, Some(&channel), &linked).await);
let sent = channel_state.sent.lock().unwrap();
assert_eq!(sent.len(), 1);
assert!(sent[0].content.contains("Started new session"));
diff --git a/crates/openhuman-core/src/channels/runtime/test_support.rs b/crates/openhuman-core/src/channels/runtime/test_support.rs
index 7b1582265a..6438d8bf02 100644
--- a/crates/openhuman-core/src/channels/runtime/test_support.rs
+++ b/crates/openhuman-core/src/channels/runtime/test_support.rs
@@ -161,6 +161,22 @@ impl LinkedTelegramRuntime {
/// Prepare an actual linked TinyChannels module with mocked Telegram HTTP.
pub(crate) async fn linked_telegram_runtime() -> LinkedTelegramRuntime {
let server = MockServer::start().await;
+ Mock::given(method("POST"))
+ .and(path("/bottoken/getUpdates"))
+ .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
+ "ok": true,
+ "result": []
+ })))
+ .mount(&server)
+ .await;
+ Mock::given(method("POST"))
+ .and(path("/bottoken/deleteWebhook"))
+ .respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
+ "ok": true,
+ "result": true
+ })))
+ .mount(&server)
+ .await;
Mock::given(method("POST"))
.and(path("/bottoken/sendChatAction"))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
@@ -204,10 +220,16 @@ pub(crate) async fn linked_telegram_runtime() -> LinkedTelegramRuntime {
mention_only: false,
});
let (dispatch, _receiver) = tokio::sync::mpsc::channel(4);
- let runtime =
- crate::channels::runtime::prepare_module_runtime_for_test(Arc::new(config), dispatch)
- .await
- .expect("linked TinyChannels runtime should prepare");
+ let mut runtime = crate::channels::runtime::prepare_module_runtime_for_test(
+ Arc::new(config.clone()),
+ dispatch,
+ )
+ .await
+ .expect("linked TinyChannels runtime should prepare");
+ runtime
+ .start(&config)
+ .await
+ .expect("mock Telegram provider should start without network access");
LinkedTelegramRuntime {
_env: env,
@@ -218,6 +240,26 @@ pub(crate) async fn linked_telegram_runtime() -> LinkedTelegramRuntime {
}
}
+/// Bind a test runtime context to a real core context so module callbacks that
+/// clear durable channel history exercise the host reset path.
+pub(crate) fn bind_test_core_context(
+ context: &mut crate::channels::context::ChannelRuntimeContext,
+) -> Arc<crate::core::runtime::CoreContext> {
+ use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};
+
+ let workspace = context.workspace_dir.as_ref().clone();
+ let mut config = crate::config::Config::default();
+ config.workspace_dir = workspace.clone();
+ config.action_dir = workspace.clone();
+ config.config_path = workspace.join("config.toml");
+ let core = CoreContext::for_test(DomainSet::none(), Some(workspace)).derive_with(
+ ContextOverlay::new(config, DomainSet::full(), Default::default())
+ .profile("channel-handle-test"),
+ );
+ context.core = Some(Arc::downgrade(&core));
+ core
+}
+
#[derive(Debug, Clone)]
pub struct HarnessModelCall {
pub roles: Vec<String>,
diff --git a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
index f0780217bb..38f100b29c 100644
--- a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
+++ b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
@@ -670,7 +670,7 @@ async fn process_channel_message_hardens_against_relative_path_markers() {
assert!(!observed.allow_remote_fetch);
}
-#[tokio::test(start_paused = true)]
+#[tokio::test]
async fn dispatch_replies_with_timeout_notice_when_handler_exceeds_deadline() {
let timed_out = run_dispatch_harness(DispatchHarnessOptions {
channel_name: "test-channel".to_string(),
diff --git a/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs b/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs
index b6af6b138f..e1fbeb23f5 100644
--- a/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs
+++ b/crates/openhuman-core/src/channels/tests/runtime_tool_calls.rs
@@ -104,7 +104,7 @@ async fn process_channel_message_handles_models_command_without_llm_call() {
crate::agent::tinyagents::TurnModelSource::from_model(fallback_provider),
);
- let runtime_ctx = Arc::new(ChannelRuntimeContext {
+ let mut runtime_ctx = ChannelRuntimeContext {
relay_thread: None,
channels_by_name: Arc::new(channels_by_name),
module_objects: Arc::new(HashMap::new()),
@@ -129,7 +129,9 @@ async fn process_channel_message_handles_models_command_without_llm_call() {
multimodal_files: crate::config::MultimodalFileConfig::default(),
config: None,
core: None,
- });
+ };
+ let _core = crate::channels::runtime::test_support::bind_test_core_context(&mut runtime_ctx);
+ let runtime_ctx = Arc::new(runtime_ctx);
let cmd_msg = traits::ChannelMessage {
reply_to_id: None,