Files
magpie/internal/gui/plugins_agents_test.go
T
yetone e8e9245ecf agents: Install another agent says Plugins has more agents, and opens them
The owner, on the Agents page: 因为我们支持Agent插件了,这里是不是也应该
显示插件中有更多? Install another agent listed only the agents magpie has
an install command for; the agents a plugin adds were nowhere on that page.

- GET /api/plugins/agents names the suggested agent plugins (the market's
  kind "agent") not installed here. One installed but turned off, or
  pinned to a version, counts as installed: Plugins turns it on.
- Install another agent counts them in its header and ends with one row,
  "More in Plugins" with their names, as the Providers add sheet does for
  subscriptions. The row opens Plugins › Discover scrolled to its Agents,
  only while the click is fresh (scrollOnPurpose), on the section drawn
  last, since npm's answers draw it again.
- The list is fetched beside the install commands, not before them, so a
  slow market never holds the commands back. With no install command left,
  the section shows the plugins' row alone and no install note.
- Budgets: app.js 1,311,681 and the core 1,530,449 (+1,430 / +2,408 over main),
  the Agents page and Plugins page are the core's own, no room added.

Run at this tree, rebased on e2efbd357 (on mote):
- go test -tags nogui ./internal/gui -count=1: ok (budgets included);
  GOOS=linux and GOOS=windows go vet ./internal/gui: ok; gofmt -l: none.
- TestPluginAgentsNotInstalled: a fake registry with every kind, installed,
  turned-off and pinned agents; all installed gives [], never null.
- agent-plugin-agents.test.cjs: chromium and webkit, en zh zh-TW ja de,
  1100 and 420px: count, row order, words, tooltip, one line, name not cut,
  no sideways scroll, the click landing Agents at the top and staying.
- 69 GUI files that reach this (install section, Plugins Discover, strict
  fixtures, i18n), 1044 tests: 1033 pass. The reds were i18n-keys' #4053
  (fixed in the next commit) and mobile-web, whose copy had no .git for
  origin/main; run again with one fetched (d4f1d64): 30/30.

Broken by hand: main's assets under the new GUI test, 11/11 red; the
scroll line taken out, 11/11 red (webkit); the Go installed filter taken
out, TestPluginAgentsNotInstalled red.

Not run: the whole GUI suite (mote was busy with other sessions' suites),
and the real app with the live market.
2026-10-28 22:34:52 +08:00

73 lines
2.8 KiB
Go

package gui
import (
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"slices"
"testing"
"github.com/yetone/magpie/internal/plugin"
"github.com/yetone/magpie/internal/settings"
)
// The Agents page's Install another agent says Plugins has more agents
// (the owner: 因为我们支持Agent插件了,这里是不是也应该显示插件中有更多?):
// /api/plugins/agents names the agents a suggested plugin adds, leaving
// out every other kind and one installed here, turned off or pinned to a
// version too.
func TestPluginAgentsNotInstalled(t *testing.T) {
t.Setenv("XDG_CACHE_HOME", t.TempDir())
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(`{"version":1,"plugins":[
{"package":"@magpie-community/opencode-x-auth","name":"X","community":true},
{"package":"@magpie-community/middleware-guard","name":"Guard","kind":"middleware","community":true},
{"package":"@magpie-community/agent-kilo","name":"Kilo Code","kind":"agent","community":true},
{"package":"@magpie-community/agent-aider","name":"Aider","kind":"agent","community":true},
{"package":"@magpie-community/agent-pig","name":"PiG","kind":"agent","community":true},
{"package":"@magpie-community/agent-bub","name":"Bub","kind":"agent","community":true},
{"package":"agent-elsewhere","name":"Elsewhere","kind":"agent"}
]}`))
}))
defer srv.Close()
t.Setenv("MAGPIE_PLUGIN_MARKET", srv.URL)
plugin.RefreshMarket()
t.Cleanup(plugin.RefreshMarket)
dir := settings.Dir()
if err := os.MkdirAll(dir, 0o755); err != nil {
t.Fatal(err)
}
installed := `{"plugins":[{"spec":"@magpie-community/agent-aider@0.1.3"},{"spec":"@magpie-community/agent-bub","off":true}]}`
if err := os.WriteFile(filepath.Join(dir, "plugins.json"), []byte(installed), 0o644); err != nil {
t.Fatal(err)
}
mux := http.NewServeMux()
pluginRoutes(mux, nil)
rec := httptest.NewRecorder()
mux.ServeHTTP(rec, httptest.NewRequest("GET", "/api/plugins/agents", nil))
if rec.Code != 200 {
t.Fatalf("%d %s", rec.Code, rec.Body)
}
var got []string
if err := json.Unmarshal(rec.Body.Bytes(), &got); err != nil {
t.Fatal(err)
}
if want := []string{"Kilo Code", "PiG"}; !slices.Equal(got, want) {
t.Errorf("got %q, want %q", got, want)
}
// every one installed: the page gets an empty list, never null
if err := os.WriteFile(filepath.Join(dir, "plugins.json"), []byte(`{"plugins":[{"spec":"@magpie-community/agent-kilo"},{"spec":"@magpie-community/agent-aider"},{"spec":"@magpie-community/agent-pig"},{"spec":"@magpie-community/agent-bub"}]}`), 0o644); err != nil {
t.Fatal(err)
}
rec = httptest.NewRecorder()
mux.ServeHTTP(rec, httptest.NewRequest("GET", "/api/plugins/agents", nil))
if body := rec.Body.String(); body != "[]\n" && body != "[]" {
t.Errorf("all installed: %q, want []", body)
}
}