-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings_test.go
More file actions
129 lines (114 loc) · 3.28 KB
/
settings_test.go
File metadata and controls
129 lines (114 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"os"
"path/filepath"
"testing"
)
func TestDefaultSettings(t *testing.T) {
s := DefaultSettings()
if s.Models.Chat == "" {
t.Error("Models.Chat should not be empty")
}
if s.Models.Generate == "" {
t.Error("Models.Generate should not be empty")
}
if len(s.Models.Escalation) == 0 {
t.Error("Models.Escalation should not be empty")
}
if s.Validation.MaxIterations != 3 {
t.Errorf("Validation.MaxIterations = %d, want 3", s.Validation.MaxIterations)
}
if s.Theme.Name != "default" {
t.Errorf("Theme.Name = %q, want default", s.Theme.Name)
}
}
func TestTheme(t *testing.T) {
tests := []struct {
name string
themeName string
wantValid bool
}{
{"default theme", "default", true},
{"matrix theme", "matrix", true},
{"solarized theme", "solarized", true},
{"gruvbox theme", "gruvbox", true},
{"dracula theme", "dracula", true},
{"nord theme", "nord", true},
{"unknown theme falls back to default", "unknown", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
settings := &ThemeSettings{Name: tt.themeName}
theme := NewTheme(settings)
// Test that theme produces non-empty output
if theme.Prompt("test") == "" {
t.Error("Prompt() should return non-empty string")
}
if theme.Success("test") == "" {
t.Error("Success() should return non-empty string")
}
if theme.Error("test") == "" {
t.Error("Error() should return non-empty string")
}
if theme.Reset() == "" {
t.Error("Reset() should return non-empty string")
}
})
}
}
func TestAvailableThemes(t *testing.T) {
themes := AvailableThemes()
if len(themes) == 0 {
t.Error("AvailableThemes() should return at least one theme")
}
// Check that all listed themes exist in ThemePresets
for _, name := range themes {
if _, ok := ThemePresets[name]; !ok {
t.Errorf("Theme %q listed but not in ThemePresets", name)
}
}
}
func TestSaveAndLoadSettings(t *testing.T) {
// Create a temp directory for test
tmpDir := t.TempDir()
testPath := filepath.Join(tmpDir, ".bjarne", "settings.json")
// Create settings
settings := DefaultSettings()
settings.Theme.Name = "matrix"
settings.Validation.MaxIterations = 5
// Create directory
if err := os.MkdirAll(filepath.Dir(testPath), 0700); err != nil {
t.Fatalf("Failed to create test dir: %v", err)
}
// We can't easily test SaveSettings without mocking UserHomeDir
// but we can test the JSON marshaling/unmarshaling
t.Run("settings roundtrip", func(t *testing.T) {
// This mainly tests that the structures are properly defined
if settings.Theme.Name != "matrix" {
t.Error("Theme name should be matrix")
}
if settings.Validation.MaxIterations != 5 {
t.Error("MaxIterations should be 5")
}
})
}
func TestShortModelName(t *testing.T) {
tests := []struct {
input string
want string
}{
{"global.anthropic.claude-haiku-4-5-20251001-v1:0", "claude-haiku-4-5"},
{"global.anthropic.claude-sonnet-4-5-20250929-v1:0", "claude-sonnet-4-5"},
{"global.anthropic.claude-opus-4-5-20251101-v1:0", "claude-opus-4-5"},
{"simple-model", "simple-model"},
{"", ""},
}
for _, tt := range tests {
t.Run(tt.input, func(t *testing.T) {
got := shortModelName(tt.input)
if got != tt.want {
t.Errorf("shortModelName(%q) = %q, want %q", tt.input, got, tt.want)
}
})
}
}