- internal/ai/types.go: IntakeRequest, IntakeResult, TierConfig, AIConfig domain types - internal/ai/client.go: AIClient interface + TierClient (go-openai, BaseURL tier-routing) - internal/ai/mock.go: MockAIClient test double with HighConfidenceResult/LowConfidenceResult fixtures - internal/ai/prompts/intake.go: BuildIntakePrompt() JSON-extraction prompt template - internal/config/config.go: Config.AI AIConfig field, tier defaults, env bindings, ai_config.json merge - ai_config.json: template config with placeholder Tier2 API key - .gitignore: add ai_config.local.json pattern for real keys (T-02-01 mitigation) - All tests pass: TestMockAIClient, TestMockAIClientError, TestTierClientConstruction, TestAIConfigDefaults
73 lines
1.9 KiB
Go
73 lines
1.9 KiB
Go
package config_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"git.georgsen.dk/hwlab/internal/config"
|
|
)
|
|
|
|
func TestAIConfigDefaults(t *testing.T) {
|
|
// Unset any AI env overrides that might interfere
|
|
os.Unsetenv("HWLAB_AI_TIER1_BASE_URL")
|
|
os.Unsetenv("HWLAB_AI_TIER1_MODEL")
|
|
os.Unsetenv("HWLAB_AI_CONFIDENCE_THRESHOLD")
|
|
os.Unsetenv("HWLAB_AI_QUICK_ADD_ENABLED")
|
|
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
t.Fatalf("Load() error: %v", err)
|
|
}
|
|
if cfg.AI.Tier1.BaseURL != "http://localhost:8000/v1" {
|
|
t.Errorf("AI.Tier1.BaseURL: want http://localhost:8000/v1, got %q", cfg.AI.Tier1.BaseURL)
|
|
}
|
|
if cfg.AI.Tier1.Model != "gemma-4-e4b" {
|
|
t.Errorf("AI.Tier1.Model: want gemma-4-e4b, got %q", cfg.AI.Tier1.Model)
|
|
}
|
|
if cfg.AI.ConfidenceThreshold != 0.75 {
|
|
t.Errorf("AI.ConfidenceThreshold: want 0.75, got %f", cfg.AI.ConfidenceThreshold)
|
|
}
|
|
if cfg.AI.QuickAddEnabled != false {
|
|
t.Errorf("AI.QuickAddEnabled: want false, got %v", cfg.AI.QuickAddEnabled)
|
|
}
|
|
}
|
|
|
|
func TestLoadDefaults(t *testing.T) {
|
|
// Unset env vars that might interfere
|
|
os.Unsetenv("HWLAB_PORT")
|
|
os.Unsetenv("HWLAB_NETBOX_URL")
|
|
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
t.Fatalf("Load() error: %v", err)
|
|
}
|
|
if cfg.Port != 8080 {
|
|
t.Errorf("default port: want 8080, got %d", cfg.Port)
|
|
}
|
|
}
|
|
|
|
func TestLoadEnvOverride(t *testing.T) {
|
|
os.Setenv("HWLAB_PORT", "9999")
|
|
defer os.Unsetenv("HWLAB_PORT")
|
|
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
t.Fatalf("Load() error: %v", err)
|
|
}
|
|
if cfg.Port != 9999 {
|
|
t.Errorf("env override port: want 9999, got %d", cfg.Port)
|
|
}
|
|
}
|
|
|
|
func TestLoadNetBoxURL(t *testing.T) {
|
|
os.Setenv("HWLAB_NETBOX_URL", "http://10.5.0.130:8000/api")
|
|
defer os.Unsetenv("HWLAB_NETBOX_URL")
|
|
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
t.Fatalf("Load() error: %v", err)
|
|
}
|
|
if cfg.NetBoxURL != "http://10.5.0.130:8000/api" {
|
|
t.Errorf("netbox url: want http://10.5.0.130:8000/api, got %s", cfg.NetBoxURL)
|
|
}
|
|
}
|