From 73b0ffecc0fdfc272616dda93cf048f6bb449e3e Mon Sep 17 00:00:00 2001 From: Virgil Date: Sat, 4 Apr 2026 02:03:49 +0000 Subject: [PATCH] fix(process): reject nil start context --- service.go | 4 ++++ service_test.go | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/service.go b/service.go index 4794310..13cc019 100644 --- a/service.go +++ b/service.go @@ -25,6 +25,7 @@ var ( ErrProcessNotFound = coreerr.E("", "process not found", nil) ErrProcessNotRunning = coreerr.E("", "process is not running", nil) ErrStdinNotAvailable = coreerr.E("", "stdin not available", nil) + ErrContextRequired = coreerr.E("", "context is required", nil) ) // Service manages process execution with Core IPC integration. @@ -138,6 +139,9 @@ func (s *Service) StartWithOptions(ctx context.Context, opts RunOptions) (*Proce if opts.Command == "" { return nil, coreerr.E("Service.StartWithOptions", "command is required", nil) } + if ctx == nil { + return nil, coreerr.E("Service.StartWithOptions", "context is required", ErrContextRequired) + } id := fmt.Sprintf("proc-%d", s.idCounter.Add(1)) startedAt := time.Now() diff --git a/service_test.go b/service_test.go index 3824ac7..6579bdf 100644 --- a/service_test.go +++ b/service_test.go @@ -90,6 +90,16 @@ func TestService_Start(t *testing.T) { assert.Contains(t, err.Error(), "command is required") }) + t.Run("nil context is rejected", func(t *testing.T) { + svc, _ := newTestService(t) + + _, err := svc.StartWithOptions(nil, RunOptions{ + Command: "echo", + }) + require.Error(t, err) + assert.ErrorIs(t, err, ErrContextRequired) + }) + t.Run("with working directory", func(t *testing.T) { svc, _ := newTestService(t) @@ -698,6 +708,16 @@ func TestService_RunWithOptions(t *testing.T) { assert.Error(t, err) assert.Contains(t, err.Error(), "exited with code 2") }) + + t.Run("rejects nil context", func(t *testing.T) { + svc, _ := newTestService(t) + + _, err := svc.RunWithOptions(nil, RunOptions{ + Command: "echo", + }) + require.Error(t, err) + assert.ErrorIs(t, err, ErrContextRequired) + }) } func TestService_Running(t *testing.T) {