summaryrefslogtreecommitdiff
path: root/internal/storage/db_test.go
diff options
context:
space:
mode:
authorClaudomator Agent <agent@claudomator>2026-03-13 19:26:15 +0000
committerClaudomator Agent <agent@claudomator>2026-03-13 19:26:15 +0000
commite2656fcaaed85028785822493a93c7be50dd44c2 (patch)
treef4a5e91553ca18d6ae0d2adbeb1a75114ea8edbb /internal/storage/db_test.go
parent0b4cb1bdeaa6ce3b93a924eaa1fafee508c37de9 (diff)
test: add storage tests for UpdateTaskSummary and AppendTaskInteraction
The summary+interactions feature was already fully implemented but lacked storage-layer tests. Added tests covering round-trip persistence of task summaries, accumulation of Q&A interactions, and error handling for nonexistent tasks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/storage/db_test.go')
-rw-r--r--internal/storage/db_test.go125
1 files changed, 125 insertions, 0 deletions
diff --git a/internal/storage/db_test.go b/internal/storage/db_test.go
index 2956be0..31be246 100644
--- a/internal/storage/db_test.go
+++ b/internal/storage/db_test.go
@@ -768,3 +768,128 @@ func TestListRecentExecutions_LargeDataset(t *testing.T) {
})
}
+func TestUpdateTaskSummary(t *testing.T) {
+ db := testDB(t)
+ now := time.Now().UTC().Truncate(time.Second)
+ tk := &task.Task{
+ ID: "sum-task",
+ Name: "Summary Task",
+ 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)
+ }
+
+ // Initially summary should be empty.
+ got, err := db.GetTask("sum-task")
+ if err != nil {
+ t.Fatalf("getting task: %v", err)
+ }
+ if got.Summary != "" {
+ t.Errorf("initial summary: want empty, got %q", got.Summary)
+ }
+
+ // Set summary.
+ if err := db.UpdateTaskSummary("sum-task", "All done successfully."); err != nil {
+ t.Fatalf("UpdateTaskSummary: %v", err)
+ }
+
+ got, err = db.GetTask("sum-task")
+ if err != nil {
+ t.Fatalf("getting task after summary update: %v", err)
+ }
+ if got.Summary != "All done successfully." {
+ t.Errorf("summary: want 'All done successfully.', got %q", got.Summary)
+ }
+}
+
+func TestAppendTaskInteraction(t *testing.T) {
+ db := testDB(t)
+ now := time.Now().UTC().Truncate(time.Second)
+ tk := &task.Task{
+ ID: "qa-task",
+ Name: "QA Task",
+ 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)
+ }
+
+ // Initially interactions should be empty.
+ got, err := db.GetTask("qa-task")
+ if err != nil {
+ t.Fatalf("getting task: %v", err)
+ }
+ if len(got.Interactions) != 0 {
+ t.Errorf("initial interactions: want 0, got %d", len(got.Interactions))
+ }
+
+ // Append first interaction.
+ i1 := task.Interaction{
+ QuestionText: "Which color?",
+ Options: []string{"red", "blue"},
+ Answer: "blue",
+ AskedAt: now,
+ }
+ if err := db.AppendTaskInteraction("qa-task", i1); err != nil {
+ t.Fatalf("AppendTaskInteraction #1: %v", err)
+ }
+
+ got, err = db.GetTask("qa-task")
+ if err != nil {
+ t.Fatalf("getting task after first append: %v", err)
+ }
+ if len(got.Interactions) != 1 {
+ t.Fatalf("interactions count: want 1, got %d", len(got.Interactions))
+ }
+ if got.Interactions[0].QuestionText != "Which color?" {
+ t.Errorf("question: want 'Which color?', got %q", got.Interactions[0].QuestionText)
+ }
+ if got.Interactions[0].Answer != "blue" {
+ t.Errorf("answer: want 'blue', got %q", got.Interactions[0].Answer)
+ }
+
+ // Append second interaction — verify it accumulates.
+ i2 := task.Interaction{
+ QuestionText: "Which size?",
+ Answer: "large",
+ AskedAt: now.Add(time.Minute),
+ }
+ if err := db.AppendTaskInteraction("qa-task", i2); err != nil {
+ t.Fatalf("AppendTaskInteraction #2: %v", err)
+ }
+
+ got, err = db.GetTask("qa-task")
+ if err != nil {
+ t.Fatalf("getting task after second append: %v", err)
+ }
+ if len(got.Interactions) != 2 {
+ t.Fatalf("interactions count: want 2, got %d", len(got.Interactions))
+ }
+ if got.Interactions[1].QuestionText != "Which size?" {
+ t.Errorf("second question: want 'Which size?', got %q", got.Interactions[1].QuestionText)
+ }
+}
+
+func TestAppendTaskInteraction_NotFound(t *testing.T) {
+ db := testDB(t)
+ err := db.AppendTaskInteraction("nonexistent", task.Interaction{QuestionText: "hi"})
+ if err == nil {
+ t.Error("expected error for nonexistent task")
+ }
+}
+