Files
magpie/internal/plugin/notplugin_test.go
T
yetone 28430c9b90 gui: magpie's own paths are written with ›
A path through magpie's own screens was written with › in some places
and → in others (11-17 scan, item 18). Every one the user reads is now
›: Settings › Network and sharing, Settings › Privacy, Library › MCP
servers, Providers › … › Use it anyway, Settings › Usage, in the GUI and
in the Go errors and notices that reach it, in every language. The GUI
matches errNotAsked by its prefix, so it still finds it.

Left as they are: gateway errors written for agents, AiHubMix's and
Claude Desktop's own menu paths (their apps' words), the image MCP tool
description (it goes to agents), and comments.

Own tests: chatgpt-usage-why, websearch-places, library-mcp-hub,
i18n-keys; Go: internal/library (TestPrivateRepoInstallsWithToken, red
on the first try because skills.go still had →), internal/plugin
(notplugin_test), internal/pii, internal/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

75 lines
2.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package plugin
import (
"context"
"os"
"path/filepath"
"strings"
"testing"
"time"
)
// A package that is only a command — magpie-x-search 1.2.0's own
// package.json, an MCP stdio server with a bin and no main, exports or
// index file (#1327) — isn't added as a plugin: Add says what it is and
// where it goes instead. One on the list already (added before) says so
// when the host loads it, without a stack.
func TestCommandOnlyPackageIsNoPlugin(t *testing.T) {
sandbox(t)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
abs, _ := filepath.Abs("testdata/notplugin/magpie-x-search")
_, err := Add(ctx, abs)
if err == nil || !strings.Contains(err.Error(), "magpie-x-search isn't an OpenCode or magpie plugin") || !strings.Contains(err.Error(), "Library › MCP servers") {
t.Fatalf("Add = %v", err)
}
if l := Load().Plugins; len(l) != 0 {
t.Fatalf("listed: %+v", l)
}
// added by an older magpie: the host says the same, plainly
if err := save(List{Plugins: []Entry{{Spec: abs}}}); err != nil {
t.Fatal(err)
}
Restart()
ps, err := Plugins(ctx)
if err != nil {
t.Fatal(err)
}
if len(ps) != 1 || !strings.Contains(ps[0].Error, "magpie-x-search isn't an OpenCode or magpie plugin") || !strings.Contains(ps[0].Error, "MCP servers") || strings.Contains(ps[0].Error, " at ") {
t.Fatalf("loaded: %+v", ps)
}
}
// What a package that names no file still loads stays a plugin: an index
// file, main or exports; so do pi's packages and middleware, and a file.
func TestNotPluginKeepsPlugins(t *testing.T) {
sandbox(t)
pkg := func(json string, files ...string) string {
d := t.TempDir()
if err := os.WriteFile(filepath.Join(d, "package.json"), []byte(json), 0o644); err != nil {
t.Fatal(err)
}
for _, f := range files {
if err := os.WriteFile(filepath.Join(d, f), []byte("export default {}\n"), 0o644); err != nil {
t.Fatal(err)
}
}
return d
}
for name, d := range map[string]string{
"index.mjs": pkg(`{"name":"a","bin":{"a":"cli.js"}}`, "index.mjs"),
"main": pkg(`{"name":"b","main":"dist/x.js"}`),
"exports": pkg(`{"name":"c","exports":{"./server":"./s.js"}}`),
"middleware": pkg(`{"name":"d","magpie":{"middleware":"d.middleware.js"}}`),
"pi": pkg(`{"name":"e","pi":{"extensions":["./x.ts"]},"peerDependencies":{"@earendil-works/pi-coding-agent":"*"}}`),
} {
if err := notPlugin(d); err != nil {
t.Errorf("%s: %v", name, err)
}
}
if abs, _ := filepath.Abs("testdata/fake/index.js"); notPlugin(abs) != nil {
t.Error("a file")
}
}