|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "bytes" |
| 5 | + "context" |
| 6 | + "os" |
| 7 | + "os/exec" |
| 8 | + "path/filepath" |
| 9 | + "strings" |
| 10 | + "testing" |
| 11 | +) |
| 12 | + |
| 13 | +// buildBinary builds the aicodingagentteam binary for testing. |
| 14 | +func buildBinary(t *testing.T) string { |
| 15 | + t.Helper() |
| 16 | + bin := filepath.Join(t.TempDir(), "aicodingagentteam-test") |
| 17 | + if os.PathSeparator == '\\' { |
| 18 | + bin += ".exe" |
| 19 | + } |
| 20 | + cmd := exec.Command("go", "build", "-o", bin, ".") |
| 21 | + if out, err := cmd.CombinedOutput(); err != nil { |
| 22 | + t.Fatalf("build binary: %v\n%s", err, out) |
| 23 | + } |
| 24 | + return bin |
| 25 | +} |
| 26 | + |
| 27 | +func TestCLI_Version(t *testing.T) { |
| 28 | + bin := buildBinary(t) |
| 29 | + out, err := exec.Command(bin, "version").Output() |
| 30 | + if err != nil { |
| 31 | + t.Fatalf("version command failed: %v", err) |
| 32 | + } |
| 33 | + if !strings.Contains(string(out), "aicodingagentteam") { |
| 34 | + t.Errorf("version output unexpected: %s", out) |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +func TestCLI_Init(t *testing.T) { |
| 39 | + bin := buildBinary(t) |
| 40 | + dir := t.TempDir() |
| 41 | + cmd := exec.Command(bin, "init") |
| 42 | + cmd.Dir = dir |
| 43 | + out, err := cmd.CombinedOutput() |
| 44 | + if err != nil { |
| 45 | + t.Fatalf("init command failed: %v\n%s", err, out) |
| 46 | + } |
| 47 | + if !strings.Contains(string(out), "initialized") { |
| 48 | + t.Errorf("init output unexpected: %s", out) |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +func TestCLI_NoArgs_PrintsUsage(t *testing.T) { |
| 53 | + bin := buildBinary(t) |
| 54 | + out, err := exec.Command(bin).CombinedOutput() |
| 55 | + if err == nil { |
| 56 | + t.Error("expected non-zero exit with no args") |
| 57 | + } |
| 58 | + if !strings.Contains(string(out), "AiCodingAgentTeam") { |
| 59 | + t.Errorf("usage output unexpected: %s", out) |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +func TestCLI_Memory_NoArgs_PrintsUsage(t *testing.T) { |
| 64 | + bin := buildBinary(t) |
| 65 | + out, err := exec.Command(bin, "memory").CombinedOutput() |
| 66 | + if err != nil { |
| 67 | + t.Fatalf("memory command failed: %v", err) |
| 68 | + } |
| 69 | + if !strings.Contains(string(out), "Usage") { |
| 70 | + t.Errorf("memory usage output unexpected: %s", out) |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +func TestCLI_MemoryShow_EmptyMemory(t *testing.T) { |
| 75 | + bin := buildBinary(t) |
| 76 | + dir := t.TempDir() |
| 77 | + cmd := exec.Command(bin, "memory", "show") |
| 78 | + cmd.Dir = dir |
| 79 | + out, err := cmd.CombinedOutput() |
| 80 | + if err != nil { |
| 81 | + t.Fatalf("memory show failed: %v\n%s", err, out) |
| 82 | + } |
| 83 | + if !strings.Contains(string(out), "Facts") { |
| 84 | + t.Errorf("expected Facts section, got: %s", out) |
| 85 | + } |
| 86 | + if !strings.Contains(string(out), "(none)") { |
| 87 | + t.Errorf("expected (none) for empty memory, got: %s", out) |
| 88 | + } |
| 89 | +} |
| 90 | + |
| 91 | +func TestCLI_MemoryCapture_Toggle(t *testing.T) { |
| 92 | + bin := buildBinary(t) |
| 93 | + dir := t.TempDir() |
| 94 | + cmd := exec.Command(bin, "memory", "capture", "on") |
| 95 | + cmd.Dir = dir |
| 96 | + out, err := cmd.CombinedOutput() |
| 97 | + if err != nil { |
| 98 | + t.Fatalf("memory capture failed: %v\n%s", err, out) |
| 99 | + } |
| 100 | + if !strings.Contains(string(out), "on") { |
| 101 | + t.Errorf("expected 'on' in output, got: %s", out) |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +func TestCLI_KnowledgeDemo(t *testing.T) { |
| 106 | + bin := buildBinary(t) |
| 107 | + dir := t.TempDir() |
| 108 | + cmd := exec.Command(bin, "knowledge", "demo") |
| 109 | + cmd.Dir = dir |
| 110 | + out, err := cmd.CombinedOutput() |
| 111 | + if err != nil { |
| 112 | + t.Fatalf("knowledge demo failed: %v\n%s", err, out) |
| 113 | + } |
| 114 | + if !strings.Contains(string(out), "RAG + memory end-to-end complete") { |
| 115 | + t.Errorf("demo did not complete: %s", out) |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +func TestCLI_Verify(t *testing.T) { |
| 120 | + bin := buildBinary(t) |
| 121 | + dir := t.TempDir() |
| 122 | + cmd := exec.Command(bin, "verify") |
| 123 | + cmd.Dir = dir |
| 124 | + var stdout, stderr bytes.Buffer |
| 125 | + cmd.Stdout = &stdout |
| 126 | + cmd.Stderr = &stderr |
| 127 | + _ = cmd.Run() // may fail if golangci-lint not installed |
| 128 | + output := stdout.String() + stderr.String() |
| 129 | + if !strings.Contains(output, "quality-gate") { |
| 130 | + t.Errorf("verify output unexpected: %s", output) |
| 131 | + } |
| 132 | +} |
| 133 | + |
| 134 | +func TestCLI_KnowledgeIndex(t *testing.T) { |
| 135 | + bin := buildBinary(t) |
| 136 | + dir := t.TempDir() |
| 137 | + // Create a sample file |
| 138 | + _ = filepath.Join(dir, "main.go") |
| 139 | + cmd := exec.Command(bin, "knowledge", "index", dir) |
| 140 | + cmd.Dir = dir |
| 141 | + out, err := cmd.CombinedOutput() |
| 142 | + if err != nil { |
| 143 | + t.Fatalf("knowledge index failed: %v\n%s", err, out) |
| 144 | + } |
| 145 | + if !strings.Contains(string(out), "indexed") { |
| 146 | + t.Errorf("index output unexpected: %s", out) |
| 147 | + } |
| 148 | +} |
| 149 | + |
| 150 | +// Ensure context import is used |
| 151 | +var _ = context.Background |
0 commit comments