From 6970da5c49ff19479143da3988ba261e4b4501f6 Mon Sep 17 00:00:00 2001 From: Snider Date: Sun, 22 Feb 2026 21:00:17 +0000 Subject: [PATCH] refactor: apply go fix modernizers for Go 1.26 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Automated fixes: interface{} → any, range-over-int, t.Context(), wg.Go(), strings.SplitSeq, strings.Builder, slices.Contains, maps helpers, min/max builtins. Co-Authored-By: Virgil --- allowance_redis_test.go | 10 +++++----- allowance_sqlite_test.go | 10 +++++----- cmd/tasks/cmd.go | 6 +++--- cmd/tasks/updates.go | 2 +- config.go | 2 +- context.go | 2 +- context_git_test.go | 4 ++-- dispatcher_test.go | 2 +- events_integration_test.go | 2 +- events_test.go | 8 +++----- lifecycle_test.go | 8 ++++---- registry_redis_test.go | 2 +- registry_sqlite_test.go | 2 +- registry_test.go | 2 +- types.go | 2 +- 15 files changed, 31 insertions(+), 33 deletions(-) diff --git a/allowance_redis_test.go b/allowance_redis_test.go index 339fd7c..3d1b682 100644 --- a/allowance_redis_test.go +++ b/allowance_redis_test.go @@ -289,7 +289,7 @@ func TestRedisStore_ConcurrentIncrementUsage_Good(t *testing.T) { var wg sync.WaitGroup wg.Add(goroutines) - for i := 0; i < goroutines; i++ { + for range goroutines { go func() { defer wg.Done() err := s.IncrementUsage("agent-1", tokensEach, 1) @@ -313,7 +313,7 @@ func TestRedisStore_ConcurrentModelUsage_Good(t *testing.T) { var wg sync.WaitGroup wg.Add(goroutines) - for i := 0; i < goroutines; i++ { + for range goroutines { go func() { defer wg.Done() err := s.IncrementModelUsage("claude-opus-4-6", tokensEach) @@ -342,7 +342,7 @@ func TestRedisStore_ConcurrentMixed_Good(t *testing.T) { wg.Add(goroutines * 3) // Increment usage - for i := 0; i < goroutines; i++ { + for range goroutines { go func() { defer wg.Done() _ = s.IncrementUsage("agent-1", 100, 1) @@ -350,7 +350,7 @@ func TestRedisStore_ConcurrentMixed_Good(t *testing.T) { } // Decrement active jobs - for i := 0; i < goroutines; i++ { + for range goroutines { go func() { defer wg.Done() _ = s.DecrementActiveJobs("agent-1") @@ -358,7 +358,7 @@ func TestRedisStore_ConcurrentMixed_Good(t *testing.T) { } // Return tokens - for i := 0; i < goroutines; i++ { + for range goroutines { go func() { defer wg.Done() _ = s.ReturnTokens("agent-1", 10) diff --git a/allowance_sqlite_test.go b/allowance_sqlite_test.go index 2f22ac8..60e1c62 100644 --- a/allowance_sqlite_test.go +++ b/allowance_sqlite_test.go @@ -282,7 +282,7 @@ func TestSQLiteStore_ConcurrentIncrementUsage_Good(t *testing.T) { var wg sync.WaitGroup wg.Add(goroutines) - for i := 0; i < goroutines; i++ { + for range goroutines { go func() { defer wg.Done() err := s.IncrementUsage("agent-1", tokensEach, 1) @@ -306,7 +306,7 @@ func TestSQLiteStore_ConcurrentModelUsage_Good(t *testing.T) { var wg sync.WaitGroup wg.Add(goroutines) - for i := 0; i < goroutines; i++ { + for range goroutines { go func() { defer wg.Done() err := s.IncrementModelUsage("claude-opus-4-6", tokensEach) @@ -335,7 +335,7 @@ func TestSQLiteStore_ConcurrentMixed_Good(t *testing.T) { wg.Add(goroutines * 3) // Increment usage - for i := 0; i < goroutines; i++ { + for range goroutines { go func() { defer wg.Done() _ = s.IncrementUsage("agent-1", 100, 1) @@ -343,7 +343,7 @@ func TestSQLiteStore_ConcurrentMixed_Good(t *testing.T) { } // Decrement active jobs - for i := 0; i < goroutines; i++ { + for range goroutines { go func() { defer wg.Done() _ = s.DecrementActiveJobs("agent-1") @@ -351,7 +351,7 @@ func TestSQLiteStore_ConcurrentMixed_Good(t *testing.T) { } // Return tokens - for i := 0; i < goroutines; i++ { + for range goroutines { go func() { defer wg.Done() _ = s.ReturnTokens("agent-1", 10) diff --git a/cmd/tasks/cmd.go b/cmd/tasks/cmd.go index 6946c6c..601c4ce 100644 --- a/cmd/tasks/cmd.go +++ b/cmd/tasks/cmd.go @@ -53,8 +53,8 @@ var ( // task command flags var ( - taskAutoSelect bool - taskClaim bool + taskAutoSelect bool + taskClaim bool taskShowContext bool ) @@ -236,7 +236,7 @@ func AddTaskCommands(parent *cli.Command) { } func printTaskList(tasks []agentic.Task) { - cli.Print("\n%s\n\n", i18n.T("cmd.ai.tasks.found", map[string]interface{}{"Count": len(tasks)})) + cli.Print("\n%s\n\n", i18n.T("cmd.ai.tasks.found", map[string]any{"Count": len(tasks)})) for _, task := range tasks { id := taskIDStyle.Render(task.ID) diff --git a/cmd/tasks/updates.go b/cmd/tasks/updates.go index a1d8922..e35b2bc 100644 --- a/cmd/tasks/updates.go +++ b/cmd/tasks/updates.go @@ -101,7 +101,7 @@ var taskCompleteCmd = &cli.Command{ }) if taskCompleteFailed { - cli.Print("%s %s\n", errorStyle.Render(">>"), i18n.T("cmd.ai.task_complete.failed", map[string]interface{}{"ID": taskID})) + cli.Print("%s %s\n", errorStyle.Render(">>"), i18n.T("cmd.ai.task_complete.failed", map[string]any{"ID": taskID})) } else { cli.Print("%s %s\n", successStyle.Render(">>"), i18n.T("i18n.done.complete", "task")) } diff --git a/config.go b/config.go index a201e21..d063757 100644 --- a/config.go +++ b/config.go @@ -101,7 +101,7 @@ func loadEnvFile(path string, cfg *Config) error { return err } - for _, line := range strings.Split(content, "\n") { + for line := range strings.SplitSeq(content, "\n") { line = strings.TrimSpace(line) // Skip empty lines and comments diff --git a/context.go b/context.go index e7b2b0c..5545c0c 100644 --- a/context.go +++ b/context.go @@ -142,7 +142,7 @@ func findRelatedCode(task *Task, dir string) ([]FileContent, error) { } // Parse matched files - for _, line := range strings.Split(output, "\n") { + for line := range strings.SplitSeq(output, "\n") { line = strings.TrimSpace(line) if line == "" || seen[line] { continue diff --git a/context_git_test.go b/context_git_test.go index 23b842f..9c17a99 100644 --- a/context_git_test.go +++ b/context_git_test.go @@ -79,7 +79,7 @@ func TestFindRelatedCode_Good_NoKeywords(t *testing.T) { task := &Task{ ID: "code-2", - Title: "do it", // too short, all stop words + Title: "do it", // too short, all stop words Description: "fix the bug in the code", } @@ -101,7 +101,7 @@ func TestFindRelatedCode_Good_LimitsTo10Files(t *testing.T) { dir := initGitRepoWithCode(t) // Create 15 files all containing the keyword "validation". - for i := 0; i < 15; i++ { + for i := range 15 { name := filepath.Join(dir, "validation_"+string(rune('a'+i))+".go") content := "package main\n// validation logic\nfunc Validate" + string(rune('A'+i)) + "() {}\n" err := os.WriteFile(name, []byte(content), 0644) diff --git a/dispatcher_test.go b/dispatcher_test.go index cc207ed..fdc0dce 100644 --- a/dispatcher_test.go +++ b/dispatcher_test.go @@ -257,7 +257,7 @@ func TestDispatcher_Dispatch_Good_Concurrent(t *testing.T) { }) var wg sync.WaitGroup - for i := 0; i < 10; i++ { + for i := range 10 { wg.Add(1) go func(n int) { defer wg.Done() diff --git a/events_integration_test.go b/events_integration_test.go index cee1a5b..c06b971 100644 --- a/events_integration_test.go +++ b/events_integration_test.go @@ -271,7 +271,7 @@ func TestAllowanceService_NoEventsWithoutEmitter(t *testing.T) { func drainEvents(em *ChannelEmitter, n int, timeout time.Duration) []Event { var events []Event deadline := time.After(timeout) - for i := 0; i < n; i++ { + for range n { select { case e := <-em.Events(): events = append(events, e) diff --git a/events_test.go b/events_test.go index 21b14e0..ea5712c 100644 --- a/events_test.go +++ b/events_test.go @@ -119,12 +119,10 @@ func TestChannelEmitter_ConcurrentEmit(t *testing.T) { ctx := context.Background() var wg sync.WaitGroup - for i := 0; i < 50; i++ { - wg.Add(1) - go func() { - defer wg.Done() + for range 50 { + wg.Go(func() { _ = em.Emit(ctx, Event{Type: EventTaskDispatched}) - }() + }) } wg.Wait() diff --git a/lifecycle_test.go b/lifecycle_test.go index d284217..bdd42e3 100644 --- a/lifecycle_test.go +++ b/lifecycle_test.go @@ -237,7 +237,7 @@ func TestTaskLifecycle_MultipleAgentsConcurrent(t *testing.T) { wg.Add(1) go func(aid string) { defer wg.Done() - for i := 0; i < 10; i++ { + for range 10 { // Check allowance. result, err := svc.Check(aid, "") assert.NoError(t, err) @@ -268,9 +268,9 @@ func TestTaskLifecycle_MultipleAgentsConcurrent(t *testing.T) { for _, agentID := range agents { usage, err := store.GetUsage(agentID) require.NoError(t, err) - assert.Equal(t, int64(1500), usage.TokensUsed) // 10 jobs x 150 tokens - assert.Equal(t, 10, usage.JobsStarted) // 10 starts - assert.Equal(t, 0, usage.ActiveJobs) // all completed + assert.Equal(t, int64(1500), usage.TokensUsed) // 10 jobs x 150 tokens + assert.Equal(t, 10, usage.JobsStarted) // 10 starts + assert.Equal(t, 0, usage.ActiveJobs) // all completed } } diff --git a/registry_redis_test.go b/registry_redis_test.go index 928321e..3fe8b42 100644 --- a/registry_redis_test.go +++ b/registry_redis_test.go @@ -275,7 +275,7 @@ func TestRedisRegistry_Concurrent_Good(t *testing.T) { reg := newTestRedisRegistry(t) var wg sync.WaitGroup - for i := 0; i < 20; i++ { + for i := range 20 { wg.Add(1) go func(n int) { defer wg.Done() diff --git a/registry_sqlite_test.go b/registry_sqlite_test.go index c3b8957..dc8251d 100644 --- a/registry_sqlite_test.go +++ b/registry_sqlite_test.go @@ -280,7 +280,7 @@ func TestSQLiteRegistry_Concurrent_Good(t *testing.T) { reg := newTestSQLiteRegistry(t) var wg sync.WaitGroup - for i := 0; i < 20; i++ { + for i := range 20 { wg.Add(1) go func(n int) { defer wg.Done() diff --git a/registry_test.go b/registry_test.go index e8123e3..55ba3df 100644 --- a/registry_test.go +++ b/registry_test.go @@ -273,7 +273,7 @@ func TestMemoryRegistry_Concurrent_Good(t *testing.T) { reg := NewMemoryRegistry() var wg sync.WaitGroup - for i := 0; i < 20; i++ { + for i := range 20 { wg.Add(1) go func(n int) { defer wg.Done() diff --git a/types.go b/types.go index 1cca663..f47ba7c 100644 --- a/types.go +++ b/types.go @@ -56,7 +56,7 @@ type Task struct { // CreatedAt is when the task was created. CreatedAt time.Time `json:"created_at"` // UpdatedAt is when the task was last modified. - UpdatedAt time.Time `json:"updated_at,omitempty"` + UpdatedAt time.Time `json:"updated_at"` // ClaimedBy is the identifier of the agent or developer who claimed the task. ClaimedBy string `json:"claimed_by,omitempty"` // ClaimedAt is when the task was claimed.