feat(workflow): surface adversarial review findings on the PR body
StageReview now stashes its ReviewReport on TaskContext, and implementPRBody
appends a findings section when the review ran -- explicit in the zero-findings
case ('ran and found no defects') and listing non-blocking warn/plausible
findings. A disabled or never-run review renders no section, so silence is not
mistaken for a clean review. The parked-task park reason already carries
blocking findings (renderReviewDetail), satisfying the dashboard/api-tasks half
of the acceptance criteria.
Closes archie-core-h019.6.
This commit is contained in:
1 parent
fa1d3ee27d
commit
8462cd5e3b
4 files changed
+136
-2
No files matched your search
@@ -199,8 +199,13 @@ func Implement() Workflow {
|
||||
// reports the fresh-vs-cached breakdown of tc.Task.TokensUsed (see
|
||||
// formatTokenUsage) so the operator isn't misled by the raw prompt-token sum
|
||||
// -- most of it is typically prefix-cache hits billed at a steep discount,
|
||||
// not full price.
|
||||
// not full price. When the adversarial review ran, its findings section is
|
||||
// appended so the PR states what the reviewer checked and found (h019.6).
|
||||
func implementPRBody(tc *TaskContext) string {
|
||||
return fmt.Sprintf("%s\n\n---\n*workflow: implement · %d iterations · %s*",
|
||||
body := fmt.Sprintf("%s\n\n---\n*workflow: implement · %d iterations · %s*",
|
||||
tc.BuildSummary, tc.Task.Iterations, formatTokenUsage(tc.Task.TokensUsed, tc.RunUsage))
|
||||
if section := renderPRReviewSection(tc.ReviewReport); section != "" {
|
||||
body += "\n\n" + section
|
||||
}
|
||||
return body
|
||||
}
|
||||
@@ -64,6 +64,10 @@ func StageReview() Stage {
|
||||
if err != nil {
|
||||
return fmt.Errorf("review: %w", err)
|
||||
}
|
||||
// Stash the report regardless of outcome: the PR-body findings
|
||||
// section (h019.6) needs it when the review passes, and the parked
|
||||
// task's park reason already carries it when it does not.
|
||||
tc.ReviewReport = report
|
||||
if !report.Passed() {
|
||||
tc.Outcome = Outcome{Status: StatusParked, Detail: renderReviewDetail(report)}
|
||||
}
|
||||
@@ -121,3 +125,36 @@ func renderReviewDetail(report ReviewReport) string {
|
||||
}
|
||||
return clip(b.String(), reviewDetailBytes)
|
||||
}
|
||||
|
||||
// renderPRReviewSection renders the PR-body findings section (h019.6). It
|
||||
// returns "" when the review did not run, so a review that was disabled or
|
||||
// never wired does not claim one ran -- silence would be indistinguishable
|
||||
// from the review running and finding nothing. When it did run, the section
|
||||
// states the outcome explicitly, including the zero-findings case.
|
||||
func renderPRReviewSection(report ReviewReport) string {
|
||||
if !report.Ran() {
|
||||
return ""
|
||||
}
|
||||
var b strings.Builder
|
||||
b.WriteString("## Adversarial review\n\n")
|
||||
if len(report.Findings) == 0 {
|
||||
b.WriteString("Adversarial self-review ran on the committed diff and found no defects.\n")
|
||||
} else {
|
||||
b.WriteString("Adversarial self-review ran and found no blocking defects. Non-blocking notes:\n\n")
|
||||
for _, f := range report.Findings {
|
||||
loc := f.File
|
||||
if f.Line > 0 {
|
||||
loc = fmt.Sprintf("%s:%d", f.File, f.Line)
|
||||
}
|
||||
fmt.Fprintf(&b, "- `%s` (%s, %s): %s", loc, f.Verdict, f.Level, f.Defect)
|
||||
if f.FailureScenario != "" {
|
||||
fmt.Fprintf(&b, " — %s", f.FailureScenario)
|
||||
}
|
||||
b.WriteString("\n")
|
||||
}
|
||||
}
|
||||
if report.Summary != "" {
|
||||
fmt.Fprintf(&b, "\nSummary: %s\n", report.Summary)
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
package workflow
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestRenderPRReviewSection(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
report ReviewReport
|
||||
empty bool
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "zero value renders nothing",
|
||||
report: ReviewReport{},
|
||||
empty: true,
|
||||
},
|
||||
{
|
||||
name: "not run renders nothing",
|
||||
report: NewNotRunReviewReport("provider down"),
|
||||
empty: true,
|
||||
},
|
||||
{
|
||||
name: "zero findings is explicit",
|
||||
report: NewCompletedReviewReport(nil, "checked and cleared"),
|
||||
want: []string{"Adversarial self-review ran", "found no defects"},
|
||||
},
|
||||
{
|
||||
name: "non-blocking findings listed",
|
||||
report: NewCompletedReviewReport([]ReviewFinding{
|
||||
{File: "a.go", Line: 12, Defect: "style nit", FailureScenario: "x", Verdict: ReviewVerdictPlausible, Level: ReviewLevelWarn, Category: ReviewCategoryOther},
|
||||
}, "one note"),
|
||||
want: []string{"found no blocking defects", "a.go:12", "style nit"},
|
||||
},
|
||||
{
|
||||
name: "whole-file finding omits line",
|
||||
report: NewCompletedReviewReport([]ReviewFinding{
|
||||
{File: "README.md", Defect: "typo", FailureScenario: "x", Verdict: ReviewVerdictPlausible, Level: ReviewLevelWarn, Category: ReviewCategoryOther},
|
||||
}, ""),
|
||||
want: []string{"README.md", "typo"},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := renderPRReviewSection(tt.report)
|
||||
if tt.empty {
|
||||
if got != "" {
|
||||
t.Fatalf("renderPRReviewSection = %q, want empty", got)
|
||||
}
|
||||
return
|
||||
}
|
||||
for _, w := range tt.want {
|
||||
if !strings.Contains(got, w) {
|
||||
t.Errorf("renderPRReviewSection missing %q in:\n%s", w, got)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestImplementPRBodyOmitsFindingsWhenReviewDidNotRun(t *testing.T) {
|
||||
tc := &TaskContext{BuildSummary: "did the thing", Task: &Task{}}
|
||||
body := implementPRBody(tc)
|
||||
if strings.Contains(body, "Adversarial review") {
|
||||
t.Fatalf("PR body includes a review section when no review ran:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, "did the thing") {
|
||||
t.Fatalf("PR body lost the build summary:\n%s", body)
|
||||
}
|
||||
}
|
||||
|
||||
func TestImplementPRBodyCarriesZeroFindingSection(t *testing.T) {
|
||||
tc := &TaskContext{
|
||||
BuildSummary: "did the thing",
|
||||
Task: &Task{},
|
||||
ReviewReport: NewCompletedReviewReport(nil, "checked and cleared"),
|
||||
}
|
||||
body := implementPRBody(tc)
|
||||
if !strings.Contains(body, "found no defects") {
|
||||
t.Fatalf("PR body missing the zero-findings review section:\n%s", body)
|
||||
}
|
||||
if !strings.Contains(body, "did the thing") {
|
||||
t.Fatalf("PR body lost the build summary:\n%s", body)
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,11 @@ type TaskContext struct {
|
||||
// reported prompt-token sum was cache hits (billed at a steep discount)
|
||||
// rather than fresh, full-price tokens; see formatTokenUsage.
|
||||
RunUsage agentexec.Usage
|
||||
// ReviewReport is the adversarial self-review stage's result, stashed
|
||||
// by StageReview so StageOpenPR can render a findings section on the PR
|
||||
// body (h019.6). Zero value means the review did not run (disabled or
|
||||
// skipped); ReviewReport.Ran() is the test for "render the section".
|
||||
ReviewReport ReviewReport
|
||||
}
|
||||
|
||||
// Emit publishes an observability event stamped with the task's
|
||||
|
||||
Reference in new issue
Block a user