agent_integration_test.go
1 package test 2 3 import ( 4 "os/exec" 5 "strings" 6 "testing" 7 ) 8 9 func TestAgentIntegration_CLICommand(t *testing.T) { 10 // Test that the CLI command builds and runs 11 cmd := exec.Command("go", "build", "-o", "bin/kamaji-test", "./cmd/kamaji") 12 cmd.Dir = "/home/tao/kamaji/go" 13 14 output, err := cmd.CombinedOutput() 15 if err != nil { 16 t.Fatalf("Failed to build kamaji: %v\nOutput: %s", err, output) 17 } 18 19 // Test basic agent command 20 cmd = exec.Command("./bin/kamaji-test", "agent", "test task") 21 cmd.Dir = "/home/tao/kamaji/go" 22 23 output, err = cmd.Output() 24 if err != nil { 25 t.Fatalf("Agent command failed: %v", err) 26 } 27 28 result := string(output) 29 if !strings.Contains(result, "Mock response to:") { 30 t.Errorf("Expected mock response, got: %s", result) 31 } 32 33 // Test verbose mode 34 cmd = exec.Command("./bin/kamaji-test", "agent", "--verbose", "test verbose task") 35 cmd.Dir = "/home/tao/kamaji/go" 36 37 output, err = cmd.Output() 38 if err != nil { 39 t.Fatalf("Agent verbose command failed: %v", err) 40 } 41 42 result = string(output) 43 if !strings.Contains(result, "Starting agent with task:") { 44 t.Errorf("Expected verbose output, got: %s", result) 45 } 46 47 if !strings.Contains(result, "Loaded 8 tools") { 48 t.Errorf("Expected tool count in verbose output, got: %s", result) 49 } 50 51 if !strings.Contains(result, "Agent Status: ready") { 52 t.Errorf("Expected agent status in verbose output, got: %s", result) 53 } 54 } 55 56 func TestAgentIntegration_ToolsAvailable(t *testing.T) { 57 // Test that all expected tools are available 58 cmd := exec.Command("./bin/kamaji-test", "agent", "--verbose", "list tools") 59 cmd.Dir = "/home/tao/kamaji/go" 60 61 output, err := cmd.Output() 62 if err != nil { 63 t.Fatalf("Agent command failed: %v", err) 64 } 65 66 result := string(output) 67 68 expectedTools := []string{ 69 "git_status", 70 "git_add", 71 "git_commit", 72 "git_diff", 73 "git_log", 74 "shell_execute", 75 "change_directory", 76 "get_current_directory", 77 } 78 79 for _, tool := range expectedTools { 80 if !strings.Contains(result, tool) { 81 t.Errorf("Expected tool '%s' not found in output: %s", tool, result) 82 } 83 } 84 } 85 86 func TestAgentIntegration_ErrorHandling(t *testing.T) { 87 // Test error handling with invalid arguments 88 cmd := exec.Command("./bin/kamaji-test", "agent") 89 cmd.Dir = "/home/tao/kamaji/go" 90 91 output, err := cmd.CombinedOutput() 92 if err == nil { 93 t.Error("Expected error for missing task argument") 94 } 95 96 result := string(output) 97 if !strings.Contains(result, "Error:") && !strings.Contains(result, "Usage:") { 98 t.Errorf("Expected error message, got: %s", result) 99 } 100 }