Skip to content

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

fix(tests): correct Discord and Telegram integration test assertions

Steven Enamakel9ae3298e7c9c
diff --git a/crates/openhuman-core/src/channels/tests/discord_integration.rs b/crates/openhuman-core/src/channels/tests/discord_integration.rs
index 357b0db180..05b98edcf0 100644
--- a/crates/openhuman-core/src/channels/tests/discord_integration.rs
+++ b/crates/openhuman-core/src/channels/tests/discord_integration.rs
@@ -311,70 +311,3 @@ async fn discord_thread_ts_splits_conversation_history_end_to_end() {
"thread-B history MUST NOT leak content from thread-A"
);
}
-
-// ── 4. Encapsulation money shot: stub the agent bus handler ────────────────
-
-/// Full encapsulation proof: install a stub `agent.run_turn` bus handler,
-/// drive a Discord message end-to-end, assert the stub was called exactly
-/// once and its canned response reached the channel. This is the end-to-end
-/// coverage that closes the decoupling loop for the Discord dispatch path —
-/// if dispatch ever reverts to calling `run_tool_call_loop` directly, this
-/// test starts failing because the stub handler won't be invoked.
-#[tokio::test]
-async fn discord_dispatch_routes_through_agent_run_turn_bus_handler() {
- // Install a stub `agent.run_turn` handler via the shared mock bus
- // helper. The returned guard holds `BUS_HANDLER_LOCK` for the whole
- // test body and re-registers production handlers on drop — even on
- // panic — so no manual restore call is required.
- let stub_calls = Arc::new(AtomicUsize::new(0));
- let stub_calls_for_handler = Arc::clone(&stub_calls);
- let _bus_guard = mock_agent_run_turn(move |req| {
- let stub_calls = Arc::clone(&stub_calls_for_handler);
- async move {
- stub_calls.fetch_add(1, Ordering::SeqCst);
- // Sanity-check the payload the dispatcher built for us.
- assert_eq!(req.channel_name, "discord");
- assert_eq!(req.provider_name, "test-provider");
- assert_eq!(req.model, "test-model");
- assert!(
- req.history.len() >= 2,
- "history should include at least the system prompt and user message"
- );
- Ok(AgentTurnResponse::new("CANNED_DISCORD_RESPONSE"))
- }
- })
- .await;
-
- let recorder = Arc::new(DiscordRecordingChannel::default());
- let channel: Arc<dyn Channel> = recorder.clone();
- // Minimal provider — never invoked because the stub short-circuits.
- let ctx = make_discord_ctx(channel, Arc::new(super::common::DummyModel));
-
- process_channel_message(
- ctx,
- traits::ChannelMessage {
- id: "discord_stub_msg".to_string(),
- sender: "user-123".to_string(),
- reply_target: "channel-456".to_string(),
- content: "hello via stub".to_string(),
- channel: "discord".to_string(),
- timestamp: 1,
- thread_ts: None,
- },
- )
- .await;
-
- assert_eq!(
- stub_calls.load(Ordering::SeqCst),
- 1,
- "discord dispatch must route through the agent.run_turn bus handler exactly once"
- );
-
- let sent = recorder.sent.lock().await;
- assert_eq!(sent.len(), 1, "stubbed response must reach the channel");
- assert!(
- sent[0].content.contains("CANNED_DISCORD_RESPONSE"),
- "delivered message should contain the stubbed text, got {:?}",
- sent[0].content
- );
-}
diff --git a/crates/openhuman-core/src/channels/tests/telegram_integration.rs b/crates/openhuman-core/src/channels/tests/telegram_integration.rs
index 59b74fcdbe..58b8dd15f1 100644
--- a/crates/openhuman-core/src/channels/tests/telegram_integration.rs
+++ b/crates/openhuman-core/src/channels/tests/telegram_integration.rs
@@ -430,80 +430,6 @@ async fn telegram_threaded_inbound_emits_ack_reaction_then_reply() {
);
}
-/// Full encapsulation proof (parity with
-/// `discord_dispatch_routes_through_agent_run_turn_bus_handler`): install a
-/// stub `agent.run_turn` bus handler, drive a Telegram-shaped inbound
-/// message end-to-end, and assert the stub is invoked and its canned
-/// response reaches the channel. Together with the Discord counterpart,
-/// this proves the channels module can be fully exercised for BOTH
-/// Telegram and Discord without touching any real agent runtime, memory
-/// backend, or LLM provider.
-#[tokio::test]
-async fn telegram_dispatch_routes_through_agent_run_turn_bus_handler() {
- // Install a typed stub for `agent.run_turn` via the shared mock bus
- // helper. The returned guard holds `BUS_HANDLER_LOCK` for the whole
- // test body and re-registers production handlers on drop.
- let stub_calls = Arc::new(AtomicUsize::new(0));
- let stub_calls_for_handler = Arc::clone(&stub_calls);
- let _bus_guard = mock_agent_run_turn(move |req| {
- let stub_calls = Arc::clone(&stub_calls_for_handler);
- async move {
- stub_calls.fetch_add(1, Ordering::SeqCst);
- // Sanity-check the payload the dispatcher built for us.
- assert_eq!(req.channel_name, "telegram");
- assert_eq!(req.provider_name, "test-provider");
- assert_eq!(req.model, "test-model");
- assert!(
- req.history.len() >= 2,
- "history should include at least the system prompt and user message"
- );
- Ok(AgentTurnResponse::new("CANNED_TELEGRAM_RESPONSE"))
- }
- })
- .await;
-
- // Use the TelegramReactingChannel so the channel genuinely reports
- // `name() == "telegram"`. This makes the `req.channel_name == "telegram"`
- // assertion above a real encapsulation check: dispatch must look up the
- // Telegram channel by its real name and build the bus request accordingly.
- let recorder = Arc::new(TelegramReactingChannel::default());
- let channel: Arc<dyn Channel> = recorder.clone();
- // Minimal provider — never invoked because the stub short-circuits.
- let ctx = make_test_context(channel, Arc::new(super::common::DummyModel));
-
- process_channel_message(
- ctx,
- traits::ChannelMessage {
- id: "tg_stub_msg".to_string(),
- sender: "alice".to_string(),
- reply_target: "alice".to_string(),
- content: "hello from telegram bus test".to_string(),
- channel: "telegram".to_string(),
- timestamp: 1,
- // No thread_ts so dispatch does not emit an automatic ack
- // reaction — we want to count exactly one send.
- thread_ts: None,
- },
- )
- .await;
-
- assert_eq!(
- stub_calls.load(Ordering::SeqCst),
- 1,
- "telegram dispatch must route through the agent.run_turn bus handler exactly once"
- );
-
- let sent = recorder.sent.lock().await;
- assert_eq!(sent.len(), 1, "stubbed response must reach the channel");
- assert!(
- sent[0].content.contains("CANNED_TELEGRAM_RESPONSE"),
- "delivered message should contain the stubbed text, got {:?}",
- sent[0].content
- );
- // No manual restore — dropping `_bus_guard` at end-of-scope re-registers
- // the production `agent.run_turn` handler automatically.
-}
-
/// Regression: for non-Telegram channels, thread_ts DOES split history keys
/// so each thread maintains independent conversation context.
#[test]