diff options
| author | Claudomator Agent <agent@claudomator> | 2026-03-09 07:41:37 +0000 |
|---|---|---|
| committer | Claudomator Agent <agent@claudomator> | 2026-03-09 07:41:37 +0000 |
| commit | 441ed9eef3d9691cd9269772857307b84a7f5700 (patch) | |
| tree | 6143f175382ab74f9de9c664a7d6f351fdc78553 /internal/executor/executor_test.go | |
| parent | 96d1c439ce27be80b751ea0085f53602606473d1 (diff) | |
executor: BLOCKED→READY for top-level tasks with subtasks
When a top-level task (ParentTaskID == "") finishes successfully,
check for subtasks before deciding the next state:
- subtasks exist → BLOCKED (waiting for subtasks to complete)
- no subtasks → READY (existing behavior, unchanged)
This applies to both execute() and executeResume().
Adds ListSubtasks to the Store interface.
Tests:
- TestPool_Submit_TopLevel_WithSubtasks_GoesBlocked
- TestPool_Submit_TopLevel_NoSubtasks_GoesReady
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/executor/executor_test.go')
| -rw-r--r-- | internal/executor/executor_test.go | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/internal/executor/executor_test.go b/internal/executor/executor_test.go index 1adba7e..91f7636 100644 --- a/internal/executor/executor_test.go +++ b/internal/executor/executor_test.go @@ -620,6 +620,70 @@ func TestPool_RateLimited_StaleEntryCleaned(t *testing.T) { } } +// TestPool_Submit_TopLevel_NoSubtasks_GoesReady verifies that a top-level task +// with no subtasks still transitions to READY after successful execution. +func TestPool_Submit_TopLevel_NoSubtasks_GoesReady(t *testing.T) { + store := testStore(t) + runner := &mockRunner{} + runners := map[string]Runner{"claude": runner} + logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})) + pool := NewPool(2, runners, store, logger) + + tk := makeTask("no-subtasks-1") // no ParentTaskID, no subtasks + store.CreateTask(tk) + + if err := pool.Submit(context.Background(), tk); err != nil { + t.Fatalf("submit: %v", err) + } + + result := <-pool.Results() + if result.Err != nil { + t.Errorf("expected no error, got: %v", result.Err) + } + if result.Execution.Status != "READY" { + t.Errorf("status: want READY, got %q", result.Execution.Status) + } + got, _ := store.GetTask(tk.ID) + if got.State != task.StateReady { + t.Errorf("task state: want READY, got %v", got.State) + } +} + +// TestPool_Submit_TopLevel_WithSubtasks_GoesBlocked verifies that when a +// top-level task finishes successfully but has subtasks, it transitions to +// BLOCKED (waiting for subtasks) rather than READY. +func TestPool_Submit_TopLevel_WithSubtasks_GoesBlocked(t *testing.T) { + store := testStore(t) + runner := &mockRunner{} + runners := map[string]Runner{"claude": runner} + logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{Level: slog.LevelError})) + pool := NewPool(2, runners, store, logger) + + parent := makeTask("parent-with-subtasks") + store.CreateTask(parent) + + // Create a subtask in the store but do NOT submit it. + sub := makeTask("sub-of-parent") + sub.ParentTaskID = parent.ID + store.CreateTask(sub) + + if err := pool.Submit(context.Background(), parent); err != nil { + t.Fatalf("submit: %v", err) + } + + result := <-pool.Results() + if result.Err != nil { + t.Errorf("expected no error, got: %v", result.Err) + } + if result.Execution.Status != "BLOCKED" { + t.Errorf("status: want BLOCKED, got %q", result.Execution.Status) + } + got, _ := store.GetTask(parent.ID) + if got.State != task.StateBlocked { + t.Errorf("task state: want BLOCKED, got %v", got.State) + } +} + func TestPool_UnsupportedAgent(t *testing.T) { store := testStore(t) runners := map[string]Runner{"claude": &mockRunner{}} |
