track_c_test.go
1 package test 2 3 import ( 4 "context" 5 "testing" 6 "time" 7 8 "github.com/TransformerOS/kamaji-go/internal/agents" 9 "github.com/TransformerOS/kamaji-go/internal/providers" 10 "github.com/TransformerOS/kamaji-go/internal/tools" 11 ) 12 13 func TestTrackC_AgentSystem(t *testing.T) { 14 // Test agent creation 15 llm, err := providers.NewOllamaProvider("http://localhost:11434", "test-model") 16 if err != nil { 17 t.Fatalf("Failed to create LLM provider: %v", err) 18 } 19 20 // Get available tools 21 availableTools := tools.GetAll() 22 if len(availableTools) == 0 { 23 t.Fatal("No tools available") 24 } 25 26 // Create agent 27 agent := agents.NewBasicAgentExecutor(llm, availableTools, false) 28 if agent == nil { 29 t.Fatal("Failed to create agent") 30 } 31 32 // Test agent status 33 status := agent.GetStatus() 34 if status.Status != "ready" { 35 t.Errorf("Expected agent status 'ready', got '%s'", status.Status) 36 } 37 38 // Test agent tools 39 agentTools := agent.GetTools() 40 if len(agentTools) != len(availableTools) { 41 t.Errorf("Expected %d tools, got %d", len(availableTools), len(agentTools)) 42 } 43 44 // Test agent execution 45 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) 46 defer cancel() 47 48 result, err := agent.Execute(ctx, "test task") 49 if err != nil { 50 t.Errorf("Agent execution failed: %v", err) 51 } 52 53 if result == "" { 54 t.Error("Agent returned empty result") 55 } 56 57 // Test agent status after execution 58 status = agent.GetStatus() 59 if status.TasksRun != 1 { 60 t.Errorf("Expected 1 task run, got %d", status.TasksRun) 61 } 62 63 // Clean up 64 err = agent.Close() 65 if err != nil { 66 t.Errorf("Failed to close agent: %v", err) 67 } 68 } 69 70 func TestTrackC_AgentTools(t *testing.T) { 71 // Test tool availability 72 availableTools := tools.GetAll() 73 74 expectedTools := []string{ 75 "git_status", 76 "git_add", 77 "git_commit", 78 "git_diff", 79 "git_log", 80 "shell_execute", 81 "change_directory", 82 "get_current_directory", 83 } 84 85 toolNames := make(map[string]bool) 86 for _, tool := range availableTools { 87 toolNames[tool.Name()] = true 88 } 89 90 for _, expectedTool := range expectedTools { 91 if !toolNames[expectedTool] { 92 t.Errorf("Expected tool '%s' not found", expectedTool) 93 } 94 } 95 } 96 97 func TestTrackC_AgentStreaming(t *testing.T) { 98 llm, err := providers.NewOllamaProvider("http://localhost:11434", "test-model") 99 if err != nil { 100 t.Fatalf("Failed to create LLM provider: %v", err) 101 } 102 103 agent := agents.NewBasicAgentExecutor(llm, tools.GetAll(), false) 104 105 ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) 106 defer cancel() 107 108 streamChan, err := agent.ExecuteStream(ctx, "test streaming task") 109 if err != nil { 110 t.Fatalf("Failed to start streaming: %v", err) 111 } 112 113 var chunks []string 114 for chunk := range streamChan { 115 if chunk.Error != nil { 116 t.Errorf("Stream error: %v", chunk.Error) 117 break 118 } 119 chunks = append(chunks, chunk.Content) 120 if chunk.Done { 121 break 122 } 123 } 124 125 if len(chunks) == 0 { 126 t.Error("No chunks received from stream") 127 } 128 }