Skip to content

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

test(channels): cover callback slot reactions and threads

Steven Enamakel0e7cf0c0af80
diff --git a/crates/openhuman-core/src/channels/callback_slot_tests.rs b/crates/openhuman-core/src/channels/callback_slot_tests.rs
index 9925a5cd23..67570c5d95 100644
--- a/crates/openhuman-core/src/channels/callback_slot_tests.rs
+++ b/crates/openhuman-core/src/channels/callback_slot_tests.rs
@@ -88,3 +88,58 @@ async fn the_callback_is_told_the_config_it_serves() {
Some("https://callback.example")
);
}
+
+#[tokio::test]
+async fn reactions_and_threads_without_a_callback_answer_the_unavailable_sentinel() {
+ let backend = OpenHumanChannelBackend::new(Config::default());
+ let channels = crate::config::ChannelsConfig::default();
+ let sentinel = crate::core::observability::BACKEND_UNAVAILABLE_PREFIX;
+ let reaction = backend
+ .send_reaction(&channels, "telegram", serde_json::json!({"emoji": "+1"}))
+ .await
+ .err()
+ .expect("no callback");
+ assert!(reaction.to_string().starts_with(sentinel), "{reaction}");
+ let listed = backend
+ .list_threads(&channels, "telegram", None)
+ .await
+ .err()
+ .expect("no callback");
+ assert!(listed.to_string().starts_with(sentinel), "{listed}");
+}
+
+#[tokio::test]
+async fn a_registered_callback_serves_thread_requests_with_the_channel_it_is_told() {
+ use tinychannels_bus::controllers::ChannelThreadResult;
+ let seen = Arc::new(std::sync::Mutex::new(None));
+ let sink = Arc::clone(&seen);
+ register_channel_callback("threads", move |ctx, request| {
+ *sink.lock().unwrap() = Some((
+ ctx.channel.clone(),
+ matches!(request, ChannelBackendRequest::CreateThread { .. }),
+ ));
+ Box::pin(async {
+ Ok(ChannelBackendResult::Thread(ChannelThreadResult {
+ raw: Some(serde_json::json!({"id": "t1"})),
+ ..Default::default()
+ }))
+ })
+ });
+ let backend = OpenHumanChannelBackend::new(Config::default());
+ let created = backend
+ .create_thread(
+ &crate::config::ChannelsConfig::default(),
+ "telegram",
+ "topic",
+ )
+ .await;
+ unregister_channel_callback("threads");
+ assert_eq!(
+ created.expect("served").raw,
+ Some(serde_json::json!({"id": "t1"}))
+ );
+ assert_eq!(
+ seen.lock().unwrap().clone(),
+ Some((Some("telegram".to_string()), true))
+ );
+}
diff --git a/crates/openhuman-core/src/channels/controllers/backend.rs b/crates/openhuman-core/src/channels/controllers/backend.rs
index e883cadf82..fef919d25b 100644
--- a/crates/openhuman-core/src/channels/controllers/backend.rs
+++ b/crates/openhuman-core/src/channels/controllers/backend.rs
@@ -200,7 +200,10 @@ impl OpenHumanChannelBackend {
request: tinychannels_bus::ChannelBackendRequest,
) -> anyhow::Result<tinychannels_bus::ChannelBackendResult> {
let Some(callback) = crate::channels::callback_slot::current() else {
- tracing::debug!(channel, "[channels][backend] no channel callback registered");
+ tracing::debug!(
+ channel,
+ "[channels][backend] no channel callback registered"
+ );
anyhow::bail!(
"{} no channel transport registered",
crate::core::observability::BACKEND_UNAVAILABLE_PREFIX