diff options
Diffstat (limited to 'internal/storage/db_test.go')
| -rw-r--r-- | internal/storage/db_test.go | 68 |
1 files changed, 51 insertions, 17 deletions
diff --git a/internal/storage/db_test.go b/internal/storage/db_test.go index 2738a41..f737096 100644 --- a/internal/storage/db_test.go +++ b/internal/storage/db_test.go @@ -37,7 +37,8 @@ func TestCreateTask_AndGetTask(t *testing.T) { ID: "task-1", Name: "Test Task", Description: "A test", - Claude: task.ClaudeConfig{ + Agent: task.AgentConfig{ + Type: "claude", Model: "sonnet", Instructions: "do it", ProjectDir: "/tmp", @@ -64,11 +65,11 @@ func TestCreateTask_AndGetTask(t *testing.T) { if got.Name != "Test Task" { t.Errorf("name: want 'Test Task', got %q", got.Name) } - if got.Claude.Model != "sonnet" { - t.Errorf("model: want 'sonnet', got %q", got.Claude.Model) + if got.Agent.Model != "sonnet" { + t.Errorf("model: want 'sonnet', got %q", got.Agent.Model) } - if got.Claude.MaxBudgetUSD != 2.5 { - t.Errorf("budget: want 2.5, got %f", got.Claude.MaxBudgetUSD) + if got.Agent.MaxBudgetUSD != 2.5 { + t.Errorf("budget: want 2.5, got %f", got.Agent.MaxBudgetUSD) } if got.Priority != task.PriorityHigh { t.Errorf("priority: want 'high', got %q", got.Priority) @@ -93,7 +94,7 @@ func TestUpdateTaskState(t *testing.T) { tk := &task.Task{ ID: "task-2", Name: "Stateful", - Claude: task.ClaudeConfig{Instructions: "test"}, + Agent: task.AgentConfig{Type: "claude", Instructions: "test"}, Priority: task.PriorityNormal, Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"}, Tags: []string{}, @@ -162,7 +163,7 @@ func TestListTasks_FilterByState(t *testing.T) { for i, state := range []task.State{task.StatePending, task.StatePending, task.StateRunning} { tk := &task.Task{ ID: fmt.Sprintf("t-%d", i), Name: fmt.Sprintf("Task %d", i), - Claude: task.ClaudeConfig{Instructions: "x"}, Priority: task.PriorityNormal, + Agent: task.AgentConfig{Type: "claude", Instructions: "x"}, Priority: task.PriorityNormal, Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"}, Tags: []string{}, DependsOn: []string{}, State: state, CreatedAt: now, UpdatedAt: now, @@ -195,7 +196,7 @@ func TestListTasks_WithLimit(t *testing.T) { for i := 0; i < 5; i++ { tk := &task.Task{ ID: fmt.Sprintf("lt-%d", i), Name: fmt.Sprintf("T%d", i), - Claude: task.ClaudeConfig{Instructions: "x"}, Priority: task.PriorityNormal, + Agent: task.AgentConfig{Type: "claude", Instructions: "x"}, Priority: task.PriorityNormal, Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"}, Tags: []string{}, DependsOn: []string{}, State: task.StatePending, CreatedAt: now.Add(time.Duration(i) * time.Second), UpdatedAt: now, @@ -218,7 +219,7 @@ func TestCreateExecution_AndGet(t *testing.T) { // Need a task first. tk := &task.Task{ - ID: "etask", Name: "E", Claude: task.ClaudeConfig{Instructions: "x"}, + ID: "etask", Name: "E", Agent: task.AgentConfig{Type: "claude", Instructions: "x"}, Priority: task.PriorityNormal, Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"}, Tags: []string{}, DependsOn: []string{}, State: task.StatePending, CreatedAt: now, UpdatedAt: now, @@ -259,7 +260,7 @@ func TestListExecutions(t *testing.T) { db := testDB(t) now := time.Now().UTC() tk := &task.Task{ - ID: "ltask", Name: "L", Claude: task.ClaudeConfig{Instructions: "x"}, + ID: "ltask", Name: "L", Agent: task.AgentConfig{Type: "claude", Instructions: "x"}, Priority: task.PriorityNormal, Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"}, Tags: []string{}, DependsOn: []string{}, State: task.StatePending, CreatedAt: now, UpdatedAt: now, @@ -292,7 +293,7 @@ func TestDB_UpdateTask(t *testing.T) { ID: "upd-1", Name: "Original Name", Description: "original desc", - Claude: task.ClaudeConfig{Model: "sonnet", Instructions: "original"}, + Agent: task.AgentConfig{Type: "claude", Model: "sonnet", Instructions: "original"}, Priority: task.PriorityNormal, Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"}, Tags: []string{"old"}, @@ -309,7 +310,7 @@ func TestDB_UpdateTask(t *testing.T) { u := TaskUpdate{ Name: "Updated Name", Description: "updated desc", - Config: task.ClaudeConfig{Model: "opus", Instructions: "updated"}, + Config: task.AgentConfig{Type: "claude", Model: "opus", Instructions: "updated"}, Priority: task.PriorityHigh, TimeoutNS: int64(15 * time.Minute), Retry: task.RetryConfig{MaxAttempts: 3, Backoff: "exponential"}, @@ -330,8 +331,8 @@ func TestDB_UpdateTask(t *testing.T) { if got.Description != "updated desc" { t.Errorf("description: want 'updated desc', got %q", got.Description) } - if got.Claude.Model != "opus" { - t.Errorf("model: want 'opus', got %q", got.Claude.Model) + if got.Agent.Model != "opus" { + t.Errorf("model: want 'opus', got %q", got.Agent.Model) } if got.Priority != task.PriorityHigh { t.Errorf("priority: want 'high', got %q", got.Priority) @@ -376,7 +377,7 @@ func TestRejectTask(t *testing.T) { db := testDB(t) now := time.Now().UTC() tk := &task.Task{ - ID: "reject-1", Name: "R", Claude: task.ClaudeConfig{Instructions: "x"}, + ID: "reject-1", Name: "R", Agent: task.AgentConfig{Type: "claude", Instructions: "x"}, Priority: task.PriorityNormal, Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"}, Tags: []string{}, DependsOn: []string{}, State: task.StateReady, CreatedAt: now, UpdatedAt: now, @@ -413,7 +414,7 @@ func TestUpdateExecution(t *testing.T) { db := testDB(t) now := time.Now().UTC() tk := &task.Task{ - ID: "utask", Name: "U", Claude: task.ClaudeConfig{Instructions: "x"}, + ID: "utask", Name: "U", Agent: task.AgentConfig{Type: "claude", Instructions: "x"}, Priority: task.PriorityNormal, Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"}, Tags: []string{}, DependsOn: []string{}, State: task.StatePending, CreatedAt: now, UpdatedAt: now, @@ -456,7 +457,7 @@ func TestUpdateExecution(t *testing.T) { func makeTestTask(id string, now time.Time) *task.Task { return &task.Task{ - ID: id, Name: "T-" + id, Claude: task.ClaudeConfig{Instructions: "x"}, + ID: id, Name: "T-" + id, Agent: task.AgentConfig{Type: "claude", Instructions: "x"}, Priority: task.PriorityNormal, Retry: task.RetryConfig{MaxAttempts: 1, Backoff: "linear"}, Tags: []string{}, DependsOn: []string{}, State: task.StatePending, CreatedAt: now, UpdatedAt: now, @@ -579,3 +580,36 @@ func TestStorage_GetLatestExecution(t *testing.T) { t.Errorf("want le-2, got %q", got.ID) } } + +func TestGetTask_BackwardCompatibility(t *testing.T) { + db := testDB(t) + now := time.Now().UTC().Truncate(time.Second) + + // Legacy config JSON using "claude" field instead of "agent" + legacyConfig := `{"claude":{"model":"haiku","instructions":"legacy instructions","max_budget_usd":0.5}}` + + _, err := db.db.Exec(` + INSERT INTO tasks (id, name, description, config_json, priority, timeout_ns, retry_json, tags_json, depends_on_json, state, created_at, updated_at) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, + "legacy-id", "Legacy Task", "A legacy test", legacyConfig, "normal", + 0, "{}", "[]", "[]", "PENDING", now, now, + ) + if err != nil { + t.Fatalf("inserting legacy task: %v", err) + } + + got, err := db.GetTask("legacy-id") + if err != nil { + t.Fatalf("getting legacy task: %v", err) + } + + if got.Agent.Instructions != "legacy instructions" { + t.Errorf("instructions: want 'legacy instructions', got %q", got.Agent.Instructions) + } + if got.Agent.Model != "haiku" { + t.Errorf("model: want 'haiku', got %q", got.Agent.Model) + } + if got.Agent.MaxBudgetUSD != 0.5 { + t.Errorf("budget: want 0.5, got %f", got.Agent.MaxBudgetUSD) + } +} |
