Files
audita/internal/framework/llm/effective_config_test.go

107 lines
3.2 KiB
Go

package llm
import (
"testing"
"time"
"gitea.maximumdirect.net/eric/audita/internal/core/config"
)
func TestResolvePrimaryConfig(t *testing.T) {
cfg := config.Default()
cfg.PrimaryLLM.APIKey = " primary-key "
cfg.PrimaryLLM.Model = " model-x "
cfg.PrimaryLLM.BaseURL = " https://example.test/v1 "
cfg.PrimaryLLM.TimeoutSeconds = 42
cfg.PrimaryLLM.MaxRetries = 7
cfg.TotalLLMConcurrency = 3
cfg.ProposalLLMConcurrency = 3
effective := ResolvePrimaryConfig(cfg)
if effective.APIKey != "primary-key" {
t.Fatalf("unexpected api key: %q", effective.APIKey)
}
if effective.Model != "model-x" {
t.Fatalf("unexpected model: %q", effective.Model)
}
if effective.BaseURL != "https://example.test/v1" {
t.Fatalf("unexpected base url: %q", effective.BaseURL)
}
if effective.RequestTimeout != 42*time.Second {
t.Fatalf("unexpected timeout: %s", effective.RequestTimeout)
}
if effective.MaxRetries != 7 {
t.Fatalf("unexpected max retries: %d", effective.MaxRetries)
}
if effective.Concurrency != 3 {
t.Fatalf("unexpected concurrency: %d", effective.Concurrency)
}
}
func TestResolveValidationConfigInheritsPrimaryWhenUnset(t *testing.T) {
cfg := config.Default()
cfg.PrimaryLLM.APIKey = "primary-key"
cfg.PrimaryLLM.Model = "primary-model"
cfg.PrimaryLLM.BaseURL = "https://primary.example/v1"
cfg.PrimaryLLM.TimeoutSeconds = 90
cfg.PrimaryLLM.MaxRetries = 4
cfg.TotalLLMConcurrency = 2
cfg.ProposalLLMConcurrency = 2
effective := ResolveValidationConfig(cfg)
if effective.APIKey != "primary-key" ||
effective.Model != "primary-model" ||
effective.BaseURL != "https://primary.example/v1" ||
effective.RequestTimeout != 90*time.Second ||
effective.MaxRetries != 4 ||
effective.Concurrency != 2 {
t.Fatalf("unexpected inherited config: %+v", effective)
}
}
func TestResolveValidationConfigOverridesPrimaryWhenSet(t *testing.T) {
cfg := config.Default()
cfg.PrimaryLLM.APIKey = "primary-key"
cfg.PrimaryLLM.Model = "primary-model"
cfg.PrimaryLLM.BaseURL = "https://primary.example/v1"
cfg.PrimaryLLM.TimeoutSeconds = 90
cfg.PrimaryLLM.MaxRetries = 4
cfg.TotalLLMConcurrency = 2
cfg.ProposalLLMConcurrency = 2
timeout := 12
retries := 9
concurrency := 6
cfg.ValidationLLM.APIKey = "validation-key"
cfg.ValidationLLM.Model = "validation-model"
cfg.ValidationLLM.BaseURL = "https://validation.example/v1"
cfg.ValidationLLM.TimeoutSeconds = &timeout
cfg.ValidationLLM.MaxRetries = &retries
cfg.ValidationLLMConcurrency = &concurrency
effective := ResolveValidationConfig(cfg)
if effective.APIKey != "validation-key" ||
effective.Model != "validation-model" ||
effective.BaseURL != "https://validation.example/v1" ||
effective.RequestTimeout != 12*time.Second ||
effective.MaxRetries != 9 ||
effective.Concurrency != 6 {
t.Fatalf("unexpected override config: %+v", effective)
}
}
func TestResolveConfigOptionalAPIKey(t *testing.T) {
cfg := config.Default()
cfg.PrimaryLLM.APIKey = ""
cfg.ValidationLLM.APIKey = ""
primary := ResolvePrimaryConfig(cfg)
validation := ResolveValidationConfig(cfg)
if primary.APIKey != "" {
t.Fatalf("expected empty primary api key, got %q", primary.APIKey)
}
if validation.APIKey != "" {
t.Fatalf("expected empty validation api key, got %q", validation.APIKey)
}
}