b409dff4ed
Build & push image / build-and-push (push) Successful in 8s
A section that led with '**Blocking issues**' (no 'found') fell through to unknown, so the consolidated header wrongly read 'No material issues found' (seen live on gpt-oss). Now matches 'blocking issue'/'minor issue'/'no material issue' and picks the earliest-appearing phrase (the lead verdict). + tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
139 lines
4.2 KiB
Go
139 lines
4.2 KiB
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func names(specs []Specialist) []string {
|
|
out := make([]string, len(specs))
|
|
for i, s := range specs {
|
|
out[i] = s.Name
|
|
}
|
|
return out
|
|
}
|
|
|
|
func eq(a, b []string) bool {
|
|
if len(a) != len(b) {
|
|
return false
|
|
}
|
|
for i := range a {
|
|
if a[i] != b[i] {
|
|
return false
|
|
}
|
|
}
|
|
return true
|
|
}
|
|
|
|
func TestResolveSpecialists_DefaultSuite(t *testing.T) {
|
|
t.Setenv("GADFLY_SPECIALISTS", "")
|
|
specs, _, _, errs := resolveSpecialists(t.TempDir())
|
|
if len(errs) != 0 {
|
|
t.Fatalf("unexpected errors: %v", errs)
|
|
}
|
|
if !eq(names(specs), defaultSuite) {
|
|
t.Errorf("default = %v, want %v", names(specs), defaultSuite)
|
|
}
|
|
}
|
|
|
|
func TestResolveSpecialists_EnvSelection(t *testing.T) {
|
|
t.Setenv("GADFLY_SPECIALISTS", "security, tests")
|
|
specs, _, _, errs := resolveSpecialists(t.TempDir())
|
|
if len(errs) != 0 {
|
|
t.Fatalf("unexpected errors: %v", errs)
|
|
}
|
|
if !eq(names(specs), []string{"security", "tests"}) {
|
|
t.Errorf("got %v", names(specs))
|
|
}
|
|
}
|
|
|
|
func TestResolveSpecialists_AutoFlag(t *testing.T) {
|
|
t.Setenv("GADFLY_SPECIALISTS", "auto")
|
|
specs, registry, auto, errs := resolveSpecialists(t.TempDir())
|
|
if len(errs) != 0 {
|
|
t.Fatalf("unexpected errors: %v", errs)
|
|
}
|
|
if !auto {
|
|
t.Error("expected auto=true for GADFLY_SPECIALISTS=auto")
|
|
}
|
|
if specs != nil {
|
|
t.Errorf("auto mode should return nil specs, got %v", names(specs))
|
|
}
|
|
if len(registry) == 0 {
|
|
t.Error("auto mode should still return the registry catalog")
|
|
}
|
|
}
|
|
|
|
func TestResolveSpecialists_UnknownNameErrors(t *testing.T) {
|
|
t.Setenv("GADFLY_SPECIALISTS", "security,bogus")
|
|
specs, _, _, errs := resolveSpecialists(t.TempDir())
|
|
if len(errs) == 0 {
|
|
t.Fatal("expected an error for unknown specialist")
|
|
}
|
|
if !eq(names(specs), []string{"security"}) {
|
|
t.Errorf("valid ones should still resolve, got %v", names(specs))
|
|
}
|
|
}
|
|
|
|
func TestResolveSpecialists_EnvCustomDefinition(t *testing.T) {
|
|
t.Setenv("GADFLY_SPECIALIST_MIGRATIONS", "Review DB migrations for destructive ops.")
|
|
t.Setenv("GADFLY_SPECIALISTS", "migrations")
|
|
specs, _, _, errs := resolveSpecialists(t.TempDir())
|
|
if len(errs) != 0 {
|
|
t.Fatalf("unexpected errors: %v", errs)
|
|
}
|
|
if len(specs) != 1 || specs[0].Name != "migrations" || specs[0].Focus == "" {
|
|
t.Fatalf("custom specialist not registered: %+v", specs)
|
|
}
|
|
}
|
|
|
|
func TestResolveSpecialists_FileConfig(t *testing.T) {
|
|
dir := t.TempDir()
|
|
cfg := `specialists: [security, migrations]
|
|
define:
|
|
- name: migrations
|
|
title: "DB migrations"
|
|
focus: "Review schema migrations for destructive or unindexed changes."
|
|
`
|
|
if err := os.WriteFile(filepath.Join(dir, ".gadfly.yml"), []byte(cfg), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Setenv("GADFLY_SPECIALISTS", "") // let the file drive selection
|
|
specs, _, _, errs := resolveSpecialists(dir)
|
|
if len(errs) != 0 {
|
|
t.Fatalf("unexpected errors: %v", errs)
|
|
}
|
|
if !eq(names(specs), []string{"security", "migrations"}) {
|
|
t.Errorf("got %v", names(specs))
|
|
}
|
|
}
|
|
|
|
func TestParseVerdictAndWorst(t *testing.T) {
|
|
cases := map[string]verdict{
|
|
"VERDICT: No material issues found.": verdictClean,
|
|
"Minor issues\n- nit": verdictMinor,
|
|
"**Blocking issues found**": verdictBlocking,
|
|
"**Blocking issues**\n- bug": verdictBlocking, // no "found" suffix
|
|
"VERDICT: Blocking issue\n- one": verdictBlocking, // singular
|
|
"No material issues found. There are no blocking issues.": verdictClean, // earliest phrase wins
|
|
"something unparseable": verdictUnknown,
|
|
}
|
|
for in, want := range cases {
|
|
if got := parseVerdict(in); got != want {
|
|
t.Errorf("parseVerdict(%q) = %v, want %v", in, got, want)
|
|
}
|
|
}
|
|
results := []specialistResult{
|
|
{spec: Specialist{Name: "security"}, verdict: verdictMinor},
|
|
{spec: Specialist{Name: "correctness"}, verdict: verdictBlocking},
|
|
{spec: Specialist{Name: "improvements"}, verdict: verdictBlocking}, // must not count
|
|
}
|
|
if w := worstVerdict(results[:2]); w != verdictBlocking {
|
|
t.Errorf("worst = %v, want blocking", w)
|
|
}
|
|
if w := worstVerdict([]specialistResult{results[0], results[2]}); w != verdictMinor {
|
|
t.Errorf("improvements should not escalate; worst = %v, want minor", w)
|
|
}
|
|
}
|