@@ -27,6 +27,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
27
27
defaultName = "default-name"
28
28
defaultURL = "default-url"
29
29
defaultModel = "default-model"
30
+ defaultRole = "default-role"
30
31
defaultApiKey = "default-api-key"
31
32
defaultThread = "default-thread"
32
33
defaultCompletionsPath = "default-completions-path"
@@ -55,6 +56,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
55
56
CompletionsPath : defaultCompletionsPath ,
56
57
ModelsPath : defaultModelsPath ,
57
58
OmitHistory : defaultOmitHistory ,
59
+ Role : defaultRole ,
58
60
Thread : defaultThread ,
59
61
}
60
62
@@ -87,6 +89,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
87
89
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
88
90
Expect (subject .Config .Name ).To (Equal (defaultName ))
89
91
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
92
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
90
93
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
91
94
})
92
95
it ("gives precedence to the user provided model" , func () {
@@ -105,6 +108,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
105
108
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
106
109
Expect (subject .Config .Name ).To (Equal (defaultName ))
107
110
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
111
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
108
112
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
109
113
})
110
114
it ("gives precedence to the user provided name" , func () {
@@ -123,6 +127,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
123
127
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
124
128
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
125
129
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
130
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
126
131
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
127
132
})
128
133
it ("gives precedence to the user provided max-tokens" , func () {
@@ -141,6 +146,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
141
146
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
142
147
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
143
148
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
149
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
144
150
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
145
151
146
152
})
@@ -160,6 +166,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
160
166
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
161
167
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
162
168
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
169
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
163
170
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
164
171
})
165
172
it ("gives precedence to the user provided completions-path" , func () {
@@ -178,6 +185,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
178
185
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
179
186
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
180
187
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
188
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
181
189
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
182
190
})
183
191
it ("gives precedence to the user provided models-path" , func () {
@@ -196,6 +204,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
196
204
Expect (subject .Config .ModelsPath ).To (Equal (modelsPath ))
197
205
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
198
206
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
207
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
199
208
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
200
209
})
201
210
it ("gives precedence to the user provided api-key" , func () {
@@ -214,6 +223,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
214
223
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
215
224
Expect (subject .Config .APIKey ).To (Equal (apiKey ))
216
225
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
226
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
217
227
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
218
228
})
219
229
it ("gives precedence to the user provided omit-history" , func () {
@@ -231,6 +241,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
231
241
Expect (subject .Config .CompletionsPath ).To (Equal (defaultCompletionsPath ))
232
242
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
233
243
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
244
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
234
245
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
235
246
Expect (subject .Config .OmitHistory ).To (Equal (omitHistory ))
236
247
})
@@ -250,8 +261,28 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
250
261
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
251
262
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
252
263
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
264
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
253
265
Expect (subject .Config .Thread ).To (Equal (userThread ))
254
266
})
267
+ it ("gives precedence to the user provided role" , func () {
268
+ userRole := "user-role"
269
+
270
+ mockConfigStore .EXPECT ().ReadDefaults ().Return (defaultConfig ).Times (1 )
271
+ mockConfigStore .EXPECT ().Read ().Return (types.Config {Role : userRole }, nil ).Times (1 )
272
+
273
+ subject := configmanager .New (mockConfigStore ).WithEnvironment ()
274
+
275
+ Expect (subject .Config .Name ).To (Equal (defaultName ))
276
+ Expect (subject .Config .Model ).To (Equal (defaultModel ))
277
+ Expect (subject .Config .MaxTokens ).To (Equal (defaultMaxTokens ))
278
+ Expect (subject .Config .URL ).To (Equal (defaultURL ))
279
+ Expect (subject .Config .CompletionsPath ).To (Equal (defaultCompletionsPath ))
280
+ Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
281
+ Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
282
+ Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
283
+ Expect (subject .Config .Thread ).To (Equal (defaultThread ))
284
+ Expect (subject .Config .Role ).To (Equal (userRole ))
285
+ })
255
286
it ("gives precedence to the OMIT_HISTORY environment variable" , func () {
256
287
var (
257
288
environmentValue = true
@@ -272,6 +303,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
272
303
Expect (subject .Config .CompletionsPath ).To (Equal (defaultCompletionsPath ))
273
304
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
274
305
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
306
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
275
307
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
276
308
Expect (subject .Config .OmitHistory ).To (Equal (environmentValue ))
277
309
})
@@ -296,8 +328,33 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
296
328
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
297
329
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
298
330
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
331
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
299
332
Expect (subject .Config .Thread ).To (Equal (environmentValue ))
300
333
})
334
+ it ("gives precedence to the ROLE environment variable" , func () {
335
+ var (
336
+ environmentValue = "env-role"
337
+ configValue = "conf-role"
338
+ )
339
+
340
+ Expect (os .Setenv (envPrefix + "ROLE" , environmentValue )).To (Succeed ())
341
+
342
+ mockConfigStore .EXPECT ().ReadDefaults ().Return (defaultConfig ).Times (1 )
343
+ mockConfigStore .EXPECT ().Read ().Return (types.Config {Role : configValue }, nil ).Times (1 )
344
+
345
+ subject := configmanager .New (mockConfigStore ).WithEnvironment ()
346
+
347
+ Expect (subject .Config .Name ).To (Equal (defaultName ))
348
+ Expect (subject .Config .Model ).To (Equal (defaultModel ))
349
+ Expect (subject .Config .MaxTokens ).To (Equal (defaultMaxTokens ))
350
+ Expect (subject .Config .URL ).To (Equal (defaultURL ))
351
+ Expect (subject .Config .CompletionsPath ).To (Equal (defaultCompletionsPath ))
352
+ Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
353
+ Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
354
+ Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
355
+ Expect (subject .Config .Thread ).To (Equal (defaultThread ))
356
+ Expect (subject .Config .Role ).To (Equal (environmentValue ))
357
+ })
301
358
it ("gives precedence to the API_KEY environment variable" , func () {
302
359
var (
303
360
environmentKey = "environment-api-key"
@@ -319,6 +376,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
319
376
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
320
377
Expect (subject .Config .APIKey ).To (Equal (environmentKey ))
321
378
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
379
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
322
380
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
323
381
})
324
382
it ("gives precedence to the MODEL environment variable" , func () {
@@ -342,6 +400,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
342
400
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
343
401
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
344
402
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
403
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
345
404
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
346
405
})
347
406
it ("gives precedence to the MAX_TOKENS environment variable" , func () {
@@ -365,6 +424,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
365
424
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
366
425
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
367
426
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
427
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
368
428
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
369
429
})
370
430
it ("gives precedence to the URL environment variable" , func () {
@@ -388,6 +448,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
388
448
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
389
449
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
390
450
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
451
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
391
452
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
392
453
})
393
454
it ("gives precedence to the COMPLETIONS_PATH environment variable" , func () {
@@ -411,6 +472,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
411
472
Expect (subject .Config .ModelsPath ).To (Equal (defaultModelsPath ))
412
473
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
413
474
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
475
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
414
476
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
415
477
})
416
478
it ("gives precedence to the MODELS_PATH environment variable" , func () {
@@ -434,6 +496,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
434
496
Expect (subject .Config .ModelsPath ).To (Equal (envModelsPath ))
435
497
Expect (subject .Config .APIKey ).To (Equal (defaultApiKey ))
436
498
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
499
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
437
500
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
438
501
})
439
502
})
@@ -455,6 +518,7 @@ func testConfig(t *testing.T, when spec.G, it spec.S) {
455
518
Expect (result ).To (ContainSubstring (defaultModelsPath ))
456
519
Expect (result ).To (ContainSubstring (fmt .Sprintf ("%d" , defaultMaxTokens )))
457
520
Expect (subject .Config .OmitHistory ).To (Equal (defaultOmitHistory ))
521
+ Expect (subject .Config .Role ).To (Equal (defaultRole ))
458
522
Expect (subject .Config .Thread ).To (Equal (defaultThread ))
459
523
})
460
524
})
@@ -499,4 +563,5 @@ func cleanEnv(envPrefix string) {
499
563
Expect (os .Unsetenv (envPrefix + "MODELS_PATH" )).To (Succeed ())
500
564
Expect (os .Unsetenv (envPrefix + "OMIT_HISTORY" )).To (Succeed ())
501
565
Expect (os .Unsetenv (envPrefix + "THREAD" )).To (Succeed ())
566
+ Expect (os .Unsetenv (envPrefix + "ROLE" )).To (Succeed ())
502
567
}
0 commit comments