On Windows magpie lists the running distros and probes each one for agents, their sessions and Claude Code. Etsuya233 asked for a way to turn that off. settings.NoWSLAgents (per machine, kept by KeepOwn) now gates every auto-discovery path: agent.wslAgents/wslHomes/WSLRunning, sessions' wslFiles/wslDirs (via the new sessions.WSLOff hook), and wslrun.Find, which the Claude subscription uses to run Claude Code in WSL. The toggle is shown on Windows only and is on by default. Verified: - red without the change: TestWSLDetectionOff (1 WSL agent with detection off; with only sessions reverted, a distro's session is listed), TestFindWithDetectionOff (Find returned Ubuntu after asking wsl.exe). - go test -tags nogui ./... in a sandbox HOME: every package ok except TestPluginLoginTakesTheLapseOff, which timed out at 63.7s under the full run and passes alone (-count=3) and with its package (-count=1); it doesn't reach WSL. - go vet -tags nogui on agent, wslrun, sessions, settings and gui for darwin, linux and windows. - GUI: wsl-agents-setting (en/zh/zh-TW/ja/de, 900 and 440px) 30/30; gui-ja, gui-de, gui-zh-tw, i18n-keys, keep-awake, lightweight, settings-sections, settings-groups 44/44 in Chromium and 44/44 in WebKit. - Windows box (10.0.0.132), nogui magpie.exe in a sandbox profile with a logging wsl.exe first on PATH: on, `magpie agents` listed Claude Code · WSL magpie-desktop after 3 wsl.exe calls; off, `agents`, `ls` and `sessions` made no wsl.exe call and wrote no wsl.json. Not tried: the toggle in the real Windows GUI window, and Claude Code in WSL through the Claude subscription with the setting off (unit-tested only).
89 lines
2.5 KiB
Go
89 lines
2.5 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/sessions"
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// #1264 (Etsuya233): with Settings' Detect agents in WSL off, magpie asks
|
|
// wsl.exe nothing on its own: no distro is listed or probed, no agent of
|
|
// one is shown, and the Sessions page lists none of a distro's sessions,
|
|
// even one it listed while the setting was on. Turned on again, the
|
|
// distro's agents are back.
|
|
func TestWSLDetectionOff(t *testing.T) {
|
|
syncHome(t)
|
|
root := t.TempDir()
|
|
home := filepath.Join(root, "home", "me")
|
|
id := "44444444-2222-3333-4444-555555555555"
|
|
project := filepath.Join(home, ".claude", "projects", "-home-me-app")
|
|
if err := os.MkdirAll(project, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
line := `{"type":"user","message":{"role":"user","content":"Tidy the README"},"uuid":"u1","timestamp":"2026-09-20T10:00:01.000Z","cwd":"/home/me/app","sessionId":"` + id + `"}` + "\n"
|
|
if err := os.WriteFile(filepath.Join(project, id+".jsonl"), []byte(line), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(FakeWSL(map[string]string{"Ubuntu": "home:/home/me\ndir:.claude\n"}, map[string]string{"Ubuntu": root}))
|
|
var asked []string
|
|
run := wslRun
|
|
wslRun = func(d time.Duration, args ...string) ([]byte, error) {
|
|
asked = append(asked, strings.Join(args, " "))
|
|
return run(d, args...)
|
|
}
|
|
sessions.Reset()
|
|
t.Cleanup(sessions.Reset)
|
|
t.Cleanup(func() { settings.Save(settings.Settings{}) })
|
|
listed := func() bool {
|
|
for _, s := range sessions.List(0) {
|
|
if s.ID == id {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
inWSL := func() int {
|
|
n := 0
|
|
for _, a := range All() {
|
|
if a.WSL != "" {
|
|
n++
|
|
}
|
|
}
|
|
return n
|
|
}
|
|
|
|
// on (the default): the distro's Claude Code and its session are found
|
|
if inWSL() == 0 || !listed() {
|
|
t.Fatal("with detection on, the distro's agent or session isn't found")
|
|
}
|
|
|
|
if err := settings.Save(settings.Settings{NoWSLAgents: true}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
asked = nil
|
|
if n := inWSL(); n != 0 {
|
|
t.Fatalf("%d WSL agents with detection off", n)
|
|
}
|
|
if listed() {
|
|
t.Fatal("a distro's session is listed with detection off")
|
|
}
|
|
if WSLRunning("Ubuntu") || len(wslHomes()) != 0 {
|
|
t.Fatal("a distro is said to run, or its home given, with detection off")
|
|
}
|
|
if len(asked) != 0 {
|
|
t.Fatalf("wsl.exe asked with detection off: %q", asked)
|
|
}
|
|
|
|
if err := settings.Save(settings.Settings{}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if inWSL() == 0 {
|
|
t.Fatal("turned on again, the distro's agent isn't back")
|
|
}
|
|
}
|