From 8f359bb004cf8c69fda91be0b7a8bff8d1de3778 Mon Sep 17 00:00:00 2001 From: Virgil Date: Tue, 31 Mar 2026 19:46:05 +0000 Subject: [PATCH] fix(process): make process.start non-detached by default Co-Authored-By: Virgil --- actions.go | 7 +------ service_test.go | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/actions.go b/actions.go index 14d66eb..a9eddd8 100644 --- a/actions.go +++ b/actions.go @@ -70,15 +70,10 @@ func (s *Service) handleStart(ctx context.Context, opts core.Options) core.Resul return core.Result{Value: core.E("process.start", "command is required", nil), OK: false} } - detach := true - if opts.Has("detach") { - detach = opts.Bool("detach") - } - runOpts := RunOptions{ Command: command, Dir: opts.String("dir"), - Detach: detach, + Detach: opts.Bool("detach"), } if r := opts.Get("args"); r.OK { runOpts.Args = optionStrings(r.Value) diff --git a/service_test.go b/service_test.go index f68fde9..5c6d1e9 100644 --- a/service_test.go +++ b/service_test.go @@ -126,6 +126,28 @@ func TestService_HandleStart_Good(t *testing.T) { t.Fatal("process should honor detached=false context cancellation") } }) + + t.Run("defaults to non-detached", func(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + + start := c.Action("process.start").Run(ctx, framework.NewOptions( + framework.Option{Key: "command", Value: "sleep"}, + framework.Option{Key: "args", Value: []string{"60"}}, + )) + require.True(t, start.OK) + + id := start.Value.(string) + proc, err := svc.Get(id) + require.NoError(t, err) + + cancel() + + select { + case <-proc.Done(): + case <-time.After(2 * time.Second): + t.Fatal("process should honor context cancellation by default") + } + }) } func TestService_HandleStart_Bad(t *testing.T) {