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:
@@ -7,28 +7,23 @@ import (
|
||||
|
||||
func validConfig() Config {
|
||||
return Config{
|
||||
Server: ServerConfig{Port: 8080},
|
||||
MCP: MCPConfig{Path: "/mcp", SessionTimeout: 10 * time.Minute},
|
||||
Version: CurrentConfigVersion,
|
||||
Server: ServerConfig{Port: 8080},
|
||||
MCP: MCPConfig{Path: "/mcp", SessionTimeout: 10 * time.Minute},
|
||||
Auth: AuthConfig{
|
||||
Keys: []APIKey{{ID: "test", Value: "secret"}},
|
||||
},
|
||||
Database: DatabaseConfig{URL: "postgres://example"},
|
||||
AI: AIConfig{
|
||||
Provider: "litellm",
|
||||
Embeddings: AIEmbeddingConfig{
|
||||
Providers: map[string]ProviderConfig{
|
||||
"default": {Type: "litellm", BaseURL: "http://localhost:4000/v1", APIKey: "key"},
|
||||
},
|
||||
Embeddings: EmbeddingsRoleConfig{
|
||||
Dimensions: 1536,
|
||||
Primary: RoleTarget{Provider: "default", Model: "text-embed"},
|
||||
},
|
||||
LiteLLM: LiteLLMConfig{
|
||||
BaseURL: "http://localhost:4000/v1",
|
||||
APIKey: "key",
|
||||
},
|
||||
Ollama: OllamaConfig{
|
||||
BaseURL: "http://localhost:11434/v1",
|
||||
APIKey: "ollama",
|
||||
},
|
||||
OpenRouter: OpenRouterAIConfig{
|
||||
BaseURL: "https://openrouter.ai/api/v1",
|
||||
APIKey: "key",
|
||||
Metadata: MetadataRoleConfig{
|
||||
Primary: RoleTarget{Provider: "default", Model: "gpt-4"},
|
||||
},
|
||||
},
|
||||
Search: SearchConfig{DefaultLimit: 10, MaxLimit: 50},
|
||||
@@ -36,29 +31,44 @@ func validConfig() Config {
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateAcceptsSupportedProviders(t *testing.T) {
|
||||
cfg := validConfig()
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Fatalf("Validate litellm error = %v", err)
|
||||
}
|
||||
|
||||
cfg.AI.Provider = "ollama"
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Fatalf("Validate ollama error = %v", err)
|
||||
}
|
||||
|
||||
cfg.AI.Provider = "openrouter"
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Fatalf("Validate openrouter error = %v", err)
|
||||
func TestValidateAcceptsSupportedProviderTypes(t *testing.T) {
|
||||
for _, providerType := range []string{"litellm", "ollama", "openrouter"} {
|
||||
cfg := validConfig()
|
||||
p := cfg.AI.Providers["default"]
|
||||
p.Type = providerType
|
||||
cfg.AI.Providers["default"] = p
|
||||
if err := cfg.Validate(); err != nil {
|
||||
t.Fatalf("Validate %s error = %v", providerType, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRejectsInvalidProvider(t *testing.T) {
|
||||
func TestValidateRejectsInvalidProviderType(t *testing.T) {
|
||||
cfg := validConfig()
|
||||
cfg.AI.Provider = "unknown"
|
||||
p := cfg.AI.Providers["default"]
|
||||
p.Type = "unknown"
|
||||
cfg.AI.Providers["default"] = p
|
||||
|
||||
if err := cfg.Validate(); err == nil {
|
||||
t.Fatal("Validate() error = nil, want error for unsupported provider")
|
||||
t.Fatal("Validate() error = nil, want error for unsupported provider type")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRejectsChainWithUnknownProvider(t *testing.T) {
|
||||
cfg := validConfig()
|
||||
cfg.AI.Metadata.Primary = RoleTarget{Provider: "does-not-exist", Model: "x"}
|
||||
|
||||
if err := cfg.Validate(); err == nil {
|
||||
t.Fatal("Validate() error = nil, want error for chain referencing unknown provider")
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateRejectsEmptyProviders(t *testing.T) {
|
||||
cfg := validConfig()
|
||||
cfg.AI.Providers = map[string]ProviderConfig{}
|
||||
|
||||
if err := cfg.Validate(); err == nil {
|
||||
t.Fatal("Validate() error = nil, want error for empty providers")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user