generated from nhcarrigan/template
feat: start setting up CI
This commit is contained in:
@@ -472,3 +472,127 @@ pub type SharedBridge = Arc<Mutex<WslBridge>>;
|
||||
pub fn create_shared_bridge() -> SharedBridge {
|
||||
Arc::new(Mutex::new(WslBridge::new()))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_get_tool_state_search_tools() {
|
||||
assert!(matches!(get_tool_state("Read"), CharacterState::Searching));
|
||||
assert!(matches!(get_tool_state("Glob"), CharacterState::Searching));
|
||||
assert!(matches!(get_tool_state("Grep"), CharacterState::Searching));
|
||||
assert!(matches!(get_tool_state("WebSearch"), CharacterState::Searching));
|
||||
assert!(matches!(get_tool_state("WebFetch"), CharacterState::Searching));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_tool_state_coding_tools() {
|
||||
assert!(matches!(get_tool_state("Edit"), CharacterState::Coding));
|
||||
assert!(matches!(get_tool_state("Write"), CharacterState::Coding));
|
||||
assert!(matches!(get_tool_state("NotebookEdit"), CharacterState::Coding));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_tool_state_mcp_tools() {
|
||||
assert!(matches!(get_tool_state("mcp__github__create_issue"), CharacterState::Mcp));
|
||||
assert!(matches!(get_tool_state("mcp__notion__search"), CharacterState::Mcp));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_tool_state_task() {
|
||||
assert!(matches!(get_tool_state("Task"), CharacterState::Thinking));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_tool_state_unknown() {
|
||||
assert!(matches!(get_tool_state("SomeUnknownTool"), CharacterState::Typing));
|
||||
assert!(matches!(get_tool_state("Bash"), CharacterState::Typing));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_tool_description_read() {
|
||||
let input = serde_json::json!({"file_path": "/home/test/file.txt"});
|
||||
let desc = format_tool_description("Read", &input);
|
||||
assert_eq!(desc, "Reading file: /home/test/file.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_tool_description_read_no_path() {
|
||||
let input = serde_json::json!({});
|
||||
let desc = format_tool_description("Read", &input);
|
||||
assert_eq!(desc, "Reading file...");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_tool_description_glob() {
|
||||
let input = serde_json::json!({"pattern": "**/*.rs"});
|
||||
let desc = format_tool_description("Glob", &input);
|
||||
assert_eq!(desc, "Searching for files: **/*.rs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_tool_description_grep() {
|
||||
let input = serde_json::json!({"pattern": "TODO"});
|
||||
let desc = format_tool_description("Grep", &input);
|
||||
assert_eq!(desc, "Searching for: TODO");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_tool_description_edit() {
|
||||
let input = serde_json::json!({"file_path": "/home/test/main.rs"});
|
||||
let desc = format_tool_description("Edit", &input);
|
||||
assert_eq!(desc, "Editing: /home/test/main.rs");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_tool_description_write() {
|
||||
let input = serde_json::json!({"file_path": "/home/test/new.txt"});
|
||||
let desc = format_tool_description("Write", &input);
|
||||
assert_eq!(desc, "Editing: /home/test/new.txt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_tool_description_bash_short() {
|
||||
let input = serde_json::json!({"command": "ls -la"});
|
||||
let desc = format_tool_description("Bash", &input);
|
||||
assert_eq!(desc, "Running: ls -la");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_tool_description_bash_long() {
|
||||
let long_cmd = "a".repeat(100);
|
||||
let input = serde_json::json!({"command": long_cmd});
|
||||
let desc = format_tool_description("Bash", &input);
|
||||
assert!(desc.starts_with("Running: "));
|
||||
assert!(desc.ends_with("..."));
|
||||
assert!(desc.len() < 70);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_format_tool_description_unknown() {
|
||||
let input = serde_json::json!({"some": "data"});
|
||||
let desc = format_tool_description("CustomTool", &input);
|
||||
assert_eq!(desc, "Using tool: CustomTool");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wsl_bridge_new() {
|
||||
let bridge = WslBridge::new();
|
||||
assert!(!bridge.is_running());
|
||||
assert_eq!(bridge.get_working_directory(), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wsl_bridge_default() {
|
||||
let bridge = WslBridge::default();
|
||||
assert!(!bridge.is_running());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_shared_bridge() {
|
||||
let shared = create_shared_bridge();
|
||||
let bridge = shared.lock();
|
||||
assert!(!bridge.is_running());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user