internal/legal/contractdocs holds the released contract documents as
committed PDFs with pinned SHA-256: the Leistungsbeschreibungen Breakpilot
(Plattform), Managed Git, Build-Runner, Werkpilot, Firmwerk, Werkmeister
1.0.0 and Prüfwerk 1.0.3. AGB, AVV and TOM are added later by one table
line plus their PDF. The table also says which LB applies to whom.
The pins are checked at startup (the server refuses to start on a
mismatch) and by a test; CI now runs ./internal/legal/... too.
CONTRACT_DOCUMENTS ("on"/"off", default off) is the release gate.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
104 lines
3.1 KiB
Go
104 lines
3.1 KiB
Go
package config
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestLoad_defaults(t *testing.T) {
|
|
t.Setenv("APP_ENV", "")
|
|
t.Setenv("ADDR", "")
|
|
t.Setenv("KEYCLOAK_ISSUER", "")
|
|
t.Setenv("DATABASE_URL", "")
|
|
|
|
cfg, err := Load()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.Env != "dev" {
|
|
t.Errorf("Env = %q, want dev", cfg.Env)
|
|
}
|
|
if cfg.Addr != ":8090" {
|
|
t.Errorf("Addr = %q, want :8090", cfg.Addr)
|
|
}
|
|
if cfg.KeycloakIssuer == "" {
|
|
t.Error("KeycloakIssuer is empty; expected a default")
|
|
}
|
|
if cfg.DatabaseURL != "" {
|
|
t.Errorf("DatabaseURL = %q, want empty default", cfg.DatabaseURL)
|
|
}
|
|
}
|
|
|
|
func TestLoad_overrides(t *testing.T) {
|
|
t.Setenv("APP_ENV", "stage")
|
|
t.Setenv("ADDR", ":9000")
|
|
t.Setenv("KEYCLOAK_ISSUER", "https://auth.example/realms/r")
|
|
t.Setenv("DATABASE_URL", "postgres://x")
|
|
|
|
cfg, err := Load()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.Env != "stage" || cfg.Addr != ":9000" || cfg.KeycloakIssuer != "https://auth.example/realms/r" || cfg.DatabaseURL != "postgres://x" {
|
|
t.Errorf("overrides not applied: %+v", cfg)
|
|
}
|
|
}
|
|
|
|
func TestLoad_invalidEnv(t *testing.T) {
|
|
t.Setenv("APP_ENV", "bogus")
|
|
_, err := Load()
|
|
if err == nil {
|
|
t.Fatal("expected error for invalid APP_ENV")
|
|
}
|
|
}
|
|
|
|
func TestLoad_litellmDefaultsAndOverrides(t *testing.T) {
|
|
t.Setenv("APP_ENV", "")
|
|
for _, k := range []string{"LITELLM_BASE_URL", "LITELLM_MASTER_KEY", "LITELLM_MODELS", "LITELLM_BUDGET_TRIAL", "LITELLM_BUDGET_DEFAULT"} {
|
|
t.Setenv(k, "")
|
|
}
|
|
cfg, err := Load()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.LiteLLMBaseURL != "https://llm.breakpilot.com" || cfg.LiteLLMMasterKey != "" ||
|
|
len(cfg.LiteLLMModels) != 3 || cfg.LiteLLMModels[0] != "Qwen3-Coder-30B-A3B-Instruct" || cfg.LiteLLMModels[1] != "gpt-oss-120b" || cfg.LiteLLMModels[2] != "Qwen3.8-27B" ||
|
|
cfg.LiteLLMBudgetTrial != 5 || cfg.LiteLLMBudgetDefault != 50 {
|
|
t.Errorf("litellm defaults: %+v", cfg)
|
|
}
|
|
|
|
t.Setenv("LITELLM_BASE_URL", "http://llm.local")
|
|
t.Setenv("LITELLM_MASTER_KEY", "sk-master")
|
|
t.Setenv("LITELLM_MODELS", " a , ,b ")
|
|
t.Setenv("LITELLM_BUDGET_TRIAL", "2.5")
|
|
t.Setenv("LITELLM_BUDGET_DEFAULT", "not-a-number")
|
|
cfg, err = Load()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.LiteLLMBaseURL != "http://llm.local" || cfg.LiteLLMMasterKey != "sk-master" ||
|
|
len(cfg.LiteLLMModels) != 2 || cfg.LiteLLMModels[0] != "a" || cfg.LiteLLMModels[1] != "b" ||
|
|
cfg.LiteLLMBudgetTrial != 2.5 || cfg.LiteLLMBudgetDefault != 50 {
|
|
t.Errorf("litellm overrides: %+v", cfg)
|
|
}
|
|
// a list of only separators falls back to the default
|
|
t.Setenv("LITELLM_MODELS", " , ")
|
|
if cfg, _ = Load(); len(cfg.LiteLLMModels) != 3 {
|
|
t.Errorf("blank list should fall back: %v", cfg.LiteLLMModels)
|
|
}
|
|
}
|
|
|
|
// Contract documents stay off unless the env says exactly "on".
|
|
func TestLoad_contractDocumentsGate(t *testing.T) {
|
|
t.Setenv("APP_ENV", "")
|
|
for value, want := range map[string]bool{"": false, "off": false, "true": false, "ON": false, "on": true} {
|
|
t.Setenv("CONTRACT_DOCUMENTS", value)
|
|
cfg, err := Load()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if cfg.ContractDocuments != want {
|
|
t.Errorf("CONTRACT_DOCUMENTS=%q: %v, want %v", value, cfg.ContractDocuments, want)
|
|
}
|
|
}
|
|
}
|