Files
magpie/internal/gui/client_icons_test.go
T
yetone fa5e86cf2b agents: Kimi Code and Kimi Code Desktop requests show their own name and icon, not the raw id and the cube (jiabubu)
jiabubu on Discord (magpie 0.1.2245, Windows, Kimi Code 2.4.1, Kimi Code
Desktop 1.2.1.0): the Routing page's request list drew Kimi Code's
requests as the grey cube and "kimi-code-cli", and Kimi Code Desktop's as
the cube and "kimi-code-desktop".

The request list, Usage and Sessions already take a client's name and
icon from one table, /api/state's clients (agent.Clients). The drift was
in usage.AgentOf: Kimi Code 2.x sends "kimi-code-cli/…", which matched
neither the kimi agent's "kimicli" prefix nor its "kimi-code" alias, and
Kimi Code Desktop ("kimi-code-desktop/…", its bundle's clientName) had
no entry at all, so both kept their raw product names.

- kimi's UA list takes kimi-code-cli.
- Kimi Code Desktop is a client of its own (agents.go's others). It runs
  Kimi Code's engine on ~/.kimi-code, so it is set up through Kimi
  Code's row. Its icon is the app's own: the 128px entry of build/icon.ico
  in KimiCode-1.2.1-win-x64.exe, the installer winget's
  MoonshotAI.KimiCodeDesktop 1.2.1 points to on code.kimi.com (sha256
  75111cb6…c312, as the manifest says). Nothing was drawn by hand.
- app.js's pngIcons names it (comment shortened, app.js 5 bytes smaller,
  budget untouched); app.css's tile rule names it, as icon-tile measures
  it solid to its edges.
- Old records re-resolve through AgentOf, so earlier kimi-code-cli
  requests read as Kimi Code too.

Guard: TestEveryClientHasNameAndIcon checks that every client has a
name and an icon file app.js's icon() really loads (a PNG only if
pngIcons names it), and that the ids the gateway records by more than a
User-Agent (claude-desktop, claude-science, cursor-local, codex, magpie)
and kimi / kimi-code-desktop are all clients. The cube is allowed only
for the six clients with no logo yet (ante, pencil, openpencil, newmax,
kirocrew, raft), filed as #4487. routing-client-icons.test.cjs draws the
request list from a history fixture and checks names, data-icon, and that
the desktop PNG loads.

Run (mote unless said):
- Red on the old code: TestAgentOf (got "kimi-code-cli" want "kimi"),
  TestEveryClientHasNameAndIcon (kimi-code-desktop not among the
  clients); routing-client-icons in Chromium on the old app.js
  (0/2, the desktop row is the cube).
- Broken by hand: pngIcons without the entry makes the guard fail ("a PNG
  app.js's pngIcons doesn't name, so it is drawn as the cube").
- go test ./internal/agent ./internal/usage ./internal/usageapi: ok.
  ./internal/gui: ok except the ten real-window AppKit tests killed at
  their deadline on mote (#4125, #2645). ok with those skipped, after
  the rebase.
- go vet (darwin), GOOS=linux -tags nogui and GOOS=windows vet of
  internal/agent and internal/gui: ok. gofmt -l: nothing.
- routing-client-icons: Chromium 2/2 on mote, WebKit 2/2 on Linux
  (wsl-run; WebKit launch hangs on mote, #4125).
- routing-*, i18n-keys, icon-tile, mono-icon-redraw and
  models-add-and-icons in Chromium on mote and WebKit on Linux: i18n-keys
  green. icon-tile caught the missing tile entry (fixed here). The other
  Routing reds are still being compared against a fresh origin/main copy
  in both engines (running at push time). Any that turns out to be ours
  gets a follow-up commit.

Not tried: a real Kimi Code 2.4.1 or Kimi Code Desktop 1.2.1 against
magpie (the UA strings come from their bundles: appName kimi-code-cli,
clientName kimi-code-desktop). Only the Windows installer's icon was
read; the macOS app's wasn't compared. Full Go suite to follow the tag.
2026-10-31 04:12:17 +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)
}
}
}