@@ -0,0 +1,124 @@
1+package provider
2+
3+import (
4+ "testing"
5+)
6+
7+// TestProviderNameFromConfig verifies that provider names come from config keys,
8+// not hardcoded values in factory implementations.
9+func TestProviderNameFromConfig(t *testing.T) {
10+ tests := []struct {
11+ name string
12+ configName string
13+ factoryFunc func(name string) ProviderFactory
14+ expectedName string
15+ }{
16+ {
17+ name: "Ollama with custom name",
18+ configName: "ollama-qwen",
19+ factoryFunc: func(name string) ProviderFactory {
20+ return NewOllamaFactory(name, "http://localhost:11434", 1.0, 2)
21+ },
22+ expectedName: "ollama-qwen",
23+ },
24+ {
25+ name: "Ollama with another custom name",
26+ configName: "ollama-llama",
27+ factoryFunc: func(name string) ProviderFactory {
28+ return NewOllamaFactory(name, "http://localhost:11434", 1.0, 2)
29+ },
30+ expectedName: "ollama-llama",
31+ },
32+ {
33+ name: "OpenCode with custom name",
34+ configName: "zen-nano",
35+ factoryFunc: func(name string) ProviderFactory {
36+ return NewOpenCodeFactory(name, "https://opencode.ai/zen/v1", "test-key", 5.0, 3)
37+ },
38+ expectedName: "zen-nano",
39+ },
40+ {
41+ name: "OpenCode with another custom name",
42+ configName: "zen-pickle",
43+ factoryFunc: func(name string) ProviderFactory {
44+ return NewOpenCodeFactory(name, "https://opencode.ai/zen/v1", "test-key", 5.0, 3)
45+ },
46+ expectedName: "zen-pickle",
47+ },
48+ {
49+ name: "OpenCode with default name",
50+ configName: "opencode_zen",
51+ factoryFunc: func(name string) ProviderFactory {
52+ return NewOpenCodeFactory(name, "https://opencode.ai/zen/v1", "test-key", 5.0, 3)
53+ },
54+ expectedName: "opencode_zen",
55+ },
56+ }
57+
58+ for _, tt := range tests {
59+ t.Run(tt.name, func(t *testing.T) {
60+ factory := tt.factoryFunc(tt.configName)
61+
62+ // Verify factory name matches config name
63+ if factory.Name() != tt.expectedName {
64+ t.Errorf("Factory.Name() = %q, want %q", factory.Name(), tt.expectedName)
65+ }
66+
67+ // Create a provider instance and verify it also returns the correct name
68+ provider := factory.Create("test-model", 0.7)
69+ if provider.Name() != tt.expectedName {
70+ t.Errorf("Provider.Name() = %q, want %q", provider.Name(), tt.expectedName)
71+ }
72+ })
73+ }
74+}
75+
76+// TestProviderNameNotHardcoded verifies that different config names produce
77+// different provider names, proving the name is not hardcoded.
78+func TestProviderNameNotHardcoded(t *testing.T) {
79+ // Create two Ollama factories with different names
80+ factory1 := NewOllamaFactory("ollama-qwen", "http://localhost:11434", 1.0, 2)
81+ factory2 := NewOllamaFactory("ollama-llama", "http://localhost:11434", 1.0, 2)
82+
83+ if factory1.Name() == factory2.Name() {
84+ t.Errorf("Different config names should produce different factory names, both returned %q", factory1.Name())
85+ }
86+
87+ // Create providers from the factories
88+ provider1 := factory1.Create("qwen2.5:7b", 0.7)
89+ provider2 := factory2.Create("llama3.2:3b", 0.7)
90+
91+ if provider1.Name() == provider2.Name() {
92+ t.Errorf("Different config names should produce different provider names, both returned %q", provider1.Name())
93+ }
94+
95+ // Verify each provider returns its expected name
96+ if provider1.Name() != "ollama-qwen" {
97+ t.Errorf("provider1.Name() = %q, want %q", provider1.Name(), "ollama-qwen")
98+ }
99+ if provider2.Name() != "ollama-llama" {
100+ t.Errorf("provider2.Name() = %q, want %q", provider2.Name(), "ollama-llama")
101+ }
102+
103+ // Same test for OpenCode providers
104+ factory3 := NewOpenCodeFactory("zen-nano", "https://opencode.ai/zen/v1", "key", 5.0, 3)
105+ factory4 := NewOpenCodeFactory("zen-pickle", "https://opencode.ai/zen/v1", "key", 5.0, 3)
106+
107+ if factory3.Name() == factory4.Name() {
108+ t.Errorf("Different config names should produce different factory names, both returned %q", factory3.Name())
109+ }
110+
111+ provider3 := factory3.Create("gpt-5-nano", 0.7)
112+ provider4 := factory4.Create("big-pickle", 0.7)
113+
114+ if provider3.Name() == provider4.Name() {
115+ t.Errorf("Different config names should produce different provider names, both returned %q", provider3.Name())
116+ }
117+
118+ if provider3.Name() != "zen-nano" {
119+ t.Errorf("provider3.Name() = %q, want %q", provider3.Name(), "zen-nano")
120+ }
121+ if provider4.Name() != "zen-pickle" {
122+ t.Errorf("provider4.Name() = %q, want %q", provider4.Name(), "zen-pickle")
123+ }
124+}