Skip to content

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

test(channels): add module client fixture for channel tests

Steven Enamakel57b9a25b828b
diff --git a/crates/openhuman-core/src/channels/context.rs b/crates/openhuman-core/src/channels/context.rs
index 1e4c83b8ee..9821ec0f4f 100644
--- a/crates/openhuman-core/src/channels/context.rs
+++ b/crates/openhuman-core/src/channels/context.rs
@@ -59,6 +59,15 @@ pub(crate) struct ChannelRuntimeContext {
pub(crate) config: Option<Arc<crate::config::Config>>,
}
+/// Resolve the configured module client; unit tests use an attested bus fixture.
+pub(crate) async fn module_client(ctx: &ChannelRuntimeContext) -> crate::modules::client::ModuleClient {
+ #[cfg(test)]
+ if ctx.config.is_none() {
+ return super::module_fixture::client().await;
+ }
+ crate::modules::client::ModuleClient::new(ctx.config.as_deref().cloned().unwrap_or_default())
+}
+
pub(crate) fn conversation_history_key(msg: &super::traits::ChannelMessage) -> String {
tinychannels::context::conversation_history_key(msg)
}
diff --git a/crates/openhuman-core/src/channels/mod.rs b/crates/openhuman-core/src/channels/mod.rs
index 9a35434541..8344daf543 100644
--- a/crates/openhuman-core/src/channels/mod.rs
+++ b/crates/openhuman-core/src/channels/mod.rs
@@ -121,3 +121,7 @@ pub use crate::agent::context::channels_prompt::build_system_prompt;
pub use runtime::start_channels;
#[cfg(feature = "channels")]
pub(crate) use runtime::{session, start_channels_with_session};
+
+#[cfg(all(test, feature = "channels", feature = "modules"))]
+#[path = "module_fixture_tests.rs"]
+pub(crate) mod module_fixture;
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
index 9de2ee4f1b..d5fe028815 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
@@ -51,7 +51,6 @@ pub(crate) async fn process_channel_runtime_message(
let prepared = match prepared_inbound {
Some(prepared) => prepared,
None => {
- let config = ctx.config.as_deref().cloned().unwrap_or_default();
let source = if message.channel.is_empty() {
let Some(envelope) = inbound_envelope else {
return;
@@ -67,7 +66,7 @@ pub(crate) async fn process_channel_runtime_message(
}
};
match crate::modules::channel_controller::prepare_inbound(
- &crate::modules::client::ModuleClient::new(config),
+ &crate::channels::context::module_client(&ctx).await,
PrepareChannelInboundRequest {
source,
namespace: "main".into(),
diff --git a/crates/openhuman-core/src/threads/store/bus.rs b/crates/openhuman-core/src/threads/store/bus.rs
index e13b39b888..f02a11583c 100644
--- a/crates/openhuman-core/src/threads/store/bus.rs
+++ b/crates/openhuman-core/src/threads/store/bus.rs
@@ -351,11 +351,16 @@ async fn persist_channel_turn(
workspace_dir: &Path,
descriptor: ChannelTurnDescriptor<'_>,
) -> Result<(), String> {
- let config = crate::config::rpc::load_config_with_timeout().await?;
- if config.workspace_dir != workspace_dir {
- return Err("channel workspace changed".into());
- }
- let client = crate::modules::client::ModuleClient::new(config);
+ #[cfg(test)]
+ let client = crate::channels::module_fixture::client().await;
+ #[cfg(not(test))]
+ let client = {
+ let config = crate::config::rpc::load_config_with_timeout().await?;
+ if config.workspace_dir != workspace_dir {
+ return Err("channel workspace changed".into());
+ }
+ crate::modules::client::ModuleClient::new(config)
+ };
let prepared: tinychannels_bus::module_inbound::PreparedChannelInbound = client
.call_confidential(
"tinychannels",