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(runtime): share process sandbox construction between seatbelt and bwrap (#307) (#308)
fx-kurumi6b0d09021619
diff --git a/internal/runtime/process_sandbox_ctor_test.go b/internal/runtime/process_sandbox_ctor_test.gonew file mode 100644index 00000000..6c1be5a1--- /dev/null+++ b/internal/runtime/process_sandbox_ctor_test.go@@ -0,0 +1,57 @@+package runtime++import (+ "os/exec"+ goruntime "runtime"+ "strings"+ "testing"++ "agentflow/internal/domain"+)++func TestCreateProcessSandboxRejectsOtherOS(t *testing.T) {+ _, err := createProcessSandbox("demo", "not-"+goruntime.GOOS, "DemoOS", "sh", "x", t.TempDir(), domain.SandboxProfile{}, SandboxRequirements{})+ if err == nil || err.Error() != "demo sandbox requires DemoOS" {+ t.Fatalf("err = %v", err)+ }+}++func TestCreateProcessSandboxMissingBinary(t *testing.T) {+ _, err := createProcessSandbox("demo", goruntime.GOOS, "DemoOS", "agentflow-no-such-binary", "x", t.TempDir(), domain.SandboxProfile{}, SandboxRequirements{})+ if err == nil || !strings.HasPrefix(err.Error(), "demo sandbox unavailable: ") {+ t.Fatalf("err = %v", err)+ }+}++func TestCreateProcessSandboxBuildsSandbox(t *testing.T) {+ want, err := exec.LookPath("sh")+ if err != nil {+ t.Skip("sh not on PATH")+ }+ workspace := t.TempDir()+ profile := domain.SandboxProfile{Driver: "demo"}+ sb, err := createProcessSandbox("demo", goruntime.GOOS, "DemoOS", "sh", "sb-1", workspace, profile, SandboxRequirements{})+ if err != nil {+ t.Fatal(err)+ }+ ps, ok := sb.(*processSandbox)+ if !ok {+ t.Fatalf("type = %T", sb)+ }+ if ps.ID() != "sb-1" || ps.Workspace() != workspace || ps.Driver() != "demo" || ps.binary != want || ps.profile.Driver != "demo" {+ t.Fatalf("sandbox = %+v", ps)+ }+}++func TestCreateSeatbeltAndBwrapKeepErrorText(t *testing.T) {+ if goruntime.GOOS != "darwin" {+ if _, err := createSeatbelt("x", t.TempDir(), domain.SandboxProfile{}, SandboxRequirements{}); err == nil || err.Error() != "seatbelt sandbox requires macOS" {+ t.Fatalf("seatbelt err = %v", err)+ }+ }+ if goruntime.GOOS != "linux" {+ if _, err := createBwrap("x", t.TempDir(), domain.SandboxProfile{}, SandboxRequirements{}); err == nil || err.Error() != "bwrap sandbox requires Linux" {+ t.Fatalf("bwrap err = %v", err)+ }+ }+}diff --git a/internal/runtime/sandbox_process.go b/internal/runtime/sandbox_process.goindex 3b244bb4..855ca853 100644--- a/internal/runtime/sandbox_process.go+++ b/internal/runtime/sandbox_process.go@@ -201,25 +201,24 @@ func (s *processSandbox) Close(context.Context) error {}func createSeatbelt(id, workspace string, profile domain.SandboxProfile, requirements SandboxRequirements) (Sandbox, error) {- if goruntime.GOOS != "darwin" {- return nil, fmt.Errorf("seatbelt sandbox requires macOS")- }- binary, err := exec.LookPath("sandbox-exec")- if err != nil {- return nil, fmt.Errorf("seatbelt sandbox unavailable: %w", err)- }- return &processSandbox{id: id, workspace: workspace, driver: "seatbelt", profile: profile, requirements: requirements, binary: binary}, nil+ return createProcessSandbox("seatbelt", "darwin", "macOS", "sandbox-exec", id, workspace, profile, requirements)}func createBwrap(id, workspace string, profile domain.SandboxProfile, requirements SandboxRequirements) (Sandbox, error) {- if goruntime.GOOS != "linux" {- return nil, fmt.Errorf("bwrap sandbox requires Linux")+ return createProcessSandbox("bwrap", "linux", "Linux", "bwrap", id, workspace, profile, requirements)+}++// createProcessSandbox builds a processSandbox for driver once the host runs+// requiredOS (named osName in errors) and binaryName is on PATH.+func createProcessSandbox(driver, requiredOS, osName, binaryName, id, workspace string, profile domain.SandboxProfile, requirements SandboxRequirements) (Sandbox, error) {+ if goruntime.GOOS != requiredOS {+ return nil, fmt.Errorf("%s sandbox requires %s", driver, osName)}- binary, err := exec.LookPath("bwrap")+ binary, err := exec.LookPath(binaryName)if err != nil {- return nil, fmt.Errorf("bwrap sandbox unavailable: %w", err)+ return nil, fmt.Errorf("%s sandbox unavailable: %w", driver, err)}- return &processSandbox{id: id, workspace: workspace, driver: "bwrap", profile: profile, requirements: requirements, binary: binary}, nil+ return &processSandbox{id: id, workspace: workspace, driver: driver, profile: profile, requirements: requirements, binary: binary}, nil}func (s *processSandbox) Exec(ctx context.Context, command CommandSpec, sink EventSink) (string, error) {