use super::*;
#[test]
fn test_extract_grep_pattern() {
assert_eq!(
extract_search_query_from_bash("grep -r \"Stmt::Import\" src/"),
Some("Stmt::Import".to_string())
);
assert_eq!(
extract_search_query_from_bash("rg \"fn main\" --type rust"),
Some("fn main".to_string())
);
assert_eq!(
extract_search_query_from_bash("grep -ri \"error handling\" ."),
Some("error handling".to_string())
);
assert_eq!(
extract_search_query_from_bash("rg 'impl Display' src/"),
Some("impl Display".to_string())
);
assert_eq!(
extract_search_query_from_bash("git grep \"TODO\" -- '*.rs'"),
Some("TODO".to_string())
);
assert_eq!(
extract_search_query_from_bash("cargo build --release"),
None
);
assert_eq!(
extract_search_query_from_bash("grep -r -e \"pattern\" src/"),
Some("pattern".to_string())
);
}
#[test]
fn test_extract_find_pattern() {
assert_eq!(
extract_search_query_from_bash("find . -name \"*.test.rs\""),
Some("test.rs".to_string())
);
assert_eq!(
extract_search_query_from_bash("find src/ -iname \"*.py\""),
Some("py".to_string())
);
assert_eq!(extract_search_query_from_bash("find . -type f"), None);
}
#[test]
fn test_clean_regex_for_search() {
assert_eq!(clean_regex_for_search("fn\\s+main"), "fn main");
assert_eq!(clean_regex_for_search("impl.*Display"), "impl Display");
assert_eq!(clean_regex_for_search("^use\\b"), "use");
assert_eq!(clean_regex_for_search("Stmt::Import"), "Stmt::Import");
}
#[test]
fn test_is_meaningful_search_query() {
assert!(!is_meaningful_search_query(""));
assert!(!is_meaningful_search_query("fn"));
assert!(!is_meaningful_search_query("rs"));
assert!(!is_meaningful_search_query("let"));
assert!(!is_meaningful_search_query("import"));
assert!(!is_meaningful_search_query("toml"));
assert!(!is_meaningful_search_query("json"));
assert!(is_meaningful_search_query("PostToolUse"));
assert!(is_meaningful_search_query("context assembler"));
assert!(is_meaningful_search_query("fn main")); assert!(is_meaningful_search_query("search query"));
assert!(is_meaningful_search_query("ContextConfig"));
}
#[test]
fn test_strip_system_tags() {
assert_eq!(
strip_system_tags("Hello <system-reminder>noise</system-reminder> world"),
"Hello world"
);
assert_eq!(
strip_system_tags("Query <task-notification>task-id: abc</task-notification> here"),
"Query here"
);
let input = "<system-reminder>sys</system-reminder>real content<task-notification>task</task-notification>";
assert_eq!(strip_system_tags(input), "real content");
assert_eq!(strip_system_tags("plain text"), "plain text");
}
#[test]
fn test_is_automated_message() {
assert!(is_automated_message(
"Auto-patrol: pick up aegis-abc123 (Some task). Run: bd show aegis-abc123"
));
assert!(is_automated_message(
"PATROL LOOP — you must keep working until context is below 20%."
));
assert!(is_automated_message(
"RANGER PATROL: You are a ranger. Patrol your domain."
));
assert!(is_automated_message(
"PATROL: Run gt hook, gt mail inbox, bd ready."
));
assert!(is_automated_message(
"[reactor] ⚠️ ESCALATION: E2ESmokeTestFailing — node-5 | Paging: aegis/crew/wu"
));
assert!(is_automated_message(
"[reactor] 🟠 P1 bead: aegis-sc86f0 Skills Framework Phase 1"
));
assert!(is_automated_message(
"[reactor] 🟠 P0 bead: aegis-thmbt2 Claude token expires"
));
assert!(is_automated_message("WORK: You are stryder (Bobbin Ranger). Check gt hook and gt mail inbox. Keep working until context below 25%, then /handoff."));
assert!(is_automated_message("╔══════╗\n║ ✅ HANDOFF COMPLETE - You are the NEW session ║\n╚══════╝\nYour predecessor handed off to you."));
assert!(is_automated_message(
"**STARTUP PROTOCOL**: Please:\n1. Run `gt hook` — What's hooked?"
));
assert!(is_automated_message(
"[from dog] Marshal check: You appear idle (7+ days no commits). Check bd ready."
));
assert!(is_automated_message("QUEUED NUDGE (1 message(s)):\n\n [from dog] check status\n\nThis is a background notification. Continue current work."));
assert!(is_automated_message("aegis Crew ian, checking in."));
assert!(is_automated_message("\naegis Crew mel, checking in.\n"));
assert!(is_automated_message(
"<system-reminder>\nUserPromptSubmit hook success\n</system-reminder>"
));
assert!(is_automated_message(
"[GAS TOWN] crew ian (rig: aegis) <- self"
));
assert!(is_automated_message(
"Check your hook and mail, then act on the hook if present:\n1. `gt hook`"
));
assert!(!is_automated_message("Fix the bug in bobbin search"));
assert!(!is_automated_message("How do I deploy bobbin to node-4?"));
assert!(!is_automated_message("bd show aegis-abc123"));
assert!(!is_automated_message(
"Run the tests and check for failures"
));
assert!(!is_automated_message(""));
assert!(is_automated_message(
" \n<system-reminder>\nhook output\n</system-reminder>"
));
assert!(is_automated_message(
"\n[GAS TOWN] crew ian (rig: aegis) <- self"
));
}
#[test]
fn test_is_bead_command() {
assert!(is_bead_command("remove bo-qq5h"));
assert!(is_bead_command("show aegis-abc123"));
assert!(is_bead_command("close gt-xyz"));
assert!(is_bead_command("hook gt-h8x"));
assert!(is_bead_command("bd show aegis-ky3wc9"));
assert!(is_bead_command("unhook hq-abc"));
assert!(is_bead_command("aegis-mlpgac"));
assert!(!is_bead_command("Fix the bug in bobbin search"));
assert!(!is_bead_command("How do I deploy bobbin to node-4?"));
assert!(!is_bead_command("Run the tests and check for failures"));
assert!(!is_bead_command("")); assert!(!is_bead_command(
"what is the architecture of the system and how does deployment work across all rigs"
));
assert!(!is_bead_command("show x-ab"));
assert!(!is_bead_command("show ABC-def123"));
}