fix(process): make process.start non-detached by default

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-03-31 19:46:05 +00:00
parent c60f355b25
commit 8f359bb004
2 changed files with 23 additions and 6 deletions

View file

@ -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)

View file

@ -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) {