diff options
Diffstat (limited to 'internal/storage/db_test.go')
| -rw-r--r-- | internal/storage/db_test.go | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/internal/storage/db_test.go b/internal/storage/db_test.go index b53234a..3adf17f 100644 --- a/internal/storage/db_test.go +++ b/internal/storage/db_test.go @@ -1057,6 +1057,71 @@ func TestCreateTask_Project_RoundTrip(t *testing.T) { } } +func TestCreateTask_AcceptanceCriteria_RoundTrip(t *testing.T) { + db := testDB(t) + now := time.Now().UTC().Truncate(time.Second) + + tk := &task.Task{ + ID: "ac-1", + Name: "Task With Criteria", + Agent: task.AgentConfig{Type: "claude", Instructions: "do it"}, + Priority: task.PriorityNormal, + Tags: []string{}, + DependsOn: []string{}, + AcceptanceCriteria: []string{"tests pass", "no new lint warnings"}, + Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"}, + State: task.StatePending, + CreatedAt: now, + UpdatedAt: now, + } + if err := db.CreateTask(tk); err != nil { + t.Fatalf("creating task: %v", err) + } + + got, err := db.GetTask("ac-1") + if err != nil { + t.Fatalf("getting task: %v", err) + } + if len(got.AcceptanceCriteria) != 2 || got.AcceptanceCriteria[0] != "tests pass" || got.AcceptanceCriteria[1] != "no new lint warnings" { + t.Errorf("AcceptanceCriteria: want [tests pass, no new lint warnings], got %+v", got.AcceptanceCriteria) + } +} + +// TestCreateTask_AcceptanceCriteria_DefaultsEmpty proves a task created +// without AcceptanceCriteria round-trips as an empty (not nil) slice, the +// same "never null" convention story.Story.AcceptanceCriteria already uses. +func TestCreateTask_AcceptanceCriteria_DefaultsEmpty(t *testing.T) { + db := testDB(t) + now := time.Now().UTC().Truncate(time.Second) + + tk := &task.Task{ + ID: "ac-2", + Name: "Task Without Criteria", + Agent: task.AgentConfig{Type: "claude", Instructions: "do it"}, + Priority: task.PriorityNormal, + Tags: []string{}, + DependsOn: []string{}, + Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"}, + State: task.StatePending, + CreatedAt: now, + UpdatedAt: now, + } + if err := db.CreateTask(tk); err != nil { + t.Fatalf("creating task: %v", err) + } + + got, err := db.GetTask("ac-2") + if err != nil { + t.Fatalf("getting task: %v", err) + } + if got.AcceptanceCriteria == nil { + t.Error("AcceptanceCriteria: want empty slice, got nil") + } + if len(got.AcceptanceCriteria) != 0 { + t.Errorf("AcceptanceCriteria: want empty, got %+v", got.AcceptanceCriteria) + } +} + // ── Push subscription tests ─────────────────────────────────────────────────── func TestPushSubscription_SaveAndList(t *testing.T) { |
