Files
magpie/internal/cli/groups_account_cli_test.go
T
yetone 65f93ac27d routing: a group's member may be pinned to one account, tried in the group's order (EastonXvii on X)
EastonXvii asked for a group like Codex/Astra on account A, then Astra
on B, then Sol on C, tried strictly in that order, with the same model on
two accounts as two members. Before this, Group.Accounts held the whole
group to a set of accounts with no order among one provider's accounts,
so the only way was one group per account.

A member id may now end with the account: provider/model[:effort][:fast]#<account>
(provider.MemberAccount, groupaccount.go).
- Every list keyed by a member's spelling (rules, Fast, Off, Weights,
  Placed, EffortMaps, Pick) and membersFound's dedup key include it, so
  the same model on two accounts is two members. The vendor is still
  asked for the model's own id. A group saved before has no "#" and
  reads as it did.
- SaveGroup stores the account's stable id (a typed name is resolved by
  ResolveAccount). It refuses an account on group/ and auto/ members,
  and a new account magpie doesn't have. One the stored group had
  already that is gone since stays, matching nothing.
- Gateway: planLevel's keys() leaves the provider's other accounts out
  for such a member (memberHeld; Held rows with HeldOwn in the trace).
  Fallback goes to the next member, never to another account under the
  same member. count_tokens counts on the resolved member's account
  (heldByGroupAt). Images and videos: drawingTries keeps one try per
  member account, and each try runs on a request held to that account
  (memberOn).
- Sharing and importing a group drop members' accounts.
- GUI: Routing → edit a group → each model row has an account chip
  (openPicker menu): "Any account", each account, and "Also on another
  account…", which adds the model on a free account as a member of its
  own after the row. Strings in en, zh, zh-TW, ja, de.
- CLI: models=relay/m#B,relay/m#A,other/m (by name or id); show prints
  "on <name> alone". TUI effort cycling keeps the account.

Run (mote, at the pushed head after rebasing on 40d39e117):
- gofmt clean. go vet passes for darwin, linux -tags nogui and windows.
- go test for internal/provider, internal/cli, internal/tui and
  internal/gui (full packages, so the budgets are included), and
  internal/gateway -run Group|Draw|Image|Video|Held|Count|Trace.
- GUI: group-member-account.test.cjs (5 languages x 420/1100px x
  chromium/webkit, plus "reasoning set on a member keeps its account"),
  i18n-keys, i18n-en-no-cjk, and every routing/group test file (114
  files): 578 passed.
  - Red: menu-input-scroll, 4 of 4, also red on base 5c47d59b5 (#3402,
    commented).
  - Red: mobile-web's "desktop matches origin/main", which needs
    `git show origin/main`, and a mote-run copy has no .git.
- Real run with a sandbox HOME on mote, built with -tags nogui. A fake
  upstream logged each key. Provider relay has keys A (first) and B,
  and other has key C. `magpie group add Chain
  models=relay/astra#B,relay/astra#A,other/sol routing=order`, then
  `magpie serve`, then a chat to group/chain. Results:
  - nothing refused → B;
  - B refused → B, A;
  - B and A refused → B, A, C (sol on other).
  B came first, though A is the provider's first key.

Broken by hand (each went red):
- memberHeld returning "": InOrder and NeverSpills;
- membersFound's key without the account: InOrder and Saved;
- the CLI's #account resolve turned off: TestGroupMembersOnAccounts;
- the drawing loop on r instead of memberOn: Draw asked sk-mine;
- drawingTries' key without the account: Draw never reached the second
  member.
- count_tokens spent the other key before heldByGroupAt narrowed it.

Not tried: a video group with real vendors (the path is the same as
drawing's, through drawingTries and memberOn, with no test of its own).
Not tried with real Codex accounts; the e2e used API-key accounts. Not
tried on the Linux and Windows apps.
2026-11-10 08:38:12 +08:00

43 lines
1.3 KiB
Go

package cli
import (
"slices"
"strings"
"testing"
"github.com/yetone/magpie/internal/provider"
)
// A member typed on an account of its own (EastonXvii on X) is the model
// resolved as any other, at its effort and fast, and the account after
// it, kept by its id though typed by its name: the same model on two
// accounts is two members, in the order typed. A group on an account,
// and an account the provider lacks, are refused.
func TestGroupMembersOnAccounts(t *testing.T) {
groupsHome(t)
p, err := provider.Find("a")
if err != nil {
t.Fatal(err)
}
p.Keys = []provider.KeyAccount{{Key: "ka2", Name: "Work"}}
if err := provider.Save(*p); err != nil {
t.Fatal(err)
}
work, mine := provider.KeyID("ka2"), provider.KeyID("ka")
g, err := addGroup("Chain", []string{"models=a/m#Work,m:high#" + mine + ",b/gpt-5.5", "routing=order"})
if err != nil {
t.Fatal(err)
}
if want := []string{"a/m#" + work, "a/m:high#" + mine, "b/gpt-5.5"}; !slices.Equal(g.Members, want) {
t.Fatalf("members %v, want %v", g.Members, want)
}
if s, ok := memberLabel(g.Members[0], catalogByID()); !ok || !strings.Contains(s, "Work") {
t.Errorf("label %q %v", s, ok)
}
for _, bad := range []string{"a/m#nobody", "group/chain#" + work} {
if _, err := addGroup("Bad", []string{"models=a/m," + bad}); err == nil {
t.Errorf("%s: added", bad)
}
}
}