f19b271642
Rebuild the Gitea Codex review bot from the product contract with a Go HTTP service, durable SQL queue, typed Gitea client, isolated runner, and deployment updates. Co-Authored-By: Claude <noreply@anthropic.com>
46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
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("<!-- codex-review:head_sha=abcdef123 -->")] != "<!-- codex-review:head_sha=abcdef123 -->" {
|
|
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
|
|
}
|