Self-hosted workflows for coding-agent delivery. Orchestrate CodeBuddy, Codex and Claude Code with scripts and human approval gates. Includes Local workflows for coding assistants.
JavaScript agent-orchestrationagentic-workflowai-agentsai-codingclaude-codecode-reviewcodebuddycodexcoding-agentscursordeveloper-toolshuman-on-the-loopllmmcpmulti-agentsdlcself-hostedsopworkflow-automationworkflow-engine
refactor(notification): extract renderAIReport from generateReport (#593) (#594)
fx-kurumidab7ac719729
diff --git a/internal/notification/report.go b/internal/notification/report.goindex 0e4ca169..0f9479d4 100644--- a/internal/notification/report.go+++ b/internal/notification/report.go@@ -80,29 +80,13 @@ func (s *Service) generateReport(ctx context.Context, item *domain.NotificationDif !ok {return errors.New("汇报对应的运行已删除")}- if s.GenerateReport == nil {- err = errors.New("独立汇报服务不可用")- } else {- reportCtx, cancel := context.WithTimeout(ctx, 60*time.Second)- ai, generationErr := s.GenerateReport(reportCtx, run, item.ReportModel, ReportPrompt(run, request))- cancel()- err = generationErr- if err == nil && strings.TrimSpace(ai.Body) == "" {- err = errors.New("AI 未返回有效整体报告")- }- if err == nil {- raw, _ := json.Marshal(ai)- _, plain, _ := domain.ParseNotificationResult(request.Context.Result)- request.Context.Result = plain + "\n\n```notification\n" + string(raw) + "\n```"- content, source, renderErr := domain.RenderNotification(request.Binding, request.Context)- err = renderErr- if err == nil {- item.Content = content- item.ContentSource = source- item.ReportState = "generated"- return nil- }- }+ var content, source string+ content, source, err = s.renderAIReport(ctx, run, item.ReportModel, request)+ if err == nil {+ item.Content = content+ item.ContentSource = source+ item.ReportState = "generated"+ return nil}}if ctx.Err() != nil {@@ -114,3 +98,25 @@ func (s *Service) generateReport(ctx context.Context, item *domain.NotificationDitem.Content = fmt.Sprintf("需求「%s」的 SOP「%s」已完成。\n整体 AI 汇报暂不可用,请查看运行结果。\n%s", domain.NotificationText(request.Context.Values["issue.title"], 200), domain.NotificationText(item.SourceName, 200), domain.NotificationURLMarker)return nil}++// renderAIReport asks the independent report generator for an overall run+// summary and renders it through the binding template. Any error means the+// caller should fall back to the standard completion message.+func (s *Service) renderAIReport(ctx context.Context, run domain.Run, model string, request domain.NotificationReportRequest) (string, string, error) {+ if s.GenerateReport == nil {+ return "", "", errors.New("独立汇报服务不可用")+ }+ reportCtx, cancel := context.WithTimeout(ctx, 60*time.Second)+ ai, err := s.GenerateReport(reportCtx, run, model, ReportPrompt(run, request))+ cancel()+ if err != nil {+ return "", "", err+ }+ if strings.TrimSpace(ai.Body) == "" {+ return "", "", errors.New("AI 未返回有效整体报告")+ }+ raw, _ := json.Marshal(ai)+ _, plain, _ := domain.ParseNotificationResult(request.Context.Result)+ request.Context.Result = plain + "\n\n```notification\n" + string(raw) + "\n```"+ return domain.RenderNotification(request.Binding, request.Context)+}diff --git a/internal/notification/report_render_test.go b/internal/notification/report_render_test.gonew file mode 100644index 00000000..e958e9bc--- /dev/null+++ b/internal/notification/report_render_test.go@@ -0,0 +1,53 @@+package notification++import (+ "agentflow/internal/domain"+ "context"+ "errors"+ "strings"+ "testing"+)++func TestRenderAIReportErrors(t *testing.T) {+ request := domain.NotificationReportRequest{Binding: domain.NotificationBinding{Scope: "run", Events: []string{"succeeded"}, ContentMode: "ai"}}+ if _, _, err := (&Service{}).renderAIReport(context.Background(), domain.Run{}, "m", request); err == nil || err.Error() != "独立汇报服务不可用" {+ t.Fatalf("missing generator err = %v", err)+ }+ failed := errors.New("generator failed")+ svc := &Service{GenerateReport: func(context.Context, domain.Run, string, string) (domain.AINotificationContent, error) {+ return domain.AINotificationContent{}, failed+ }}+ if _, _, err := svc.renderAIReport(context.Background(), domain.Run{}, "m", request); !errors.Is(err, failed) {+ t.Fatalf("generator err = %v", err)+ }+ svc.GenerateReport = func(context.Context, domain.Run, string, string) (domain.AINotificationContent, error) {+ return domain.AINotificationContent{Title: "t", Body: " "}, nil+ }+ if _, _, err := svc.renderAIReport(context.Background(), domain.Run{}, "m", request); err == nil || err.Error() != "AI 未返回有效整体报告" {+ t.Fatalf("blank body err = %v", err)+ }+}++func TestRenderAIReportRendersBindingTemplate(t *testing.T) {+ request := domain.NotificationReportRequest{+ Binding: domain.NotificationBinding{Scope: "run", Events: []string{"succeeded"}, ContentMode: "ai", Template: "汇报\n{{ai.body}}"},+ Context: domain.NotificationContext{Result: "节点原始输出"},+ }+ var gotModel string+ var hasDeadline bool+ svc := &Service{GenerateReport: func(ctx context.Context, _ domain.Run, model, _ string) (domain.AINotificationContent, error) {+ gotModel = model+ _, hasDeadline = ctx.Deadline()+ return domain.AINotificationContent{Title: "整体成果", Body: "需求已交付"}, nil+ }}+ content, source, err := svc.renderAIReport(context.Background(), domain.Run{}, "model-x", request)+ if err != nil {+ t.Fatal(err)+ }+ if gotModel != "model-x" || !hasDeadline {+ t.Fatalf("model %q deadline %v", gotModel, hasDeadline)+ }+ if source != "ai" || !strings.Contains(content, "需求已交付") || strings.Contains(content, "节点原始输出") {+ t.Fatalf("source %q content %q", source, content)+ }+}