edussss (Windows 11) on 10-15: "昨天早上的版本还能找到,今天早上更新后又找不到了". Their screenshot shows both Claude Code and Codex marked "CLI not found", with no model or effort pickers. v0.1.1231 listed both. Cause:d0fcb8bcd(#2177, in v0.1.1238). It made cliHeld declare a shared folder (~/.claude, ~/.codex, ~/.cline) a leftover when neither the CLI nor a known reader is here. The known readers are editor extensions under ~/.<editor>/extensions, Claude.app, Claude Desktop, JetBrains and Zed. Before that commit a shared folder was never gone. The list was checked on a Mac only. On Windows, other programs read these folders too: a Store app, an editor run portable or with --extensions-dir, or a CLI on a PATH that only a shell profile sets (fnm). The Agents page, the TUI, `magpie ls`, Install another agent and the Library targets (all through CLIMissing) treated both of the reporter's agents as uninstalled. Fix: on Windows, cliHeld says "can't tell" for a shared folder whose CLI isn't found. A shared folder is then never gone, as before v0.1.1238, and as OpenCode and Goose already are off a Mac. A found CLI still holds it. Agents whose folder only their CLI keeps (dsh, Hermes) are still gone on Windows. The Windows-only branches in that path became unreachable and are dropped: desktopdir.Installed in the claude case, and the Windows dirs of jetBrainsHere and zedAgentsHere. goneOS lets a test judge for Windows on any host. docs/subsystems/agent-wiring.md says so. What was run: - Windows box (Windows 11 x64), sandbox USERPROFILE/APPDATA/LOCALAPPDATA holding only ~\.claude\settings.json and ~\.codex\config.toml, PATH C:\Windows\system32 (the registry PATH has the box's real ~\.local\bin\claude.exe; there is no codex on the box): - `magpie ls` at v0.1.1231 lists Codex "gpt-5 · effort". - At origin/main69d7ee33ait lists "Codex CLI not found". That is the regression. - With this fix it lists "Codex gpt-5 · effort" again. - At main, a fake openai.chatgpt extension in ~\.vscode or ~\.cursor also kept Codex listed. So the extension check works on Windows, and the reporter's reader is something cliHeld doesn't list. - agent.test.exe -test.run TestCLIMissing on the Windows box: all four pass (TestCLIMissing, Hermes, SharedFolders, SharedFoldersWindows). - Broken by hand: with the Windows branch disabled, TestCLIMissingSharedFoldersWindows goes red for claude, codex and cline. Each is taken for gone and offered again as missing. - gofmt -l clean. go vet -tags nogui passes for GOOS darwin, linux and windows. - set -o pipefail; go test -p 4 -timeout 40m ./... on macOS at base69d7ee33aplus this change: all 55 packages ok, exit 0 (internal/agent, cli, gui, library and tui among them). Not tried: the reporter's own setup. Their screenshot doesn't say what reads their folders. The reply on #1482 asks for `where.exe claude`, the install method and the magpie version.
302 lines
11 KiB
Go
302 lines
11 KiB
Go
package agent
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/testenv"
|
|
)
|
|
|
|
// An agent whose settings are left but whose CLI is gone (#843: dsh
|
|
// uninstalled, ~/.dsh kept) is still listed, and Install another agent
|
|
// offers it again, marked; one found where users' tools go though not on
|
|
// PATH (#839) isn't missing. Codex's folder with neither its CLI nor
|
|
// anything else that reads it is a leftover too (#2177).
|
|
func TestCLIMissing(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("PATH", t.TempDir())
|
|
judgeOffWindows(t)
|
|
// no desktop app either, whatever this machine has installed
|
|
was := appFolders
|
|
appFolders = func() []string { return nil }
|
|
t.Cleanup(func() { appFolders = was })
|
|
bin := "magpie-test-gone-dsh"
|
|
dir := filepath.Join(home, ".dsh")
|
|
if err := os.MkdirAll(dir, 0o700); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
dsh := &Agent{ID: "dsh", Name: "DeepSeek Harness", Icon: "deepseek-color", Bin: bin, Dir: dir, Path: filepath.Join(dir, "config.yaml")}
|
|
codex := &Agent{ID: "codex", Name: "Codex", Bin: "magpie-test-gone-codex", Dir: dir, Path: filepath.Join(dir, "config.toml")}
|
|
never := &Agent{ID: "crush", Name: "Crush", Bin: "magpie-test-gone-crush", Dir: filepath.Join(home, "nope"), Path: filepath.Join(home, "nope", "crush.json")}
|
|
wsl := &Agent{ID: "dsh@wsl:Ubuntu", Name: "DeepSeek Harness", Bin: bin, WSL: "Ubuntu", Dir: dir, Path: filepath.Join(dir, "config.yaml")}
|
|
if !dsh.Detected() || !dsh.CLIMissing() {
|
|
t.Fatalf("dsh with ~/.dsh and no dsh: detected %v, missing %v", dsh.Detected(), dsh.CLIMissing())
|
|
}
|
|
if !codex.CLIMissing() {
|
|
t.Fatal("codex's folder alone, nothing reading it, not taken for missing")
|
|
}
|
|
if never.CLIMissing() || wsl.CLIMissing() {
|
|
t.Fatalf("missing: crush not here %v, wsl %v", never.CLIMissing(), wsl.CLIMissing())
|
|
}
|
|
got := installsOf([]*Agent{dsh, codex, never, wsl}, "darwin", true)
|
|
ids := map[string]Install{}
|
|
for _, x := range got {
|
|
ids[x.ID] = x
|
|
}
|
|
if x, ok := ids["dsh"]; !ok || !x.Missing || len(x.Commands) != 1 || x.Commands[0].Command != "npm install -g @deepseek-ai/dsh" {
|
|
t.Fatalf("dsh offered as %+v (all: %+v)", x, got)
|
|
}
|
|
if x, ok := ids["crush"]; !ok || x.Missing {
|
|
t.Fatalf("crush, not here at all, offered as %+v", x)
|
|
}
|
|
if x, ok := ids["codex"]; !ok || !x.Missing {
|
|
t.Fatalf("codex, its folder left, offered as %+v", x)
|
|
}
|
|
|
|
// installed in ~/.local/bin, which magpie's PATH hasn't: found
|
|
local := filepath.Join(home, ".local", "bin")
|
|
if err := os.MkdirAll(local, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
name := bin
|
|
if runtime.GOOS == "windows" {
|
|
name += ".exe"
|
|
}
|
|
testenv.Program(t, filepath.Join(local, name), "#!/bin/sh\n")
|
|
if dsh.CLIMissing() {
|
|
t.Fatal("dsh in ~/.local/bin taken for missing")
|
|
}
|
|
for _, x := range installsOf([]*Agent{dsh}, "darwin", true) {
|
|
t.Fatalf("installed dsh offered: %+v", x)
|
|
}
|
|
}
|
|
|
|
// noApps points the app folders at an empty folder of the test's, so
|
|
// whatever this machine has installed counts for nothing.
|
|
func noApps(t *testing.T) string {
|
|
t.Helper()
|
|
apps := t.TempDir()
|
|
was := appFolders
|
|
appFolders = func() []string { return []string{apps} }
|
|
t.Cleanup(func() { appFolders = was })
|
|
return apps
|
|
}
|
|
|
|
func mkdirT(t *testing.T, p string) {
|
|
t.Helper()
|
|
if err := os.MkdirAll(p, 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func writeT(t *testing.T, p, body string) {
|
|
t.Helper()
|
|
mkdirT(t, filepath.Dir(p))
|
|
if err := os.WriteFile(p, []byte(body), 0o600); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
// #2173 (SkyTodInfi): Hermes uninstalled, ~/.hermes/config.yaml left with
|
|
// 37 bytes, no hermes anywhere: listed, as gone. Its own install.sh's
|
|
// checkout, or hermes in ~/.local/bin, is Hermes installed.
|
|
func TestCLIMissingHermes(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("PATH", t.TempDir())
|
|
noApps(t)
|
|
dir := filepath.Join(home, ".hermes")
|
|
writeT(t, filepath.Join(dir, "config.yaml"), "custom_providers: []\nmcp_servers: {}\n")
|
|
h := &Agent{ID: "hermes", Name: "Hermes Agent", Bin: "magpie-test-gone-hermes", Dir: dir, Path: filepath.Join(dir, "config.yaml")}
|
|
if !h.Detected() || !h.CLIMissing() {
|
|
t.Fatalf("hermes by its config.yaml alone: detected %v, missing %v", h.Detected(), h.CLIMissing())
|
|
}
|
|
// no install command magpie knows: not offered, though gone
|
|
for _, x := range installsOf([]*Agent{h}, runtime.GOOS, true) {
|
|
t.Fatalf("hermes offered: %+v", x)
|
|
}
|
|
mkdirT(t, filepath.Join(dir, "hermes-agent"))
|
|
if h.CLIMissing() {
|
|
t.Fatal("hermes with its checkout taken for missing")
|
|
}
|
|
if err := os.RemoveAll(filepath.Join(dir, "hermes-agent")); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
name := h.Bin
|
|
if runtime.GOOS == "windows" {
|
|
name += ".exe"
|
|
}
|
|
local := filepath.Join(home, ".local", "bin")
|
|
mkdirT(t, local)
|
|
testenv.Program(t, filepath.Join(local, name), "#!/bin/sh\n")
|
|
if h.CLIMissing() {
|
|
t.Fatal("hermes in ~/.local/bin taken for missing")
|
|
}
|
|
}
|
|
|
|
// An agent whose folder isn't only its CLI's is gone only when nothing
|
|
// else that reads it is here: an editor's extension, a desktop app, an
|
|
// IDE whose agents bring their own program. Never one magpie can't tell
|
|
// about (OpenCode off a Mac, Gemini, detected its own way).
|
|
type goneCase struct {
|
|
id string
|
|
folder string
|
|
with func(t *testing.T, home, apps string)
|
|
missing bool
|
|
}
|
|
|
|
func TestCLIMissingSharedFolders(t *testing.T) {
|
|
judgeOffWindows(t)
|
|
cases := []goneCase{
|
|
{"claude", ".claude", nil, true},
|
|
{"claude", ".claude", func(t *testing.T, home, _ string) {
|
|
mkdirT(t, filepath.Join(home, ".vscode", "extensions", "anthropic.claude-code-2.1.3-darwin-arm64"))
|
|
}, false},
|
|
{"claude", ".claude", func(t *testing.T, home, _ string) {
|
|
mkdirT(t, filepath.Join(home, ".cursor", "extensions", "anthropic.claude-code-2.1.3"))
|
|
}, false},
|
|
{"claude", ".claude", func(t *testing.T, home, _ string) {
|
|
writeT(t, filepath.Join(home, ".claude", "local", exe("claude")), "")
|
|
}, false},
|
|
{"claude", ".claude", func(t *testing.T, home, _ string) {
|
|
mkdirT(t, jetBrainsDirFor(home))
|
|
}, false},
|
|
{"codex", ".codex", nil, true},
|
|
{"codex", ".codex", func(t *testing.T, home, _ string) {
|
|
mkdirT(t, filepath.Join(home, ".vscode-server", "extensions", "openai.chatgpt-26.5.1"))
|
|
}, false},
|
|
{"codex", ".codex", func(t *testing.T, home, _ string) {
|
|
mkdirT(t, filepath.Join(home, ".codex", "packages", "standalone"))
|
|
}, false},
|
|
{"codex", ".codex", func(t *testing.T, home, _ string) {
|
|
mkdirT(t, zedAgentsDirFor(home))
|
|
}, false},
|
|
// another extension's folder of the same prefix is not Codex's
|
|
{"codex", ".codex", func(t *testing.T, home, _ string) {
|
|
mkdirT(t, filepath.Join(home, ".vscode", "extensions", "openai.chatgpt.other"))
|
|
}, true},
|
|
{"cline", ".cline", nil, true},
|
|
{"cline", ".cline", func(t *testing.T, home, _ string) {
|
|
mkdirT(t, filepath.Join(home, ".windsurf", "extensions", "saoudrizwan.claude-dev-3.40.0"))
|
|
}, false},
|
|
}
|
|
if runtime.GOOS == "darwin" {
|
|
cases = append(cases,
|
|
goneCase{"claude", ".claude", func(t *testing.T, _, apps string) { mkdirT(t, filepath.Join(apps, "Claude.app")) }, false},
|
|
goneCase{"opencode", ".opencode-config", nil, true},
|
|
goneCase{"opencode", ".opencode-config", func(t *testing.T, _, apps string) { mkdirT(t, filepath.Join(apps, "OpenCode.app")) }, false},
|
|
)
|
|
} else {
|
|
cases = append(cases, goneCase{"opencode", ".opencode-config", nil, false})
|
|
}
|
|
for i, c := range cases {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming"))
|
|
t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local"))
|
|
t.Setenv("PATH", t.TempDir())
|
|
apps := noApps(t)
|
|
dir := filepath.Join(home, c.folder)
|
|
writeT(t, filepath.Join(dir, "settings.json"), "{}")
|
|
a := &Agent{ID: c.id, Name: c.id, Bin: "magpie-test-gone-" + c.id, Dir: dir, Path: filepath.Join(dir, "settings.json")}
|
|
if c.with != nil {
|
|
c.with(t, home, apps)
|
|
}
|
|
if got := a.CLIMissing(); got != c.missing {
|
|
t.Errorf("case %d (%s): missing %v, want %v", i, c.id, got, c.missing)
|
|
}
|
|
}
|
|
|
|
// detected its own way: never taken for gone
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
g := &Agent{ID: "gemini", Bin: "magpie-test-gone-gemini", Dir: home, Path: filepath.Join(home, "x"), detect: func() bool { return true }}
|
|
if g.CLIMissing() {
|
|
t.Fatal("gemini, detected its own way, taken for missing")
|
|
}
|
|
}
|
|
|
|
// judgeOffWindows has cliHeld judge as on Linux when the tests run on
|
|
// Windows, where a shared folder is never gone (#1482): the cases above
|
|
// are about the systems where its readers can be told.
|
|
func judgeOffWindows(t *testing.T) {
|
|
if runtime.GOOS == "windows" {
|
|
judgeFor(t, "linux")
|
|
}
|
|
}
|
|
|
|
func judgeFor(t *testing.T, goos string) {
|
|
t.Helper()
|
|
was := goneOS
|
|
goneOS = goos
|
|
t.Cleanup(func() { goneOS = was })
|
|
}
|
|
|
|
// #1482 (edussss, Windows 11): from v0.1.1238 Claude Code and Codex both
|
|
// showed "CLI not found", their settings hidden, though v0.1.1231 listed
|
|
// them and the user runs them. On Windows what reads ~\.claude and
|
|
// ~\.codex can't all be told (a Store app, a portable editor, a PATH only
|
|
// a shell profile sets), so a shared folder is never gone there. An agent
|
|
// whose folder is only its CLI's still is.
|
|
func TestCLIMissingSharedFoldersWindows(t *testing.T) {
|
|
judgeFor(t, "windows")
|
|
for _, c := range []struct{ id, folder string }{{"claude", ".claude"}, {"codex", ".codex"}, {"cline", ".cline"}} {
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("APPDATA", filepath.Join(home, "AppData", "Roaming"))
|
|
t.Setenv("LOCALAPPDATA", filepath.Join(home, "AppData", "Local"))
|
|
t.Setenv("PATH", t.TempDir())
|
|
noApps(t)
|
|
dir := filepath.Join(home, c.folder)
|
|
writeT(t, filepath.Join(dir, "settings.json"), "{}")
|
|
a := &Agent{ID: c.id, Name: c.id, Bin: "magpie-test-gone-" + c.id, Dir: dir, Path: filepath.Join(dir, "settings.json")}
|
|
if !a.Detected() {
|
|
t.Fatalf("%s: its folder not detected", c.id)
|
|
}
|
|
if a.CLIMissing() {
|
|
t.Errorf("%s: its folder alone taken for gone on Windows", c.id)
|
|
}
|
|
for _, x := range installsOf([]*Agent{a}, "windows", true) {
|
|
if x.Missing {
|
|
t.Errorf("%s offered again as gone: %+v", c.id, x)
|
|
}
|
|
}
|
|
}
|
|
|
|
// an agent whose folder only its CLI keeps is still gone without it
|
|
home := t.TempDir()
|
|
t.Setenv("HOME", home)
|
|
t.Setenv("USERPROFILE", home)
|
|
t.Setenv("PATH", t.TempDir())
|
|
noApps(t)
|
|
hdir := filepath.Join(home, ".hermes")
|
|
writeT(t, filepath.Join(hdir, "config.yaml"), "custom_providers: []\n")
|
|
h := &Agent{ID: "hermes", Name: "Hermes Agent", Bin: "magpie-test-gone-hermes", Dir: hdir, Path: filepath.Join(hdir, "config.yaml")}
|
|
if !h.CLIMissing() {
|
|
t.Fatal("hermes by its config.yaml alone not gone when judged for Windows")
|
|
}
|
|
}
|
|
|
|
// jetBrainsDirFor and zedAgentsDirFor are where jetBrainsHere and
|
|
// zedAgentsHere look on this system.
|
|
func jetBrainsDirFor(home string) string {
|
|
if runtime.GOOS == "darwin" {
|
|
return filepath.Join(home, "Library", "Application Support", "JetBrains")
|
|
}
|
|
return filepath.Join(home, ".config", "JetBrains")
|
|
}
|
|
|
|
func zedAgentsDirFor(home string) string {
|
|
if runtime.GOOS == "darwin" {
|
|
return filepath.Join(home, "Library", "Application Support", "Zed", "external_agents")
|
|
}
|
|
return filepath.Join(home, ".local", "share", "zed", "external_agents")
|
|
}
|