Skip to content

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.

refactor(engine): simplify hasRunEvent with slices.ContainsFunc (#376)

fx-kurumi8afb58617f4e
diff --git a/internal/engine/codebuddy_auth.go b/internal/engine/codebuddy_auth.go
index 4ceddf2c..48696cfb 100644
--- a/internal/engine/codebuddy_auth.go
+++ b/internal/engine/codebuddy_auth.go
@@ -1,6 +1,7 @@
package engine
import (
+ "slices"
"strings"
"agentflow/internal/domain"
@@ -65,10 +66,5 @@ func (e *Engine) sponsoredExecutor(runID string, ex domain.ExecutorDefinition, m
}
func hasRunEvent(run domain.Run, typ string) bool {
- for _, event := range run.Events {
- if event.Type == typ {
- return true
- }
- }
- return false
+ return slices.ContainsFunc(run.Events, func(event domain.RunEvent) bool { return event.Type == typ })
}
diff --git a/internal/engine/has_run_event_test.go b/internal/engine/has_run_event_test.go
new file mode 100644
index 00000000..2118e96d
--- /dev/null
+++ b/internal/engine/has_run_event_test.go
@@ -0,0 +1,29 @@
+package engine
+
+import (
+ "testing"
+
+ "agentflow/internal/domain"
+)
+
+func TestHasRunEvent(t *testing.T) {
+ cases := []struct {
+ name string
+ events []domain.RunEvent
+ typ string
+ want bool
+ }{
+ {name: "no events", typ: sponsoredRunEvent, want: false},
+ {name: "single match", events: []domain.RunEvent{{Type: sponsoredRunEvent}}, typ: sponsoredRunEvent, want: true},
+ {name: "no match", events: []domain.RunEvent{{Type: "node_started"}, {Type: "node_completed"}}, typ: sponsoredRunEvent, want: false},
+ {name: "match among many", events: []domain.RunEvent{{Type: "node_started"}, {Type: sponsoredRunEvent}, {Type: "node_completed"}}, typ: sponsoredRunEvent, want: true},
+ {name: "case sensitive", events: []domain.RunEvent{{Type: "Node_Started"}}, typ: "node_started", want: false},
+ }
+ for _, tc := range cases {
+ t.Run(tc.name, func(t *testing.T) {
+ if got := hasRunEvent(domain.Run{Events: tc.events}, tc.typ); got != tc.want {
+ t.Fatalf("hasRunEvent(%v, %q) = %v, want %v", tc.events, tc.typ, got, tc.want)
+ }
+ })
+ }
+}