package gotoolchain import ( "os" "os/exec" "path/filepath" "strings" "testing" ) // TestEnvironmentKeepsMakeOnLocalToolchain: production 2026-11-22, a // project Makefile began `export GOTOOLCHAIN := go1.26.5`. A Makefile // assignment beats the environment, so its go commands asked for that // release, which the offline checks cannot fetch (GOSUMDB=off refuses a // toolchain download). The shared environment carries GOTOOLCHAIN=local // as a make command-line variable (MAKEFLAGS), which beats the Makefile, // for every launch that uses it and for nested makes. func TestEnvironmentKeepsMakeOnLocalToolchain(t *testing.T) { makeBin, err := exec.LookPath("make") if err != nil { t.Skip("make is not installed") } dir := t.TempDir() makefile := "export GOTOOLCHAIN := go1.26.5\nGOTOOLCHAIN = go1.26.6\nall:\n\t@echo \"recipe=$$GOTOOLCHAIN\"; sh -c 'echo child=$$GOTOOLCHAIN'\nnested:\n\t@$(MAKE) --no-print-directory all\n" if err := os.WriteFile(filepath.Join(dir, "Makefile"), []byte(makefile), 0o600); err != nil { t.Fatal(err) } for _, p := range []string{"", "claude", "codex", "pi"} { env := Environment(p) if env["GOTOOLCHAIN"] != "local" { t.Fatalf("%q: GOTOOLCHAIN %q", p, env["GOTOOLCHAIN"]) } for _, target := range []string{"all", "nested"} { cmd := exec.Command(makeBin, "-s", target) cmd.Dir = dir cmd.Env = []string{"PATH=" + os.Getenv("PATH")} for k, v := range env { if k != "PATH" { cmd.Env = append(cmd.Env, k+"="+v) } } out, err := cmd.CombinedOutput() if err != nil || strings.TrimSpace(string(out)) != "recipe=local\nchild=local" { t.Fatalf("provider %q, make %s: %q %v", p, target, out, err) } } } }