Files
review-bot/review/prompt_test.go
T
Rodin 3c536c42d5
CI / test (push) Successful in 18s
CI / review (push) Has been skipped
Add unit tests, integration test, CI workflow, and conventions
- gitea/client_test.go: mock HTTP tests for all API methods + error cases
- llm/client_test.go: mock tests for completion, errors, timeouts
- review/parser_test.go: JSON parsing, markdown fences, validation
- review/formatter_test.go: markdown output, empty/multiple findings
- review/prompt_test.go: system/user prompt construction
- integration_test.go: full end-to-end flow (build tag: integration)
- .gitea/workflows/ci.yml: test + vet + build on push, dual LLM review on PRs
- CONVENTIONS.md: coding standards for self-review dogfooding
- README.md: usage docs, env vars, architecture
2026-05-01 10:03:44 -07:00

78 lines
2.1 KiB
Go

package review
import (
"strings"
"testing"
)
func TestBuildSystemPrompt_NoConventions(t *testing.T) {
prompt := BuildSystemPrompt("")
if !strings.Contains(prompt, "expert code reviewer") {
t.Error("expected system prompt to mention code reviewer role")
}
if strings.Contains(prompt, "coding conventions") {
t.Error("should not mention conventions when empty")
}
}
func TestBuildSystemPrompt_WithConventions(t *testing.T) {
conventions := "- Use stdlib only\n- No panics\n"
prompt := BuildSystemPrompt(conventions)
if !strings.Contains(prompt, "coding conventions") {
t.Error("expected conventions section")
}
if !strings.Contains(prompt, "Use stdlib only") {
t.Error("expected conventions content")
}
}
func TestBuildUserPrompt_Basic(t *testing.T) {
prompt := BuildUserPrompt("Fix bug", "Fixes the crash", "diff content here", true, "all checks passed")
if !strings.Contains(prompt, "Fix bug") {
t.Error("expected PR title")
}
if !strings.Contains(prompt, "Fixes the crash") {
t.Error("expected PR description")
}
if !strings.Contains(prompt, "diff content here") {
t.Error("expected diff content")
}
if !strings.Contains(prompt, "PASSED") {
t.Error("expected CI status PASSED")
}
}
func TestBuildUserPrompt_CIFailed(t *testing.T) {
prompt := BuildUserPrompt("Add tests", "", "some diff", false, "lint: failed")
if !strings.Contains(prompt, "FAILED") {
t.Error("expected CI status FAILED")
}
if !strings.Contains(prompt, "lint: failed") {
t.Error("expected CI details")
}
}
func TestBuildUserPrompt_NoDescription(t *testing.T) {
prompt := BuildUserPrompt("Quick fix", "", "diff", true, "")
if strings.Contains(prompt, "### Description") {
t.Error("should not contain Description header when body is empty")
}
}
func TestBuildUserPrompt_DiffIncluded(t *testing.T) {
diff := "+func Hello() string {\n+\treturn \"hello\"\n+}"
prompt := BuildUserPrompt("Greeting", "Add greeting func", diff, true, "")
if !strings.Contains(prompt, "```diff") {
t.Error("expected diff fence")
}
if !strings.Contains(prompt, diff) {
t.Error("expected diff content in prompt")
}
}