Skip to content

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

refactor(channels): update channel context and tests

Steven Enamakel29b1e3ec746b
diff --git a/crates/openhuman-core/src/channels/bus.rs b/crates/openhuman-core/src/channels/bus.rs
index 16d72e36a9..5f729a827a 100644
--- a/crates/openhuman-core/src/channels/bus.rs
+++ b/crates/openhuman-core/src/channels/bus.rs
@@ -10,9 +10,6 @@ mod subscriber;
pub(crate) use delivery::NativeProgressiveReply;
pub use subscriber::ChannelInboundSubscriber;
-#[cfg(test)]
-#[path = "bus_inbound_thread_id_tests_tests.rs"]
-mod inbound_thread_id_tests;
#[cfg(test)]
#[path = "bus_tests.rs"]
diff --git a/crates/openhuman-core/src/channels/context.rs b/crates/openhuman-core/src/channels/context.rs
index 3f358abc55..ee93f1b9d5 100644
--- a/crates/openhuman-core/src/channels/context.rs
+++ b/crates/openhuman-core/src/channels/context.rs
@@ -13,9 +13,34 @@ use tinytools::Tool;
pub(crate) use tinychannels_bus::context::ChannelRouteSelection;
pub(crate) use tinychannels_bus::{
CHANNEL_TYPING_REFRESH_INTERVAL_SECS, DEFAULT_CHANNEL_INITIAL_BACKOFF_SECS,
- DEFAULT_CHANNEL_MAX_BACKOFF_SECS, MAX_CHANNEL_HISTORY,
+ DEFAULT_CHANNEL_MAX_BACKOFF_SECS, MAX_CHANNEL_HISTORY, CHANNEL_MESSAGE_TIMEOUT_SECS,
+ MIN_CHANNEL_MESSAGE_TIMEOUT_SECS,
};
+#[cfg(test)]
+pub(crate) fn effective_channel_message_timeout_secs(configured: u64) -> u64 {
+ configured.max(MIN_CHANNEL_MESSAGE_TIMEOUT_SECS)
+}
+
+// Compatibility projection for tests that exercise route-state consumers with
+// legacy message fixtures. Runtime turns consume TinyChannels' prepared
+// `history_key` directly; provider identity derivation stays in TinyChannels.
+#[cfg(test)]
+pub(crate) fn conversation_history_key(msg: &tinychannels_bus::ChannelMessage) -> String {
+ let mut key = [msg.channel.as_str(), msg.sender.as_str(), msg.reply_target.as_str()]
+ .iter()
+ .map(|part| part.replace('%', "%25").replace('_', "%5F"))
+ .collect::<Vec<_>>()
+ .join("_");
+ if !crate::channels::capabilities::capabilities_for(&msg.channel).history_key_ignores_thread {
+ if let Some(thread) = msg.thread_ts.as_deref() {
+ key.push_str("_thread:");
+ key.push_str(&thread.replace('%', "%25").replace('_', "%5F"));
+ }
+ }
+ key
+}
+
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/runtime/startup/callback_tests.rs b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
index ead17d3ecf..0a6a5aa908 100644
--- a/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup/callback_tests.rs
@@ -3,6 +3,7 @@ use super::{ProgressiveChannelTransport, ProgressiveOutputObserver};
use crate::channels::context::ChannelRuntimeContext;
use crate::channels::runtime::dispatch::RuntimeChannelMessage;
+use crate::channels::runtime::{ChannelHandle, TestChannel};
use std::collections::HashMap;
use std::sync::{Arc, Mutex, OnceLock, Weak};
use tinychannels_bus::channel::{
@@ -182,9 +183,9 @@ fn callback_for_channels(
#[tokio::test]
async fn voice_media_projection_accepts_only_durable_refs_for_the_configured_account() {
let channel = Arc::new(RecordingChannel::new("telegram:bot-a"));
- let channels: HashMap<String, Arc<dyn Channel>> = HashMap::from([(
- channel.name().to_owned(),
- channel.clone() as Arc<dyn Channel>,
+ let channels: HashMap<String, Arc<ChannelHandle>> = HashMap::from([(
+ channel.name.clone(),
+ Arc::new(ChannelHandle::test(TestChannel::new(channel.name.clone()))),
)]);
let (callback, _context) = callback_for_channels(channels, HashMap::new(), None);
let request = || tinychannels_bus::HostStoreVoiceMediaRequest {