-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes_test.go
More file actions
296 lines (279 loc) · 7.82 KB
/
Copy pathtypes_test.go
File metadata and controls
296 lines (279 loc) · 7.82 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
package types
import (
"encoding/json"
"testing"
)
func TestParseStatusJSON(t *testing.T) {
tests := []struct {
name string
input string
verify func(t *testing.T, status StatusJSON)
}{
{
name: "model string parsing",
input: `{
"model": "Claude 3.5 Sonnet",
"session_id": "test-session",
"cwd": "/path/to/project"
}`,
verify: func(t *testing.T, status StatusJSON) {
if status.SessionID != "test-session" {
t.Errorf("Expected SessionID %q, got %q", "test-session", status.SessionID)
}
if status.Model.ID != "Claude 3.5 Sonnet" || status.Model.DisplayName != "Claude 3.5 Sonnet" {
t.Errorf("Expected Model string to be parsed into ID/DisplayName, got ID=%q, DisplayName=%q", status.Model.ID, status.Model.DisplayName)
}
},
},
{
name: "model object parsing",
input: `{
"model": {
"id": "claude-3-5-sonnet-20241022",
"display_name": "Claude 3.5 Sonnet"
}
}`,
verify: func(t *testing.T, status StatusJSON) {
if status.Model.ID != "claude-3-5-sonnet-20241022" {
t.Errorf("Expected Model.ID %q, got %q", "claude-3-5-sonnet-20241022", status.Model.ID)
}
if status.Model.DisplayName != "Claude 3.5 Sonnet" {
t.Errorf("Expected Model.DisplayName %q, got %q", "Claude 3.5 Sonnet", status.Model.DisplayName)
}
},
},
{
name: "quota map parsing",
input: `{
"quota": {
"gemini-5h": {
"remaining_fraction": 0.5019274,
"reset_time": "2026-06-20T11:27:27Z",
"reset_in_seconds": 8891
},
"3p-weekly": {
"remaining_fraction": 1.0,
"reset_time": "2026-06-27T08:58:32Z",
"reset_in_seconds": 604756
}
}
}`,
verify: func(t *testing.T, status StatusJSON) {
if status.Quota == nil {
t.Fatalf("Expected Quota map to be parsed, got nil")
}
g5h, ok := status.Quota["gemini-5h"]
if !ok {
t.Fatalf("Expected 'gemini-5h' key in Quota map")
}
if g5h.RemainingFraction == nil || *g5h.RemainingFraction != 0.5019274 {
t.Errorf("Expected gemini-5h RemainingFraction 0.5019274, got %v", g5h.RemainingFraction)
}
if g5h.ResetTime != "2026-06-20T11:27:27Z" {
t.Errorf("Expected gemini-5h ResetTime %q, got %q", "2026-06-20T11:27:27Z", g5h.ResetTime)
}
if g5h.ResetInSeconds == nil || *g5h.ResetInSeconds != 8891 {
t.Errorf("Expected gemini-5h ResetInSeconds 8891, got %v", g5h.ResetInSeconds)
}
p3w, ok := status.Quota["3p-weekly"]
if !ok {
t.Fatalf("Expected '3p-weekly' key in Quota map")
}
if p3w.RemainingFraction == nil || *p3w.RemainingFraction != 1.0 {
t.Errorf("Expected 3p-weekly RemainingFraction 1.0, got %v", p3w.RemainingFraction)
}
},
},
{
name: "sandbox info parsing",
input: `{
"sandbox": {
"enabled": true
}
}`,
verify: func(t *testing.T, status StatusJSON) {
if status.Sandbox == nil {
t.Fatalf("Expected Sandbox info to be parsed, got nil")
}
if status.Sandbox.Enabled == nil || !*status.Sandbox.Enabled {
t.Errorf("Expected Sandbox.Enabled to be true, got %v", status.Sandbox.Enabled)
}
},
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var status StatusJSON
err := json.Unmarshal([]byte(tc.input), &status)
if err != nil {
t.Fatalf("Failed to unmarshal StatusJSON: %v", err)
}
tc.verify(t, status)
})
}
}
func TestDefaultSettings(t *testing.T) {
settings := DefaultSettings()
t.Run("version and line count", func(t *testing.T) {
if settings.Version != 3 {
t.Errorf("Expected default settings version 3, got %d", settings.Version)
}
if len(settings.Lines) != 3 {
t.Errorf("Expected 3 default lines, got %d", len(settings.Lines))
}
})
t.Run("default widgets on line 0", func(t *testing.T) {
line0 := settings.Lines[0]
if len(line0) != 7 {
t.Fatalf("Expected 7 widgets on line 0, got %d", len(line0))
}
widgetTests := []struct {
name string
index int
expectedType string
expectedColor string
}{
{"first widget agent-state", 0, "agent-state", "brightGreen"},
{"second widget model", 1, "model", "brightMagenta"},
{"seventh widget sandbox", 6, "sandbox", "yellow"},
}
for _, tc := range widgetTests {
t.Run(tc.name, func(t *testing.T) {
w := line0[tc.index]
if w.Type != tc.expectedType || w.Color != tc.expectedColor {
t.Errorf("Expected widget at index %d to be %q (%q), got Type=%q, Color=%q",
tc.index, tc.expectedType, tc.expectedColor, w.Type, w.Color)
}
})
}
})
t.Run("powerline theme", func(t *testing.T) {
if settings.Powerline.Theme != "nord-aurora" {
t.Errorf("Expected default powerline theme %q, got %q", "nord-aurora", settings.Powerline.Theme)
}
})
}
func TestModelInfo_UnmarshalJSON_Invalid(t *testing.T) {
tests := []struct {
name string
input string
}{
{"array input", `["invalid", "array"]`},
{"numeric input", `12345`},
{"boolean input", `true`},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var m ModelInfo
err := m.UnmarshalJSON([]byte(tc.input))
if err == nil {
t.Errorf("Expected error for invalid ModelInfo input %q, got nil", tc.input)
}
})
}
}
func TestContextUsage_UnmarshalJSON(t *testing.T) {
tests := []struct {
name string
input string
expectedInput float64
expectedOutput float64
expectErr bool
}{
{
name: "valid numeric context usage",
input: `1234.5`,
expectedInput: 1234.5,
expectErr: false,
},
{
name: "valid object context usage",
input: `{"input_tokens": 100, "output_tokens": 50}`,
expectedInput: 100,
expectedOutput: 50,
expectErr: false,
},
{
name: "invalid array input",
input: `["invalid"]`,
expectErr: true,
},
{
name: "invalid string input",
input: `"string"`,
expectErr: true,
},
{
name: "invalid boolean input",
input: `true`,
expectErr: true,
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
var c ContextUsage
err := c.UnmarshalJSON([]byte(tc.input))
if tc.expectErr {
if err == nil {
t.Errorf("Expected error for invalid ContextUsage input %q, got nil", tc.input)
}
return
}
if err != nil {
t.Fatalf("Unexpected error unmarshaling ContextUsage: %v", err)
}
if c.InputTokens != tc.expectedInput || c.OutputTokens != tc.expectedOutput {
t.Errorf("Got InputTokens=%f, OutputTokens=%f; expected %f, %f", c.InputTokens, c.OutputTokens, tc.expectedInput, tc.expectedOutput)
}
})
}
}
func TestRenderContext_Getters(t *testing.T) {
tests := []struct {
name string
ctx RenderContext
expectedCwd string
expectedWorkCur string
expectedWorkProj string
}{
{
name: "with workspace and cwd",
ctx: RenderContext{
Data: StatusJSON{
CWD: "/cwd/path",
Workspace: &WorkspaceInfo{
CurrentDir: "/workspace/current",
ProjectDir: "/workspace/project",
},
},
},
expectedCwd: "/cwd/path",
expectedWorkCur: "/workspace/current",
expectedWorkProj: "/workspace/project",
},
{
name: "nil workspace",
ctx: RenderContext{
Data: StatusJSON{
CWD: "/cwd/path",
},
},
expectedCwd: "/cwd/path",
expectedWorkCur: "",
expectedWorkProj: "",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
if tc.ctx.GetCwd() != tc.expectedCwd {
t.Errorf("Expected GetCwd() %q, got %q", tc.expectedCwd, tc.ctx.GetCwd())
}
if tc.ctx.GetWorkspaceCurrentDir() != tc.expectedWorkCur {
t.Errorf("Expected GetWorkspaceCurrentDir() %q, got %q", tc.expectedWorkCur, tc.ctx.GetWorkspaceCurrentDir())
}
if tc.ctx.GetWorkspaceProjectDir() != tc.expectedWorkProj {
t.Errorf("Expected GetWorkspaceProjectDir() %q, got %q", tc.expectedWorkProj, tc.ctx.GetWorkspaceProjectDir())
}
})
}
}