A plugin installed from git whose package.json says
"magpie": { "name": "华为云 HUAWEI" } read as its dependency key
(magpie-officeace) on Settings → Plugins. Bun takes no non-ASCII key, so
a package outside the community's list had no way to show a readable
name. magpie.name was never read at all: #3608's route (MYCF711's branch
1cc33700) didn't reach main, so no release has it, git or npm.
plugin.InstalledName reads magpie.name from the installed package's own
package.json, beside magpie.icon (installedOwn, one parse for both): one
line of at most 80 bytes, no control or format characters (a bidi
override would show it as another name), else nothing. /api/plugins gives
each row it as ownName, and plugins.js's shownName takes it after the
community list's name and before the git package or the spec, so a
listed package is still named by the list. The row's page, the "is up to
date" status and every message that names the row (options, prefer, Update
all) go through shownName; a page plugin's sidebar tab takes it when the
page names no title (windowParts). It is never used to resolve a name and
never shown with the community badge. Not changed: the CLI's plugin list
(the dependency key, as the reporter expects), Discover's cards for
uninstalled GitHub/npm packages, and magpie.summary. Documented in
docs/reference.md and site/public/docs (en, zh, ja).
Run:
- mote: go test -timeout 45m ./internal/plugin/ ./internal/gui/ — plugin
ok; gui red only in TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
the AppKit window tests killed at their deadline (TestPanelCloseHidesIt,
TestPluginPageLoadsItsFilesInTheWindow, TestMainWindowCorners, …;
#4125, #2645). The first three run the same red on origin/main 7aa67e9e5.
- mote: go vet, GOOS=linux go vet -tags nogui, GOOS=windows go vet on
internal/plugin and internal/gui: clean. gofmt -l internal/: nothing.
- wsl-run (magpie-desktop): plugin-own-name.test.cjs, Chromium and
WebKit, en/zh/zh-TW/ja/de at 980 and 420: 22/22. Every plugin*,
plugins-*, agent-plugin*, account-plugin*, signin-paste-plugin,
sidebar* and i18n-keys file (67): all green but i18n-keys "a plugin's words are its own" (#4524), plugin-card-update webkit en/zh (#3079) and plugin-github-filter webkit ja 420px (#4564, filed now), each red the same at origin/main 7aa67e9e5
- Rebased on origin/main 7b883cc61, mote: -run "Budget|OwnName|TestPluginsState|
TestWindowParts" on internal/gui and internal/plugin: ok (core scripts
under the budget, no raise).
Broken by hand:
- InstalledName returning "": TestPluginsStateGivesAGitPackagesOwnName red
(ownName "", and the sidebar title magpie-officeace).
- shownName without e.ownName: plugin-own-name.test.cjs red, the row
reads 'magpie-officeace'.
Not tried: the desktop window itself, and a real git repository with
magpie.name (the fixture is shaped from the reporter's installed
package.json: name magpie-officeace, version 0.2.4).
87 lines
3.4 KiB
Go
87 lines
3.4 KiB
Go
package gui
|
||
|
||
import (
|
||
"context"
|
||
"encoding/json"
|
||
"os"
|
||
"path/filepath"
|
||
"testing"
|
||
|
||
"github.com/yetone/magpie/internal/plugin"
|
||
"github.com/yetone/magpie/internal/settings"
|
||
)
|
||
|
||
// #4558 (MYCF711): a plugin installed from git whose package.json says
|
||
// magpie.name ("华为云 HUAWEI") read as its dependency key
|
||
// (magpie-officeace) in Settings → Plugins. Bun takes no non-ASCII key, so
|
||
// the package's own name is the only readable one it has. The row is told
|
||
// it (ownName), as is the sidebar's title for a page that names none; a
|
||
// package that gives none is told none, and the community's list still
|
||
// names a package it lists.
|
||
func TestPluginsStateGivesAGitPackagesOwnName(t *testing.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("MAGPIE_BUN", "")
|
||
t.Setenv("PATH", "")
|
||
write := func(path string, v any) {
|
||
t.Helper()
|
||
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
b, _ := json.Marshal(v)
|
||
if err := os.WriteFile(path, b, 0o644); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
}
|
||
const (
|
||
office = "github:example/magpie-officeace"
|
||
plain = "github:example/magpie-loomy-auth"
|
||
bidi = "github:example/magpie-bidi"
|
||
)
|
||
dir := plugin.Dir()
|
||
// the reporter's: the dependency key bun installed it under, and the
|
||
// installed copy's package.json carrying the field
|
||
write(filepath.Join(dir, "package.json"), map[string]any{"dependencies": map[string]string{
|
||
"magpie-officeace": office, "magpie-loomy-auth": plain, "magpie-bidi": bidi,
|
||
}})
|
||
write(filepath.Join(dir, "node_modules", "magpie-officeace", "package.json"), map[string]any{
|
||
"name": "magpie-officeace", "version": "0.2.4", "main": "index.js",
|
||
"magpie": map[string]any{"name": "华为云 HUAWEI", "summary": "…", "page": map[string]any{"file": "page.html"}},
|
||
})
|
||
if err := os.WriteFile(filepath.Join(dir, "node_modules", "magpie-officeace", "page.html"), []byte("<p>hi</p>"), 0o644); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
write(filepath.Join(dir, "node_modules", "magpie-loomy-auth", "package.json"), map[string]any{
|
||
"name": "magpie-loomy-auth", "version": "0.1.0", "main": "index.js",
|
||
})
|
||
// a right-to-left override would show it as another name
|
||
write(filepath.Join(dir, "node_modules", "magpie-bidi", "package.json"), map[string]any{
|
||
"name": "magpie-bidi", "version": "0.1.0", "main": "index.js", "magpie": map[string]any{"name": "Qoder"},
|
||
})
|
||
write(filepath.Join(settings.Dir(), "plugins.json"), map[string]any{"plugins": []map[string]any{{"spec": office}, {"spec": plain}, {"spec": bidi}}})
|
||
|
||
got := map[string]pluginEntryJSON{}
|
||
for _, p := range pluginsState(context.Background(), nil).Plugins {
|
||
got[p.Spec] = p
|
||
}
|
||
if len(got) != 3 {
|
||
t.Fatalf("plugins: %v", got)
|
||
}
|
||
if o := got[office]; o.OwnName != "华为云 HUAWEI" || o.Package != "magpie-officeace" {
|
||
t.Errorf("the reporter's: ownName %q, package %q; want 华为云 HUAWEI, magpie-officeace", o.OwnName, o.Package)
|
||
}
|
||
if n := got[plain].OwnName; n != "" {
|
||
t.Errorf("one that gives no name: ownName %q, want none", n)
|
||
}
|
||
if n := got[bidi].OwnName; n != "" {
|
||
t.Errorf("a name with a bidi override: ownName %q, want none", n)
|
||
}
|
||
pages, _ := windowParts()
|
||
if len(pages) != 1 || pages[0].Title != "华为云 HUAWEI" {
|
||
t.Errorf("its page's sidebar title: %+v, want 华为云 HUAWEI", pages)
|
||
}
|
||
}
|