Repository: cli/cli

Issue:
Bump go toolchain to 1.24
## Description

We're a little bit behind on our Go releases, and probably are missing a few security patches as called out correctly in https://github.com/cli/cli/pull/10893. I'd like us to bump out toolchain to latest, and while we're at it, I think we should just bump the go module version since we are shipping a binary anyway, it's not a huge issue. It also gives access to some minor goodies like `t.Chdir` in tests.

Less important, I think there's also one or more dependabot PRs that might depend on go1.24 but I can't quite find them right now.

### Expected Output

* The go directive is 1.24
* The go toolchain directive is 1.24.4 

### Follow On

I believe we should investigate whether dependabot can notify us of toolchain updates. I don't think there's any reason we shouldn't be bumping it each time.

Hints from issue comments:
@williammartin: > I believe we should investigate whether dependabot can notify us of toolchain updates. I don't think there's any reason we shouldn't be bumping it each time.

Dependabot cannot do this as per this action: https://github.com/030/gomod-go-version-updater-action. Not sure I want this enough to introduce a random action into our workflows.

Solution patch:
diff --git a/go.mod b/go.mod
index 66383962f..238a06eb1 100644
--- a/go.mod
+++ b/go.mod
@@ -1,8 +1,8 @@
 module github.com/cli/cli/v2
 
-go 1.23.0
+go 1.24
 
-toolchain go1.23.5
+toolchain go1.24.4
 
 require (
 	github.com/AlecAivazis/survey/v2 v2.3.7



Test patch:
diff --git a/pkg/cmd/extension/command_test.go b/pkg/cmd/extension/command_test.go
index 76741714a..7001c8f1a 100644
--- a/pkg/cmd/extension/command_test.go
+++ b/pkg/cmd/extension/command_test.go
@@ -23,15 +23,14 @@ import (
 	"github.com/cli/cli/v2/pkg/iostreams"
 	"github.com/spf13/cobra"
 	"github.com/stretchr/testify/assert"
+	"github.com/stretchr/testify/require"
 )
 
 func TestNewCmdExtension(t *testing.T) {
 	tempDir := t.TempDir()
-	oldWd, _ := os.Getwd()
 	localExtensionTempDir := filepath.Join(tempDir, "gh-hello")
-	assert.NoError(t, os.MkdirAll(localExtensionTempDir, 0755))
-	assert.NoError(t, os.Chdir(localExtensionTempDir))
-	t.Cleanup(func() { _ = os.Chdir(oldWd) })
+	require.NoError(t, os.MkdirAll(localExtensionTempDir, 0755))
+	t.Chdir(localExtensionTempDir)
 
 	tests := []struct {
 		name          string
diff --git a/pkg/cmd/extension/manager_test.go b/pkg/cmd/extension/manager_test.go
index 167af3439..e933f0bdf 100644
--- a/pkg/cmd/extension/manager_test.go
+++ b/pkg/cmd/extension/manager_test.go
@@ -1251,9 +1251,10 @@ func TestManager_repo_not_found(t *testing.T) {
 }
 
 func TestManager_Create(t *testing.T) {
-	chdirTemp(t)
+	tempDir := t.TempDir()
+	t.Chdir(tempDir)
 	err := os.MkdirAll("gh-test", 0755)
-	assert.NoError(t, err)
+	require.NoError(t, err)
 
 	ios, _, stdout, stderr := iostreams.Test()
 
@@ -1279,9 +1280,10 @@ func TestManager_Create(t *testing.T) {
 }
 
 func TestManager_Create_go_binary(t *testing.T) {
-	chdirTemp(t)
+	tempDir := t.TempDir()
+	t.Chdir(tempDir)
 	err := os.MkdirAll("gh-test", 0755)
-	assert.NoError(t, err)
+	require.NoError(t, err)
 
 	reg := httpmock.Registry{}
 	defer reg.Verify(t)
@@ -1329,9 +1331,10 @@ func TestManager_Create_go_binary(t *testing.T) {
 }
 
 func TestManager_Create_other_binary(t *testing.T) {
-	chdirTemp(t)
+	tempDir := t.TempDir()
+	t.Chdir(tempDir)
 	err := os.MkdirAll("gh-test", 0755)
-	assert.NoError(t, err)
+	require.NoError(t, err)
 
 	ios, _, stdout, stderr := iostreams.Test()
 
@@ -1392,18 +1395,6 @@ func Test_ensurePrefixed(t *testing.T) {
 	}
 }
 
-// chdirTemp changes the current working directory to a temporary directory for the duration of the test.
-func chdirTemp(t *testing.T) {
-	oldWd, _ := os.Getwd()
-	tempDir := t.TempDir()
-	if err := os.Chdir(tempDir); err != nil {
-		t.Fatal(err)
-	}
-	t.Cleanup(func() {
-		_ = os.Chdir(oldWd)
-	})
-}
-
 func fileNames(files []os.DirEntry) []string {
 	names := make([]string, len(files))
 	for i, f := range files {
diff --git a/pkg/cmd/release/download/download_test.go b/pkg/cmd/release/download/download_test.go
index 9337c9b65..37c0e3c02 100644
--- a/pkg/cmd/release/download/download_test.go
+++ b/pkg/cmd/release/download/download_test.go
@@ -174,11 +174,6 @@ func Test_NewCmdDownload(t *testing.T) {
 }
 
 func Test_downloadRun(t *testing.T) {
-	oldwd, err := os.Getwd()
-	if err != nil {
-		t.Fatalf("could not determine working directory: %v", err)
-	}
-
 	tests := []struct {
 		name       string
 		isTTY      bool
@@ -526,11 +521,7 @@ func Test_downloadRun(t *testing.T) {
 	for _, tt := range tests {
 		t.Run(tt.name, func(t *testing.T) {
 			tempDir := t.TempDir()
-			if err := os.Chdir(tempDir); err == nil {
-				t.Cleanup(func() { _ = os.Chdir(oldwd) })
-			} else {
-				t.Fatal(err)
-			}
+			t.Chdir(tempDir)
 
 			ios, _, stdout, stderr := iostreams.Test()
 			ios.SetStdoutTTY(tt.isTTY)
diff --git a/pkg/cmdutil/args_test.go b/pkg/cmdutil/args_test.go
index 4e880dd27..58f0dc0b6 100644
--- a/pkg/cmdutil/args_test.go
+++ b/pkg/cmdutil/args_test.go
@@ -210,17 +210,10 @@ func createTestDir(t *testing.T) (cleanupFn func()) {
 	rootDir := t.TempDir()
 
 	// Move workspace to temporary directory
-	cwd, err := os.Getwd()
-	if err != nil {
-		t.Fatal(err)
-	}
-	err = os.Chdir(rootDir)
-	if err != nil {
-		t.Fatal(err)
-	}
+	t.Chdir(rootDir)
 
 	// Make subdirectories
-	err = os.Mkdir(filepath.Join(rootDir, "subDir1"), 0755)
+	err := os.Mkdir(filepath.Join(rootDir, "subDir1"), 0755)
 	if err != nil {
 		t.Fatal(err)
 	}
@@ -253,10 +246,6 @@ func createTestDir(t *testing.T) (cleanupFn func()) {
 
 	cleanupFn = func() {
 		os.RemoveAll(rootDir)
-		err = os.Chdir(cwd)
-		if err != nil {
-			t.Fatal(err)
-		}
 	}
 	return cleanupFn
 }