|
5 | 5 | "errors" |
6 | 6 | "strings" |
7 | 7 | "testing" |
8 | | - "time" |
9 | 8 |
|
10 | 9 | "neo-code/internal/runtime/controlplane" |
11 | 10 | "neo-code/internal/subagent" |
@@ -182,6 +181,50 @@ func TestServiceRunSubAgentTaskFailureFlows(t *testing.T) { |
182 | 181 | }) |
183 | 182 | }) |
184 | 183 |
|
| 184 | + t.Run("context deadline should emit failed timeout", func(t *testing.T) { |
| 185 | + t.Parallel() |
| 186 | + |
| 187 | + service := NewWithFactory(nil, nil, nil, nil, nil) |
| 188 | + service.SetSubAgentFactory(stubSubAgentFactory{ |
| 189 | + create: func(role subagent.Role) (subagent.WorkerRuntime, error) { |
| 190 | + return &stubSubAgentWorker{ |
| 191 | + current: subagent.StateRunning, |
| 192 | + stepErr: context.DeadlineExceeded, |
| 193 | + resultErr: errors.New("no result"), |
| 194 | + result: subagent.Result{ |
| 195 | + Role: role, |
| 196 | + TaskID: "task-timeout", |
| 197 | + }, |
| 198 | + }, nil |
| 199 | + }, |
| 200 | + }) |
| 201 | + |
| 202 | + result, err := service.RunSubAgentTask(context.Background(), SubAgentTaskInput{ |
| 203 | + RunID: "sub-run-timeout-emit", |
| 204 | + Role: subagent.RoleReviewer, |
| 205 | + Task: subagent.Task{ |
| 206 | + ID: "task-timeout", |
| 207 | + Goal: "review", |
| 208 | + }, |
| 209 | + }) |
| 210 | + if err == nil || !errors.Is(err, context.DeadlineExceeded) { |
| 211 | + t.Fatalf("error = %v, want context deadline exceeded", err) |
| 212 | + } |
| 213 | + if result.State != subagent.StateFailed { |
| 214 | + t.Fatalf("result state = %q, want %q", result.State, subagent.StateFailed) |
| 215 | + } |
| 216 | + if result.StopReason != subagent.StopReasonTimeout { |
| 217 | + t.Fatalf("stop reason = %q, want %q", result.StopReason, subagent.StopReasonTimeout) |
| 218 | + } |
| 219 | + |
| 220 | + events := collectRuntimeEvents(service.Events()) |
| 221 | + assertEventSequence(t, events, []EventType{ |
| 222 | + EventSubAgentStarted, |
| 223 | + EventSubAgentProgress, |
| 224 | + EventSubAgentFailed, |
| 225 | + }) |
| 226 | + }) |
| 227 | + |
185 | 228 | t.Run("worker start failed by disallowed capability", func(t *testing.T) { |
186 | 229 | t.Parallel() |
187 | 230 |
|
@@ -340,9 +383,8 @@ func TestServiceRunSubAgentTaskInputValidation(t *testing.T) { |
340 | 383 | t.Fatalf("expected invalid role error") |
341 | 384 | } |
342 | 385 |
|
343 | | - ctx, cancel := context.WithTimeout(context.Background(), time.Nanosecond) |
344 | | - defer cancel() |
345 | | - time.Sleep(2 * time.Millisecond) |
| 386 | + ctx, cancel := context.WithCancel(context.Background()) |
| 387 | + cancel() |
346 | 388 | if _, err := service.RunSubAgentTask(ctx, SubAgentTaskInput{ |
347 | 389 | RunID: "sub-run-timeout", |
348 | 390 | Role: subagent.RoleCoder, |
|
0 commit comments