From 2bc6eb70d7ebaabca7203c4aec3407fb08d74d3b Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 00:04:54 +0000 Subject: [PATCH] fix(process): copy info slices defensively --- process.go | 2 +- process_test.go | 17 +++++++++++++++++ service.go | 4 ++-- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/process.go b/process.go index 5b4ae84..17da313 100644 --- a/process.go +++ b/process.go @@ -49,7 +49,7 @@ func (p *Process) Info() Info { return Info{ ID: p.ID, Command: p.Command, - Args: p.Args, + Args: append([]string(nil), p.Args...), Dir: p.Dir, StartedAt: p.StartedAt, Running: p.Status == StatusRunning, diff --git a/process_test.go b/process_test.go index 1447f01..f7590d0 100644 --- a/process_test.go +++ b/process_test.go @@ -28,6 +28,23 @@ func TestProcess_Info(t *testing.T) { assert.Greater(t, info.Duration, time.Duration(0)) } +func TestProcess_InfoSnapshot(t *testing.T) { + svc, _ := newTestService(t) + + proc, err := svc.Start(context.Background(), "echo", "snapshot") + require.NoError(t, err) + + <-proc.Done() + + info := proc.Info() + require.NotEmpty(t, info.Args) + + info.Args[0] = "mutated" + + assert.Equal(t, "snapshot", proc.Args[0]) + assert.Equal(t, "mutated", info.Args[0]) +} + func TestProcess_Output(t *testing.T) { t.Run("captures stdout", func(t *testing.T) { svc, _ := newTestService(t) diff --git a/service.go b/service.go index 9a5c211..6ed34dc 100644 --- a/service.go +++ b/service.go @@ -157,9 +157,9 @@ func (s *Service) StartWithOptions(ctx context.Context, opts RunOptions) (*Proce proc := &Process{ ID: id, Command: opts.Command, - Args: opts.Args, + Args: append([]string(nil), opts.Args...), Dir: opts.Dir, - Env: opts.Env, + Env: append([]string(nil), opts.Env...), StartedAt: startedAt, Status: StatusRunning, cmd: cmd,