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(runner): extract runtimeProviderSpecs and builtinRuntimes from detectRuntimes (#661) (#662)

fx-kurumidfd9e2c2a257
diff --git a/internal/runner/detect.go b/internal/runner/detect.go
index 1b4f123e..b7bd4da3 100644
--- a/internal/runner/detect.go
+++ b/internal/runner/detect.go
@@ -108,38 +108,9 @@ func DetectRuntimes(ctx context.Context, extraBinaries map[string]string) []doma
}
func detectRuntimes(ctx context.Context, extraBinaries map[string]string, inventory managedcli.Inventory) []domain.RunnerRuntime {
- specs := make([]providerSpec, 0, len(defaultProviders)+len(extraBinaries)+1)
- seen := map[string]bool{}
- for _, spec := range defaultProviders {
- specs = append(specs, spec)
- seen[spec.Kind] = true
- }
- kinds := make([]string, 0, len(extraBinaries))
- for kind := range extraBinaries {
- kinds = append(kinds, kind)
- }
- sort.Strings(kinds)
- for _, kind := range kinds {
- if !seen[kind] {
- specs = append(specs, providerSpec{Kind: kind, Binary: extraBinaries[kind]})
- seen[kind] = true
- }
- }
+ specs := runtimeProviderSpecs(extraBinaries)
out := make([]domain.RunnerRuntime, 0, len(specs)+2)
- out = append(out, domain.RunnerRuntime{
- Provider: mockProviderKind,
- BinaryPath: "(builtin)",
- Capabilities: []string{"non_interactive"},
- Status: domain.RuntimeStatusOnline,
- })
- // The terminal capability lets the platform run verification gates and
- // sandbox-side commands on this machine.
- out = append(out, domain.RunnerRuntime{
- Provider: terminalProviderKind,
- BinaryPath: "(builtin)",
- Capabilities: []string{"terminal"},
- Status: domain.RuntimeStatusOnline,
- })
+ out = append(out, builtinRuntimes()...)
for _, spec := range specs {
binary, managed := inventory.BinaryFor(spec.Kind)
if !managed {
@@ -171,6 +142,52 @@ func detectRuntimes(ctx context.Context, extraBinaries map[string]string, invent
return out
}
+// runtimeProviderSpecs returns the CLIs to probe: every default provider in
+// declaration order, followed by extra kinds configured only through
+// extraBinaries in sorted order. An extra binary for a default kind does not
+// add a second spec; detectRuntimes applies it as an explicit override.
+func runtimeProviderSpecs(extraBinaries map[string]string) []providerSpec {
+ specs := make([]providerSpec, 0, len(defaultProviders)+len(extraBinaries))
+ seen := make(map[string]bool, len(defaultProviders)+len(extraBinaries))
+ for _, spec := range defaultProviders {
+ specs = append(specs, spec)
+ seen[spec.Kind] = true
+ }
+ kinds := make([]string, 0, len(extraBinaries))
+ for kind := range extraBinaries {
+ kinds = append(kinds, kind)
+ }
+ sort.Strings(kinds)
+ for _, kind := range kinds {
+ if !seen[kind] {
+ specs = append(specs, providerSpec{Kind: kind, Binary: extraBinaries[kind]})
+ seen[kind] = true
+ }
+ }
+ return specs
+}
+
+// builtinRuntimes returns the in-process runtimes every runner reports
+// regardless of installed CLIs: the mock provider and the terminal
+// capability, which lets the platform run verification gates and
+// sandbox-side commands on this machine.
+func builtinRuntimes() []domain.RunnerRuntime {
+ return []domain.RunnerRuntime{
+ {
+ Provider: mockProviderKind,
+ BinaryPath: "(builtin)",
+ Capabilities: []string{"non_interactive"},
+ Status: domain.RuntimeStatusOnline,
+ },
+ {
+ Provider: terminalProviderKind,
+ BinaryPath: "(builtin)",
+ Capabilities: []string{"terminal"},
+ Status: domain.RuntimeStatusOnline,
+ },
+ }
+}
+
func probeVersion(ctx context.Context, path string, flags []string, environments ...map[string]string) string {
probeCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
diff --git a/internal/runner/detect_runtime_specs_test.go b/internal/runner/detect_runtime_specs_test.go
new file mode 100644
index 00000000..82f0f27d
--- /dev/null
+++ b/internal/runner/detect_runtime_specs_test.go
@@ -0,0 +1,77 @@
+package runner
+
+import (
+ "context"
+ "testing"
+
+ "agentflow/internal/domain"
+)
+
+func TestRuntimeProviderSpecsDefaultsOnly(t *testing.T) {
+ specs := runtimeProviderSpecs(nil)
+ if len(specs) != len(defaultProviders) {
+ t.Fatalf("len(specs) = %d, want %d", len(specs), len(defaultProviders))
+ }
+ for i, spec := range defaultProviders {
+ if specs[i].Kind != spec.Kind || specs[i].Binary != spec.Binary {
+ t.Fatalf("specs[%d] = %+v, want %+v", i, specs[i], spec)
+ }
+ }
+}
+
+func TestRuntimeProviderSpecsAppendsSortedExtraKinds(t *testing.T) {
+ specs := runtimeProviderSpecs(map[string]string{
+ "zeta": "/opt/zeta",
+ "alpha": "/opt/alpha",
+ "claude-code": "/opt/claude",
+ })
+ if len(specs) != len(defaultProviders)+2 {
+ t.Fatalf("len(specs) = %d, want %d", len(specs), len(defaultProviders)+2)
+ }
+ for i, spec := range defaultProviders {
+ // An extra binary for a default kind is an override applied later,
+ // not a replacement of the default spec.
+ if specs[i].Kind != spec.Kind || specs[i].Binary != spec.Binary {
+ t.Fatalf("specs[%d] = %+v, want %+v", i, specs[i], spec)
+ }
+ }
+ extra := specs[len(defaultProviders):]
+ want := []providerSpec{{Kind: "alpha", Binary: "/opt/alpha"}, {Kind: "zeta", Binary: "/opt/zeta"}}
+ for i := range want {
+ if extra[i].Kind != want[i].Kind || extra[i].Binary != want[i].Binary {
+ t.Fatalf("extra[%d] = %+v, want %+v", i, extra[i], want[i])
+ }
+ }
+}
+
+func TestBuiltinRuntimes(t *testing.T) {
+ got := builtinRuntimes()
+ if len(got) != 2 {
+ t.Fatalf("len(builtinRuntimes()) = %d, want 2", len(got))
+ }
+ want := []struct {
+ provider string
+ capability string
+ }{{mockProviderKind, "non_interactive"}, {terminalProviderKind, "terminal"}}
+ for i, w := range want {
+ rt := got[i]
+ if rt.Provider != w.provider || rt.BinaryPath != "(builtin)" || rt.Status != domain.RuntimeStatusOnline {
+ t.Fatalf("builtinRuntimes()[%d] = %+v", i, rt)
+ }
+ if len(rt.Capabilities) != 1 || rt.Capabilities[0] != w.capability {
+ t.Fatalf("builtinRuntimes()[%d].Capabilities = %v, want [%s]", i, rt.Capabilities, w.capability)
+ }
+ }
+}
+
+func TestDetectRuntimesStartsWithBuiltinRuntimes(t *testing.T) {
+ t.Setenv("HOME", t.TempDir())
+ t.Setenv("PATH", t.TempDir())
+ got := detectRuntimes(context.Background(), nil, nil)
+ if len(got) < 2 {
+ t.Fatalf("detectRuntimes = %+v, want builtin runtimes first", got)
+ }
+ if got[0].Provider != mockProviderKind || got[1].Provider != terminalProviderKind {
+ t.Fatalf("detectRuntimes providers = %s, %s", got[0].Provider, got[1].Provider)
+ }
+}