The root held 89 .go files (30 commands, 59 tests). They move as they are to internal/cli (package cli), with git mv so history follows them. The only code change is main() becoming cli.Main(version): the root's new main.go keeps `var version` in package main, so -ldflags "-X main.version=…" in the Makefile, the Dockerfile and magpie-releases, and every workflow, work unchanged. go-winres's rsrc_windows_*.syso still land next to package main in the root. Tests that read testdata by a root-relative path now go up one level (../plugin/testdata/fake, ../sessions/testdata). Five subsystem doc links point at internal/cli/. Run: - go build ./..., gofmt -l, go vet on darwin, linux and windows (nogui) - builds with tags production, dev, "production nogui"; windows -H windowsgui; linux CGO_ENABLED=0 - make release-cli TARGETS="darwin/arm64 linux/amd64 windows/amd64 android/arm64" VERSION=9.9.9-tidy: all four built, binary prints "magpie 9.9.9-tidy" - docker build --build-arg VERSION=7.7.7-tidy: container prints "magpie 7.7.7-tidy" - go test ./internal/cli (default and nogui): 152 tests, the same count as the root on main - go test ./...: all packages pass (agent, gateway, library, provider timed out at 10m under other sessions' load and passed rerun alone with -timeout 40m; none of them changed) - the built binary in a sandbox HOME: version, help, ls, providers, claude, and an unknown command's error
65 lines
2.2 KiB
Go
65 lines
2.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"slices"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// models= takes patterns among the ids (#766): the group keeps the
|
|
// patterns, not what they match, and models+= / models-= add and drop them.
|
|
func TestGroupPatternsCLI(t *testing.T) {
|
|
groupsHome(t)
|
|
g, err := addGroup("Pool", []string{"models=b/gpt-5.5,a/*"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// named first, then matched in the catalog's order
|
|
if !slices.Equal(g.Members, []string{"b/gpt-5.5", "a/m", "a/only-a", "a/claude-opus-5-5"}) || !slices.Equal(g.Match, []string{"a/*"}) {
|
|
t.Fatalf("added: %v %v", g.Members, g.Match)
|
|
}
|
|
gs := storedGroups(t)
|
|
if fmt.Sprint(gs[0]["members"]) != "[b/gpt-5.5]" || fmt.Sprint(gs[0]["match"]) != "[a/*]" {
|
|
t.Fatalf("stored: %v", gs)
|
|
}
|
|
// a matched model can't be dropped by id: the pattern would bring it back
|
|
if _, err := setGroup("pool", []string{"models-=a/m"}); err == nil || !strings.Contains(err.Error(), "a/*") {
|
|
t.Fatalf("dropped a matched model: %v", err)
|
|
}
|
|
// named, it moves to where it is named
|
|
if g, err = setGroup("pool", []string{"models+=a/only-a,re:b/vendor/.*"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !slices.Equal(g.Members, []string{"b/gpt-5.5", "a/only-a", "a/m", "a/claude-opus-5-5", "b/vendor/m"}) || len(g.Match) != 2 {
|
|
t.Fatalf("models+=: %v %v", g.Members, g.Match)
|
|
}
|
|
if g, err = setGroup("pool", []string{"models-=a/*"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !slices.Equal(g.Members, []string{"b/gpt-5.5", "a/only-a", "b/vendor/m"}) || !slices.Equal(g.Match, []string{"re:b/vendor/.*"}) {
|
|
t.Fatalf("models-= a pattern: %v %v", g.Members, g.Match)
|
|
}
|
|
// a pattern alone, matching nothing: the group stays, said so
|
|
if g, err = setGroup("pool", []string{"models=zzz/*"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(g.Members) != 0 || !slices.Equal(g.Match, []string{"zzz/*"}) {
|
|
t.Fatalf("models=zzz/*: %+v", g)
|
|
}
|
|
if _, ms, ok := provider.FindGroup("group/pool"); !ok || len(ms) != 0 {
|
|
t.Fatalf("routed: %v %+v", ok, ms)
|
|
}
|
|
if err := showGroup(g); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := addGroup("Bad", []string{"models=re:a/(m"}); err == nil {
|
|
t.Fatal("a broken regexp was taken")
|
|
}
|
|
if !strings.Contains(groupUsage, "re:<regexp>") {
|
|
t.Fatal("help says nothing of patterns")
|
|
}
|
|
}
|