The reporter's Routing page showed only "null is not an object
(evaluating 'g.members.map')" and no group, while every group still
routed. A group made of patterns only whose models a provider stops
listing (a plugin behind on updates) has no members, and Go's nil slice
went out of /api/groups as "members": null. groupRow, pickedRow, the
filter and the group editor (inGroups reads every group) all call
members.map/some/flatMap, so one such group threw out the whole list.
- groups.go: groupsState says a group's members as [] when it has none,
and an unmakeable template's too.
- providers.go: the Gateway's group entries say icons and providers as
[], never null (app.js gatewayModels joined g.providers).
- routing.js: every /api/groups response goes through groupsFrom, which
makes each list a list and leaves out an entry that isn't a group;
drawGroups draws a group that still throws as one flagged row
("This group can't be shown: …", zh/zh-TW/ja/de), never the whole list;
the filter shows such a group rather than throwing.
- app.js: gatewayModels reads null icons/providers as none.
Verified: a probe through provider.SaveGroup({Match: a/m*}) then the
provider listing other models gave "members":null on main; the Go test
TestGroupsNeverNullMembers goes red with groups.go reverted (group and
3 templates null) and green with it. GUI test group-null-members.test.cjs
uses that response's literal bytes: 12/12 red on the old assets, 12/12
green now (Chromium + WebKit, en + zh, 1100 and 420 wide, plus the
Gateway list). gui-de, gui-ja, i18n-keys, group-*, panel-routing,
gateway-model-info and the routing-manual/save/provider-off tests pass
(221/221). Which plugin the reporter has was not asked; the fix covers
any provider whose models a pattern group stops matching.
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/provider"
|
|
)
|
|
|
|
// A group made of patterns only whose provider stops listing the models
|
|
// they matched — a plugin behind on updates lists none — has no members.
|
|
// /api/groups says so as [], never null: the Routing page read null as
|
|
// "null is not an object (evaluating 'g.members.map')" and drew no group
|
|
// at all (#1585, dbydd). The templates that can't be made say [] too.
|
|
func TestGroupsNeverNullMembers(t *testing.T) {
|
|
t.Setenv("HOME", t.TempDir())
|
|
t.Setenv("USERPROFILE", os.Getenv("HOME"))
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
if err := provider.Save(provider.Provider{ID: "a", Name: "a", Key: "ka", Chat: "http://127.0.0.1:1/v1", Models: []string{"m1"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := provider.SaveGroup(provider.Group{ID: "p", Name: "P", Match: []string{"a/m*"}}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p, err := provider.Find("a")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p.Models = []string{"other"} // what the pattern matched is gone
|
|
if err := provider.Save(*p); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mux := http.NewServeMux()
|
|
groupRoutes(mux)
|
|
w := httptest.NewRecorder()
|
|
mux.ServeHTTP(w, httptest.NewRequest("GET", "/api/groups", nil))
|
|
var got struct {
|
|
Groups []struct {
|
|
ID string `json:"id"`
|
|
Members *json.RawMessage `json:"members"`
|
|
} `json:"groups"`
|
|
Templates []struct {
|
|
Kind string `json:"kind"`
|
|
Group struct {
|
|
Members *json.RawMessage `json:"members"`
|
|
} `json:"group"`
|
|
} `json:"templates"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &got); err != nil {
|
|
t.Fatalf("%v: %s", err, w.Body)
|
|
}
|
|
seen := false
|
|
for _, g := range got.Groups {
|
|
if g.ID == "p" {
|
|
seen = true
|
|
}
|
|
if g.Members == nil || string(*g.Members) == "null" {
|
|
t.Errorf("group %s: members %v, want a list", g.ID, g.Members)
|
|
}
|
|
}
|
|
if !seen {
|
|
t.Fatalf("no group p: %s", w.Body)
|
|
}
|
|
for _, tp := range got.Templates {
|
|
if tp.Group.Members == nil || string(*tp.Group.Members) == "null" {
|
|
t.Errorf("template %s: members null, want a list", tp.Kind)
|
|
}
|
|
}
|
|
}
|