From 8462cd5e3b15974729bcdb5c81ef3dba87d23b75 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Thu, 10 Sep 2026 00:43:26 +1000 Subject: [PATCH] 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. --- internal/domain/workflow/implement.go | 9 +- internal/domain/workflow/review.go | 37 ++++++++ .../domain/workflow/review_surface_test.go | 87 +++++++++++++++++++ internal/domain/workflow/workflow.go | 5 ++ 4 files changed, 136 insertions(+), 2 deletions(-) create mode 100644 internal/domain/workflow/review_surface_test.go diff --git a/internal/domain/workflow/implement.go b/internal/domain/workflow/implement.go index 4871bce7c..55f005fdd 100644 --- a/internal/domain/workflow/implement.go +++ b/internal/domain/workflow/implement.go @@ -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 } diff --git a/internal/domain/workflow/review.go b/internal/domain/workflow/review.go index 636631b2f..1f27ba109 100644 --- a/internal/domain/workflow/review.go +++ b/internal/domain/workflow/review.go @@ -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() +} diff --git a/internal/domain/workflow/review_surface_test.go b/internal/domain/workflow/review_surface_test.go new file mode 100644 index 000000000..b931b7849 --- /dev/null +++ b/internal/domain/workflow/review_surface_test.go @@ -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) + } +} diff --git a/internal/domain/workflow/workflow.go b/internal/domain/workflow/workflow.go index 2335a0f13..de743adda 100644 --- a/internal/domain/workflow/workflow.go +++ b/internal/domain/workflow/workflow.go @@ -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