diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-03-08 06:43:06 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-03-08 06:43:06 +0000 |
| commit | 0ff0bf75544bbf565288e61bb8e10c3f903830f8 (patch) | |
| tree | 302f152b14d3ef2a81cfebdb4925d41e734ab8d5 /internal/storage | |
| parent | 5d6d79e8925693c0740d8c31c614396d70dfb8a5 (diff) | |
refactor: address code review notes (backward compat, Gemini tests, unknown agent test)
Diffstat (limited to 'internal/storage')
| -rw-r--r-- | internal/storage/db.go | 9 | ||||
| -rw-r--r-- | internal/storage/db_test.go | 33 |
2 files changed, 42 insertions, 0 deletions
diff --git a/internal/storage/db.go b/internal/storage/db.go index 31927a0..c396bbe 100644 --- a/internal/storage/db.go +++ b/internal/storage/db.go @@ -515,6 +515,15 @@ func scanTask(row scanner) (*task.Task, error) { if err := json.Unmarshal([]byte(configJSON), &t.Agent); err != nil { return nil, fmt.Errorf("unmarshaling agent config: %w", err) } + // Fallback for legacy 'claude' field + if t.Agent.Instructions == "" { + var legacy struct { + Claude task.AgentConfig `json:"claude"` + } + if err := json.Unmarshal([]byte(configJSON), &legacy); err == nil && legacy.Claude.Instructions != "" { + t.Agent = legacy.Claude + } + } if err := json.Unmarshal([]byte(retryJSON), &t.Retry); err != nil { return nil, fmt.Errorf("unmarshaling retry: %w", err) } diff --git a/internal/storage/db_test.go b/internal/storage/db_test.go index 4c3f011..36f1644 100644 --- a/internal/storage/db_test.go +++ b/internal/storage/db_test.go @@ -548,3 +548,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) + } +} |
