summaryrefslogtreecommitdiff
path: root/internal/storage/db_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/storage/db_test.go')
-rw-r--r--internal/storage/db_test.go68
1 files changed, 68 insertions, 0 deletions
diff --git a/internal/storage/db_test.go b/internal/storage/db_test.go
index 4f9069a..395574c 100644
--- a/internal/storage/db_test.go
+++ b/internal/storage/db_test.go
@@ -421,3 +421,71 @@ func TestUpdateExecution(t *testing.T) {
t.Errorf("artifact_dir: want /tmp/exec, got %q", got.ArtifactDir)
}
}
+
+func makeTestTask(id string, now time.Time) *task.Task {
+ return &task.Task{
+ ID: id, Name: "T-" + id, Claude: task.ClaudeConfig{Instructions: "x"},
+ Priority: task.PriorityNormal, Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"},
+ Tags: []string{}, DependsOn: []string{},
+ State: task.StatePending, CreatedAt: now, UpdatedAt: now,
+ }
+}
+
+func TestStorage_SessionID_RoundTrip(t *testing.T) {
+ db := testDB(t)
+ now := time.Now().UTC()
+ db.CreateTask(makeTestTask("sid-task", now))
+
+ exec := &Execution{
+ ID: "sid-exec", TaskID: "sid-task", StartTime: now, Status: "RUNNING",
+ SessionID: "550e8400-e29b-41d4-a716-446655440000",
+ }
+ if err := db.CreateExecution(exec); err != nil {
+ t.Fatalf("create: %v", err)
+ }
+
+ got, err := db.GetExecution("sid-exec")
+ if err != nil {
+ t.Fatalf("get: %v", err)
+ }
+ if got.SessionID != exec.SessionID {
+ t.Errorf("session_id: want %q, got %q", exec.SessionID, got.SessionID)
+ }
+}
+
+func TestStorage_UpdateTaskQuestion(t *testing.T) {
+ db := testDB(t)
+ now := time.Now().UTC()
+ tk := makeTestTask("q-task", now)
+ db.CreateTask(tk)
+
+ q := `{"text":"Which branch?","options":["main","develop"]}`
+ if err := db.UpdateTaskQuestion("q-task", q); err != nil {
+ t.Fatalf("update question: %v", err)
+ }
+
+ got, err := db.GetTask("q-task")
+ if err != nil {
+ t.Fatalf("get: %v", err)
+ }
+ if got.QuestionJSON != q {
+ t.Errorf("question_json: want %q, got %q", q, got.QuestionJSON)
+ }
+}
+
+func TestStorage_GetLatestExecution(t *testing.T) {
+ db := testDB(t)
+ now := time.Now().UTC()
+ db.CreateTask(makeTestTask("le-task", now))
+
+ db.CreateExecution(&Execution{ID: "le-1", TaskID: "le-task", StartTime: now, Status: "COMPLETED"})
+ db.CreateExecution(&Execution{ID: "le-2", TaskID: "le-task", StartTime: now.Add(time.Minute), Status: "RUNNING"})
+
+ got, err := db.GetLatestExecution("le-task")
+ if err != nil {
+ t.Fatalf("get latest: %v", err)
+ }
+ if got.ID != "le-2" {
+ t.Errorf("want le-2, got %q", got.ID)
+ }
+}