test(config): add migration tests for litellm provider
Some checks failed
CI / build-and-test (push) Failing after -32m22s
Some checks failed
CI / build-and-test (push) Failing after -32m22s
* Implement tests for migrating configuration from v1 to v2 for the litellm provider. * Validate the structure and values of the migrated configuration. * Ensure migration rejects newer versions of the configuration. fix(validate): enhance AI provider validation logic * Consolidate provider validation into a dedicated method. * Ensure at least one provider is specified and validate its type. * Check for required fields based on provider type. fix(mcpserver): update tool set to use new enrichment tool * Replace RetryMetadataTool with RetryEnrichmentTool in the ToolSet. fix(tools): refactor tools to use embedding and metadata runners * Update tools to utilize EmbeddingRunner and MetadataRunner instead of Provider. * Adjust method calls to align with the new runner interfaces.
This commit is contained in:
@@ -31,9 +31,8 @@ func TestResolvePathIgnoresBareYAMLExtension(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadAppliesEnvOverrides(t *testing.T) {
|
||||
configPath := filepath.Join(t.TempDir(), "test.yaml")
|
||||
if err := os.WriteFile(configPath, []byte(`
|
||||
const v2ConfigYAML = `
|
||||
version: 2
|
||||
server:
|
||||
port: 8080
|
||||
mcp:
|
||||
@@ -46,18 +45,30 @@ auth:
|
||||
database:
|
||||
url: "postgres://from-file"
|
||||
ai:
|
||||
provider: "litellm"
|
||||
providers:
|
||||
default:
|
||||
type: "litellm"
|
||||
base_url: "http://localhost:4000/v1"
|
||||
api_key: "file-key"
|
||||
embeddings:
|
||||
dimensions: 1536
|
||||
litellm:
|
||||
base_url: "http://localhost:4000/v1"
|
||||
api_key: "file-key"
|
||||
primary:
|
||||
provider: "default"
|
||||
model: "text-embed"
|
||||
metadata:
|
||||
primary:
|
||||
provider: "default"
|
||||
model: "gpt-4"
|
||||
search:
|
||||
default_limit: 10
|
||||
max_limit: 50
|
||||
logging:
|
||||
level: "info"
|
||||
`), 0o600); err != nil {
|
||||
`
|
||||
|
||||
func TestLoadAppliesEnvOverrides(t *testing.T) {
|
||||
configPath := filepath.Join(t.TempDir(), "test.yaml")
|
||||
if err := os.WriteFile(configPath, []byte(v2ConfigYAML), 0o600); err != nil {
|
||||
t.Fatalf("write config: %v", err)
|
||||
}
|
||||
|
||||
@@ -76,8 +87,8 @@ logging:
|
||||
if cfg.Database.URL != "postgres://from-env" {
|
||||
t.Fatalf("database url = %q, want env override", cfg.Database.URL)
|
||||
}
|
||||
if cfg.AI.LiteLLM.APIKey != "env-key" {
|
||||
t.Fatalf("litellm api key = %q, want env override", cfg.AI.LiteLLM.APIKey)
|
||||
if cfg.AI.Providers["default"].APIKey != "env-key" {
|
||||
t.Fatalf("litellm api key = %q, want env override", cfg.AI.Providers["default"].APIKey)
|
||||
}
|
||||
if cfg.Server.Port != 9090 {
|
||||
t.Fatalf("server port = %d, want 9090", cfg.Server.Port)
|
||||
@@ -90,10 +101,12 @@ logging:
|
||||
func TestLoadAppliesOllamaEnvOverrides(t *testing.T) {
|
||||
configPath := filepath.Join(t.TempDir(), "test.yaml")
|
||||
if err := os.WriteFile(configPath, []byte(`
|
||||
version: 2
|
||||
server:
|
||||
port: 8080
|
||||
mcp:
|
||||
path: "/mcp"
|
||||
session_timeout: "10m"
|
||||
auth:
|
||||
keys:
|
||||
- id: "test"
|
||||
@@ -101,15 +114,20 @@ auth:
|
||||
database:
|
||||
url: "postgres://from-file"
|
||||
ai:
|
||||
provider: "ollama"
|
||||
providers:
|
||||
local:
|
||||
type: "ollama"
|
||||
base_url: "http://localhost:11434/v1"
|
||||
api_key: "ollama"
|
||||
embeddings:
|
||||
model: "nomic-embed-text"
|
||||
dimensions: 768
|
||||
primary:
|
||||
provider: "local"
|
||||
model: "nomic-embed-text"
|
||||
metadata:
|
||||
model: "llama3.2"
|
||||
ollama:
|
||||
base_url: "http://localhost:11434/v1"
|
||||
api_key: "ollama"
|
||||
primary:
|
||||
provider: "local"
|
||||
model: "llama3.2"
|
||||
search:
|
||||
default_limit: 10
|
||||
max_limit: 50
|
||||
@@ -127,10 +145,77 @@ logging:
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
}
|
||||
|
||||
if cfg.AI.Ollama.BaseURL != "https://ollama.example.com/v1" {
|
||||
t.Fatalf("ollama base url = %q, want env override", cfg.AI.Ollama.BaseURL)
|
||||
p := cfg.AI.Providers["local"]
|
||||
if p.BaseURL != "https://ollama.example.com/v1" {
|
||||
t.Fatalf("ollama base url = %q, want env override", p.BaseURL)
|
||||
}
|
||||
if cfg.AI.Ollama.APIKey != "remote-key" {
|
||||
t.Fatalf("ollama api key = %q, want env override", cfg.AI.Ollama.APIKey)
|
||||
if p.APIKey != "remote-key" {
|
||||
t.Fatalf("ollama api key = %q, want env override", p.APIKey)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLoadMigratesV1Config(t *testing.T) {
|
||||
configPath := filepath.Join(t.TempDir(), "v1.yaml")
|
||||
v1 := `
|
||||
server:
|
||||
port: 8080
|
||||
mcp:
|
||||
path: "/mcp"
|
||||
session_timeout: "10m"
|
||||
auth:
|
||||
keys:
|
||||
- id: "test"
|
||||
value: "secret"
|
||||
database:
|
||||
url: "postgres://from-file"
|
||||
ai:
|
||||
provider: "litellm"
|
||||
embeddings:
|
||||
model: "text-embed"
|
||||
dimensions: 1536
|
||||
metadata:
|
||||
model: "gpt-4"
|
||||
temperature: 0.2
|
||||
fallback_models: ["gpt-3.5"]
|
||||
litellm:
|
||||
base_url: "http://localhost:4000/v1"
|
||||
api_key: "file-key"
|
||||
search:
|
||||
default_limit: 10
|
||||
max_limit: 50
|
||||
logging:
|
||||
level: "info"
|
||||
`
|
||||
if err := os.WriteFile(configPath, []byte(v1), 0o600); err != nil {
|
||||
t.Fatalf("write config: %v", err)
|
||||
}
|
||||
|
||||
cfg, _, err := Load(configPath)
|
||||
if err != nil {
|
||||
t.Fatalf("Load() error = %v", err)
|
||||
}
|
||||
|
||||
if cfg.Version != CurrentConfigVersion {
|
||||
t.Fatalf("version = %d, want %d", cfg.Version, CurrentConfigVersion)
|
||||
}
|
||||
if p, ok := cfg.AI.Providers["default"]; !ok || p.Type != "litellm" || p.APIKey != "file-key" {
|
||||
t.Fatalf("providers[default] = %+v, want litellm/file-key", p)
|
||||
}
|
||||
if cfg.AI.Embeddings.Primary.Model != "text-embed" || cfg.AI.Embeddings.Primary.Provider != "default" {
|
||||
t.Fatalf("embeddings.primary = %+v, want default/text-embed", cfg.AI.Embeddings.Primary)
|
||||
}
|
||||
if cfg.AI.Metadata.Primary.Model != "gpt-4" || cfg.AI.Metadata.Primary.Provider != "default" {
|
||||
t.Fatalf("metadata.primary = %+v, want default/gpt-4", cfg.AI.Metadata.Primary)
|
||||
}
|
||||
if len(cfg.AI.Metadata.Fallbacks) != 1 || cfg.AI.Metadata.Fallbacks[0].Model != "gpt-3.5" {
|
||||
t.Fatalf("metadata.fallbacks = %+v, want [default/gpt-3.5]", cfg.AI.Metadata.Fallbacks)
|
||||
}
|
||||
|
||||
entries, err := filepath.Glob(configPath + ".bak.*")
|
||||
if err != nil {
|
||||
t.Fatalf("glob backups: %v", err)
|
||||
}
|
||||
if len(entries) != 1 {
|
||||
t.Fatalf("backup files = %d, want 1", len(entries))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user