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(engine): dedupe cloud pool runner listing and enablement check (#466) (#467)
fx-kurumidddc948595ea
diff --git a/internal/engine/cloud_pool.go b/internal/engine/cloud_pool.goindex e4c99954..b802c209 100644--- a/internal/engine/cloud_pool.go+++ b/internal/engine/cloud_pool.go@@ -54,25 +54,37 @@ func (e *Engine) cloudPoolRunner(projectID string) (domain.Runner, bool) {e.mu.Lock()pool := e.cloudPoole.mu.Unlock()- if pool.Label == "" || !cloudPoolServes(pool.Projects, projectID) {+ if !pool.serves(projectID) {return domain.Runner{}, false}return e.pickPoolRunner(pool.Label)}+// serves reports whether the pool is enabled and covers projectID.+func (pool CloudRunnerPool) serves(projectID string) bool {+ return pool.Label != "" && cloudPoolServes(pool.Projects, projectID)+}+func (e *Engine) pickPoolRunner(label string) (domain.Runner, bool) {- var candidates []domain.Runner- for _, runner := range e.repo.Runners() {- if poolRunnerEligible(runner, label) {- candidates = append(candidates, runner)- }- }+ candidates := e.eligiblePoolRunners(label)if len(candidates) == 0 {return domain.Runner{}, false}return candidates[rand.Intn(len(candidates))], true}+// eligiblePoolRunners lists the registered runners that can take pool work+// for label right now.+func (e *Engine) eligiblePoolRunners(label string) []domain.Runner {+ var out []domain.Runner+ for _, runner := range e.repo.Runners() {+ if poolRunnerEligible(runner, label) {+ out = append(out, runner)+ }+ }+ return out+}+func poolRunnerEligible(runner domain.Runner, label string) bool {// Pool runners receive every user's credentials, so only runners// registered with the platform bootstrap token (no owner) qualify;@@ -104,7 +116,7 @@ func (e *Engine) cloudPoolRequired(projectID string) bool {e.mu.Lock()pool := e.cloudPoole.mu.Unlock()- return pool.Required && pool.Label != "" && cloudPoolServes(pool.Projects, projectID)+ return pool.Required && pool.serves(projectID)}// CloudPoolStatus reports whether the cloud runner pool is configured and@@ -114,12 +126,7 @@ func (e *Engine) CloudPoolStatus() (configured bool, online int) {if label == "" {return false, 0}- for _, runner := range e.repo.Runners() {- if poolRunnerEligible(runner, label) {- online++- }- }- return true, online+ return true, len(e.eligiblePoolRunners(label))}func (e *Engine) cloudPoolLabel() string {diff --git a/internal/engine/cloud_pool_helpers_test.go b/internal/engine/cloud_pool_helpers_test.gonew file mode 100644index 00000000..003f359e--- /dev/null+++ b/internal/engine/cloud_pool_helpers_test.go@@ -0,0 +1,61 @@+package engine++import (+ "testing"++ "agentflow/internal/domain"+)++func TestCloudRunnerPoolServes(t *testing.T) {+ cases := []struct {+ name string+ pool CloudRunnerPool+ project string+ want bool+ }{+ {"disabled without label", CloudRunnerPool{Projects: []string{"*"}}, "p1", false},+ {"wildcard", CloudRunnerPool{Label: "pool", Projects: []string{"*"}}, "p1", true},+ {"listed project", CloudRunnerPool{Label: "pool", Projects: []string{"p1"}}, " p1 ", true},+ {"unlisted project", CloudRunnerPool{Label: "pool", Projects: []string{"p1"}}, "p2", false},+ {"empty project", CloudRunnerPool{Label: "pool", Projects: []string{"p1"}}, "", false},+ {"no projects", CloudRunnerPool{Label: "pool"}, "p1", false},+ }+ for _, tc := range cases {+ if got := tc.pool.serves(tc.project); got != tc.want {+ t.Errorf("%s: serves(%q) = %v, want %v", tc.name, tc.project, got, tc.want)+ }+ }+}++func TestEligiblePoolRunnersFiltersRegisteredRunners(t *testing.T) {+ e, st := cvEEngine(t)+ if got := e.eligiblePoolRunners("pool"); len(got) != 0 {+ t.Fatalf("empty registry = %+v", got)+ }+ runners := []domain.Runner{+ {ID: "ok", Name: "ok", Status: domain.RunnerStatusOnline, RunnerVersion: domain.RunnerVersionWorkspaceOwnerPreparation, Labels: []string{" pool "}},+ {ID: "other-label", Name: "other", Status: domain.RunnerStatusOnline, RunnerVersion: domain.RunnerVersionWorkspaceOwnerPreparation, Labels: []string{"gpu"}},+ {ID: "owned", Name: "owned", OwnerUserID: 7, Status: domain.RunnerStatusOnline, RunnerVersion: domain.RunnerVersionWorkspaceOwnerPreparation, Labels: []string{"pool"}},+ {ID: "offline", Name: "offline", Status: domain.RunnerStatusOffline, RunnerVersion: domain.RunnerVersionWorkspaceOwnerPreparation, Labels: []string{"pool"}},+ {ID: "old", Name: "old", Status: domain.RunnerStatusOnline, RunnerVersion: domain.RunnerVersionWorkBranchSync, Labels: []string{"pool"}},+ }+ for _, r := range runners {+ if err := st.PutRunner(r); err != nil {+ t.Fatal(err)+ }+ }+ got := e.eligiblePoolRunners("pool")+ if len(got) != 1 || got[0].ID != "ok" {+ t.Fatalf("eligible = %+v", got)+ }+ e.ConfigureCloudRunnerPool(CloudRunnerPool{Label: "pool", Projects: []string{"*"}})+ if configured, online := e.CloudPoolStatus(); !configured || online != len(got) {+ t.Fatalf("status = %v %d, want true %d", configured, online, len(got))+ }+ if picked, ok := e.pickPoolRunner("pool"); !ok || picked.ID != "ok" {+ t.Fatalf("picked = %+v %v", picked, ok)+ }+ if _, ok := e.pickPoolRunner("gpu-missing"); ok {+ t.Fatal("picked runner for unknown label")+ }+}