This repository has been archived on 2026-07-17. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
gitea-codex/internal/review/review_test.go
T
Space-Banane 85c0e735dc
ci / test (pull_request) Successful in 21s
ci / publish (pull_request) Has been skipped
fix. harden Go review flow
Fix runner bootstrap and auth handling, preserve queued SHAs, make event/job acceptance atomic, fence stale runs, correct retries and prompts, add fake end-to-end coverage, and fix deployment defaults.

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-12 22:20:48 +02:00

64 lines
2.7 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 TestBuildPromptUsesGenericIntentForBareReview(t *testing.T) {
prompt := BuildPrompt(domain.ParsedCommand{Name: "review", Raw: "@codex review", Mode: "summary"}, domain.DefaultRepoReviewConfig(), domain.PullRequestContext{BaseSHA: "base", HeadSHA: "head"})
if contains(prompt, "review: review\n") || !contains(prompt, "review: review this pull request and report introduced issues.") {
t.Fatalf("unexpected bare-review prompt: %s", prompt)
}
}
func TestMarkdownCommentIncludesStructuredSummaryAndSuggestion(t *testing.T) {
suggestion := "Use a checked conversion."
result := domain.ReviewResult{Verdict: "has_issues", Confidence: .8, Summary: "Summary", MarkdownComment: "Primary markdown", Findings: []domain.Finding{{Severity: "medium", File: "x.go", LineStart: 2, LineEnd: 2, Title: "Issue", Body: "Details", Suggestion: &suggestion}}}
body := FormatResultComment("head", result, true)
for _, part := range []string{"Structured Findings", "Verdict: `has_issues`", "Summary", "Use a checked conversion."} {
if !contains(body, part) {
t.Fatalf("formatted comment missing %q: %s", part, 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
}