A remote magpie whose picks left any of its models out served no model
listed after the Save (withNewlyListed's all-or-nothing rule), so every
routing group its user made there later, group/opus here, was missing
from the agents' pickers until ticked by hand in the editor. Deleting
and adding the remote again cleared the picks, which is why it "showed
sometimes". A group the remote lists since the picks were saved
(not in PickedFrom) is now served beside them; a new model of the
remote's providers still waits for a tick, and a group listed at Save
and left unpicked stays out.
Not changed: an agent set to show only the models picked for it
(#1337) still hides any model made later, local groups too; that is
the mode's rule.
Run:
- TestRemoteMagpieNewGroupServedBesidePicks red on the old models.go
("the remote's new group isn't offered: [group/smart
fake/claude-opus-9]"), green after.
- go test -count=1 -timeout 45m ./internal/provider ./internal/gateway
./internal/gui ./internal/cli on mica at 4a4424ea8 + this change:
all ok (provider 192s, gateway 1119s, gui 227s, cli 69s).
- GOOS=linux and GOOS=windows go vet ./internal/provider; gofmt -l clean.
- Two sandbox magpies on mote (remote R with groups smart, opus,
sonnet over a fake upstream; client C with remote "office", picks
leaving fake/gpt-x out): the old binary listed 3 of 5 with
office/group/sonnet left out; the fixed one, after a restart, lists
office/group/sonnet in /v1/models and in /api/agent-models/claude
with nothing hidden, and a group added on R while C ran
(office/group/haiku) showed within seconds; fake/gpt-x stayed out.
Not tried: the reporter's own pair of machines, the GUI editor by hand
(it starts from Picks, which now holds the group).
104 lines
3.0 KiB
Go
104 lines
3.0 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"path/filepath"
|
|
"slices"
|
|
"sync/atomic"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/agentenv"
|
|
)
|
|
|
|
// A remote magpie whose picks leave one of its models out: a routing group
|
|
// its user makes there later is offered here at once, with no tick in the
|
|
// editor, while a new model of its providers still waits for one, and a
|
|
// group the user saw and unticked stays out (KoiLx0 on X: office/group/opus
|
|
// missing from the agents' picker until picked by hand).
|
|
func TestRemoteMagpieNewGroupServedBesidePicks(t *testing.T) {
|
|
isolate(t)
|
|
h := t.TempDir()
|
|
t.Setenv("HOME", h)
|
|
t.Setenv("USERPROFILE", h)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
|
t.Setenv("PATH", h)
|
|
for _, v := range agentenv.Vars {
|
|
t.Setenv(v, "")
|
|
}
|
|
|
|
var list atomic.Value
|
|
list.Store(`{"data":[{"id":"group/smart"},{"id":"fake/claude-opus-9"},{"id":"fake/gpt-x"}]}`)
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path != "/v1/models" {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
w.Write([]byte(list.Load().(string)))
|
|
}))
|
|
defer srv.Close()
|
|
|
|
if err := Save(Provider{ID: "office", Name: "Office", Preset: RemoteMagpiePreset, Chat: srv.URL, Key: "sk-office"}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fetch := func() *Provider {
|
|
p, err := Find("office")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := p.Fetch(context.Background()); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, _ = Find("office")
|
|
return p
|
|
}
|
|
exposed := func(p *Provider) []string {
|
|
var ids []string
|
|
for _, m := range p.Exposed() {
|
|
ids = append(ids, m.ID)
|
|
}
|
|
return ids
|
|
}
|
|
p := fetch()
|
|
p.Models = []string{"group/smart", "fake/claude-opus-9"} // fake/gpt-x left out
|
|
if err := Save(*p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
// the remote's user makes group/opus, and a provider there lists a new model
|
|
list.Store(`{"data":[{"id":"group/smart"},{"id":"group/opus"},{"id":"fake/claude-opus-9"},{"id":"fake/gpt-x"},{"id":"fake/new-1"}]}`)
|
|
p = fetch()
|
|
got := exposed(p)
|
|
if !slices.Contains(got, "group/opus") {
|
|
t.Fatalf("the remote's new group isn't offered: %v", got)
|
|
}
|
|
for _, id := range []string{"fake/gpt-x", "fake/new-1"} {
|
|
if slices.Contains(got, id) {
|
|
t.Fatalf("%s is offered beside picks that left a model out: %v", id, got)
|
|
}
|
|
}
|
|
|
|
// the editor starts from Picks: saved as it is, the group stays
|
|
p.Models = p.Picks()
|
|
if err := Save(*p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, _ = Find("office")
|
|
if got := exposed(p); !slices.Contains(got, "group/opus") {
|
|
t.Fatalf("the group is gone after a Save from the editor: %v", got)
|
|
}
|
|
|
|
// unticked in the editor, it stays out, and so after the next list
|
|
p.Models = slices.DeleteFunc(p.Picks(), func(id string) bool { return id == "group/opus" })
|
|
if err := Save(*p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p = fetch()
|
|
if got := exposed(p); slices.Contains(got, "group/opus") {
|
|
t.Fatalf("a group the user unticked is offered again: %v", got)
|
|
}
|
|
}
|