fix(process): copy info slices defensively

This commit is contained in:
Virgil 2026-04-04 00:04:54 +00:00
parent f5a940facd
commit 2bc6eb70d7
3 changed files with 20 additions and 3 deletions

View file

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

View file

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

View file

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