Files
magpie/internal/cli/provider_routing_cli_test.go
T
yetone c01988e439 routing: a group's Small context first sends a request to the smallest window that holds it
yg6888 on X (tweet 2123308968848379920): in a group routed Smart, Cursor
Plus's Composer and Grok 4.7 were never used. Not a bug: Smart orders by
allowance tier, then soonest renewal, then listed order, and never weighs
the context window, so the 1M members listed ahead always answered. The
small ones were only ever reached as a fallback.

Smart itself is unchanged; changing its order would move every Smart
user's traffic. A group gets a new routing instead, `fit` (Small context
first; 小上下文优先, 小上下文優先, 小さいコンテキスト優先, Kleiner
Kontext zuerst):

- routes.SmallFirst takes Smart's order and sorts it stably by band (a
  provider set to be used first, the rest with room, the all but used up)
  and then by window, the smaller known first, an unknown one last.
- Its strategy sets ByWindow, so weighRouted fills Seat.Window from
  windowIn (the provider's own Contexts, else the catalog's).
- roomy already leaves out every member the request is estimated past, so
  the first left is the smallest that holds it: a small model is never
  asked for a request too long for it, and keeps its last-resort place as
  under every routing.
- The trace's rows carry `context`; the Routing page says "its 200K
  context window is the smallest that holds this request".
- A group's only: provider.normalize already drops it from a provider and
  the CLI refuses it there. GUI menu, hint, why-lines, TUI and CLI
  (`routing=fit`, small-first) carry it; docs/reference.md, the
  gateway-routing and plugin-runtime pages and the en/zh/ja start pages
  say it, with the search index rebuilt (via docs-index.mjs; #7065).

Run first at the tree rebased on origin/main 6e5882109, then at this
head's (on 856423806; search index rebuilt; gateway/routes vet, routes, rotation, ./internal/gui,
the gateway's new tests and routing-small-first, routing-group-strategy
and i18n-keys 42/42 again), mote over its
cores with another session's full suite on it and mica's disk full, so on
the Linux box (wsl-run) and the Windows box:
- go test -tags nogui ./internal/routes ./internal/cli ./internal/tui
  ./plugins/rotation ./internal/gateway -count=1 -timeout 45m: all ok but
  gateway, whose one red was this commit's own new test asserting a single
  group while an auto group for the shared model exists; fixed (FindGroup
  "group/g") and the window/strategy tests rerun ok, both new ones pass.
  ./internal/provider ok (its only FAIL was the stale search index, since
  rebuilt). ./internal/gui -run Budget ok.
- Broken by hand: SmallFirst returning Smart's order makes
  TestSmallFirstOrdersByWindow and the gateway test red ("a short request
  went to big first"); dropping fit from SaveGroup's whitelist makes the
  gateway test red ("the group didn't keep Small context first").
- GUI (Chromium + WebKit, en zh zh-TW ja de): routing-small-first,
  routing-group-strategy, i18n-keys, routing-cheapest-first,
  routing-free-expiring 112/112 before and after the rebase;
  every routing*, group* and builtins* file (253): 4139 of 4198, the 59
  reds in 11 files that fail the same at origin/main 239da9991 run alone
  (57; routing-many-keys moves between languages each run), all filed:
  #7016, #7097, #6520, #5049, #6512, #4711, #3954, #3799, #4082.
- Windows: CGO_ENABLED=0 go vet -tags nogui ./internal/... ./plugins/...
  ok. gofmt -l clean.

Not tried: the full `go test ./...` and darwin vet (mote busy, mica out
of disk); a real Cursor/Grok account in a group (the window comes from
the same windowIn roomy already trusts). Seen on the way: a recovered
"close of closed channel" in continuation_test.go's doneHold fake, no
test failed from it.
2026-11-19 17:34:30 +08:00

27 lines
993 B
Go

package cli
import (
"testing"
"github.com/yetone/magpie/internal/provider"
)
// routing= on a provider spreads requests over its keys or accounts as
// the editor's Routing does: fast (fastest, speed) is Speed first; manual,
// cheapest, expiring and fit are a group's alone, and a name magpie
// doesn't know is refused.
func TestProviderRoutingPair(t *testing.T) {
var p provider.Provider
for in, want := range map[string]string{"fast": provider.Fastest, "fastest": provider.Fastest, "Speed": provider.Fastest, "order": provider.Ordered, "smart": ""} {
if err := applyPairs(&p, []string{"routing=" + in}); err != nil || p.Routing != want {
t.Errorf("routing=%s: %q %v, want %q", in, p.Routing, err, want)
}
}
p.Routing = provider.Fastest
for _, bad := range []string{"manual", "cheapest", "expiring", "fit"} {
if err := applyPairs(&p, []string{"routing=" + bad}); err == nil || p.Routing != provider.Fastest {
t.Errorf("routing=%s taken: %q", bad, p.Routing)
}
}
}