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(domain): extract default notification template selection (#319)
fx-kurumie06ed2089ca9
diff --git a/internal/domain/notification_default_template_test.go b/internal/domain/notification_default_template_test.gonew file mode 100644index 00000000..824882f6--- /dev/null+++ b/internal/domain/notification_default_template_test.go@@ -0,0 +1,33 @@+package domain++import "testing"++func TestNotificationTemplateDefaults(t *testing.T) {+ cases := []struct {+ name string+ binding NotificationBinding+ sourceType string+ want string+ }{+ {"custom template wins", NotificationBinding{ContentMode: "ai", Scope: "run", Template: "自定义 {{status}}"}, "schedule_job", "自定义 {{status}}"},+ {"blank template falls back", NotificationBinding{Template: " \n"}, "", "### {{status}}\n项目:{{project}}\n流程:{{workflow}}\n节点:{{node}}\n查看详情:{{url}}"},+ {"ai mode beats run scope", NotificationBinding{ContentMode: "ai", Scope: "run"}, "schedule_job", "### {{ai.title}}\n\n{{ai.body}}\n\n触发时状态:{{status}}\n\n{{url}}"},+ {"run scope beats source type", NotificationBinding{Scope: "run"}, "assistant_task", "### 需求「{{issue.title}}」的 SOP 已完成\n\n{{result}}\n\n{{url}}"},+ {"schedule job", NotificationBinding{}, "schedule_job", "### {{task.name}} · {{status}}\n\n{{url}}"},+ {"assistant task", NotificationBinding{}, "assistant_task", "### {{task.name}} · {{status}}\n\n{{url}}"},+ {"node default", NotificationBinding{}, "run", "### {{status}}\n项目:{{project}}\n流程:{{workflow}}\n节点:{{node}}\n查看详情:{{url}}"},+ }+ for _, tc := range cases {+ if got := notificationTemplate(tc.binding, tc.sourceType); got != tc.want {+ t.Errorf("%s: got %q want %q", tc.name, got, tc.want)+ }+ }+}++func TestRenderNotificationUsesScheduleDefaultTemplate(t *testing.T) {+ binding := NotificationBinding{Events: []string{"succeeded"}}+ content, source, err := RenderNotification(binding, NotificationContext{SourceType: "schedule_job", Values: map[string]string{"task.name": "日报", "status": "已完成"}})+ if err != nil || source != "template" || content != "### 日报 · 已完成\n\n"+NotificationURLMarker {+ t.Fatalf("%q %s %v", content, source, err)+ }+}diff --git a/internal/domain/notification_template.go b/internal/domain/notification_template.goindex 1206fc3d..e8447cf9 100644--- a/internal/domain/notification_template.go+++ b/internal/domain/notification_template.go@@ -155,18 +155,7 @@ func RenderNotification(binding NotificationBinding, ctx NotificationContext) (svalues["ai.summary"] = NotificationText(ai.Summary, 2000)values["ai.body"] = NotificationText(ai.Body, 8000)}- template := binding.Template- if strings.TrimSpace(template) == "" {- if binding.ContentMode == "ai" {- template = "### {{ai.title}}\n\n{{ai.body}}\n\n触发时状态:{{status}}\n\n{{url}}"- } else if binding.Scope == "run" {- template = "### 需求「{{issue.title}}」的 SOP 已完成\n\n{{result}}\n\n{{url}}"- } else if ctx.SourceType == "schedule_job" || ctx.SourceType == "assistant_task" {- template = "### {{task.name}} · {{status}}\n\n{{url}}"- } else {- template = "### {{status}}\n项目:{{project}}\n流程:{{workflow}}\n节点:{{node}}\n查看详情:{{url}}"- }- }+ template := notificationTemplate(binding, ctx.SourceType)// Expand once, so text inside AI/output values cannot inject further variables.content := notificationVariable.ReplaceAllStringFunc(template, func(match string) string { return values[notificationVariable.FindStringSubmatch(match)[1]] })if len(content) == 0 || len(content) > 19000 {@@ -174,6 +163,25 @@ func RenderNotification(binding NotificationBinding, ctx NotificationContext) (s}return content, source, nil}++// notificationTemplate returns the binding's own template, or the built-in+// default for its content mode, scope and source type when it has none.+func notificationTemplate(binding NotificationBinding, sourceType string) string {+ if strings.TrimSpace(binding.Template) != "" {+ return binding.Template+ }+ switch {+ case binding.ContentMode == "ai":+ return "### {{ai.title}}\n\n{{ai.body}}\n\n触发时状态:{{status}}\n\n{{url}}"+ case binding.Scope == "run":+ return "### 需求「{{issue.title}}」的 SOP 已完成\n\n{{result}}\n\n{{url}}"+ case sourceType == "schedule_job" || sourceType == "assistant_task":+ return "### {{task.name}} · {{status}}\n\n{{url}}"+ default:+ return "### {{status}}\n项目:{{project}}\n流程:{{workflow}}\n节点:{{node}}\n查看详情:{{url}}"+ }+}+func NotificationAIInstructions(bindings []NotificationBinding) string {lines := []string{}seen := map[string]bool{}