Files
magpie/internal/testenv/wslpath_test.go
T
yetone 8dfc75afd2 testenv: tests on WSL leave the Windows drives off PATH
On WSL the interop PATH holds a dozen /mnt/c directories, reached over 9P.
proc's look cache stats every PATH directory, and in tests it is never
fresh (lookFreshInTests is 0), so every command a test runs paid for a
dozen 9P stats. internal/cli took over 40 minutes on the magpie-desktop
distro and timed out at 45m; two of its tests alone took 34.9s each with
/mnt in PATH and 0.27s without. A test also found Windows programs
there (VS Code's `code`) instead of the fake it set up.

Isolate now drops every /mnt/<drive> entry from PATH when it runs under
WSL (WSL_DISTRO_NAME, WSL_INTEROP or binfmt_misc's WSLInterop). /mnt/wsl
and /mnt/wslg stay.

Run (wsl-run, magpie-desktop):
- go test ./internal/testenv: ok. TestIsolateDropsWindowsPath is red
  with dropWindowsPath returning early, green with the fix.
- internal/cli: 36.7s, was over 40m; its one red is
  TestEveryRouteHasACommandOrIsNamed, from 60fde6fb1, fixed in the next
  commit.
- internal/proc ok (3.5s), internal/library ok (68s), internal/agent ok
  (113s).
- GOOS=windows go vet and GOOS=darwin go vet -tags nogui of
  ./internal/testenv ./internal/cli: clean.
Not run: the full suite (mote and mica were over their load bar).
2026-11-12 03:06:10 +08:00

43 lines
1.1 KiB
Go

package testenv
import (
"os"
"runtime"
"testing"
)
func TestWindowsDrive(t *testing.T) {
for dir, want := range map[string]bool{
"/mnt/c": true,
"/mnt/c/Windows/System32": true,
"/mnt/D/Tools": true,
"/mnt/wsl": false,
"/mnt/wslg/runtime-dir": false,
"/mnt/": false,
"/mnt": false,
"/usr/bin": false,
"/home/u/mnt/c": false,
"/mnt/c2/bin": false,
} {
if got := windowsDrive(dir); got != want {
t.Errorf("windowsDrive(%q) = %v, want %v", dir, got, want)
}
}
}
// In WSL a test binary's PATH has no Windows drive folder: each is a 9P
// stat at every look, and they hold the machine's Windows programs.
func TestIsolateDropsWindowsPath(t *testing.T) {
if runtime.GOOS != "linux" {
t.Skip("WSL is Linux")
}
t.Setenv("WSL_DISTRO_NAME", "magpie-test")
t.Setenv("PATH", "/usr/bin:/mnt/c/Windows/System32:/mnt/wslg/x:/bin:/mnt/d")
if err := dropWindowsPath(); err != nil {
t.Fatal(err)
}
if got, want := os.Getenv("PATH"), "/usr/bin:/mnt/wslg/x:/bin"; got != want {
t.Errorf("PATH = %q, want %q", got, want)
}
}