@@ -1463,21 +1463,33 @@ func TestCheckSystemGoVersion(t *testing.T) {
14631463
14641464 // Create mock go binary
14651465 goBinary := filepath .Join (systemGoDir , "bin" , "go" )
1466+ var versionScript string
1467+
14661468 if utils .IsWindows () {
1467- goBinary += ".bat" // Use .bat on Windows for batch scripts
1468- }
1469-
1470- // Create a script that outputs version
1471- versionScript := "#!/bin/bash\n echo 'go version go" + tt .systemVersion + " darwin/arm64'\n "
1472- if utils .IsWindows () {
1473- versionScript = "@echo off\r \n echo go version go" + tt .systemVersion + " windows/amd64\r \n "
1469+ goBinary += ".bat"
1470+ // Use CRLF and ensure it always exits 0
1471+ versionScript = "@echo off\r \n " +
1472+ "echo go version go" + tt .systemVersion + " windows/amd64\r \n " +
1473+ "exit /b 0\r \n "
1474+ } else {
1475+ // Use /bin/sh (not bash-specific) and explicitly exit 0
1476+ versionScript = "#!/bin/sh\n " +
1477+ "echo \" go version go" + tt .systemVersion + " darwin/arm64\" \n " +
1478+ "exit 0\n "
14741479 }
14751480 err = os .WriteFile (goBinary , []byte (versionScript ), 0o755 )
14761481 require .NoError (t , err )
14771482
14781483 // Prepend system Go to PATH so it wins over any runner-installed Go
1479- // This ensures the test is hermetic and doesn't pick up the CI runner's Go
1480- t .Setenv (utils .EnvVarPath , filepath .Join (systemGoDir , "bin" ))
1484+ // On Windows, keep existing PATH so shell tools (cmd.exe) remain available
1485+ oldPath := os .Getenv (utils .EnvVarPath )
1486+ if utils .IsWindows () {
1487+ // Prepend but keep existing PATH for Windows system tools
1488+ t .Setenv (utils .EnvVarPath , filepath .Join (systemGoDir , "bin" )+ string (os .PathListSeparator )+ oldPath )
1489+ } else {
1490+ // On Unix, only use mock directory to ensure hermetic test
1491+ t .Setenv (utils .EnvVarPath , filepath .Join (systemGoDir , "bin" ))
1492+ }
14811493 } else {
14821494 // Explicitly set PATH to empty to ensure no system Go can be found
14831495 // This makes the "not found" test case work correctly on CI runners
0 commit comments