|
| 1 | +package deepseek |
| 2 | + |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "pentagi/pkg/config" |
| 7 | + "pentagi/pkg/providers/pconfig" |
| 8 | + "pentagi/pkg/providers/provider" |
| 9 | +) |
| 10 | + |
| 11 | +func TestConfigLoading(t *testing.T) { |
| 12 | + cfg := &config.Config{ |
| 13 | + DeepSeekAPIKey: "test-key", |
| 14 | + DeepSeekServerURL: "https://api.deepseek.com", |
| 15 | + } |
| 16 | + |
| 17 | + providerConfig, err := DefaultProviderConfig() |
| 18 | + if err != nil { |
| 19 | + t.Fatalf("Failed to create provider config: %v", err) |
| 20 | + } |
| 21 | + |
| 22 | + prov, err := New(cfg, providerConfig) |
| 23 | + if err != nil { |
| 24 | + t.Fatalf("Failed to create provider: %v", err) |
| 25 | + } |
| 26 | + |
| 27 | + rawConfig := prov.GetRawConfig() |
| 28 | + if len(rawConfig) == 0 { |
| 29 | + t.Fatal("Raw config should not be empty") |
| 30 | + } |
| 31 | + |
| 32 | + providerConfig = prov.GetProviderConfig() |
| 33 | + if providerConfig == nil { |
| 34 | + t.Fatal("Provider config should not be nil") |
| 35 | + } |
| 36 | + |
| 37 | + for _, agentType := range pconfig.AllAgentTypes { |
| 38 | + model := prov.Model(agentType) |
| 39 | + if model == "" { |
| 40 | + t.Errorf("Agent type %v should have a model assigned", agentType) |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + for _, agentType := range pconfig.AllAgentTypes { |
| 45 | + priceInfo := prov.GetPriceInfo(agentType) |
| 46 | + if priceInfo == nil { |
| 47 | + t.Errorf("Agent type %v should have price information", agentType) |
| 48 | + } else { |
| 49 | + if priceInfo.Input <= 0 || priceInfo.Output <= 0 { |
| 50 | + t.Errorf("Agent type %v should have positive input (%f) and output (%f) prices", |
| 51 | + agentType, priceInfo.Input, priceInfo.Output) |
| 52 | + } |
| 53 | + } |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +func TestProviderType(t *testing.T) { |
| 58 | + cfg := &config.Config{ |
| 59 | + DeepSeekAPIKey: "test-key", |
| 60 | + DeepSeekServerURL: "https://api.deepseek.com", |
| 61 | + } |
| 62 | + |
| 63 | + providerConfig, err := DefaultProviderConfig() |
| 64 | + if err != nil { |
| 65 | + t.Fatalf("Failed to create provider config: %v", err) |
| 66 | + } |
| 67 | + |
| 68 | + prov, err := New(cfg, providerConfig) |
| 69 | + if err != nil { |
| 70 | + t.Fatalf("Failed to create provider: %v", err) |
| 71 | + } |
| 72 | + |
| 73 | + if prov.Type() != provider.ProviderDeepSeek { |
| 74 | + t.Errorf("Expected provider type %v, got %v", provider.ProviderDeepSeek, prov.Type()) |
| 75 | + } |
| 76 | +} |
| 77 | + |
| 78 | +func TestModelsLoading(t *testing.T) { |
| 79 | + models, err := DefaultModels() |
| 80 | + if err != nil { |
| 81 | + t.Fatalf("Failed to load models: %v", err) |
| 82 | + } |
| 83 | + |
| 84 | + if len(models) == 0 { |
| 85 | + t.Fatal("Models list should not be empty") |
| 86 | + } |
| 87 | + |
| 88 | + for _, model := range models { |
| 89 | + if model.Name == "" { |
| 90 | + t.Error("Model name should not be empty") |
| 91 | + } |
| 92 | + |
| 93 | + if model.Price == nil { |
| 94 | + t.Errorf("Model %s should have price information", model.Name) |
| 95 | + continue |
| 96 | + } |
| 97 | + |
| 98 | + if model.Price.Input <= 0 { |
| 99 | + t.Errorf("Model %s should have positive input price", model.Name) |
| 100 | + } |
| 101 | + |
| 102 | + if model.Price.Output <= 0 { |
| 103 | + t.Errorf("Model %s should have positive output price", model.Name) |
| 104 | + } |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +func TestModelWithPrefix(t *testing.T) { |
| 109 | + cfg := &config.Config{ |
| 110 | + DeepSeekAPIKey: "test-key", |
| 111 | + DeepSeekServerURL: "https://api.deepseek.com", |
| 112 | + DeepSeekProvider: "deepseek", |
| 113 | + } |
| 114 | + |
| 115 | + providerConfig, err := DefaultProviderConfig() |
| 116 | + if err != nil { |
| 117 | + t.Fatalf("Failed to create provider config: %v", err) |
| 118 | + } |
| 119 | + |
| 120 | + prov, err := New(cfg, providerConfig) |
| 121 | + if err != nil { |
| 122 | + t.Fatalf("Failed to create provider: %v", err) |
| 123 | + } |
| 124 | + |
| 125 | + for _, agentType := range pconfig.AllAgentTypes { |
| 126 | + modelWithPrefix := prov.ModelWithPrefix(agentType) |
| 127 | + model := prov.Model(agentType) |
| 128 | + |
| 129 | + expected := "deepseek/" + model |
| 130 | + if modelWithPrefix != expected { |
| 131 | + t.Errorf("Agent type %v: expected prefixed model %q, got %q", agentType, expected, modelWithPrefix) |
| 132 | + } |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +func TestModelWithoutPrefix(t *testing.T) { |
| 137 | + cfg := &config.Config{ |
| 138 | + DeepSeekAPIKey: "test-key", |
| 139 | + DeepSeekServerURL: "https://api.deepseek.com", |
| 140 | + } |
| 141 | + |
| 142 | + providerConfig, err := DefaultProviderConfig() |
| 143 | + if err != nil { |
| 144 | + t.Fatalf("Failed to create provider config: %v", err) |
| 145 | + } |
| 146 | + |
| 147 | + prov, err := New(cfg, providerConfig) |
| 148 | + if err != nil { |
| 149 | + t.Fatalf("Failed to create provider: %v", err) |
| 150 | + } |
| 151 | + |
| 152 | + for _, agentType := range pconfig.AllAgentTypes { |
| 153 | + modelWithPrefix := prov.ModelWithPrefix(agentType) |
| 154 | + model := prov.Model(agentType) |
| 155 | + |
| 156 | + if modelWithPrefix != model { |
| 157 | + t.Errorf("Agent type %v: without prefix, ModelWithPrefix (%q) should equal Model (%q)", |
| 158 | + agentType, modelWithPrefix, model) |
| 159 | + } |
| 160 | + } |
| 161 | +} |
| 162 | + |
| 163 | +func TestMissingAPIKey(t *testing.T) { |
| 164 | + cfg := &config.Config{ |
| 165 | + DeepSeekServerURL: "https://api.deepseek.com", |
| 166 | + } |
| 167 | + |
| 168 | + providerConfig, err := DefaultProviderConfig() |
| 169 | + if err != nil { |
| 170 | + t.Fatalf("Failed to create provider config: %v", err) |
| 171 | + } |
| 172 | + |
| 173 | + _, err = New(cfg, providerConfig) |
| 174 | + if err == nil { |
| 175 | + t.Fatal("Expected error when API key is missing") |
| 176 | + } |
| 177 | +} |
| 178 | + |
| 179 | +func TestGetUsage(t *testing.T) { |
| 180 | + cfg := &config.Config{ |
| 181 | + DeepSeekAPIKey: "test-key", |
| 182 | + DeepSeekServerURL: "https://api.deepseek.com", |
| 183 | + } |
| 184 | + |
| 185 | + providerConfig, err := DefaultProviderConfig() |
| 186 | + if err != nil { |
| 187 | + t.Fatalf("Failed to create provider config: %v", err) |
| 188 | + } |
| 189 | + |
| 190 | + prov, err := New(cfg, providerConfig) |
| 191 | + if err != nil { |
| 192 | + t.Fatalf("Failed to create provider: %v", err) |
| 193 | + } |
| 194 | + |
| 195 | + usage := prov.GetUsage(map[string]any{ |
| 196 | + "PromptTokens": 100, |
| 197 | + "CompletionTokens": 50, |
| 198 | + }) |
| 199 | + if usage.Input != 100 || usage.Output != 50 { |
| 200 | + t.Errorf("Expected usage input=100 output=50, got input=%d output=%d", usage.Input, usage.Output) |
| 201 | + } |
| 202 | +} |
0 commit comments