diff options
Diffstat (limited to 'internal/storage/db_test.go')
| -rw-r--r-- | internal/storage/db_test.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/internal/storage/db_test.go b/internal/storage/db_test.go index d28a4a8..2956be0 100644 --- a/internal/storage/db_test.go +++ b/internal/storage/db_test.go @@ -628,6 +628,41 @@ func TestDeleteTask_DeepSubtaskCascadeAtomic(t *testing.T) { } } +// TestResetTaskForRetry_ClearsQuestionJSON verifies that restarting a BLOCKED +// or FAILED task via ResetTaskForRetry clears any stale question so the frontend +// does not show a stale "waiting for input" prompt. +func TestResetTaskForRetry_ClearsQuestionJSON(t *testing.T) { + db := testDB(t) + now := time.Now().UTC() + tk := makeTestTask("retry-task", now) + tk.State = task.StatePending + db.CreateTask(tk) + + // Transition to BLOCKED with a question. + db.UpdateTaskState("retry-task", task.StateQueued) + db.UpdateTaskState("retry-task", task.StateRunning) + db.UpdateTaskState("retry-task", task.StateBlocked) + db.UpdateTaskQuestion("retry-task", `{"question":"which branch?"}`) + + // Simulate the task failing and being restarted. + db.UpdateTaskState("retry-task", task.StateFailed) + + if _, err := db.ResetTaskForRetry("retry-task"); err != nil { + t.Fatalf("ResetTaskForRetry: %v", err) + } + + got, err := db.GetTask("retry-task") + if err != nil { + t.Fatalf("GetTask: %v", err) + } + if got.QuestionJSON != "" { + t.Errorf("question_json should be cleared after reset, got %q", got.QuestionJSON) + } + if got.State != task.StateQueued { + t.Errorf("state should be QUEUED, got %q", got.State) + } +} + func TestStorage_GetLatestExecution(t *testing.T) { db := testDB(t) now := time.Now().UTC() |
