Files
yetone 0361189f9e test: every package's tests pass on Windows, and none writes outside its sandbox (the user: 把 Windows 上那几个失败的测试修掉) — on a Windows box the suite failed in most packages, and the root package hung for 25 minutes. Tests set HOME, which os.UserHomeDir ignores on Windows (it reads USERPROFILE), so they read and wrote the runner's own home; each now sets USERPROFILE beside HOME, and Devin's, Goose's, Crush's and Claude Desktop's tests set APPDATA/LOCALAPPDATA, where those keep their files there. said() read the command's output only once it returned, and a pipe holds a few KB on Windows, so magpie model --help blocked forever; it reads while the command writes. Unix permission bits (the gateway key store's 0600 too), exec bits and symlinks Windows lacks are checked only off Windows; TOML strings hold Windows paths as literal strings, JSON as marshalled ones; a URL's path is compared as one. The provider and usage packages run in a home of their own (TestMain, as the gateway's already does), since a CLI's identity kept by a refresh still going when its test ended landed in the runner's ~/.config/magpie — and on a Mac in the user's own. Two product fixes came out of it: imagemcp took a file:///C:/… root or image for the path /C:/…, which doesn't exist on Windows, and now makes a Windows path of it (a host for a UNC share); and session discovery could keep a new Cowork session hidden on Linux, where a folder's mtime is a kernel tick and its size doesn't change, so an entry added within the tick of the last listing left both as they were — a listing made within 2s of its folder's last change is read again, as git does for racy files. TestFilePath and TestRacyDirectoryListedAgain fail without the change. On Windows 11 every package passes (32 of 32) and a run of each package in a fresh home leaves nothing in home, APPDATA or LOCALAPPDATA; on Linux (WSL) and macOS go test -tags nogui ./... passes. go vet, go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build pass.
2026-10-01 23:15:07 +08:00

58 lines
2.0 KiB
Go

package agent
import (
"fmt"
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// A routing group with max ticked offers max in omp (whqtian on Discord:
// only xhigh was listed though max was picked, while Pi had it). omp has
// taken max in models.yml since 16.4.0; only an older one, or one whose
// version isn't known, has max stand in as xhigh. A group that names both
// had no way to max at all, as the gateway keeps an xhigh asked for.
func TestOmpGroupOffersMax(t *testing.T) {
home := t.TempDir()
t.Setenv("HOME", home)
t.Setenv("USERPROFILE", home)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(home, ".config"))
t.Setenv("XDG_CACHE_HOME", filepath.Join(home, ".cache"))
if err := provider.Save(provider.Provider{ID: "a", Name: "A", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: []string{"sol", "flash"}}); err != nil {
t.Fatal(err)
}
if err := provider.SetModelEfforts("a/sol", []string{"low", "medium", "high", "xhigh", "max"}); err != nil {
t.Fatal(err)
}
if err := provider.SetModelEfforts("a/flash", []string{"low", "high", "max"}); err != nil {
t.Fatal(err)
}
if err := provider.SaveGroup(provider.Group{Name: "mix", Members: []string{"a/sol"}, Levels: []string{"high", "xhigh", "max"}}); err != nil {
t.Fatal(err)
}
efforts := func(version, id string) string {
was := ompVersion
ompVersion = func() string { return version }
defer func() { ompVersion = was }()
for _, m := range ompProvider().Models {
if m.ID == id && m.Thinking != nil {
return fmt.Sprint(m.Thinking.Efforts)
}
}
return "none"
}
for _, c := range []struct{ version, id, want string }{
{"18.4.8", "group/mix", "[high xhigh max]"},
{"16.4.0", "group/mix", "[high xhigh max]"},
{"18.4.8", "a/flash", "[low high max]"},
{"16.3.5", "group/mix", "[high xhigh]"},
{"16.3.5", "a/flash", "[low high xhigh]"},
{"", "group/mix", "[high xhigh]"},
} {
if got := efforts(c.version, c.id); got != c.want {
t.Errorf("omp %q, %s: efforts %s, want %s", c.version, c.id, got, c.want)
}
}
}