Files
magpie/internal/agent/spelled_test.go
T
yetone 5e3f14f21f agent: Paimon, magpie's models through its litellm provider (ditangongyuan on X)
Paimon (aisk/paimon, `uv tool install paimon`) is a terminal coding agent
on pydantic-ai. Read at 7f7fa51 (config.py, llm.py): its settings are one
JSON file, $PAIMON_CONFIG_HOME/config.json, else ~/.config/paimon/config.json
on every OS. "model" is provider:name, and "providers" keeps each
provider's api_base and api_key.

magpie connects it through pydantic-ai's litellm provider, an
OpenAI-compatible proxy that profiles a vendor/model name by its vendor,
as magpie's ids are spelled, and which Paimon's login never offers:
model = litellm:<catalog id>, providers.litellm = the gateway's /v1 and
magpie's key for Paimon (0600, as Paimon writes it), and
compaction.context_window = the model's window. Paimon compacts against
that only for names genai-prices doesn't know, which magpie's ids aren't;
for a model whose window magpie doesn't know it gets the user's own back,
never the last model's. What the user had in the three keys is stashed and
put back on Disconnect (or `magpie paimon default`); the rest of the file
is untouched, and a file magpie made goes again. A model picked in Paimon
itself while magpie's provider stays is the user's from then on. Requests
are told apart by Paimon's paimon/<version> User-Agent. WSL distros, the
PAIMON_CONFIG_HOME isolation, notices in every language, icon, READMEs,
docs/reference.md, agent-wiring.md and the site's list come with it.

Run:
mote refused SSH all session (kex reset), so the Linux runs went
through wsl-run (magpie-desktop) and Windows through win-run:
- go vet: linux -tags nogui, GOOS=windows, GOOS=darwin -tags nogui on
  internal/agent, agentenv, library: ok. gofmt -l: clean.
- go test -tags nogui ./internal/agent/... agentenv library gui cli (WSL,
  base f03ec97b8): all ok except TestGrokInstalled, the known WSL binfmt
  red #3548.
- Windows: TestPaimon, TestHandWired*, TestEveryNoticeIsTranslated,
  TestPortMovesEveryAgent ok (file-mode checks skipped there).
- GUI, chromium + webkit (WSL): i18n-keys, i18n-en-no-cjk,
  agent-notice-lang, gui-de, gui-ja, gui-zh-tw, icon-one-tone, icon-tile,
  mono-icon-redraw, routing-client-icons, usage-agent-filter-icons,
  agent-connect(-no-models), agent-models(-own, -picker), agent-layout:
  150/151; the red is gui-ja's usage price string, untouched here, filed
  as #5943.
- Real Paimon 0.2.8 (uv pip install paimon) in a sandbox HOME on WSL,
  against a sandbox magpie gateway over a fake OpenAI upstream:
  `magpie paimon magpie/fakeup/m1` wrote litellm:fakeup/m1 and
  providers.litellm at 0600; `paimon -p ping` answered "pong from fake
  upstream", the upstream saw POST /v1/chat/completions with
  "paimon/0.2.8 (Python 3.10.19; Linux x86_64)", and magpie usage counted
  the call under Paimon; `magpie paimon default` put the file back equal
  to the user's.
- After the rebase on origin/main 9c39edb92: the three vets, the targeted
  agent tests and internal/gui ok; internal/library's
  TestEveryAgentInLibrary red for avibe from 9c39edb92 (#5945, not this
  change); i18n-keys, i18n-en-no-cjk, agent-notice-lang, gui-de, gui-zh-tw
  ok; icon-one-tone's every-logo case ok in both engines, its webkit
  Plugins-page case timed out on page.goto's 5s at WSL load 92 (#5425).

Broken by hand, each red in TestPaimon:
- the user's window not put back for a model magpie doesn't know (switch
  window: <nil>);
- stashing again while providers.litellm is magpie's (switch window: 200000);
- a file magpie made not removed (made file left: {});
- a model picked in Paimon not kept as the user's (restore after a pick).

Not tried: macOS (mote unreachable) and the GUI's own Connect click with
the real binary; Paimon's auto-compaction at a window magpie wrote (the
fake model had none, so Paimon said compaction was off, as it does for any
name it doesn't know); a model picked in Paimon's own /model while
connected beyond the unit test.
2026-11-10 19:54:37 +08:00

96 lines
3.5 KiB
Go

package agent
import (
"path/filepath"
"testing"
)
// An agent that spells a model provider/model, magpie's as magpie/<ref>:
// one of its own providers named as one of magpie's (its own relay, and
// magpie's relay) is its own model, not magpie's. The row isn't connected
// on it, and Disconnect from magpie puts it back and is done, rather than
// leaving the row connected on the model it went back to (#835, OpenHanako's
// own deepseek/deepseek-v4-pro).
func TestOwnProviderNamedAsMagpies(t *testing.T) {
ids := []string{"agy", "opencode", "openchamber", "mimocode", "deveco", "pi", "aside", "omo", "prime-agent", "mu", "goose", "zed", "vscode",
"crush", "dsh", "ds-bot", "commandcode", "fx", "omp", "hermes", "morph", "kimi", "empryo", "nanobot", "miniq", "paimon", "craft-agents", "minimax-code", "droid",
"qoder", "qoder-cn", "grok", "atomcode", "cline", "snow", "qwenpaw"}
for _, id := range ids {
t.Run(id, func(t *testing.T) {
if id == "aside" {
asideHome(t)
} else if home := syncHome(t); id == "qwenpaw" {
qwenpawFixture(t, home)
}
a, err := Find(id)
if err != nil {
t.Fatal(err)
}
f := &a.Fields[0]
if id == "miniq" {
// a provider of the user's own, for its own model to be on
hanakoWrite(t, a.Path, `{"provider":{"baseUrl":"https://relay.example/v1","apiKey":"sk-own","model":"glm-4.5","apiProtocol":"auto"}}`, 0o600)
}
if id == "craft-agents" {
// Craft's own config, with a connection of the user's
hanakoWrite(t, a.Path, craftUser, 0o644)
}
if id == "cline" {
// a model of OpenRouter's, the provider Cline is on
hanakoWrite(t, a.Path, `{"version":1,"modes":{},"providers":{},"lastUsedProvider":"openrouter"}`, 0o600)
}
if err := f.Set("relay/glm-4.6"); err != nil {
t.Fatal(err)
}
if v := f.Get(); v != "relay/glm-4.6" {
t.Fatalf("own model reads %q", v)
}
if a.Wired() {
t.Fatal("its own relay/glm-4.6 reads as magpie's")
}
if err := a.Connect(); err != nil {
t.Fatal(err)
}
if !a.Wired() {
t.Fatalf("not connected after Connect: %v", a.Values())
}
if err := a.Disconnect(); err != nil {
t.Fatal(err)
}
if a.Wired() {
t.Fatalf("still connected after Disconnect: %v", a.Values())
}
if v := f.Get(); v != "relay/glm-4.6" {
t.Errorf("Disconnect left %q, not its own relay/glm-4.6", v)
}
})
}
}
// OpenCode's own provider that sends to magpie's gateway is magpie's all
// the same (openCodeRef names a model there by it), once magpie set
// OpenCode up: before that, it is a provider the user wrote by hand and
// theirs (handWired, JFunfunfun on X).
func TestOpenCodeGatewayProviderIsMagpies(t *testing.T) {
syncHome(t)
a, err := Find("opencode")
if err != nil {
t.Fatal(err)
}
hanakoWrite(t, a.Path, `{"provider":{"relay":{"options":{"baseURL":"`+gatewayV1()+`"},"models":{"relay/glm-4.6":{}}}},"model":"relay/relay/glm-4.6"}`, 0o644)
if a.Wired() {
t.Fatalf("its own provider at the gateway, written by hand, reads as connected: %v", a.Values())
}
// as magpie opencode relay/glm-4.6 sets it (9b1641a49)
if err := a.Apply("model", "relay/relay/glm-4.6"); err != nil {
t.Fatal(err)
}
if !a.Wired() {
t.Fatalf("a model through its own provider at the gateway isn't magpie's: %v (%s)", a.Values(), filepath.Base(a.Path))
}
hanakoWrite(t, a.Path, `{"provider":{"relay":{"options":{"baseURL":"https://x/v1"},"models":{"glm-4.6":{}}}},"model":"relay/glm-4.6"}`, 0o644)
if a.Wired() {
t.Fatalf("its own relay elsewhere reads as magpie's: %v", a.Values())
}
}