Files
magpie/internal/gui/plugins_own_icon_test.go
T
yetone d90780c5d4 gateway, gui: a built-in is turned on in Plugins › Built-in, not a Settings › Plugins that isn't there
Errors and notices sent people to "Settings › Plugins" or called a
built-in "the … plugin", where no such page is and the thing is a
built-in (item 18, "Plugin" qualified where it's ambiguous). They now
name Plugins › Built-in and say built-in.

Own tests: builtins, websearch-places; Go: the gateway tests whose
strings changed (TestKeyLimitsOnAndOff, TestSearchOnAndOff,
TestToolsMCP*, TestHubMCPHeldToKeyLimit, TestVisionMCPHeldToKeyLimit),
internal/gui's plugins_own_* tests, davsync, gwbudget, gwmw, provider.

Run (mote, Chromium and WebKit, en zh zh-TW ja de):
- before the rebase, 23 GUI files: every one green except
  plugin-provider-options (my bug, fixed in this branch before the push)
  and settings-groups' "warm-ups and check-in in each service's provider
  editor", red the same way at fresh origin/main 98c487d09 (an extra
  "Spend extra usage" row; #6597, commented with the sha).
- rebased on origin/main 98c487d09: advanced-headings,
  plugin-provider-options, i18n-keys, routing-advanced, provider-prefs,
  settings-search, panel-profiles, builtins, chatgpt-usage-why,
  provider-concurrency, websearch-places, library-mcp-hub all green;
  go test ./internal/gui -run 'TestCoreScriptBudget|TestI18n|TestCSS' ok;
  ./internal/library, pii, plugin, provider and access ok; go vet ok.
  No budget raised.

Again at the pushed head, rebased on origin/main 39c5040d7 and 07d19510f
(mote, Chromium and WebKit, every language): advanced-headings,
plugin-provider-options, i18n-keys, routing-advanced, provider-prefs,
settings-search, panel-profiles, builtins, chatgpt-usage-why,
provider-concurrency, websearch-places, library-mcp-hub, codex-client,
codex-client-editor and nav-timeout all green; go test ./internal/gui
-run 'TestCoreScriptBudget|TestI18n|TestCSS' ok; ./internal/library, pii,
plugin, provider, access, ghtoken, davsync and gwmw ok, and the gateway
and agent tests whose strings changed; gofmt -l empty; go vet,
GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./internal/...
clean. (GOOS=linux go vet ./... without nogui stops in Wails' cgo-only
webview_window_linux.go, the same on origin/main 39c5040d7.)

Not tried: the real app window, and Linux/Windows runs (cross-OS go vet
only).
2026-11-18 14:32:44 +08:00

64 lines
2.1 KiB
Go

package gui
import (
"context"
"encoding/json"
"os"
"path/filepath"
"testing"
"github.com/yetone/magpie/internal/settings"
)
// #1775 (peterroe): a plugin of several providers gives each its own
// picture in the auth hook and itself one in package.json's magpie.icon.
// the Plugins page is told the plugin's own, checked and kept as a
// listed plugin's is, apart from its providers'; one that gives none, or
// a picture magpie doesn't take (plain http), is told none.
func TestPluginsStateGivesThePluginsOwnIcon(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", "")
const png = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=="
dir := func(name, icon string) string {
d := filepath.Join(h, "src", name)
if err := os.MkdirAll(d, 0o755); err != nil {
t.Fatal(err)
}
pj := map[string]any{"name": name, "version": "1.0.0", "main": "index.js"}
if icon != "" {
pj["magpie"] = map[string]any{"icon": icon}
}
b, _ := json.Marshal(pj)
if err := os.WriteFile(filepath.Join(d, "package.json"), b, 0o644); err != nil {
t.Fatal(err)
}
return d
}
suite, plain, http := dir("suite", png), dir("plain", ""), dir("http", "http://example.invalid/x.png")
if err := os.MkdirAll(settings.Dir(), 0o755); err != nil {
t.Fatal(err)
}
b, _ := json.Marshal(map[string]any{"plugins": []map[string]any{{"spec": suite}, {"spec": plain}, {"spec": http}}})
if err := os.WriteFile(filepath.Join(settings.Dir(), "plugins.json"), b, 0o644); err != nil {
t.Fatal(err)
}
got := map[string]string{}
for _, p := range pluginsState(context.Background(), nil).Plugins {
got[p.Spec] = p.Icon
}
if len(got) != 3 {
t.Fatalf("plugins: %v", got)
}
if got[suite] == "" || got[suite] == png {
t.Errorf("the suite's own picture: %q, want it kept as an icon", got[suite])
}
if got[plain] != "" || got[http] != "" {
t.Errorf("none of its own: %q, http: %q", got[plain], got[http])
}
}