Files
ds2api/internal/config/validation_test.go
CJACK c09a4b51a5 feat: 新增 thinking 注入配置支持,扩展设置管理与前端交互
新增 promptcompat 和 OpenAI shared 层的 thinking 注入逻辑,
完善配置系统的编解码与校验,更新设置管理 API 与前端 UI。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-26 13:35:20 +08:00

86 lines
2.1 KiB
Go

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: "history split",
cfg: Config{HistorySplit: HistorySplitConfig{
TriggerAfterTurns: intPtr(0),
}},
want: "history_split.trigger_after_turns",
},
{
name: "current input file",
cfg: Config{CurrentInputFile: CurrentInputFileConfig{MinChars: -1}},
want: "current_input_file.min_chars",
},
{
name: "split modes mutually exclusive",
cfg: Config{
HistorySplit: HistorySplitConfig{Enabled: boolPtr(true)},
CurrentInputFile: CurrentInputFileConfig{Enabled: boolPtr(true)},
},
want: "cannot both be true",
},
}
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)
}
}
func intPtr(v int) *int { return &v }
func boolPtr(v bool) *bool { return &v }