千里不再 on Discord: Pi installed in WSL wasn't detected. The WSL probe runs `sh -lc`, which reads ~/.profile but not ~/.bashrc, where fnm's installer puts its PATH, so `command -v pi` missed it and wslbin had no fnm folder. A Pi not run yet has no ~/.pi either, so nothing found it (and for fnm users who had run it, its version was lost). Also, WSL appends Windows' PATH, so a Pi npm installed on Windows answered `command -v pi` with a /mnt/c path; that stopped the `|| wslbin` fallback and parseProbe then dropped it as a Windows command (#406), so the distro's own Pi was hidden. Now wslcmd takes `command -v` only when it isn't on a Windows drive (/mnt/X or any drive /proc/mounts lists), else walks PATH past Windows drives, else wslbin. wslbin gains the folders proc.UserBinDirs has here: fnm (aliases/default, then the highest version; FNM_DIR, ~/.local/share/fnm, ~/.fnm), mise's installs (highest), ~/.npmrc's prefix, ~/.npm/bin, cargo, deno, Homebrew. Every WSL kind goes through it, not only Pi. Run: - mote: GOOS=windows/linux/darwin go vet ./internal/agent; go test -run "TestWSL|TestOmo|TestPi" ./internal/agent ok. gofmt -l clean. - wsl-run (magpie-desktop, Ubuntu 24.04): same tests ok. - Real WSL: in magpie-desktop, a scratch HOME with the real fnm installer, `fnm install 22`, `npm i -g @mariozechner/pi-coding-agent` (pi 0.73.1), never run. Old probe: no bin:pi. New probe: `bin:pi .../fnm/aliases/default/bin/pi`, `ver:pi 0.73.1`, pi@wsl listed; a fnm codex was found past a /mnt/c one. Real home still finds codex, pi and claude (3.9s). Through proc.CommandContext on Windows (win-run) with Detect agents in WSL on, the probe runs (#4872 gates only when it is off). Broken by hand: origin/main's wsl.go with the new tests: all four subtests of TestWSLProbeFindsNodeManagersBins and TestWSLProbeLooksPastWindowsCommand red. Not tried: the reporter's own install (method unknown; fnm with a never-run Pi is the case reproduced). Asking bash -i for ~/.bashrc's PATH was tried and dropped: under timeout(1) an interactive bash stops itself (state T) on WSL and outlived its timeout. Reported-by: 千里不再 (Discord)
179 lines
6.7 KiB
Go
179 lines
6.7 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
"path/filepath"
|
|
"runtime"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/edit"
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
"github.com/yetone/magpie/internal/usage"
|
|
)
|
|
|
|
// OmO (#264) is an agent of its own, wired as Pi is but in ~/.omo/agent:
|
|
// a model through magpie sets settings.json's defaultProvider/defaultModel
|
|
// and magpie's provider in models.json there, the same block Pi gets, and
|
|
// Pi's ~/.pi is left alone; its own model takes magpie out again.
|
|
func TestOmo(t *testing.T) {
|
|
home := syncHome(t)
|
|
t.Setenv("PATH", t.TempDir()) // no omo on PATH: only its folder tells (#1646)
|
|
var a *Agent
|
|
for _, x := range All() {
|
|
if x.ID == "omo" {
|
|
a = x
|
|
}
|
|
}
|
|
if a == nil {
|
|
t.Fatal("no omo in All()")
|
|
}
|
|
dir := filepath.Join(home, ".omo", "agent")
|
|
settings, models := filepath.Join(dir, "settings.json"), filepath.Join(dir, "models.json")
|
|
if a.Name != "OmO" || a.Icon != "omo" || a.Bin != "omo" || a.Dir != dir || a.Path != settings || a.Detected() {
|
|
t.Fatalf("%+v", a)
|
|
}
|
|
os.MkdirAll(dir, 0o755)
|
|
os.WriteFile(settings, []byte(`{"theme": "dark", "defaultProvider": "xai", "defaultModel": "grok-4.6"}`), 0o644)
|
|
if !a.Detected() || a.Field("model").Get() != "xai/grok-4.6" {
|
|
t.Fatalf("detected %v, model %q", a.Detected(), a.Field("model").Get())
|
|
}
|
|
|
|
if err := a.Field("model").Set("magpie/relay/glm-4.6"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := a.Field("effort").Set("high"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
for k, want := range map[string]string{"defaultProvider": "magpie", "defaultModel": "relay/glm-4.6", "defaultThinkingLevel": "high", "theme": "dark"} {
|
|
if v, _ := edit.GetJSON(settings, k); v != want {
|
|
t.Fatalf("%s = %q:\n%s", k, v, readFile(settings))
|
|
}
|
|
}
|
|
var file struct {
|
|
Providers map[string]map[string]any `json:"providers"`
|
|
}
|
|
if err := json.Unmarshal([]byte(readFile(models)), &file); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got := file.Providers["magpie"]
|
|
if got["baseUrl"] != gateway.URL()+"/v1" || got["apiKey"] != gateway.Token {
|
|
t.Fatalf("models:\n%s", readFile(models))
|
|
}
|
|
want, _ := json.Marshal(magpieProviderJSON("pi"))
|
|
if b, _ := json.Marshal(got); string(b) != string(want) {
|
|
t.Fatalf("not Pi's block:\n got %s\nwant %s", b, want)
|
|
}
|
|
if c := a.Check(); c != "" {
|
|
t.Fatal(c)
|
|
}
|
|
if _, err := os.Stat(filepath.Join(home, ".pi")); !os.IsNotExist(err) {
|
|
t.Fatalf("~/.pi was touched: %v", err)
|
|
}
|
|
|
|
if err := a.Field("model").Set("xai/grok-4.6"); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if p, _ := edit.GetJSON(settings, "defaultProvider"); p != "xai" {
|
|
t.Fatalf("own:\n%s", readFile(settings))
|
|
}
|
|
|
|
// its requests say omo/<version>
|
|
if got := usage.AgentOf("omo/5.1.4 (darwin; bun/1.3.0; arm64)"); got != "omo" {
|
|
t.Fatalf("user agent: %q", got)
|
|
}
|
|
}
|
|
|
|
// OMO_CODING_AGENT_DIR, else SENPI_CODING_AGENT_DIR, moves OmO's folder,
|
|
// as OmO's own agent-dir.js has it; a relative one is not taken.
|
|
func TestOmoDir(t *testing.T) {
|
|
home := syncHome(t)
|
|
own, senpi := filepath.Join(home, "own"), filepath.Join(home, "senpi")
|
|
for _, c := range []struct{ omo, senpi, want string }{
|
|
{"", "", filepath.Join(home, ".omo", "agent")},
|
|
{own, senpi, own},
|
|
{"", senpi, senpi},
|
|
{"rel/dir", "", filepath.Join(home, ".omo", "agent")},
|
|
} {
|
|
t.Setenv("OMO_CODING_AGENT_DIR", c.omo)
|
|
t.Setenv("SENPI_CODING_AGENT_DIR", c.senpi)
|
|
if a := omo(home); a.Dir != c.want || a.Path != filepath.Join(c.want, "settings.json") {
|
|
t.Errorf("%+v: %s", c, a.Dir)
|
|
}
|
|
}
|
|
// a distro's OmO is at its home, whatever this machine's says
|
|
t.Setenv("OMO_CODING_AGENT_DIR", own)
|
|
root := t.TempDir()
|
|
d := distro{Name: "Ubuntu", Root: root, Home: "/home/me", Has: map[string]bool{"dir:.omo": true}, Mirrored: true, Running: true}
|
|
a := wslAgent(wslKindOf("omo"), d)
|
|
if a.ID != "omo@wsl:Ubuntu" || a.Name != "OmO · WSL Ubuntu" || a.Dir != filepath.Join(root, "home", "me", ".omo", "agent") {
|
|
t.Fatalf("%+v", a)
|
|
}
|
|
}
|
|
|
|
// The WSL probe asks after OmO too.
|
|
func TestWSLProbeFindsOmo(t *testing.T) {
|
|
for _, want := range []string{`[ -d "$HOME/.omo" ] && echo dir:.omo`, `p=$(wslcmd omo) && echo "bin:omo $p"`} {
|
|
if !strings.Contains(wslProbeScript, want) {
|
|
t.Errorf("probe lacks %q", want)
|
|
}
|
|
}
|
|
if d := parseProbe("U", "home:/home/me\nbin:omo\n"); d == nil || !wslFound(*d) {
|
|
t.Fatalf("%+v", d)
|
|
}
|
|
}
|
|
|
|
// omo --version names the engine after OmO's own version; omo update is
|
|
// its updater, however it was installed.
|
|
func TestOmoCLI(t *testing.T) {
|
|
if v := parseVersion("omo 5.1.4 (engine: senpi 2026.9.29-5)\n"); v != "5.1.4" {
|
|
t.Fatalf("version %q", v)
|
|
}
|
|
u := howInstalled(cliSpecs["omo"], "/home/me/.bun/bin/omo")
|
|
if u == nil || u.via != "self" || u.pkg != "omo-ai" || strings.Join(u.cmd, " ") != "/home/me/.bun/bin/omo update" {
|
|
t.Fatalf("%+v", u)
|
|
}
|
|
}
|
|
|
|
// omo update runs npm by its bare name, so it is given the npm (and node)
|
|
// of the prefix OmO was installed in first on PATH: a system node's npm in
|
|
// /usr/local/bin, which magpie's PATH holds before a version manager's
|
|
// (fnm), would install into a folder only root may change (#2021, ggbdpq).
|
|
func TestOmoUpdateTakesItsOwnNpm(t *testing.T) {
|
|
if runtime.GOOS == "windows" {
|
|
t.Skip("symlinks and sh scripts")
|
|
}
|
|
tmp, _ := filepath.EvalSymlinks(t.TempDir())
|
|
ran := filepath.Join(tmp, "ran")
|
|
// the system's npm, found first on magpie's PATH
|
|
sys := filepath.Join(tmp, "usr/local/bin")
|
|
file(t, filepath.Join(sys, "npm"), "#!/bin/sh\necho system >> "+ran+"\nexit 1\n")
|
|
// fnm's node, where OmO is
|
|
prefix := filepath.Join(tmp, "fnm/node-versions/v24.21.0/installation")
|
|
file(t, filepath.Join(prefix, "bin/npm"), "#!/bin/sh\necho fnm >> "+ran+"\n")
|
|
file(t, filepath.Join(prefix, "bin/node"), "#!/bin/sh\n")
|
|
file(t, filepath.Join(prefix, "lib/node_modules/omo-ai/bin/omo.js"), "#!/bin/sh\n[ \"$1\" = update ] && npm i -g omo-ai@5.1.32\n")
|
|
omoBin := link(t, "../lib/node_modules/omo-ai/bin/omo.js", filepath.Join(prefix, "bin/omo"))
|
|
t.Setenv("PATH", sys+string(os.PathListSeparator)+"/usr/bin:/bin")
|
|
|
|
u := howInstalled(cliSpecs["omo"], omoBin)
|
|
if u == nil || u.via != "self" || u.path != filepath.Join(prefix, "bin") {
|
|
t.Fatalf("%+v", u)
|
|
}
|
|
if out, err := runUpdate(t.Context(), u); err != nil {
|
|
t.Fatalf("%v: %s", err, out)
|
|
}
|
|
if b, _ := os.ReadFile(ran); string(b) != "fnm\n" {
|
|
t.Fatalf("omo update ran npm of %q, want fnm's", b)
|
|
}
|
|
// bun's OmO (bun add -g) keeps bun's folder first the same way
|
|
bunHome := filepath.Join(tmp, ".bun")
|
|
file(t, filepath.Join(bunHome, "bin/bun"), "#!/bin/sh\n")
|
|
file(t, filepath.Join(bunHome, "install/global/node_modules/omo-ai/bin/omo.js"), "")
|
|
bunOmo := link(t, "../install/global/node_modules/omo-ai/bin/omo.js", filepath.Join(bunHome, "bin/omo"))
|
|
if u := howInstalled(cliSpecs["omo"], bunOmo); u == nil || u.via != "self" || u.path != filepath.Join(bunHome, "bin") {
|
|
t.Fatalf("bun: %+v", u)
|
|
}
|
|
}
|