- Added file upload handler to process both multipart and raw file uploads. - Implemented parsing logic for upload requests, including handling file metadata. - Introduced SaveFileDecodedInput structure for handling decoded file uploads. - Created unit tests for file upload parsing and validation. feat: add metadata retry configuration and functionality - Introduced MetadataRetryConfig to the application configuration. - Implemented MetadataRetryer to handle retrying metadata extraction for thoughts. - Added new tool for retrying failed metadata extractions. - Updated thought metadata structure to include status and timestamps for metadata processing. fix: enhance metadata normalization and error handling - Updated metadata normalization functions to track status and errors. - Improved handling of metadata extraction failures during thought updates and captures. - Ensured that metadata status is correctly set during various operations. refactor: streamline file saving logic in FilesTool - Refactored Save method in FilesTool to utilize new SaveDecoded method. - Simplified project and thought ID resolution logic during file saving.
124 lines
2.9 KiB
Go
124 lines
2.9 KiB
Go
package config
|
|
|
|
import "testing"
|
|
|
|
func validConfig() Config {
|
|
return Config{
|
|
Server: ServerConfig{Port: 8080},
|
|
MCP: MCPConfig{Path: "/mcp"},
|
|
Auth: AuthConfig{
|
|
Keys: []APIKey{{ID: "test", Value: "secret"}},
|
|
},
|
|
Database: DatabaseConfig{URL: "postgres://example"},
|
|
AI: AIConfig{
|
|
Provider: "litellm",
|
|
Embeddings: AIEmbeddingConfig{
|
|
Dimensions: 1536,
|
|
},
|
|
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",
|
|
},
|
|
},
|
|
Search: SearchConfig{DefaultLimit: 10, MaxLimit: 50},
|
|
Logging: LoggingConfig{Level: "info"},
|
|
}
|
|
}
|
|
|
|
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 TestValidateRejectsInvalidProvider(t *testing.T) {
|
|
cfg := validConfig()
|
|
cfg.AI.Provider = "unknown"
|
|
|
|
if err := cfg.Validate(); err == nil {
|
|
t.Fatal("Validate() error = nil, want error for unsupported provider")
|
|
}
|
|
}
|
|
|
|
func TestValidateRejectsEmptyAuthKeyValue(t *testing.T) {
|
|
cfg := validConfig()
|
|
cfg.Auth.Keys[0].Value = ""
|
|
|
|
if err := cfg.Validate(); err == nil {
|
|
t.Fatal("Validate() error = nil, want error for empty auth key value")
|
|
}
|
|
}
|
|
|
|
func TestValidateAcceptsOAuthClients(t *testing.T) {
|
|
cfg := validConfig()
|
|
cfg.Auth = AuthConfig{
|
|
OAuth: OAuthConfig{
|
|
Clients: []OAuthClient{{
|
|
ID: "oauth-client",
|
|
ClientID: "client-id",
|
|
ClientSecret: "client-secret",
|
|
}},
|
|
},
|
|
}
|
|
|
|
if err := cfg.Validate(); err != nil {
|
|
t.Fatalf("Validate() error = %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidateAcceptsBothAuthMethods(t *testing.T) {
|
|
cfg := validConfig()
|
|
cfg.Auth = AuthConfig{
|
|
Keys: []APIKey{{ID: "key1", Value: "secret"}},
|
|
OAuth: OAuthConfig{
|
|
Clients: []OAuthClient{{
|
|
ID: "oauth-client",
|
|
ClientID: "client-id",
|
|
ClientSecret: "client-secret",
|
|
}},
|
|
},
|
|
}
|
|
|
|
if err := cfg.Validate(); err != nil {
|
|
t.Fatalf("Validate() error = %v", err)
|
|
}
|
|
}
|
|
|
|
func TestValidateRejectsEmptyAuth(t *testing.T) {
|
|
cfg := validConfig()
|
|
cfg.Auth = AuthConfig{}
|
|
|
|
if err := cfg.Validate(); err == nil {
|
|
t.Fatal("Validate() error = nil, want error when neither auth.keys nor auth.oauth.clients is configured")
|
|
}
|
|
}
|
|
|
|
func TestValidateRejectsInvalidMetadataRetryConfig(t *testing.T) {
|
|
cfg := validConfig()
|
|
cfg.MetadataRetry.Enabled = true
|
|
cfg.MetadataRetry.MaxPerRun = 0
|
|
|
|
if err := cfg.Validate(); err == nil {
|
|
t.Fatal("Validate() error = nil, want error for invalid metadata retry config")
|
|
}
|
|
}
|