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 runtime types

Steven Enamakel5adb995858d6
diff --git a/crates/openhuman-core/src/channels/context.rs b/crates/openhuman-core/src/channels/context.rs
index 8967e0473b..7770d11888 100644
--- a/crates/openhuman-core/src/channels/context.rs
+++ b/crates/openhuman-core/src/channels/context.rs
@@ -11,12 +11,12 @@ use std::sync::{Arc, Mutex};
use tinytools::Tool;
pub(crate) use tinychannels_bus::context::ChannelRouteSelection;
+#[cfg(test)]
+pub(crate) use tinychannels_bus::{CHANNEL_MESSAGE_TIMEOUT_SECS, MIN_CHANNEL_MESSAGE_TIMEOUT_SECS};
pub(crate) use tinychannels_bus::{
CHANNEL_TYPING_REFRESH_INTERVAL_SECS, DEFAULT_CHANNEL_INITIAL_BACKOFF_SECS,
DEFAULT_CHANNEL_MAX_BACKOFF_SECS, MAX_CHANNEL_HISTORY,
};
-#[cfg(test)]
-pub(crate) use tinychannels_bus::{CHANNEL_MESSAGE_TIMEOUT_SECS, MIN_CHANNEL_MESSAGE_TIMEOUT_SECS};
// Compatibility projection for tests that exercise route-state consumers with
// legacy message fixtures. Runtime turns consume TinyChannels' prepared
diff --git a/crates/openhuman-core/src/channels/context_tests.rs b/crates/openhuman-core/src/channels/context_tests.rs
index 9e5d60d489..b5b05cf700 100644
--- a/crates/openhuman-core/src/channels/context_tests.rs
+++ b/crates/openhuman-core/src/channels/context_tests.rs
@@ -72,7 +72,7 @@ fn channel_message(channel: &str) -> traits::ChannelMessage {
#[test]
fn timeout_and_history_keys_respect_channel_rules() {
- assert!(CHANNEL_MESSAGE_TIMEOUT_SECS >= MIN_CHANNEL_MESSAGE_TIMEOUT_SECS);
+ const { assert!(CHANNEL_MESSAGE_TIMEOUT_SECS >= MIN_CHANNEL_MESSAGE_TIMEOUT_SECS) };
let telegram = channel_message("telegram");
let discord = channel_message("discord");
diff --git a/crates/openhuman-core/src/channels/providers/relay/params_tests.rs b/crates/openhuman-core/src/channels/providers/relay/params_tests.rs
index 3fddc3bed5..348dbcffe0 100644
--- a/crates/openhuman-core/src/channels/providers/relay/params_tests.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/params_tests.rs
@@ -27,7 +27,7 @@ fn the_thread_id_is_a_reserved_channel_id() {
// reserved ID. A user cannot choose it through `threads_upsert`.
let id = "channel:telegram/42/-100123";
assert!(
- crate::profiles::surface::validate_user_thread_id(&id).is_err(),
+ crate::profiles::surface::validate_user_thread_id(id).is_err(),
"a user cannot choose it"
);
}
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs b/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs
index 37b0888810..43862f6b3a 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/mod.rs
@@ -20,12 +20,12 @@ pub(crate) use processor::progressive::{
delivery_succeeded, hosted_relay_target, NativeProgressiveTarget,
};
+#[cfg(test)]
+pub(crate) use processor::process_channel_message;
pub(crate) use processor::{
process_channel_runtime_message, reset_durable_channel_session, run_message_dispatch_loop,
RuntimeChannelMessage,
};
-#[cfg(test)]
-pub(crate) use processor::process_channel_message;
// `channel_has_approval_surface` stays pub(crate) on processor; re-export so
// the inline test module can reach it via `super::channel_has_approval_surface`.
diff --git a/crates/openhuman-core/src/channels/runtime/startup.rs b/crates/openhuman-core/src/channels/runtime/startup.rs
index aec3c53d5d..8bcb63cc75 100644
--- a/crates/openhuman-core/src/channels/runtime/startup.rs
+++ b/crates/openhuman-core/src/channels/runtime/startup.rs
@@ -13,6 +13,20 @@ mod turn_parts;
use anyhow::Result;
use tinybus::module::{ModuleCallError, ModuleClient};
+#[cfg(test)]
+type BeginTypingRefresh = std::sync::Arc<
+ dyn Fn(
+ String,
+ u64,
+ ) -> futures::future::BoxFuture<'static, anyhow::Result<Option<String>>>
+ + Send
+ + Sync,
+>;
+#[cfg(test)]
+type EndTypingRefresh = std::sync::Arc<
+ dyn Fn(String) -> futures::future::BoxFuture<'static, anyhow::Result<()>> + Send + Sync,
+>;
+
/// Host-owned handle to a configured channel instance. Production operations
/// are dispatched through the loaded TinyChannels module's bus object.
#[derive(Clone)]
@@ -36,22 +50,8 @@ pub(crate) struct TestChannel {
pub(crate) start_typing_calls: std::sync::Arc<std::sync::atomic::AtomicUsize>,
pub(crate) stop_typing_calls: std::sync::Arc<std::sync::atomic::AtomicUsize>,
pub(crate) send_error: Option<String>,
- pub(crate) begin_typing_refresh: Option<
- std::sync::Arc<
- dyn Fn(
- String,
- u64,
- )
- -> 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,
- >,
- >,
+ pub(crate) begin_typing_refresh: Option<BeginTypingRefresh>,
+ pub(crate) end_typing_refresh: Option<EndTypingRefresh>,
}
impl ChannelHandle {
diff --git a/crates/openhuman-core/src/channels/tests/host_pipeline.rs b/crates/openhuman-core/src/channels/tests/host_pipeline.rs
index ca892936e4..00aced0e4e 100644
--- a/crates/openhuman-core/src/channels/tests/host_pipeline.rs
+++ b/crates/openhuman-core/src/channels/tests/host_pipeline.rs
@@ -196,17 +196,18 @@ async fn discord_host_pipeline_keeps_thread_histories_separate() {
process_channel_message(Arc::clone(&runtime_ctx), first).await;
process_channel_message(runtime_ctx, second).await;
- 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"));
- drop(calls);
+ {
+ 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_eq!(channel_state.sent_messages.lock().await.len(), 2);
}