Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

fix(mcp): discover and verify compatible Python interpreters (#1140)

opita0499441f8a6e72
diff --git a/CONFIGURATION.md b/CONFIGURATION.md
index 0239bd84..a7ae34d3 100644
--- a/CONFIGURATION.md
+++ b/CONFIGURATION.md
@@ -103,10 +103,18 @@ These variables configure the local Go MCP server and are read from its process
| Env var | Default | Accepted values | Behavior and precedence |
|---|---|---|---|
-| `LAST30DAYS_PYTHON` | unset | An executable name or path | Selects the Python 3.12+ interpreter used by the MCP server. A caller-supplied `RunOptions.PythonPath` remains the test/caller override; otherwise this variable must resolve to an executable. When it is unset, the server looks up `python3` on `PATH`. An empty or unresolvable value is an error rather than a fallback. |
+| `LAST30DAYS_PYTHON` | unset | An executable name or path | Selects the Python 3.12+ interpreter used by the MCP server. A caller-supplied `RunOptions.PythonPath` remains the test/caller override; otherwise this variable must resolve to an executable. When it is unset, the server discovers and version-probes compatible Python executables in absolute `PATH` directories. An empty or unresolvable value is an error rather than a fallback. |
| `LAST30DAYS_MCP_ALLOW_BROWSER_COOKIES` | unset (deny) | `1`, `true`, `yes`, or `on`, case-insensitive | A recognized truthy value removes the MCP layer's default `--no-browser-cookies` flag. Every other value keeps that denial. This switch grants no consent by itself: browser-cookie access still requires the engine's separately recorded consent and `FROM_BROWSER` configuration. |
| `LAST30DAYS_MCP_TIMEOUT` | `600` seconds (10 minutes) | A positive Go duration such as `10m`, `90s`, or `1m30s`, or a positive integer number of seconds such as `600` | Caps each research subprocess. The default accommodates deep discovery enrichment. Invalid, zero, and negative values use the default. An explicit caller timeout takes precedence. Source and enrichment deadlines can finish earlier; increasing this cap also extends how long a hung subprocess can occupy an MCP slot. |
+### MCP Python interpreter
+
+The MCP server requires Python 3.12 or newer within Python 3. It checks executable candidates in absolute `PATH` directories, in directory order: `python3`, versioned `python3.N` names from newest to oldest, then `python`. Windows `.exe` names are supported. Each candidate is version-probed before research starts; an old or unusable default does not hide a compatible interpreter later on `PATH`. Relative and empty `PATH` entries are ignored.
+
+Set `LAST30DAYS_PYTHON` in the MCP server process environment to pin a compatible executable, including one outside `PATH`, for example `/absolute/path/to/python3.12`. It accepts an absolute path or a command name resolving through `PATH` to an absolute executable. A missing, old, or invalid explicit choice produces an error without automatic fallback. This variable is read by the Go launcher, so setting it only in the Python engine's `.env` file cannot select the launcher interpreter.
+
+Discovery has a five-second total budget and a two-second limit per version probe. The research timeout is separate. Embedded Go callers retain the trusted `RunOptions.PythonPath` override for custom interpreters and test doubles. This selection does not add Python 3.9 support or install Python automatically.
+
## API keys (`.env`)
The skill reads keys from a `.env` file. Two locations are supported:
diff --git a/changelog.d/1140.fixed.md b/changelog.d/1140.fixed.md
new file mode 100644
index 00000000..26857c3b
--- /dev/null
+++ b/changelog.d/1140.fixed.md
@@ -0,0 +1 @@
+The MCP launcher now finds and verifies Python 3.12+ interpreters on PATH when the default python3 is too old. Set LAST30DAYS_PYTHON to select a specific interpreter; invalid explicit choices report an error instead of silently falling back.
diff --git a/mcp/internal/engine/python.go b/mcp/internal/engine/python.go
new file mode 100644
index 00000000..ece5d1a1
--- /dev/null
+++ b/mcp/internal/engine/python.go
@@ -0,0 +1,193 @@
+package engine
+
+import (
+ "context"
+ "fmt"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "sort"
+ "strconv"
+ "strings"
+ "time"
+)
+
+// PythonEnvOverride selects an interpreter without changing the host PATH.
+const PythonEnvOverride = "LAST30DAYS_PYTHON"
+
+func resolvePython(override string) (string, error) {
+ return resolvePythonContext(context.Background(), override)
+}
+
+func resolvePythonContext(ctx context.Context, override string) (string, error) {
+ return resolvePythonWithCandidates(ctx, override, pythonCandidates)
+}
+
+func resolvePythonWithCandidates(ctx context.Context, override string, candidatesInDir func(string) []string) (string, error) {
+ // Preserve the trusted injection seam used by embedded callers and tests.
+ if override != "" {
+ return override, nil
+ }
+ ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
+ defer cancel()
+ if candidate, configured := os.LookupEnv(PythonEnvOverride); configured {
+ if candidate == "" {
+ return "", fmt.Errorf("engine: %s is set but empty", PythonEnvOverride)
+ }
+ path, err := discoveryOperation(ctx, func() (string, error) { return exec.LookPath(candidate) })
+ if err == nil && !filepath.IsAbs(path) {
+ err = fmt.Errorf("relative executable paths are not allowed")
+ }
+ if err == nil {
+ err = checkPythonVersion(ctx, path)
+ }
+ if err != nil {
+ return "", fmt.Errorf("engine: %s=%q: %w; need Python %s+, install from %s", PythonEnvOverride, candidate, err, MinPythonVersion, PythonInstallURL)
+ }
+ return path, nil
+ }
+ var failures []string
+ for _, dir := range filepath.SplitList(os.Getenv("PATH")) {
+ if !filepath.IsAbs(dir) {
+ continue
+ }
+ candidates, err := discoveryOperation(ctx, func() ([]string, error) { return candidatesInDir(dir), nil })
+ if err != nil {
+ break
+ }
+ for _, candidate := range candidates {
+ if ctx.Err() != nil {
+ break
+ }
+ path, err := discoveryOperation(ctx, func() (string, error) { return exec.LookPath(candidate) })
+ if err == nil {
+ err = checkPythonVersion(ctx, path)
+ }
+ if err == nil {
+ return path, nil
+ }
+ failures = append(failures, fmt.Sprintf("%s: %v", candidate, err))
+ }
+ }
+ if err := ctx.Err(); err != nil {
+ return "", fmt.Errorf("engine: python discovery interrupted (need Python %s+; set %s to a compatible executable); checked: %s: %w", MinPythonVersion, PythonEnvOverride, strings.Join(failures, "; "), err)
+ }
+ return "", fmt.Errorf("engine: no compatible %s on PATH (need Python %s+; set %s to a compatible executable, or install from %s); checked: %s", DefaultPythonBinary, MinPythonVersion, PythonEnvOverride, PythonInstallURL, strings.Join(failures, "; "))
+}
+
+// Windows filenames are case-insensitive, so Python3.exe and python3.EXE must
+// match the same candidate rules as python3.exe.
+var caseInsensitiveNames = runtime.GOOS == "windows"
+
+func pythonStem(name string) string {
+ if caseInsensitiveNames {
+ name = strings.ToLower(name)
+ }
+ return strings.TrimSuffix(name, ".exe")
+}
+
+// Keep PATH precedence, prefer python3 in each directory, then versioned names.
+// Discover version suffixes rather than freezing the list at today's release.
+// Empty and relative PATH entries are excluded even with GODEBUG=execerrdot=0.
+func pythonCandidates(pathValue string) []string {
+ var candidates []string
+ seen := map[string]bool{}
+ for _, dir := range filepath.SplitList(pathValue) {
+ if !filepath.IsAbs(dir) {
+ continue
+ }
+ entries, err := os.ReadDir(dir)
+ if err != nil {
+ continue
+ }
+ var names []string
+ for _, entry := range entries {
+ if entry.IsDir() {
+ continue
+ }
+ name := entry.Name()
+ stem := pythonStem(name)
+ if stem == "python3" || stem == "python" {
+ names = append(names, name)
+ continue
+ }
+ if strings.HasPrefix(stem, "python3.") {
+ minor, err := strconv.Atoi(strings.TrimPrefix(stem, "python3."))
+ if err == nil && minor >= 12 {
+ names = append(names, name)
+ }
+ }
+ }
+ sort.SliceStable(names, func(i, j int) bool {
+ rank := func(name string) int {
+ stem := pythonStem(name)
+ if stem == "python3" {
+ return 1000000
+ }
+ if stem == "python" {
+ return -1
+ }
+ minor, _ := strconv.Atoi(strings.TrimPrefix(stem, "python3."))
+ return minor
+ }
+ return rank(names[i]) > rank(names[j])
+ })
+ for _, name := range names {
+ candidate := filepath.Join(dir, name)
+ if !seen[candidate] {
+ candidates = append(candidates, candidate)
+ seen[candidate] = true
+ }
+ }
+ }
+ return candidates
+}
+
+func checkPythonVersion(ctx context.Context, path string) error {
+ probeCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
+ defer cancel()
+ // Avoid site initialization and PYTHON* environment overrides during discovery.
+ cmd := exec.CommandContext(probeCtx, path, "-I", "-S", "-c", "import sys; print('%d.%d' % sys.version_info[:2])")
+ cmd.WaitDelay = 100 * time.Millisecond
+ output, err := cmd.Output()
+ if probeCtx.Err() != nil {
+ return probeCtx.Err()
+ }
+ if err != nil {
+ return fmt.Errorf("version probe failed: %w", err)
+ }
+ parts := strings.Split(strings.TrimSpace(string(output)), ".")
+ if len(parts) != 2 {
+ return fmt.Errorf("invalid Python version response")
+ }
+ major, majorErr := strconv.Atoi(parts[0])
+ minor, minorErr := strconv.Atoi(parts[1])
+ if majorErr != nil || minorErr != nil || major != 3 || minor < 12 {
+ return fmt.Errorf("incompatible Python version %q", strings.TrimSpace(string(output)))
+ }
+ return nil
+}
+
+// Filesystem calls cannot be interrupted by context. A buffered worker lets the
+// caller honor cancellation without waiting for a stalled mount. Discovery is
+// sequential, so at most one filesystem operation is left pending per request.
+func discoveryOperation[T any](ctx context.Context, operation func() (T, error)) (T, error) {
+ type result struct {
+ value T
+ err error
+ }
+ if err := ctx.Err(); err != nil {
+ var zero T
+ return zero, err
+ }
+ done := make(chan result, 1)
+ go func() { value, err := operation(); done <- result{value, err} }()
+ select {
+ case <-ctx.Done():
+ var zero T
+ return zero, ctx.Err()
+ case r := <-done:
+ return r.value, r.err
+ }
+}
diff --git a/mcp/internal/engine/python_test.go b/mcp/internal/engine/python_test.go
new file mode 100644
index 00000000..c6310312
--- /dev/null
+++ b/mcp/internal/engine/python_test.go
@@ -0,0 +1,224 @@
+package engine
+
+import (
+ "context"
+ "errors"
+ "os"
+ "path/filepath"
+ "runtime"
+ "strings"
+ "testing"
+ "time"
+)
+
+func fakePython(t *testing.T, dir, name, version string) string {
+ t.Helper()
+ if runtime.GOOS == "windows" {
+ t.Skip("POSIX executable fixture")
+ }
+ path := filepath.Join(dir, name)
+ body := "#!/bin/sh\nif [ \"$1\" = '-I' ]; then printf '%s\\n' '" + version + "'; else printf 'research completed'; fi\n"
+ if err := os.WriteFile(path, []byte(body), 0755); err != nil {
+ t.Fatal(err)
+ }
+ return path
+}
+
+func TestPythonDiscoveryFallback(t *testing.T) {
+ for _, name := range []string{"python3", "python3.12", "python3.99", "python"} {
+ t.Run(name, func(t *testing.T) {
+ unsetPythonOverride(t)
+ first, second := t.TempDir(), t.TempDir()
+ fakePython(t, first, "python3", "3.9")
+ want := fakePython(t, second, name, "3.12")
+ t.Setenv("PATH", first+string(os.PathListSeparator)+second)
+ got, err := resolvePython("")
+ if err != nil || got != want {
+ t.Fatalf("got %q, %v; want %q", got, err, want)
+ }
+ result, err := Run(context.Background(), RunOptions{CacheDir: stageCache(t)})
+ if err != nil || string(result.Stdout) != "research completed" {
+ t.Fatalf("Run = %+v, %v", result, err)
+ }
+ })
+ }
+}
+
+func TestPythonDiscoveryPreservesDefault(t *testing.T) {
+ unsetPythonOverride(t)
+ dir := t.TempDir()
+ want := fakePython(t, dir, "python3", "3.12")
+ fakePython(t, dir, "python3.14", "3.14")
+ t.Setenv("PATH", dir)
+ got, err := resolvePython("")
+ if err != nil || got != want {
+ t.Fatalf("got %q, %v", got, err)
+ }
+}
+
+func TestPythonOverrideVerifiedWithoutFallback(t *testing.T) {
+ dir := t.TempDir()
+ fakePython(t, dir, "python3", "3.14")
+ t.Setenv("PATH", dir)
+ for _, version := range []string{"3.9", "invalid", "4.0", "3.12", "3.99"} {
+ t.Run(version, func(t *testing.T) {
+ explicit := fakePython(t, t.TempDir(), "selected-python", version)
+ t.Setenv(PythonEnvOverride, explicit)
+ got, err := resolvePython("")
+ if version == "3.12" || version == "3.99" {
+ if err != nil || got != explicit {
+ t.Fatalf("got %q, %v", got, err)
+ }
+ } else if err == nil || got != "" || !strings.Contains(err.Error(), PythonEnvOverride) {
+ t.Fatalf("invalid override fell back: %q, %v", got, err)
+ }
+ })
+ }
+ t.Setenv(PythonEnvOverride, filepath.Join(dir, "missing"))
+ if _, err := resolvePython(""); err == nil {
+ t.Fatal("missing override fell back")
+ }
+}
+
+func TestPythonDiscoveryExcludesRelativePathsAndConfigHelpers(t *testing.T) {
+ unsetPythonOverride(t)
+ dir := t.TempDir()
+ fakePython(t, dir, "python3-config", "3.14")
+ fakePython(t, dir, "python3.14-config", "3.14")
+ fakePython(t, dir, "python3", "3.14")
+ t.Chdir(dir)
+ t.Setenv("GODEBUG", "execerrdot=0")
+ t.Setenv("PATH", ".")
+ t.Setenv(PythonEnvOverride, "./python3")
+ if _, err := resolvePython(""); err == nil {
+ t.Fatal("accepted relative override")
+ }
+ unsetPythonOverride(t)
+ if _, err := resolvePython(""); err == nil {
+ t.Fatal("accepted relative PATH")
+ }
+ if err := os.Remove(filepath.Join(dir, "python3")); err != nil {
+ t.Fatal(err)
+ }
+ t.Setenv("PATH", dir)
+ if _, err := resolvePython(""); err == nil {
+ t.Fatal("accepted config helper")
+ }
+}
+
+func TestPythonProbeCancellation(t *testing.T) {
+ if runtime.GOOS == "windows" {
+ t.Skip("POSIX executable fixture")
+ }
+ path := filepath.Join(t.TempDir(), "python3")
+ if err := os.WriteFile(path, []byte("#!/bin/sh\nexec /bin/sleep 10\n"), 0755); err != nil {
+ t.Fatal(err)
+ }
+ ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond)
+ defer cancel()
+ start := time.Now()
+ if err := checkPythonVersion(ctx, path); err == nil {
+ t.Fatal("expected timeout")
+ }
+ if time.Since(start) > time.Second {
+ t.Fatal("probe ignored cancellation")
+ }
+}
+
+func unsetPythonOverride(t *testing.T) {
+ t.Helper()
+ t.Setenv(PythonEnvOverride, "")
+ if err := os.Unsetenv(PythonEnvOverride); err != nil {
+ t.Fatal(err)
+ }
+}
+
+func TestDiscoveryFilesystemCancellation(t *testing.T) {
+ release := make(chan struct{})
+ defer close(release)
+ ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond)
+ defer cancel()
+ start := time.Now()
+ _, err := discoveryOperation(ctx, func() (string, error) { <-release; return "", nil })
+ if err != context.DeadlineExceeded || time.Since(start) > time.Second {
+ t.Fatalf("filesystem cancellation: %v", err)
+ }
+}
+
+func TestDiscoveryStopsBeforeLaterDirectory(t *testing.T) {
+ unsetPythonOverride(t)
+ first, second := t.TempDir(), t.TempDir()
+ want := fakePython(t, first, "python3", "3.12")
+ t.Setenv("PATH", first+string(os.PathListSeparator)+second)
+ got, err := resolvePythonWithCandidates(context.Background(), "", func(dir string) []string {
+ if dir == second {
+ t.Error("scanned later directory after valid interpreter")
+ }
+ return pythonCandidates(dir)
+ })
+ if err != nil || got != want {
+ t.Fatalf("got %q, %v", got, err)
+ }
+}
+func TestDiscoveryCancelsStalledDirectory(t *testing.T) {
+ unsetPythonOverride(t)
+ t.Setenv("PATH", t.TempDir())
+ release := make(chan struct{})
+ defer close(release)
+ ctx, cancel := context.WithTimeout(context.Background(), 20*time.Millisecond)
+ defer cancel()
+ start := time.Now()
+ _, err := resolvePythonWithCandidates(ctx, "", func(string) []string { <-release; return nil })
+ if !errors.Is(err, context.DeadlineExceeded) || time.Since(start) > time.Second {
+ t.Fatalf("stalled discovery ignored cancellation: %v", err)
+ }
+}
+
+func TestRunDiscoveryPreservesCancellation(t *testing.T) {
+ for _, wantErr := range []error{context.Canceled, context.DeadlineExceeded} {
+ t.Run(wantErr.Error(), func(t *testing.T) {
+ unsetPythonOverride(t)
+ dir := t.TempDir()
+ fakePython(t, dir, "python3", "3.12")
+ t.Setenv("PATH", dir)
+ var ctx context.Context
+ var cancel context.CancelFunc
+ if wantErr == context.DeadlineExceeded {
+ ctx, cancel = context.WithDeadline(context.Background(), time.Now().Add(-time.Second))
+ } else {
+ ctx, cancel = context.WithCancel(context.Background())
+ }
+ cancel()
+ _, err := Run(ctx, RunOptions{CacheDir: stageCache(t)})
+ if !errors.Is(err, wantErr) {
+ t.Fatalf("Run error = %v, want %v", err, wantErr)
+ }
+ })
+ }
+}
+
+func TestPythonCandidatesCaseInsensitiveNames(t *testing.T) {
+ dir := t.TempDir()
+ for _, name := range []string{"PYTHON.exe", "python3.12.Exe", "Python3.EXE", "python3.11.exe"} {
+ if err := os.WriteFile(filepath.Join(dir, name), nil, 0755); err != nil {
+ t.Fatal(err)
+ }
+ }
+ defer func(prev bool) { caseInsensitiveNames = prev }(caseInsensitiveNames)
+
+ caseInsensitiveNames = true
+ got := pythonCandidates(dir)
+ want := []string{
+ filepath.Join(dir, "Python3.EXE"),
+ filepath.Join(dir, "python3.12.Exe"),
+ filepath.Join(dir, "PYTHON.exe"),
+ }
+ if strings.Join(got, "|") != strings.Join(want, "|") {
+ t.Fatalf("case-insensitive candidates = %q, want %q", got, want)
+ }
+
+ caseInsensitiveNames = false
+ if got := pythonCandidates(dir); len(got) != 0 {
+ t.Fatalf("case-sensitive candidates = %q, want none", got)
+ }
+}
diff --git a/mcp/internal/engine/run.go b/mcp/internal/engine/run.go
index b79a3008..453f50f4 100644
--- a/mcp/internal/engine/run.go
+++ b/mcp/internal/engine/run.go
@@ -8,15 +8,12 @@ import (
"os"
"os/exec"
"path/filepath"
- "runtime"
"strconv"
"strings"
"time"
)
-// DefaultPythonBinary is the interpreter we look up unless RunOptions
-// overrides it. Windows installs may expose only "python"; we surface a
-// clear error in that case rather than silently picking the wrong binary.
+// DefaultPythonBinary is preferred when its version meets MinPythonVersion.
const DefaultPythonBinary = "python3"
// MinPythonVersion mirrors the engine's MIN_PYTHON constant in
@@ -46,10 +43,6 @@ const termGracePeriod = 2 * time.Second
// an unregistered detached descendant still holds its output pipes.
const pipeGracePeriod = time.Second
-// PythonEnvOverride lets operators select the Python 3.12+ executable used
-// by the MCP server. When unset, Run preserves the python3 PATH lookup.
-const PythonEnvOverride = "LAST30DAYS_PYTHON"
-
// RunOptions configures one invocation of the embedded Python engine.
// PythonPath is exposed so tests can substitute a stub interpreter without
// manipulating the process PATH.
@@ -83,7 +76,7 @@ func Run(ctx context.Context, opts RunOptions) (*RunResult, error) {
if opts.CacheDir == "" {
return nil, errors.New("engine: CacheDir is required")
}
- pythonPath, err := resolvePython(opts.PythonPath)
+ pythonPath, err := resolvePythonContext(ctx, opts.PythonPath)
if err != nil {
return nil, err
}
@@ -175,42 +168,6 @@ func Run(ctx context.Context, opts RunOptions) (*RunResult, error) {
return res, fmt.Errorf("engine: subprocess failed: %w", err)
}
-// resolvePython returns a resolved interpreter path or a clear error. A
-// caller-supplied path remains the highest-priority test seam. Otherwise an
-// explicitly configured LAST30DAYS_PYTHON must resolve successfully; only
-// an absent override falls back to the existing python3 PATH lookup.
-func resolvePython(override string) (string, error) {
- if override != "" {
- return override, nil
- }
- if configured, ok := os.LookupEnv(PythonEnvOverride); ok {
- if configured == "" {
- return "", fmt.Errorf(
- "engine: %s is set but empty; set it to a Python %s+ executable or unset it to use %s on PATH",
- PythonEnvOverride, MinPythonVersion, DefaultPythonBinary,
- )
- }
- path, err := exec.LookPath(configured)
- if err != nil {
- return "", fmt.Errorf(
- "engine: %s=%q does not resolve to an executable (need Python %s+, install from %s): %w",
- PythonEnvOverride, configured, MinPythonVersion, PythonInstallURL, err,
- )
- }
- return path, nil
- }
- path, err := exec.LookPath(DefaultPythonBinary)
- // Go normally rejects relative results with ErrDot. Keep this invariant
- // even when that protection is disabled with GODEBUG=execerrdot=0.
- if err == nil && filepath.IsAbs(path) {
- return path, nil
- }
- return "", fmt.Errorf(
- "engine: %s not found on PATH (need Python %s+, install from %s; current GOOS=%s)",
- DefaultPythonBinary, MinPythonVersion, PythonInstallURL, runtime.GOOS,
- )
-}
-
func resolveTimeout(explicit time.Duration) time.Duration {
if explicit > 0 {
return explicit
diff --git a/mcp/internal/engine/run_test.go b/mcp/internal/engine/run_test.go
index d9b08484..1f3e60fc 100644
--- a/mcp/internal/engine/run_test.go
+++ b/mcp/internal/engine/run_test.go
@@ -283,10 +283,7 @@ func TestRunCanceledBeforeStart(t *testing.T) {
}
func TestResolvePythonHonorsEnvOverride(t *testing.T) {
- executable, err := os.Executable()
- if err != nil {
- t.Fatalf("os.Executable: %v", err)
- }
+ executable := fakePython(t, t.TempDir(), "selected-python", "3.12")
t.Setenv(PythonEnvOverride, executable)
t.Setenv("PATH", "")
@@ -336,15 +333,7 @@ func TestResolvePythonRejectsInvalidEnvOverride(t *testing.T) {
func TestResolvePythonDefaultsToPython3Lookup(t *testing.T) {
dir := t.TempDir()
- name := DefaultPythonBinary
- if runtime.GOOS == "windows" {
- name += ".exe"
- t.Setenv("PATHEXT", ".COM;.EXE;.BAT;.CMD")
- }
- candidate := filepath.Join(dir, name)
- if err := os.WriteFile(candidate, []byte("stub"), 0o755); err != nil {
- t.Fatalf("write default python stub: %v", err)
- }
+ candidate := fakePython(t, dir, DefaultPythonBinary, "3.12")
t.Setenv(PythonEnvOverride, "temporarily-set-for-cleanup")
if err := os.Unsetenv(PythonEnvOverride); err != nil {
t.Fatalf("unset %s: %v", PythonEnvOverride, err)
@@ -369,6 +358,7 @@ func TestResolvePythonDefaultsToPython3Lookup(t *testing.T) {
}
func TestRunMissingPython(t *testing.T) {
+ unsetPythonOverride(t)
cache := stageCache(t)
// Empty PATH guarantees the lookup fails. PythonPath stays unset so Run
// falls through to exec.LookPath.
@@ -391,6 +381,7 @@ func TestRunMissingPython(t *testing.T) {
}
func TestResolvePythonRejectsRelativePATH(t *testing.T) {
+ unsetPythonOverride(t)
if runtime.GOOS == "windows" {
t.Skip("POSIX executable fixture")
}
@@ -407,12 +398,13 @@ func TestResolvePythonRejectsRelativePATH(t *testing.T) {
}
func TestResolvePythonAcceptsAbsolutePATH(t *testing.T) {
+ unsetPythonOverride(t)
if runtime.GOOS == "windows" {
t.Skip("POSIX executable fixture")
}
dir := t.TempDir()
want := filepath.Join(dir, DefaultPythonBinary)
- if err := os.WriteFile(want, []byte("#!/bin/sh\nexit 0\n"), 0o755); err != nil {
+ if err := os.WriteFile(want, []byte("#!/bin/sh\nprintf '3.12\\n'\n"), 0o755); err != nil {
t.Fatal(err)
}
t.Setenv("PATH", dir)