Files
magpie/internal/gui/client_icons_test.go
T
yetone 611ce90d15 agent: OpenBot, magpie's models in its model picker (jiezhengj)
OpenBot (nightly-labs/openbot, openbot.run, v0.58.0) is a new row on the
Agents page. jiezhengj on Discord asked for it: today they type magpie's
address into OpenBot by hand and add each model one at a time.

OpenBot lists the user's own OpenAI-compatible endpoints from
openbot-custom-providers-v1.json in its userData folder:
~/Library/Application Support/OpenBot, %APPDATA%\OpenBot, or
~/.config/OpenBot. Connecting adds an entry with id "magpie" pointing at
the gateway's /v1 and holding the models picked for OpenBot, with
secret null. OpenBot seals an entry's key in safeStorage, which magpie
doesn't open, so the entry has no key. OpenBot hands it to OpenCode
keyless, and the gateway accepts it as a request from this computer.

What the entry keeps to:
- OpenBot's decoders drop the whole list over one bad entry. So the entry
  has at most 64 models, only ids OpenBot accepts as magpie/<id>, and a
  context window only inside 1,024 to 100,000,000.
- The user's other entries stay. The name, harness and secret they give
  magpie's entry in OpenBot stay too.
- A sync with nothing to change doesn't write.
- A file whose version isn't the number 1, or whose providers isn't a
  list, is one OpenBot refuses itself, so magpie leaves it alone.
- Disconnect takes out magpie's entry, and the file too when only the
  version and an empty list are left.

OpenBot reads the file at start, so while it runs, a notice says to
restart it. The notice is in every language.

OpenBot is detected by its userData folder, OpenBot.app
(app.openbot.desktop), or OpenBot.exe under %LOCALAPPDATA%\Programs or
%ProgramFiles%. Docs updated: agent-wiring.md, reference.md, and both
READMEs.

Run at the pushed head, on mote:
- gofmt -l: clean.
- go vet -tags nogui for internal/agent and internal/gui, and for ./...
  with GOOS=linux and GOOS=windows: ok.
- go test -tags nogui -count=1 -timeout 45m on internal/agent and every
  package that imports it (., backup, cli, davsync, gui, library,
  profile, stats, tui, uninstall, plugins/...): ok.
- GUI: agent-notice-lang, i18n-keys, header-relang and about-notices in
  Chromium and WebKit: 58 of 58 pass.

After rebasing on d20caffae (appdir, i18n.js and gui changed on main), these were run again: gofmt; linux and windows vet of agent, gui and appdir; go test of the same three: ok. The four GUI files plus checkin-now-account: 80 of 80 pass.

Real OpenBot 0.58.0: the arm64 zip, sha512 checked against
latest-mac.yml, notarized by Akudama GmbH. It ran on mote under a
sandbox HOME with --user-data-dir and --use-mock-keychain, on a file
that magpie's own openBotWire wrote.
- OpenBot started without setting the file aside.
- Asked over CDP, window.openbot.customProviders.list() returned magpie's
  entry with all three models and harness opencode.
- Saving another endpoint in OpenBot wrote magpie's entry back unchanged.
- The notice's pgrep pattern matched the running OpenBot.

Broken by hand, each red:
- the 64 cap
- the id filter
- the version check
- keeping the user's name, secret and harness
- writing version 1 into a new file
- the notice's Running check

One break stayed green: dropping openBotWire's own no-change check.
edit.SetJSON already skips a write that changes nothing, so the test
holds at that layer.

Not tried:
- a chat through OpenBot to the gateway. OpenBot's onboarding and its
  OpenCode download were not gone through, so no request reached magpie.
- OpenBot's MCP servers. They live in its SQLite database, which magpie
  doesn't write; magpie's /mcp/magpie/... servers are added by hand.
- Windows. Its install folder is read from electron-builder's defaults,
  not from a real install.
- Linux and the AppImage.
- A request from OpenBot is counted under OpenCode's name, since
  OpenCode sends it.
2026-11-02 05:37:32 +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, "openbot": 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)
}
}
}