Files
tenant-registry/internal/config/config_test.go
T
Sharang ParnerkarandClaude Opus 5.5 553f4c52fe
ci / shared (pull_request) Successful in 15s
ci / test (pull_request) Successful in 6m48s
ci / image (pull_request) Skipped
feat(feedback): POST /v1/feedback files crash and bug reports as Gitea issues
A CLI user sends a crash report or /bug report with their own token; the
registry files it as an issue in the private feedback repo, titled
"[<tenant slug>] <kind>: <title>", with a provenance block (tenant, user,
product, version, device, kind, time received) above the body. The caller
gets the issue number only.

- route group "feedback"; user tokens only; tenant from the principal
- 10 reports per person and hour (in memory)
- FEEDBACK_GITEA_URL / _REPO / _TOKEN; no token answers 503
- Gitea errors become 502 feedback_failed without body, URL or token
- audit event feedback.submitted

Refs platform/werkpilot#86

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRayW7ztyk1uAtwMJPR
2026-11-23 13:49:00 +01:00

110 lines
3.4 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", "")
t.Setenv("FEEDBACK_GITEA_URL", "")
t.Setenv("FEEDBACK_GITEA_REPO", "")
t.Setenv("FEEDBACK_GITEA_TOKEN", "")
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)
}
if cfg.FeedbackGiteaURL != "https://git.breakpilot.com" || cfg.FeedbackGiteaRepo != "platform/werkpilot-feedback" || cfg.FeedbackGiteaToken != "" {
t.Errorf("feedback = %q %q token set %v", cfg.FeedbackGiteaURL, cfg.FeedbackGiteaRepo, cfg.FeedbackGiteaToken != "")
}
}
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)
}
}
}