plugins_cli: magpie plugin off, on and rm take a plugin's short name, as options does (the owner, testing for real) — magpie plugin off think-tags answered no plugin "think-tags" while magpie plugin options think-tags found it, so the names the community READMEs and usemagpie.ai's docs write worked for one command only. installedName turns a short name (think-tags for @magpie-community/middleware-think-tags, plugin.ShortName) into the installed plugin's package name for on, off and rm; a name a plugin has itself, or one no plugin has, is kept as it was. Found and tested end to end in a sandbox HOME with a real DeepSeek account: Model Map and Think Tags installed by clicking Install under Plugins › Discover › Gateway middleware in the real app (from a local verdaccio registry holding the real packages, until their first npm publish; magpie built with npmRegistry pointed at it), an alias set in Model Map's Options editor served by deepseek-flash and named back, think-tags off by short name let the model's <think>…</think> through and on took it out ("51"), rm think-tags by short name and Model Map's Remove in the app left plugins.json empty and the alias unknown. TestPluginOnOffRmShortName is new and fails without the change. go vet, go build (GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass.
This commit is contained in:
1 parent
71d2da1f42
commit
db812921a6
2 files changed
+47
No files matched your search
@@ -42,3 +42,29 @@ func TestPluginListSaysMiddleware(t *testing.T) {
|
||||
t.Errorf("--json has no middleware:\n%s", js)
|
||||
}
|
||||
}
|
||||
|
||||
// magpie plugin off, on and rm take a plugin's short name, as options
|
||||
// does: `magpie plugin off think-tags` said there was no such plugin.
|
||||
func TestPluginOnOffRmShortName(t *testing.T) {
|
||||
groupsHome(t)
|
||||
dir := filepath.Join(t.TempDir(), "middleware-zz-tags")
|
||||
os.MkdirAll(dir, 0o755)
|
||||
os.WriteFile(filepath.Join(dir, "package.json"), []byte(`{"name": "@magpie-community/middleware-zz-tags", "magpie": {"middleware": "./zz.middleware.js"}}`), 0o644)
|
||||
os.WriteFile(filepath.Join(dir, "zz.middleware.js"), []byte("export function onRequest(b) {}\n"), 0o644)
|
||||
if _, err := plugin.Add(context.Background(), dir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
off := func() bool { return plugin.Load().Plugins[0].Off }
|
||||
if _, err := stdoutOf(t, func() error { return pluginCmd([]string{"plugin", "off", "zz-tags"}) }); err != nil || !off() {
|
||||
t.Fatalf("off by short name: err %v, off %v", err, off())
|
||||
}
|
||||
if _, err := stdoutOf(t, func() error { return pluginCmd([]string{"plugin", "on", "zz-tags"}) }); err != nil || off() {
|
||||
t.Fatalf("on by short name: err %v, off %v", err, off())
|
||||
}
|
||||
if _, err := stdoutOf(t, func() error { return pluginCmd([]string{"plugin", "rm", "zz-tags"}) }); err != nil || len(plugin.Load().Plugins) != 0 {
|
||||
t.Fatalf("rm by short name: err %v, left %v", err, plugin.Load().Plugins)
|
||||
}
|
||||
if err := pluginCmd([]string{"plugin", "off", "nothing-here"}); err == nil {
|
||||
t.Error("a name no plugin has was taken")
|
||||
}
|
||||
}
|
||||
@@ -58,6 +58,7 @@ func pluginCmd(args []string) error {
|
||||
if len(rest) != 1 {
|
||||
return errors.New(pluginUsage)
|
||||
}
|
||||
rest[0] = installedName(rest[0])
|
||||
back := provider.MovedOnto(rest[0])
|
||||
if err := provider.RemovePlugin(ctx, rest[0]); err != nil {
|
||||
return err
|
||||
@@ -78,6 +79,7 @@ func pluginCmd(args []string) error {
|
||||
if len(rest) != 1 {
|
||||
return errors.New(pluginUsage)
|
||||
}
|
||||
rest[0] = installedName(rest[0])
|
||||
var back []string
|
||||
if sub == "off" {
|
||||
back = provider.MovedOnto(rest[0])
|
||||
@@ -227,6 +229,25 @@ func listPlugins(ctx context.Context, asJSON bool) error {
|
||||
// pluginOptions prints a plugin's options, or sets them from a JSON
|
||||
// object; off takes them away. With none set, it prints what its
|
||||
// package suggests.
|
||||
// installedName is the package name of the plugin a short name, as the
|
||||
// community's READMEs write it (think-tags for
|
||||
// @magpie-community/middleware-think-tags), stands for; a name a plugin
|
||||
// has itself, or one no plugin has, is kept as it is.
|
||||
func installedName(name string) string {
|
||||
ps := plugin.Load().Plugins
|
||||
for _, x := range ps {
|
||||
if plugin.Name(x.Spec) == name || x.Spec == name {
|
||||
return name
|
||||
}
|
||||
}
|
||||
for _, x := range ps {
|
||||
if plugin.ShortName(plugin.Name(x.Spec)) == name {
|
||||
return plugin.Name(x.Spec)
|
||||
}
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
func pluginOptions(name string, set []string) error {
|
||||
var e *plugin.Entry
|
||||
ps := plugin.Load().Plugins
|
||||
|
||||
Reference in new issue
Block a user