GitHub refuses REQUEST_CHANGES from a pull request's author, so a blocking finding on the PR a task opened lost every finding. The retry's identical refusal is now reported once, and forge errors drop the gRPC framing.
61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
package workflow
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/samcharles93/archie-core/internal/domain/workflow/prreview"
|
|
)
|
|
|
|
func TestForgeReviewPlacesOnlyDiffLinesInline(t *testing.T) {
|
|
files := []prreview.FileChange{{
|
|
Path: "calc/calc.go",
|
|
Hunks: []prreview.Hunk{{NewStart: 10, Lines: []string{" ctx", "+added", "-gone", " ctx2"}}},
|
|
}}
|
|
tests := []struct {
|
|
name string
|
|
file string
|
|
line int
|
|
inline bool
|
|
}{
|
|
{"added line", "calc/calc.go", 11, true},
|
|
{"context line", "calc/calc.go", 12, true},
|
|
{"outside the hunk", "calc/calc.go", 40, false},
|
|
{"file not in the diff", "README.md", 1, false},
|
|
{"no line", "calc/calc.go", 0, false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
review := forgeReview([]prreview.ScoredFinding{{File: tt.file, LineStart: tt.line, Body: "b"}}, files, false)
|
|
if got := len(review.Comments) == 1; got != tt.inline {
|
|
t.Fatalf("inline = %v, want %v (body %q)", got, tt.inline, review.Body)
|
|
}
|
|
if !tt.inline && review.Body == "" {
|
|
t.Fatal("finding dropped: neither inline nor in the body")
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// A forge refuses REQUEST_CHANGES from a pull request's own author, which is
|
|
// every review of a pull request the task opened (task 18 lost its findings).
|
|
func TestForgeReviewEvent(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
blocking bool
|
|
ownPR bool
|
|
want prreview.ReviewEvent
|
|
}{
|
|
{"a blocking finding on someone else's pull request requests changes", true, false, prreview.ReviewEventRequestChanges},
|
|
{"a blocking finding on the task's own pull request comments", true, true, prreview.ReviewEventComment},
|
|
{"no blocking finding comments", false, false, prreview.ReviewEventComment},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
review := forgeReview([]prreview.ScoredFinding{{File: "a.go", Body: "b", Blocking: tt.blocking}}, nil, tt.ownPR)
|
|
if review.Event != string(tt.want) {
|
|
t.Fatalf("event = %q, want %q", review.Event, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|