feat(process): honor pending lifecycle

This commit is contained in:
Virgil 2026-04-04 01:11:03 +00:00
parent 1ccc61848b
commit 31be7280a6
2 changed files with 21 additions and 1 deletions

View file

@ -28,6 +28,18 @@ func TestProcess_Info(t *testing.T) {
assert.Greater(t, info.Duration, time.Duration(0))
}
func TestProcess_Info_Pending(t *testing.T) {
proc := &Process{
ID: "pending",
Status: StatusPending,
done: make(chan struct{}),
}
info := proc.Info()
assert.Equal(t, StatusPending, info.Status)
assert.False(t, info.Running)
}
func TestProcess_InfoSnapshot(t *testing.T) {
svc, _ := newTestService(t)

View file

@ -198,7 +198,7 @@ func (s *Service) StartWithOptions(ctx context.Context, opts RunOptions) (*Proce
Dir: opts.Dir,
Env: append([]string(nil), opts.Env...),
StartedAt: startedAt,
Status: StatusRunning,
Status: StatusPending,
cmd: cmd,
ctx: procCtx,
cancel: cancel,
@ -211,6 +211,10 @@ func (s *Service) StartWithOptions(ctx context.Context, opts RunOptions) (*Proce
// Start the process
if err := cmd.Start(); err != nil {
proc.mu.Lock()
proc.Status = StatusFailed
proc.mu.Unlock()
cancel()
if c := s.coreApp(); c != nil {
_ = c.ACTION(ActionProcessExited{
@ -223,6 +227,10 @@ func (s *Service) StartWithOptions(ctx context.Context, opts RunOptions) (*Proce
return nil, coreerr.E("Service.StartWithOptions", "failed to start process", err)
}
proc.mu.Lock()
proc.Status = StatusRunning
proc.mu.Unlock()
// Store process
s.mu.Lock()
s.processes[id] = proc