Files
magpie/internal/gui/plugins_serves_test.go
T
yetone 766356cd3f plugins: a row's "Serves" chip names the providers the plugin registers (#3902)
The chip named only built-ins moved onto a plugin (provider.MovedOnto),
so a plugin magpie never shipped as a built-in, like
magpie-magicrew-auth signing in to letsmagic.cn and magicrew.ai, said
nothing about what it carries. /api/plugins now sends `serves`: the
names of the providers the plugin registers (plugin.Cached, which the
row's provider names already come from), once each, leaving out the
moved ones (a moved built-in's id is the plugin's provider id; the page
names it as the built-in). It is sent when the plugin has a moved
built-in or registers two or more providers: a lone provider is the
row's title already. No package.json field. The "in place of the
built-in" tooltip stays on a chip that names a moved built-in only.
plugins.js is 27 bytes smaller; no budget touched.

Analysis and the proposal by MYCF711 (mycf_711 on Discord) in #3902.

Run:
- go test ./internal/gui -count=1: ok (107s)
- TestPluginServesItsProviders red with servesBeside returning nil
  (three cases), green restored
- plugin-release.test.cjs (chromium + webkit, en + zh): 6/6; with
  origin/main's plugins.js 0/6
- plugin-*.test.cjs plugins-*.test.cjs i18n-keys.test.cjs: 661/664.
  The 3 reds are on main too: i18n-keys "a plugin's words are its own"
  (#3897) and plugin-card-update webkit en under load (#3079; 2 of 5
  red on origin/main's plugins.js too, load ~65)
- gofmt -l, go vet, GOOS=windows go vet, GOOS=linux go vet -tags nogui
  on internal/gui: clean
Not tried: a real install of magpie-magicrew-auth in the window.
2026-10-27 23:37:46 +08:00

36 lines
1.5 KiB
Go

package gui
import (
"slices"
"testing"
"github.com/yetone/magpie/internal/plugin"
)
// TestPluginServesItsProviders: the Plugins row's "Serves" chip names the
// providers a plugin registers, not only the built-ins moved onto it
// (#3902): a plugin magpie never had as a built-in, signing in to two
// sites of one vendor, names both; a lone provider says nothing beside the
// row's title; a moved built-in is named once, by the page.
func TestPluginServesItsProviders(t *testing.T) {
two := []plugin.Provider{{ID: "letsmagic", Name: "超级麦吉"}, {ID: "magicrew", Name: "MagiCrew"}}
for _, c := range []struct {
name string
moved []string
ps []plugin.Provider
want []string
}{
{"two sites, nothing moved", nil, two, []string{"超级麦吉", "MagiCrew"}},
{"one provider", nil, two[:1], nil},
{"none", nil, nil, nil},
{"same name twice", nil, []plugin.Provider{{ID: "a", Name: "Magic"}, {ID: "b", Name: "magic "}}, nil},
{"a nameless one by its id", nil, []plugin.Provider{{ID: "a", Name: "A"}, {ID: "b"}}, []string{"A", "b"}},
{"both moved", []string{"qoder", "qoder-cn"}, []plugin.Provider{{ID: "qoder", Name: "Qoder"}, {ID: "qoder-cn", Name: "Qoder CN"}}, nil},
{"one moved, one not", []string{"qoder"}, []plugin.Provider{{ID: "qoder", Name: "Qoder"}, {ID: "qoder-cn", Name: "Qoder CN"}}, []string{"Qoder CN"}},
} {
if got := servesBeside(c.moved, c.ps); !slices.Equal(got, c.want) {
t.Errorf("%s: %q, want %q", c.name, got, c.want)
}
}
}