From 8db6d02dcf43977cc956c7eabfd7d0a9fa7a6c67 Mon Sep 17 00:00:00 2001 From: ZanzyTHEbar Date: Wed, 18 Feb 2026 13:22:16 +0000 Subject: [PATCH] test(config): add memory config validation tests --- pkg/config/config_test.go | 92 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/pkg/config/config_test.go b/pkg/config/config_test.go index a1f73f0b3..87f966c42 100644 --- a/pkg/config/config_test.go +++ b/pkg/config/config_test.go @@ -4,6 +4,7 @@ import ( "os" "path/filepath" "runtime" + "strings" "testing" ) @@ -228,6 +229,97 @@ func TestLoadConfig_OpenAIWebSearchDefaultsTrueWhenUnset(t *testing.T) { } } +func TestValidate_MemoryConfig(t *testing.T) { + tests := []struct { + name string + mutate func(*Config) + wantWarn string + }{ + { + name: "sync_url without auth_token", + mutate: func(c *Config) { + c.Memory.Enabled = true + c.Memory.Sync.SyncURL = "libsql://test.turso.io" + }, + wantWarn: "auth_token is empty", + }, + { + name: "invalid embedding dims", + mutate: func(c *Config) { + c.Memory.Enabled = true + c.Memory.EmbeddingDims = 10 + }, + wantWarn: "expected 64-4096", + }, + { + name: "unknown embedding provider", + mutate: func(c *Config) { + c.Memory.Enabled = true + c.Memory.Embedding.Provider = "nonexistent" + }, + wantWarn: "unknown", + }, + { + name: "openai without key", + mutate: func(c *Config) { + c.Memory.Enabled = true + c.Memory.Embedding.Provider = "openai" + }, + wantWarn: "no API key found", + }, + { + name: "valid openai with fallback key", + mutate: func(c *Config) { + c.Memory.Enabled = true + c.Memory.Embedding.Provider = "openai" + c.Providers.OpenAI.APIKey = "sk-test" + }, + wantWarn: "", + }, + { + name: "disabled memory skips all checks", + mutate: func(c *Config) { + c.Memory.Enabled = false + c.Memory.EmbeddingDims = -999 + c.Memory.Sync.SyncURL = "bad" + }, + wantWarn: "", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cfg := DefaultConfig() + tt.mutate(cfg) + warnings := cfg.Validate() + + if tt.wantWarn == "" { + for _, w := range warnings { + if containsMemoryWarning(w) { + t.Errorf("expected no memory warnings, got: %s", w) + } + } + return + } + + found := false + for _, w := range warnings { + if strings.Contains(w, tt.wantWarn) { + found = true + break + } + } + if !found { + t.Errorf("expected warning containing %q, got: %v", tt.wantWarn, warnings) + } + }) + } +} + +func containsMemoryWarning(s string) bool { + return strings.Contains(s, "memory.") +} + func TestLoadConfig_OpenAIWebSearchCanBeDisabled(t *testing.T) { dir := t.TempDir() configPath := filepath.Join(dir, "config.json")