package review import ( "testing" "gitea-codex-bot/internal/domain" ) func TestParseConfigAndResolveMode(t *testing.T) { cfg, err := ParseRepoConfig("enabled: true\nreview:\n default_mode: security\n include_tests: false\n focus: [correctness, security]\nignore: [generated/]\n") if err != nil { t.Fatal(err) } if !cfg.Configured || cfg.DefaultMode != "security" || len(cfg.Focus) != 2 { t.Fatalf("unexpected config: %#v", cfg) } cmd := domain.ParsedCommand{Name: "review", Raw: "@codex review", Mode: "summary"} ResolveMode(&cmd, cfg) if cmd.Mode != "security" { t.Fatalf("mode was not resolved: %q", cmd.Mode) } } func TestResultValidationAndFormatting(t *testing.T) { suggestion := "Use a checked conversion." result := domain.ReviewResult{Verdict: "has_issues", Confidence: .9, Summary: "Found one issue", Findings: []domain.Finding{{Severity: "high", File: "internal/x.go", LineStart: 4, LineEnd: 5, Title: "Unsafe conversion", Body: "The conversion can overflow.", Suggestion: &suggestion}}} if err := ValidateResult(result); err != nil { t.Fatal(err) } body := FormatResultComment("abcdef123", result, false) if len(body) == 0 || body[:len("")] != "" { t.Fatalf("missing SHA marker: %s", body) } if !contains(body, "not configured") || !contains(body, "Unsafe conversion") { t.Fatalf("missing formatted details: %s", body) } } func contains(s, needle string) bool { for i := 0; i+len(needle) <= len(s); i++ { if s[i:i+len(needle)] == needle { return true } } return false }