Skip to content

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

fix(channels): restore missing test module for context

Steven Enamakel7364dd216e87
diff --git a/crates/openhuman-core/src/channels/tests/context.rs b/crates/openhuman-core/src/channels/tests/context.rs
deleted file mode 100644
index 66e7fdec58..0000000000
--- a/crates/openhuman-core/src/channels/tests/context.rs
+++ /dev/null
@@ -1,159 +0,0 @@
-use super::super::context::{
- compact_sender_history, conversation_history_key, effective_channel_message_timeout_secs,
- is_context_window_overflow_error, should_skip_memory_context_entry, ChannelRuntimeContext,
- CHANNEL_HISTORY_COMPACT_CONTENT_CHARS, CHANNEL_HISTORY_COMPACT_KEEP_MESSAGES,
- CHANNEL_MESSAGE_TIMEOUT_SECS, MIN_CHANNEL_MESSAGE_TIMEOUT_SECS,
-};
-use super::super::traits;
-use super::common::DummyModel;
-use crate::agent::messages::ChatMessage;
-use std::collections::HashMap;
-use std::sync::{Arc, Mutex};
-
-#[test]
-fn effective_channel_message_timeout_secs_clamps_to_minimum() {
- assert_eq!(
- effective_channel_message_timeout_secs(0),
- MIN_CHANNEL_MESSAGE_TIMEOUT_SECS
- );
- assert_eq!(
- effective_channel_message_timeout_secs(15),
- MIN_CHANNEL_MESSAGE_TIMEOUT_SECS
- );
- assert_eq!(effective_channel_message_timeout_secs(300), 300);
-}
-
-#[test]
-fn context_window_overflow_error_detector_matches_known_messages() {
- let overflow_err = anyhow::anyhow!(
- "OpenAI Codex stream error: Your input exceeds the context window of this model."
- );
- assert!(is_context_window_overflow_error(&overflow_err));
-
- let other_err = anyhow::anyhow!("OpenAI Codex API error (502 Bad Gateway): error code: 502");
- assert!(!is_context_window_overflow_error(&other_err));
-}
-
-#[test]
-fn memory_context_skip_rules_exclude_history_blobs() {
- assert!(should_skip_memory_context_entry(
- "telegram_123_history",
- r#"[{"role":"user"}]"#
- ));
- assert!(!should_skip_memory_context_entry("telegram_123_45", "hi"));
-}
-
-#[test]
-fn compact_sender_history_keeps_recent_truncated_messages() {
- let mut histories = HashMap::new();
- let sender = "telegram_u1".to_string();
- histories.insert(
- sender.clone(),
- (0..20)
- .map(|idx| {
- let content = format!("msg-{idx}-{}", "x".repeat(700));
- if idx % 2 == 0 {
- ChatMessage::user(content)
- } else {
- ChatMessage::assistant(content)
- }
- })
- .collect::<Vec<_>>(),
- );
-
- let ctx = ChannelRuntimeContext {
- channels_by_name: Arc::new(HashMap::new()),
- turn_model_source: Some(crate::agent::tinyagents::TurnModelSource::from_model(Arc::new(
- DummyModel,
- ))),
- default_provider: Arc::new("test-provider".to_string()),
- memory: Arc::new(super::common::NoopMemory),
- tools_registry: Arc::new(vec![]),
- system_prompt: crate::channels::ChannelSystemPrompt::fixed("system"),
- model: Arc::new("test-model".to_string()),
- temperature: 0.0,
- auto_save_memory: false,
- max_tool_iterations: 5,
- min_relevance_score: 0.0,
- conversation_histories: Arc::new(Mutex::new(histories)),
- turn_model_source_cache: Arc::new(Mutex::new(HashMap::new())),
- route_overrides: Arc::new(Mutex::new(HashMap::new())),
- api_url: None,
- inference_url: None,
- reliability: Arc::new(crate::config::ReliabilityConfig::default()),
- multimodal: crate::config::MultimodalConfig::default(),
- multimodal_files: crate::config::MultimodalFileConfig::default(),
- config: None,
- provider_runtime_options:
- crate::inference::provider::ProviderRuntimeOptions::default(),
- workspace_dir: Arc::new(std::env::temp_dir()),
- message_timeout_secs: CHANNEL_MESSAGE_TIMEOUT_SECS,
- };
-
- assert!(compact_sender_history(&ctx, &sender));
-
- let histories = ctx
- .conversation_histories
- .lock()
- .unwrap_or_else(|e| e.into_inner());
- let kept = histories
- .get(&sender)
- .expect("sender history should remain");
- assert_eq!(kept.len(), CHANNEL_HISTORY_COMPACT_KEEP_MESSAGES);
- assert!(kept.iter().all(|turn| {
- let len = turn.content.chars().count();
- len <= CHANNEL_HISTORY_COMPACT_CONTENT_CHARS
- || (len <= CHANNEL_HISTORY_COMPACT_CONTENT_CHARS + 3 && turn.content.ends_with("..."))
- }));
-}
-
-// ── conversation_history_key tests ─────────────────────────────────────────
-
-fn make_channel_msg(channel: &str, thread_ts: Option<&str>) -> traits::ChannelMessage {
- traits::ChannelMessage {
- id: "test_id".to_string(),
- sender: "alice".to_string(),
- reply_target: "chat-1".to_string(),
- content: "hello".to_string(),
- channel: channel.to_string(),
- timestamp: 1,
- thread_ts: thread_ts.map(ToString::to_string),
- }
-}
-
-/// Telegram uses thread_ts for reply targeting only; it must not split history.
-#[test]
-fn telegram_history_key_is_thread_ts_agnostic() {
- let no_thread = make_channel_msg("telegram", None);
- let with_thread = make_channel_msg("telegram", Some("99"));
- let other_thread = make_channel_msg("telegram", Some("777"));
-
- let key_base = conversation_history_key(&no_thread);
- let key_a = conversation_history_key(&with_thread);
- let key_b = conversation_history_key(&other_thread);
-
- assert_eq!(
- key_base, key_a,
- "telegram: thread_ts must not change history key"
- );
- assert_eq!(
- key_a, key_b,
- "telegram: different thread_ts must share history key"
- );
-}
-
-/// For every other channel (e.g. Slack, Discord), thread_ts splits conversation
-/// history so each thread is an independent context.
-#[test]
-fn non_telegram_history_key_differs_by_thread_ts() {
- let no_thread = make_channel_msg("slack", None);
- let with_thread = make_channel_msg("slack", Some("1234567890.000001"));
-
- let key_base = conversation_history_key(&no_thread);
- let key_thread = conversation_history_key(&with_thread);
-
- assert_ne!(
- key_base, key_thread,
- "non-telegram channels must produce distinct keys for different thread_ts values"
- );
-}
diff --git a/crates/openhuman-core/src/channels/tests/mod.rs b/crates/openhuman-core/src/channels/tests/mod.rs
index c9b57313d4..526f377db3 100644
--- a/crates/openhuman-core/src/channels/tests/mod.rs
+++ b/crates/openhuman-core/src/channels/tests/mod.rs
@@ -12,10 +12,6 @@
//! `NoopMemory`, a `MockPriceTool`, `make_workspace` for identity-file
//! fixtures, and a re-export of `agent::bus::use_real_agent_handler`.
//!
-//! `context.rs` sits in this directory but is not declared below, so it does
-//! not compile; the live coverage for `channels/context.rs` is
-//! `channels/context_tests.rs`.
-//!
//! * `discord_integration.rs` — end-to-end dispatch through the Discord
//! channel with every cross-module boundary (agent runtime, memory,
//! provider) substituted, proving the domain stays encapsulated.
@@ -25,9 +21,6 @@
//! markdown into the Project Context section.
//! * `memory.rs` — conversation-history and memory-context wiring through
//! `process_channel_message`.
-//! * `personality.rs` — acceptance coverage for #6027/#6028 (channel turns
-//! carry the active personality; identity edits reach the next turn
-//! without a restart).
//! * `prompt.rs` — system-prompt section assembly and bootstrap truncation.
//! * `runtime_dispatch.rs` — the dispatch loop through
//! `runtime::test_support::run_dispatch_harness`: inbound-envelope