File size: 1,606 Bytes
8d3471e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
package config

import (
	"strings"
	"testing"
)

func TestValidateConfigRejectsInvalidValues(t *testing.T) {
	tests := []struct {
		name string
		cfg  Config
		want string
	}{
		{
			name: "admin",
			cfg:  Config{Admin: AdminConfig{JWTExpireHours: 721}},
			want: "admin.jwt_expire_hours",
		},
		{
			name: "runtime relation",
			cfg: Config{Runtime: RuntimeConfig{
				AccountMaxInflight: 8,
				GlobalMaxInflight:  4,
			}},
			want: "runtime.global_max_inflight must be >= runtime.account_max_inflight",
		},
		{
			name: "responses",
			cfg:  Config{Responses: ResponsesConfig{StoreTTLSeconds: 10}},
			want: "responses.store_ttl_seconds",
		},
		{
			name: "embeddings",
			cfg:  Config{Embeddings: EmbeddingsConfig{Provider: "   "}},
			want: "embeddings.provider",
		},
		{
			name: "auto delete",
			cfg:  Config{AutoDelete: AutoDeleteConfig{Mode: "maybe"}},
			want: "auto_delete.mode",
		},
		{
			name: "current input file",
			cfg:  Config{CurrentInputFile: CurrentInputFileConfig{MinChars: -1}},
			want: "current_input_file.min_chars",
		},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			err := ValidateConfig(tc.cfg)
			if err == nil {
				t.Fatal("expected validation error")
			}
			if !strings.Contains(err.Error(), tc.want) {
				t.Fatalf("expected %q in error, got %v", tc.want, err)
			}
		})
	}
}

func TestValidateConfigAcceptsLegacyAutoDeleteSessions(t *testing.T) {
	if err := ValidateConfig(Config{AutoDelete: AutoDeleteConfig{Sessions: true}}); err != nil {
		t.Fatalf("expected legacy auto_delete.sessions config to remain valid, got %v", err)
	}
}