Files
magpie/internal/gui/client_icons_test.go
T
yetone 93a33d8174 agent: OpenBot's icon, its requests named its own, its skills in the Library (SSNQT on X)
SSNQT on X, magpie 0.1.3503 on macOS, OpenBot (611ce90d1): no icon in
the Agents list, its requests listed as OpenCode's, and no way to pick
it for skills or MCP servers in the Library.

- Icon: OpenBot's production icon (build/icon-production.png in
  nightly-labs/openbot, 128px) as icons/openbot.png, in pngIcons and in
  app.css's tile rule (a solid tile, icon-tile.test.cjs); openbot is off
  client_icons_test's generic list.
- Requests: OpenBot seals an endpoint's key and headers in safeStorage,
  which magpie can't write, and hands the endpoint to the OpenCode it
  runs, so every request came with OpenCode's User-Agent and nothing of
  OpenBot's. magpie's entry is now at <gateway>/agent/openbot/v1
  (gateway.AgentURL). lanGuard takes /agent/<id> off the path when <id>
  is an agent magpie knows (takeAgentPath), agentOf names that agent
  first, and startedByAgent never takes such a request for a script. An
  unknown id is left in the path (404 as before). An entry written at
  /v1 is rewritten at the next sync; OpenBot reads it after a restart,
  which its notice already says. Requests recorded before stay
  OpenCode's.
- Library: an openbot target with skills in ~/.agents/skills, the only
  folder OpenBot reads (home-skills.ts, HOME_SKILL_FOLDER). Its MCP
  servers are rows in its SQLite database (openbot.db,
  projection_mcp_servers), which magpie doesn't write, so it stays out
  of the MCP picker: #5896.
- Guard: TestEveryAgentInLibrary fails for a built-in agent that has no
  Library target and isn't in noLibrary with a reason. 34 agents had
  none when it landed; they are listed as "not looked at (#5897)". The
  icon guard (TestEveryClientHasNameAndIcon) and the agent-name guard
  (TestIsAgentByUserAgent) were there already.

Run (mote unless said): gofmt -l internal (clean); go vet darwin, GOOS=linux
-tags nogui, GOOS=windows on agent, gateway, library, gui: ok;
go test -count=1 ./internal/agent ./internal/gateway ./internal/library
./internal/gui ./internal/usage: all ok but internal/gui's
TestUpdateSlowDownloadOutlastsTheCheckBound (its check request hit its
deadline with four other suites on the box; passes 3 of 3 alone; the
updater isn't touched here; #5905); TestAgentInPath and
TestEveryAgentInLibrary on Windows (win-run): ok; GUI i18n-keys,
icon-tile, icon-one-tone, icon-builtin-over-address,
routing-client-icons, library-pick-remove: chromium 101/101, webkit
54/54. Real gateway (nogui build, sandbox HOME, port 3591): a POST to
/agent/openbot/v1/chat/completions with OpenCode's User-Agent was
recorded as agent openbot, the same at /v1 as opencode, and
/agent/openbot/v1/models answered the list.

Broken by hand, each red: the takeAgentPath call in lanGuard taken out
(TestAgentInPath: path kept, agent opencode); the pathAgent check in
agentOf taken out (agent opencode); the openbot case in targetOf renamed
(TestEveryAgentInLibrary: openbot has no place); Icon back to generic
(TestEveryClientHasNameAndIcon).

Not tried: real OpenBot or a real OpenCode sending to the new address
(the URL is built as `${baseURL}/chat/completions` by
@ai-sdk/openai-compatible, read in its source); the full suite (runs
after the tag).
2026-11-10 15:56:21 +08:00

78 lines
2.8 KiB
Go

package gui
import (
"os"
"regexp"
"strings"
"testing"
"github.com/yetone/magpie/internal/agent"
"github.com/yetone/magpie/internal/gateway"
)
// genericIcon are the clients magpie has no logo for yet, drawn with the
// generic cube on purpose (#4487). Each leaves this list when its real
// logo, from the app or its vendor, is added.
var genericIcon = map[string]bool{"ante": true, "pencil": true, "openpencil": true, "newmax": true, "kirocrew": true, "raft": true}
// Every client a request can be recorded as is drawn by its own name and
// icon in the Routing page's request list, Usage and Sessions, which all
// look the request's client up in /api/state's clients (agent.Clients):
// one not there shows its raw id and the cube (jiabubu on Discord:
// kimi-code-cli and kimi-code-desktop). This holds the table to the ids
// the gateway records, and each entry's icon to a file app.js's icon()
// loads: a PNG only when pngIcons names it, else an SVG.
func TestEveryClientHasNameAndIcon(t *testing.T) {
js, err := os.ReadFile("assets/app.js")
if err != nil {
t.Fatal(err)
}
m := regexp.MustCompile(`const pngIcons = new Set\(\[([^\]]*)\]\)`).FindSubmatch(js)
if m == nil {
t.Fatal("app.js's pngIcons isn't found")
}
png := map[string]bool{}
for _, q := range regexp.MustCompile(`"([^"]+)"`).FindAllSubmatch(m[1], -1) {
png[string(q[1])] = true
}
exists := func(f string) bool { _, err := os.Stat("assets/icons/" + f); return err == nil }
clients := map[string]bool{}
for _, a := range agent.Clients() {
clients[a.ID] = true
if strings.TrimSpace(a.Name) == "" {
t.Errorf("%s has no name", a.ID)
}
switch {
case a.Icon == "generic":
if !genericIcon[a.ID] {
t.Errorf("%s is drawn with the generic cube: give it its real logo", a.ID)
}
case a.Icon == "" || strings.HasPrefix(a.Icon, "file:") || strings.ContainsAny(a.Icon, ":/"):
t.Errorf("%s's icon %q isn't one of magpie's", a.ID, a.Icon)
case png[a.Icon]:
if !exists(a.Icon + ".png") {
t.Errorf("%s's icon: pngIcons names %s, with no icons/%[2]s.png", a.ID, a.Icon)
}
case !exists(a.Icon + ".svg"):
if exists(a.Icon + ".png") {
t.Errorf("%s's icon %s is a PNG app.js's pngIcons doesn't name, so it is drawn as the cube", a.ID, a.Icon)
} else {
t.Errorf("%s's icon %s has no file in icons/", a.ID, a.Icon)
}
}
}
for id := range genericIcon {
if !clients[id] {
t.Errorf("genericIcon names %s, which is no client", id)
}
}
// the ids the gateway gives a request by more than its User-Agent
// (gateway.agentOf), and those it names by one: each is a client
for _, id := range []string{"claude-desktop", gateway.ScienceID, "cursor-local", "codex", "magpie", "kimi", "kimi-code-desktop"} {
if !clients[id] {
t.Errorf("the gateway records requests as %s, which isn't among the clients", id)
}
}
}