fix(process): reject nil start context
This commit is contained in:
parent
6f35954ac2
commit
73b0ffecc0
2 changed files with 24 additions and 0 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue