use crate::brain::agent::service::AgentService;
mod clean_auto_title {
use super::*;
#[test]
fn basic_title_unchanged() {
assert_eq!(
AgentService::clean_auto_title("Rust Refactoring"),
"Rust Refactoring"
);
}
#[test]
fn trims_whitespace() {
assert_eq!(
AgentService::clean_auto_title(" Hashline Debug "),
"Hashline Debug"
);
}
#[test]
fn strips_double_quotes() {
assert_eq!(
AgentService::clean_auto_title("\"Auto Title Fix\""),
"Auto Title Fix"
);
}
#[test]
fn strips_single_quotes() {
assert_eq!(
AgentService::clean_auto_title("'Session Config'"),
"Session Config"
);
}
#[test]
fn caps_at_60_chars() {
let long = "a".repeat(80);
let result = AgentService::clean_auto_title(&long);
assert_eq!(result.len(), 60);
}
#[test]
fn exactly_60_chars_unchanged() {
let exact = "b".repeat(60);
assert_eq!(AgentService::clean_auto_title(&exact), exact);
}
#[test]
fn empty_string() {
assert_eq!(AgentService::clean_auto_title(""), "");
}
#[test]
fn only_whitespace() {
assert_eq!(AgentService::clean_auto_title(" "), "");
}
#[test]
fn only_quotes() {
assert_eq!(AgentService::clean_auto_title("\"\""), "");
}
#[test]
fn quotes_and_whitespace() {
assert_eq!(
AgentService::clean_auto_title(" \"Clean Title\" "),
"Clean Title"
);
}
#[test]
fn trailing_punctuation_kept() {
assert_eq!(AgentService::clean_auto_title("Fix Bug."), "Fix Bug.");
}
}
mod is_default_channel_title {
use super::*;
#[test]
fn telegram_dm_title() {
assert!(AgentService::is_default_channel_title(
"Telegram: DM John (12345) [chat:67890]"
));
}
#[test]
fn telegram_group_title() {
assert!(!AgentService::is_default_channel_title(
"Telegram: My Group [chat:12345]"
));
}
#[test]
fn telegram_auto_titled_not_default() {
assert!(!AgentService::is_default_channel_title(
"Telegram: Fix Bug Report [chat:67890]"
));
}
#[test]
fn discord_title() {
assert!(AgentService::is_default_channel_title("Discord: #general"));
}
#[test]
fn slack_title() {
assert!(AgentService::is_default_channel_title("Slack: #random"));
}
#[test]
fn whatsapp_title() {
assert!(!AgentService::is_default_channel_title(
"WhatsApp: John Doe"
));
}
#[test]
fn trello_title() {
assert!(!AgentService::is_default_channel_title("Trello: My Board"));
}
#[test]
fn custom_title_not_default() {
assert!(!AgentService::is_default_channel_title(
"Rust Refactoring Session"
));
}
#[test]
fn empty_title_not_default() {
assert!(!AgentService::is_default_channel_title(""));
}
#[test]
fn partial_prefix_not_default() {
assert!(!AgentService::is_default_channel_title("Telegram"));
assert!(!AgentService::is_default_channel_title("TelegramBot: test"));
}
#[test]
fn new_chat_is_default() {
assert!(AgentService::is_default_channel_title("New Chat"));
}
}
mod extract_channel_prefix {
use super::*;
#[test]
fn telegram_prefix() {
assert_eq!(
AgentService::extract_channel_prefix("Telegram: DM John"),
"Telegram: "
);
}
#[test]
fn discord_prefix() {
assert_eq!(
AgentService::extract_channel_prefix("Discord: #general"),
"Discord: "
);
}
#[test]
fn slack_prefix() {
assert_eq!(
AgentService::extract_channel_prefix("Slack: #random"),
"Slack: "
);
}
#[test]
fn whatsapp_prefix() {
assert_eq!(
AgentService::extract_channel_prefix("WhatsApp: John"),
"WhatsApp: "
);
}
#[test]
fn trello_prefix() {
assert_eq!(
AgentService::extract_channel_prefix("Trello: Board"),
"Trello: "
);
}
#[test]
fn no_prefix() {
assert_eq!(AgentService::extract_channel_prefix("New Chat"), "");
assert_eq!(AgentService::extract_channel_prefix("Custom Title"), "");
assert_eq!(AgentService::extract_channel_prefix(""), "");
}
}
mod strip_channel_preamble {
use super::*;
#[test]
fn plain_message_unchanged() {
assert_eq!(
AgentService::strip_channel_preamble("Fix the login bug"),
"Fix the login bug"
);
}
#[test]
fn strips_single_channel_block() {
let input = "[Channel: Telegram (chat_id: -100123) — auto-delivery]\n\nFix the login bug";
assert_eq!(
AgentService::strip_channel_preamble(input),
"Fix the login bug"
);
}
#[test]
fn strips_multiple_preamble_blocks() {
let input = "[Channel: Telegram (chat_id: -100123) — auto-delivery]\n\n\
[Reaction directive: use <<react:EMOJI>>]\n\n\
[Recent group history (5 messages):\n[13:57] User: hello\n— end history —]\n\n\
Fix the login bug";
assert_eq!(
AgentService::strip_channel_preamble(input),
"Fix the login bug"
);
}
#[test]
fn handles_nested_brackets_in_history() {
let input =
"[Recent group history:\n[13:57] Alice: hi\n[14:02] Bob: hey\n— end —]\n\nDeploy now";
assert_eq!(AgentService::strip_channel_preamble(input), "Deploy now");
}
#[test]
fn preserves_user_bracket_text_after_preamble() {
let input = "[Channel: Telegram]\n\n[BUG] Fix the crash";
assert_eq!(
AgentService::strip_channel_preamble(input),
"[BUG] Fix the crash"
);
}
#[test]
fn unmatched_bracket_stops_stripping() {
let input = "[unclosed block\nFix the bug";
assert_eq!(
AgentService::strip_channel_preamble(input),
"[unclosed block\nFix the bug"
);
}
#[test]
fn empty_string() {
assert_eq!(AgentService::strip_channel_preamble(""), "");
}
#[test]
fn only_preamble_returns_empty() {
let input = "[Channel: Telegram]\n\n[Reaction directive: stuff]";
assert_eq!(AgentService::strip_channel_preamble(input), "");
}
#[test]
fn trims_leading_whitespace_after_strip() {
let input = "[Channel: Telegram]\n\n\n Fix the bug";
assert_eq!(AgentService::strip_channel_preamble(input), "Fix the bug");
}
}