Files
magpie/internal/gateway/desktop_moved_why_test.go
T
yetone 6b8261029b routing: a request magpie put on another model says why (Neo)
Neo (Discord #feedback, Claude Desktop through the gateway) saw a
Requests row asking chatflowsai/claude-opus-5-5 served by AgentRouter's
gpt-6.1-sol, and read it as Claude asking for another provider's model
on its own. Claude Desktop names its own short requests (a title, its
connection check) on the first Claude-looking id in the list, here
chatflowsai's opus, and magpie keeps them on the chat's model by design
(desktopTurn, 51f66fe8b/13b4a29ab). The routing is right; the row never
said why the model changed.

Changed:
- Route gets Moved {to, why}, set wherever serve puts a request on
  another model before the trace starts: Desktop's tier, title, check,
  gone-model and side-turn moves (desktopMove returns the reason), the
  classifier and Claude tier stand-ins, the stand-in, Codex's turn and
  Privacy's mask route. A subagent's own move clears it (it has its own
  tag).
- Routing's list rows, replay, panel and story tag such a row "Title"
  or "Stand-in" and say why in the tooltip and story. Desktop's
  connection_check kind (da3c5e0c0) already explains itself, so it
  gets no second sentence (movedSays).
- zh, zh-TW, ja, de for the new strings; gateway-routing.md says it.
Not changed: codexFollowTo/codexMaskRoute still show the moved model as
asked.

Run:
- Full Go suite `go test -timeout 45m ./...` on mote at e30092847
  (before the rebase onto cae01311c): 79 ok; the one FAIL is
  internal/gui TestMainWindowCorners/macOS_26_SDK, #3949, same message.
- At 557c4f950 (on cae01311c), on mote: gofmt clean, go vet ./...,
  GOOS=windows go vet ./..., GOOS=linux go vet ./internal/gateway/...
  ./internal/usage/... (a whole-tree Linux vet needs cgo for Wails):
  ok. go test internal/gateway/... and internal/usage/... ok;
  internal/gui's reds are the AppKit windows killed at their deadline
  (#2645, #4125), TestSettingsSaveKeepsWhatItDoesNotSend (#4514) and
  TestColdTurnsTaken (#4510), none of them Routing's.
- Rebased onto b1a1b950f (b52c39b65 changed routing/client.js): this
  head, on mote: gofmt clean, go vet ./internal/..., GOOS=windows go vet
  of gateway and gui, go test ./internal/gateway/... ok. Rebased again
  onto a511b11d8: go vet of gateway and gui, and go test -run
  'Desktop|Moved|Classif|StandIn|Subagent' ./internal/gateway/: ok.
- The full GUI suite at e30092847 was swamped by other sessions' suites
  (4771 browserType.launch 180s timeouts, #4125), so it tests nothing.
  mote's browsers were broken again (#4125), so the 208 GUI files that
  reach Routing or i18n ran on Linux (WSL magpie-desktop) at 557c4f950:
  2921 tests, 2823 pass, 98 fail in 37 files. Those 37 files at
  origin/main b1a1b950f: 76 of 428 red; at this head: 80 of 428, the
  differing ones the same tests in other languages or engines (rule
  drag/remove, rest-try-now, routing-flood, group-morph), filed as
  #4121, #4120, #4471, #2215, #3789, #3094, #2564. i18n-keys' one red
  is #4524 ("Unmarked", on main). At this head routing-moved-why,
  routing-session-title, claude-subagent-tag and i18n-keys: 83 of 84,
  the one is #4524.
- routing-moved-why.test.cjs runs en/zh/zh-TW/ja/de, both engines, at
  1100 and 420 wide.

Broken by hand: with `Moved: moved,` taken out of serve's Route literal,
TestClaudeDesktopMoveSaysWhy is red ("title's route moved <nil>, want
agentrouter/gpt-6.1-sol by desktop-title"); with origin/main's
client.js, routing-moved-why is red (0/2).

Not tried: a real Claude Desktop. Neo's earlier effort high-as-medium
report was not looked at here.
2026-10-31 18:05:17 +08:00

118 lines
5.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package gateway
import (
"encoding/json"
"net/http/httptest"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// Neo on Discord: a Routing › Requests row read "chatflowsai/claude-opus-5-5"
// asked and AgentRouter's gpt-6.1-sol served, with nothing saying why, and
// read as Claude Desktop asking for another provider's model by itself. It
// was Desktop's own short request (a chat's title), which Desktop names by
// the only Claude-looking id it is shown and magpie keeps on the chat's
// model. The trace says so: Route.Moved names the model served and the rule
// that moved it, and a request served as asked has none.
func TestClaudeDesktopMoveSaysWhy(t *testing.T) {
f := &fake{reply: sse(
`event: message_start`+"\n"+`data: {"type":"message_start","message":{"id":"m","type":"message","role":"assistant","model":"m","content":[],"usage":{"input_tokens":1,"output_tokens":0}}}`,
`event: message_stop`+"\n"+`data: {"type":"message_stop"}`)}
up := setup(t, provider.Anthropic, f)
for _, p := range []provider.Provider{
{ID: "agentrouter", Name: "AgentRouter", Key: "k", Anthropic: up.URL, Models: []string{"gpt-6.1-sol"}},
{ID: "chatflowsai", Name: "ChatFlowsAI", Key: "k", Anthropic: up.URL, Models: []string{"claude-opus-5-5"}},
} {
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
}
s := New()
h := s.Handler()
send := func(body string) *Route {
t.Helper()
f.got = nil
req := httptest.NewRequest("POST", "/v1/messages", strings.NewReader(body))
req.Header.Set("x-api-key", Token+"-claude-desktop")
rec := httptest.NewRecorder()
h.ServeHTTP(rec, req)
if rec.Code != 200 {
t.Fatalf("%d %s", rec.Code, rec.Body)
}
s.trace.mu.Lock()
defer s.trace.mu.Unlock()
return s.trace.routes[len(s.trace.routes)-1]
}
// the chat turn, on AgentRouter's GPT: served as asked, nothing moved
r := send(`{"model":"agentrouter/gpt-6.1-sol","max_tokens":32000,"stream":true,"tools":[{"name":"Bash","input_schema":{"type":"object"}}],"messages":[{"role":"user","content":"hi"}]}`)
if r.Moved != nil {
t.Fatalf("a turn served as asked says moved: %+v", r.Moved)
}
// Desktop's title, on the opus it picks by itself: served on the chat's
// model, and the row says so
r = send(`{"model":"chatflowsai/claude-opus-5-5","max_tokens":200,"stream":true,"system":"You write short session titles.","messages":[{"role":"user","content":"hi"}]}`)
if got := modelOf(f.got); got != "gpt-6.1-sol" {
t.Fatalf("title sent %q", got)
}
if r.Moved == nil || r.Moved.To != "agentrouter/gpt-6.1-sol" || r.Moved.Why != movedTitle {
t.Fatalf("title's route moved %+v, want agentrouter/gpt-6.1-sol by %s", r.Moved, movedTitle)
}
b, _ := json.Marshal(r)
if !strings.Contains(string(b), `"moved":{"to":"agentrouter/gpt-6.1-sol","why":"desktop-title"}`) {
t.Fatalf("history JSON: %s", b)
}
// Desktop's connection check on that opus: served elsewhere, and says so
r = send(`{"model":"chatflowsai/claude-opus-5-5","max_tokens":1,"messages":[{"role":"user","content":"."}]}`)
if r.Moved == nil || (r.Moved.Why != movedCheck && r.Moved.Why != movedCheckFirst) || r.Moved.To == "chatflowsai/claude-opus-5-5" {
t.Fatalf("check's route moved %+v", r.Moved)
}
// a turn on the opus itself is as asked
r = send(`{"model":"chatflowsai/claude-opus-5-5","max_tokens":32000,"stream":true,"tools":[{"name":"Bash","input_schema":{"type":"object"}}],"messages":[{"role":"user","content":"hi"}]}`)
if r.Moved != nil {
t.Fatalf("a turn on opus says moved: %+v", r.Moved)
}
}
// each way desktopMove takes a model elsewhere names its rule, and a
// request it leaves alone names none
func TestDesktopMoveReasons(t *testing.T) {
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
t.Setenv("XDG_CACHE_HOME", t.TempDir())
desktopPicked.Lock()
desktopPicked.model, desktopPicked.from = "", ""
desktopPicked.Unlock()
for _, p := range []provider.Provider{
{ID: "agentrouter", Name: "AgentRouter", Key: "k", Anthropic: "http://127.0.0.1:1", Models: []string{"gpt-6.1-sol"}},
{ID: "chatflowsai", Name: "ChatFlowsAI", Key: "k", Anthropic: "http://127.0.0.1:1", Models: []string{"claude-opus-5-5"}},
} {
if err := provider.Save(p); err != nil {
t.Fatal(err)
}
}
turn := []byte(`{"max_tokens":32000,"tools":[{"name":"Bash"}],"messages":[{"role":"user","content":"hi"}]}`)
title := []byte(`{"max_tokens":200,"system":"You write short session titles.","messages":[{"role":"user","content":"hi"}]}`)
// no turn yet: a title goes to the first model listed
if to, why := desktopMove("chatflowsai/claude-opus-5-5", title, false, false); why != movedTitleFirst && (why != "" || to != "chatflowsai/claude-opus-5-5") {
t.Errorf("first title: %q by %q", to, why)
}
if to, why := desktopMove("agentrouter/gpt-6.1-sol", turn, false, false); to != "agentrouter/gpt-6.1-sol" || why != "" {
t.Fatalf("turn: %q by %q", to, why)
}
if to, why := desktopMove("chatflowsai/claude-opus-5-5", title, false, false); to != "agentrouter/gpt-6.1-sol" || why != movedTitle {
t.Errorf("title: %q by %q", to, why)
}
if to, why := desktopMove("claude-haiku-4-5-20251001", turn, false, false); to != "agentrouter/gpt-6.1-sol" || why != movedGone {
t.Errorf("unserved: %q by %q", to, why)
}
if to, why := desktopMove("claude-haiku-5-5", title, true, false); to != "agentrouter/gpt-6.1-sol" || why == "" {
t.Errorf("Claude Code's haiku: %q by %q", to, why)
}
if to, why := desktopMove("chatflowsai/claude-opus-5-5", turn, false, false); to != "chatflowsai/claude-opus-5-5" || why != "" {
t.Errorf("opus turn: %q by %q", to, why)
}
}