Skip to content

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

test(channels): exercise typing cancellation through linked telegram runtime

Steven Enamakel52185c8a0717
diff --git a/crates/openhuman-core/src/channels/runtime/mod.rs b/crates/openhuman-core/src/channels/runtime/mod.rs
index 4b94a797aa..842d2381bb 100644
--- a/crates/openhuman-core/src/channels/runtime/mod.rs
+++ b/crates/openhuman-core/src/channels/runtime/mod.rs
@@ -9,6 +9,8 @@ pub(crate) use startup::prepare_runtime_limits;
pub use startup::start_channels;
pub(crate) use startup::start_channels_with_session;
pub(crate) use startup::ChannelHandle;
+#[cfg(test)]
+pub(crate) use startup::{prepare_module_runtime_for_test, ModuleRuntimeTestGuard};
// The hosted-channel relay (`channels::providers::relay`) runs one message
// through the same pipeline, with a context built from the caller's config.
#[cfg(test)]
diff --git a/crates/openhuman-core/src/channels/runtime/test_support.rs b/crates/openhuman-core/src/channels/runtime/test_support.rs
index db4ed00a1f..ab1b23edc8 100644
--- a/crates/openhuman-core/src/channels/runtime/test_support.rs
+++ b/crates/openhuman-core/src/channels/runtime/test_support.rs
@@ -143,7 +143,7 @@ pub(crate) struct LinkedTelegramRuntime {
_storage: crate::channels::module_fixture_tests::MemoryStorageGuard,
_workspace: tempfile::TempDir,
server: MockServer,
- runtime: crate::channels::runtime::startup::ModuleRuntimeTestGuard,
+ runtime: crate::channels::runtime::ModuleRuntimeTestGuard,
}
impl LinkedTelegramRuntime {
@@ -165,8 +165,7 @@ impl LinkedTelegramRuntime {
}
/// Prepare an actual linked TinyChannels module with mocked Telegram HTTP.
-pub(crate) async fn linked_telegram_runtime(
-) -> LinkedTelegramRuntime {
+pub(crate) async fn linked_telegram_runtime() -> LinkedTelegramRuntime {
let server = MockServer::start().await;
Mock::given(method("POST"))
.respond_with(ResponseTemplate::new(200).set_body_json(serde_json::json!({
@@ -178,8 +177,8 @@ pub(crate) async fn linked_telegram_runtime(
let env = crate::config::test_env::EnvVarGuard::locked_async()
.await
.with("OPENHUMAN_TELEGRAM_BOT_API_BASE", server.uri());
- let storage = crate::channels::module_fixture_tests::install_memory_storage();
- crate::channels::module_fixture_tests::client().await;
+ let storage = crate::channels::module_fixture::install_memory_storage();
+ crate::channels::module_fixture::client().await;
let workspace = tempfile::tempdir().expect("temporary module workspace");
let mut config = crate::config::Config::default();
@@ -197,12 +196,10 @@ pub(crate) async fn linked_telegram_runtime(
mention_only: false,
});
let (dispatch, _receiver) = tokio::sync::mpsc::channel(4);
- let runtime = crate::channels::runtime::startup::prepare_module_runtime_for_test(
- Arc::new(config),
- dispatch,
- )
- .await
- .expect("linked TinyChannels runtime should prepare");
+ let runtime =
+ crate::channels::runtime::prepare_module_runtime_for_test(Arc::new(config), dispatch)
+ .await
+ .expect("linked TinyChannels runtime should prepare");
LinkedTelegramRuntime {
_env: env,
diff --git a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
index 60724b91f5..7a3b55b319 100644
--- a/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
+++ b/crates/openhuman-core/src/channels/tests/runtime_dispatch.rs
@@ -1,5 +1,7 @@
use super::super::context::{ChannelRuntimeContext, CHANNEL_MESSAGE_TIMEOUT_SECS};
-use super::super::runtime::test_support::{run_dispatch_harness, DispatchHarnessOptions};
+use super::super::runtime::test_support::{
+ linked_telegram_runtime, run_dispatch_harness, DispatchHarnessOptions,
+};
use super::super::runtime::{
process_channel_message, run_message_dispatch_loop, RuntimeChannelMessage,
};
@@ -190,11 +192,15 @@ async fn message_dispatch_processes_messages_in_parallel() {
#[tokio::test]
async fn process_channel_message_cancels_scoped_typing_task() {
let _bus_guard = use_real_agent_handler().await;
- let channel_impl = Arc::new(RecordingChannel::default());
- let channel: Arc<dyn Channel> = channel_impl.clone();
+ let linked = linked_telegram_runtime().await;
+ let channel = linked
+ .channels()
+ .get("telegram")
+ .expect("linked TinyChannels fixture should expose Telegram")
+ .clone();
let mut channels_by_name = HashMap::new();
- channels_by_name.insert(channel.name().to_string(), channel);
+ channels_by_name.insert("test-channel".to_string(), channel);
let runtime_ctx = Arc::new(ChannelRuntimeContext {
relay_thread: None,
@@ -242,10 +248,23 @@ async fn process_channel_message_cancels_scoped_typing_task() {
)
.await;
- let starts = channel_impl.start_typing_calls.load(Ordering::SeqCst);
- let stops = channel_impl.stop_typing_calls.load(Ordering::SeqCst);
- assert_eq!(starts, 1, "start_typing should be called once");
- assert_eq!(stops, 1, "stop_typing should be called once");
+ let requests = linked.provider_request_paths().await;
+ assert_eq!(
+ requests
+ .iter()
+ .filter(|path| path.ends_with("/sendChatAction"))
+ .count(),
+ 2,
+ "the module-backed provider should receive one typing start and stop"
+ );
+ assert_eq!(
+ requests
+ .iter()
+ .filter(|path| path.ends_with("/sendMessage"))
+ .count(),
+ 1,
+ "the module-backed provider should receive the completed reply"
+ );
}
/// Integration test that proves channel dispatch actually routes through