Skip to content

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

refactor(channels): route test helpers through tinychannels

Steven Enamakel5edd6dc5c371
diff --git a/crates/openhuman-core/src/channels/bus.rs b/crates/openhuman-core/src/channels/bus.rs
index 1230987c24..429d696440 100644
--- a/crates/openhuman-core/src/channels/bus.rs
+++ b/crates/openhuman-core/src/channels/bus.rs
@@ -22,6 +22,6 @@ mod inbound_thread_id_tests;
#[path = "bus_tests.rs"]
mod tests;
-#[cfg(any(test, debug_assertions))]
+#[cfg(test)]
#[path = "bus_test_support_tests.rs"]
pub mod test_support;
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/mod_test_support_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/mod_test_support_tests.rs
index 14671d1bc7..f410efe876 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/mod_test_support_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/mod_test_support_tests.rs
@@ -6,6 +6,7 @@ pub fn build_channel_context_block_for_test(msg: &traits::ChannelMessage) -> Str
build_channel_context_block(msg)
}
+#[cfg(test)]
pub fn select_acknowledgment_reaction_for_test(content: &str) -> &'static str {
select_acknowledgment_reaction(content)
}
diff --git a/crates/openhuman-core/src/channels/runtime/test_support.rs b/crates/openhuman-core/src/channels/runtime/test_support.rs
index be2248058c..ee577adbb4 100644
--- a/crates/openhuman-core/src/channels/runtime/test_support.rs
+++ b/crates/openhuman-core/src/channels/runtime/test_support.rs
@@ -1,8 +1,6 @@
//! Debug-build harnesses for raw integration coverage of the channel runtime.
-pub use super::dispatch::test_support::{
- build_channel_context_block_for_test, select_acknowledgment_reaction_for_test,
-};
+pub use super::dispatch::test_support::build_channel_context_block_for_test;
use super::dispatch::{
process_channel_message, process_channel_runtime_message, RuntimeChannelMessage,
};
@@ -33,7 +31,7 @@ pub struct DispatchHarnessOptions {
pub channel_name: String,
pub content: String,
pub thread_ts: Option<String>,
- pub inbound_envelope: Option<tinychannels::ChannelInboundEnvelope>,
+ pub inbound_envelope: Option<tinychannels_bus::ChannelInboundEnvelope>,
pub streaming: bool,
pub supports_reactions: bool,
pub response_text: Option<String>,
@@ -131,7 +129,7 @@ pub struct DispatchHarnessObservation {
pub sends: Vec<ObservedSend>,
pub start_typing_calls: usize,
pub stop_typing_calls: usize,
- pub received_event_envelope: Option<tinychannels::ChannelInboundEnvelope>,
+ pub received_event_envelope: Option<tinychannels_bus::ChannelInboundEnvelope>,
pub handler_history_roles: Vec<String>,
pub handler_history_text: String,
pub handler_provider_name: String,
diff --git a/tests/raw_coverage/channels_round24_raw_coverage_e2e.rs b/tests/raw_coverage/channels_round24_raw_coverage_e2e.rs
index a9a0b501e7..343cf2574a 100644
--- a/tests/raw_coverage/channels_round24_raw_coverage_e2e.rs
+++ b/tests/raw_coverage/channels_round24_raw_coverage_e2e.rs
@@ -2,11 +2,13 @@
//!
//! Parser/state seams only: no real network traffic.
-use openhuman_core::channels::bus::test_support as bus_support;
-use openhuman_core::channels::providers::email_channel::test_support as email_support;
use openhuman_core::channels::test_support as runtime_support;
use openhuman_core::channels::traits::ChannelMessage;
use serde_json::json;
+use tinychannels::delivery::progressive::{
+ extract_message_id, latest_thinking_snippet, StreamingState,
+};
+use tinychannels::providers::email_channel::test_support as email_support;
fn channel_message(channel: &str, reply_target: &str, content: &str) -> ChannelMessage {
ChannelMessage {
@@ -24,34 +26,45 @@ fn channel_message(channel: &str, reply_target: &str, content: &str) -> ChannelM
#[test]
fn bus_state_helpers_cover_message_ids_drafts_snippets_and_thread_keys() {
assert_eq!(
- bus_support::extract_message_id_for_test(&json!({"id": "abc"})).as_deref(),
+ extract_message_id(&json!({"id": "abc"})).as_deref(),
Some("abc")
);
assert_eq!(
- bus_support::extract_message_id_for_test(&json!({"messageId": 42})).as_deref(),
+ extract_message_id(&json!({"messageId": 42})).as_deref(),
Some("42")
);
assert_eq!(
- bus_support::extract_message_id_for_test(&json!({"data": {"messageId": 99_u64}}))
- .as_deref(),
+ extract_message_id(&json!({"data": {"messageId": 99_u64}})).as_deref(),
Some("99")
);
- assert!(bus_support::extract_message_id_for_test(&json!({"ok": true})).is_none());
+ assert!(extract_message_id(&json!({"ok": true})).is_none());
- assert_eq!(bus_support::compose_draft_for_test(""), "_working…_");
+ assert_eq!(StreamingState::default().compose_draft(), "_working…_");
assert_eq!(
- bus_support::compose_draft_for_test("answer with trailing space "),
+ StreamingState {
+ content: "answer with trailing space ".into(),
+ ..Default::default()
+ }
+ .compose_draft(),
"answer with trailing space"
);
- assert!(bus_support::latest_thinking_snippet_for_test(" ").is_none());
+ assert!(latest_thinking_snippet(&StreamingState {
+ thinking_accumulator: " ".into(),
+ ..Default::default()
+ })
+ .is_none());
let long_thinking = format!("prefix {}", "alpha ".repeat(80));
- let snippet = bus_support::latest_thinking_snippet_for_test(&long_thinking).expect("snippet");
+ let snippet = latest_thinking_snippet(&StreamingState {
+ thinking_accumulator: long_thinking,
+ ..Default::default()
+ })
+ .expect("snippet");
assert!(snippet.len() <= 200);
assert!(snippet.starts_with("alpha"));
assert_eq!(
- bus_support::derive_inbound_thread_id_for_test(
+ tinychannels::channel::derive_inbound_thread_id(
"slack:T1",
Some(" U1 "),
Some(" C1 "),
@@ -60,7 +73,7 @@ fn bus_state_helpers_cover_message_ids_drafts_snippets_and_thread_keys() {
"channel:slack:T1/U1/C1#thread:1700.1"
);
assert_eq!(
- bus_support::derive_inbound_thread_id_for_test(
+ tinychannels::channel::derive_inbound_thread_id(
"telegram:123",
Some("U1"),
Some("123"),
@@ -87,15 +100,15 @@ fn dispatch_helpers_cover_channel_context_and_ack_categories() {
let no_target = channel_message("slack", "", "hello");
assert!(runtime_support::build_channel_context_block_for_test(&no_target).is_empty());
- let gratitude = runtime_support::select_acknowledgment_reaction_for_test("thank you");
+ let gratitude = tinychannels::runtime::select_acknowledgment_reaction("thank you");
assert!(["❤️", "🙏"].contains(&gratitude));
- let finance = runtime_support::select_acknowledgment_reaction_for_test("btc market?");
+ let finance = tinychannels::runtime::select_acknowledgment_reaction("btc market?");
assert!(["💯", "⚡"].contains(&finance));
- let code = runtime_support::select_acknowledgment_reaction_for_test("debug this rust api");
+ let code = tinychannels::runtime::select_acknowledgment_reaction("debug this rust api");
assert!(["👨‍💻", "🤓"].contains(&code));
- let greeting = runtime_support::select_acknowledgment_reaction_for_test("hello there");
+ let greeting = tinychannels::runtime::select_acknowledgment_reaction("hello there");
assert!(["🤗", "😁"].contains(&greeting));
- let question = runtime_support::select_acknowledgment_reaction_for_test("what happened?");
+ let question = tinychannels::runtime::select_acknowledgment_reaction("what happened?");
assert!(["🤔", "✍️"].contains(&question));
}