Files
magpie/internal/agent/omp_offpath_test.go
T
yetone 1a33d22cca agent: an omp outside magpie's PATH (bun's ~/.bun/bin) is still found and asked its version on Linux and macOS, so its models offer max (whqtian on Discord)
whqtian: "ubuntu 24 版本的 omp 最大推理级别,还是xhigh,win版和 wsl版好了". omp
gets max in models.yml only when its version is known to be 16.4.0 or
later (ompTakesMax). The version comes from cliBin → binAt, which looks in
the user's tool folders (proc.FindTool: ~/.bun/bin, npm prefixes, every nvm
Node, mise, fnm ...) only on Windows. Elsewhere it uses the PATH magpie
was started with, and only the GUI and `daemon install` widen that. Under
`magpie serve`, web, tui, the CLI or a service, an omp installed by bun in
~/.bun/bin read as no version, so max was turned into xhigh. 31626c154
fixed only WSL's probe script, and Windows already had the fallback, which
is why only native Linux stayed on xhigh. cliBin now falls back to FindTool
on every system. proc.Version reads the npm package.json first, so it
doesn't need bun on PATH.

Verified:
- TestOmpVersionOffPath (a bun-layout omp 18.9.1 in a temp HOME, with
  PATH set to an empty dir) fails without the change (version "") and
  passes with it.
- Reproduced in Docker ubuntu:24.04 with real bun and omp 18.10.4, PATH
  without ~/.bun/bin, provider a/sol with efforts low..max, then
  `magpie omp a/sol`. The old linux/arm64 nogui build wrote efforts up to
  xhigh; the new one writes max. Control: the old build with ~/.bun/bin
  on PATH also wrote max.

Checks: gofmt -l is empty. go vet passes for darwin, GOOS=linux -tags
nogui and GOOS=windows. The GOOS=windows build passes. go test -tags nogui
-count=1 ./... was run under a sandbox HOME.
- The machine's load average was 200-360, so agent, gateway, library,
  plugin and provider ran out of the 10m timeout. Rerun with -timeout
  45m -p 2, all five pass.
- TestRefreshInvalidationCancelsStaleCall (plugin) and
  TestCopilotSecretToolUsername (provider) failed once under that load
  and passed on the rerun. Neither package depends on this change.

docs/subsystems/agent-wiring.md says where an off-PATH CLI is looked
for.

Not tried: the .deb GUI on a real Ubuntu desktop, or the reporter's exact
install.
2026-10-14 18:17:38 +08:00

52 lines
1.8 KiB
Go

package agent
import (
"os"
"path/filepath"
"runtime"
"testing"
"github.com/yetone/magpie/internal/proc"
)
// An omp bun installed is asked its version though ~/.bun/bin isn't on
// magpie's PATH, as on Windows and in WSL (whqtian on Discord: on Ubuntu
// omp's models still offered xhigh in place of max). A `magpie serve`, or
// a service started with a PATH that lacks it, found no omp at all, so its
// version stayed unknown and was taken for one older than 16.4.0.
func TestOmpVersionOffPath(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("bun's Windows launcher is an .exe beside a .bunx")
}
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
empty := filepath.Join(home, "empty")
pkg := filepath.Join(home, ".bun/install/global/node_modules/@oh-my-pi/pi-coding-agent")
for _, d := range []string{empty, filepath.Join(pkg, "dist"), filepath.Join(home, ".bun/bin"), filepath.Join(home, ".omp/agent")} {
if err := os.MkdirAll(d, 0o755); err != nil {
t.Fatal(err)
}
}
if err := os.WriteFile(filepath.Join(pkg, "package.json"), []byte(`{"name":"@oh-my-pi/pi-coding-agent","version":"18.9.1"}`), 0o644); err != nil {
t.Fatal(err)
}
if err := os.WriteFile(filepath.Join(pkg, "dist/cli.js"), []byte("#!/usr/bin/env bun\n"), 0o755); err != nil {
t.Fatal(err)
}
if err := os.Symlink("../install/global/node_modules/@oh-my-pi/pi-coding-agent/dist/cli.js", filepath.Join(home, ".bun/bin/omp")); err != nil {
t.Fatal(err)
}
t.Setenv("PATH", empty)
proc.Forget()
t.Cleanup(proc.Forget)
v := ompVersion()
if v != "18.9.1" {
t.Fatalf("omp's version read as %q, want 18.9.1", v)
}
if !ompTakesMax(v) {
t.Error("its models wouldn't offer max")
}
}