Files
magpie/groups_template_cli_test.go
T
yetone e70e7ed46a routing: a routing group is made from a template in one click, of the user's own models: hard turns to the strongest and easy ones to a cheap one, cheap first, or never stuck
Making a group took the whole editor (owner, 10-10). Three templates are
made from the models the user has (provider.Templates, grouptemplate.go):

- smart (smart-split): an ordered group of the strongest model and a cheap
  one; a classifier sends a hard turn to the strong one and an easy turn or
  a compaction to the cheap one, images to a model that sees them. The
  classifier is the decision API when there is one, else the cheapest
  priced model that doesn't reason.
- thrifty (cheap-first): two cheap models of different providers, then the
  strongest, which also takes high reasoning.
- steady (never-stuck): the strongest model of up to three providers, each
  failing over to the next.

A model weighs by its maker's list price, else its provider's, else by its
id's size words; one over $100 a million output tokens is never picked. A
template that can't be made says what is missing. AddTemplate saves it
under a name and id no group has (freeGroupName, now shared with
CopyGroup), never over one.

GUI: before the user has a group of their own, the Routing page shows the
templates as cards (models, Add, Edit first); after, a Templates menu by
New group. CLI: `magpie group template [kind] [name]`, no args to list.
Pricing goes through priceOf with the served entry's provider, so
/api/groups pays ~75ms for templates on 203 models, not ~600ms.

Run, at this head rebased on origin/main 4e584faa: go test ./... green;
gofmt -l clean; go vet on darwin, GOOS=linux -tags nogui and GOOS=windows.
GUI: group-template.test.cjs and group-duplicate.test.cjs (Chromium and
WebKit, 5 languages, 420px) 30/30, the template test 3 runs in a row; it
skips WebKit's "ResizeObserver loop" notice as two other tests do. The
group-*/routing-* GUI tests ran before the rebase: 628/635, the 7 being
WebKit flights in routing-group-fold and routing-keys-fold, one Chromium
routing-proxy, and the ResizeObserver notice above; run alone at this head,
routing-proxy passes and the two fold files pass twice on WebKit, as on
origin/main. Real data in a sandbox HOME: `magpie web` on 3561, the
Templates menu added smart-split as GPT-6.1 Sol → GPT-6 Luna with 3 rules.
No real request was routed through the new group.
2026-10-10 19:46:58 +08:00

59 lines
2.1 KiB
Go

package main
import (
"slices"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// magpie group template lists the templates as the user's models make them,
// and adds one in one go: added twice, the second is numbered beside the
// first rather than written over it (yetone, 10-10).
func TestGroupTemplateCLI(t *testing.T) {
groupsHome(t)
if err := provider.Save(provider.Provider{ID: "c", Name: "C", Key: "kc", Models: []string{"gpt-5.4-mini"}, Chat: "http://127.0.0.1:1/v1"}); err != nil {
t.Fatal(err)
}
out, err := stdoutOf(t, func() error { return groupCmd([]string{"group", "template"}) })
if err != nil {
t.Fatal(err)
}
for _, k := range provider.TemplateKinds {
if !strings.Contains(out, k) {
t.Errorf("list said %q, no %s", out, k)
}
}
if _, err := stdoutOf(t, func() error { return groupCmd([]string{"group", "template", "steady"}) }); err != nil {
t.Fatal(err)
}
g, err := findGroup("never-stuck")
if err != nil || g.Name != "Never stuck" || g.Routing != provider.Ordered || len(g.Members) < 2 {
t.Fatalf("steady: %v %+v", err, g)
}
out, err = stdoutOf(t, func() error { return groupCmd([]string{"group", "template", "never-stuck", "Steady"}) })
if err != nil || !strings.Contains(out, "group/never-stuck-2") {
t.Fatalf("again: %v %q", err, out)
}
if again, err := findGroup("never-stuck-2"); err != nil || again.Name != "Steady" || !slices.Equal(again.Members, g.Members) {
t.Fatalf("again: %v %+v", err, again)
}
if g2, _ := findGroup("never-stuck"); g2.Name != "Never stuck" {
t.Errorf("the first was written over: %+v", g2)
}
if _, err := stdoutOf(t, func() error { return groupCmd([]string{"group", "template", "smart"}) }); err != nil {
t.Fatal(err)
}
s, err := findGroup("smart-split")
if err != nil || len(s.Members) != 2 || s.Classifier == "" || !slices.ContainsFunc(s.Rules, func(r provider.Rule) bool { return r.Intent == provider.IntentHard }) {
t.Fatalf("smart: %v %+v", err, s)
}
if err := groupCmd([]string{"group", "template", "nope"}); err == nil || !strings.Contains(err.Error(), "smart") {
t.Errorf("no such template: %v", err)
}
}