Files
archie/internal/domain/workflow/review_report_md_test.go
T
sam 0e6c6fc6d1 feat(artifacts): publish the completed PR review to the collaborative editor
Implements docs/prds/artifact-sender.md (Approved). archie-core now sends
generated artifacts to the offloaded.dev collaborative editor, whose
POST /api/artifacts route, bearer service token, PocketBase-backed
versions and idempotency semantics are the receiving contract.

- [artifacts] config section: base_url + token SecretRef with a
  token_env fallback naming WORKSPACE_INGEST_TOKEN. An empty base_url
  disables the sender entirely; a base_url with an unresolvable token
  disables it with a warning, because a missing credential disables a
  capability rather than stopping the daemon.
- internal/infrastructure/artifactsync: one-method Publish seam in the
  Courier posture, full source per publish (versions of record are
  snapshots), 503 retried three times with backoff, 401/400 surfaced
  immediately with the field reason, deterministic request ids
  (artifact:pr-review:<owner>/<repo>#<n>).
- ReviewReport gains a pure markdown renderer in internal/domain/workflow:
  summary, one subsection per finding with the failure scenario and
  disposition when present, verified properties as a checked-clean list.
- The daemon's PR reviewer publishes after a completed review when the
  sender is configured, records the editor deep link on the result, and
  degrades a failed publish to a log line -- publishing never fails the
  producing work.
2026-09-23 03:15:27 +10:00

79 lines
2.6 KiB
Go

package workflow
import (
"strings"
"testing"
)
func mdFixture() ReviewReport {
disposition := ReviewDisposition("fixed")
return ReviewReport{
Status: ReviewStatusCompleted,
Summary: "The nil-deref path is reachable from a malformed payload.",
Findings: []ReviewFinding{
{
File: "handler.go", Line: 42, Defect: "nil deref on empty payload",
FailureScenario: "POST with a body lacking the field crashes the handler.",
Suggestion: "guard the field before use", Verdict: ReviewVerdictConfirmed,
Level: ReviewLevelError, Category: "correctness", Disposition: disposition,
},
{
File: "store.go", Line: 9, Defect: "query loses the filter",
FailureScenario: "paged reads return rows from other scopes",
Verdict: ReviewVerdictPlausible, Level: ReviewLevelWarn,
},
},
Checked: []ReviewCheck{
{Property: "nil-safety of Foo callers", Evidence: "read all 4 callers; each nil-checks"},
},
}
}
func TestReviewReportRendersFindingsAsMarkdown(t *testing.T) {
got := mdFixture().RenderMarkdown("Review of acme/widget#42")
for _, want := range []string{
"# Review of acme/widget#42",
"The nil-deref path is reachable",
"### handler.go:42",
"**Defect:** nil deref on empty payload",
"**Failure scenario:** POST with a body lacking the field crashes the handler.",
"error (confirmed)",
"Suggested fix: guard the field before use",
"Disposition: fixed",
"### store.go:9",
"warn (plausible)",
"## Checked clean",
"- nil-safety of Foo callers — read all 4 callers; each nil-checks",
} {
if !strings.Contains(got, want) {
t.Fatalf("rendered report missing %q:\n%s", want, got)
}
}
}
func TestReviewReportRendersNotRunStatus(t *testing.T) {
report := NewNotRunReviewReport("no reviewer model configured")
got := report.RenderMarkdown("Review of acme/widget#42")
if !strings.Contains(got, "no reviewer model configured") {
t.Fatalf("skip reason missing:\n%s", got)
}
if strings.Contains(got, "## Findings") || strings.Contains(got, "## Checked clean") {
t.Fatalf("a not-run report must not render finding or check sections:\n%s", got)
}
}
func TestReviewReportRendersACleanReview(t *testing.T) {
report := ReviewReport{
Status: ReviewStatusCompleted,
Summary: "No defects found.",
Checked: []ReviewCheck{{Property: "p", Evidence: "e"}},
}
got := report.RenderMarkdown("Review")
if strings.Contains(got, "### ") {
t.Fatalf("a zero-finding review must not render finding sections:\n%s", got)
}
if !strings.Contains(got, "No defects found.") || !strings.Contains(got, "- p — e") {
t.Fatalf("summary and checks missing:\n%s", got)
}
}