duanckham has a personal and a company GPT account, one tool and one gateway, and wants a group's GPT models to spend only the company account (or only his own). A second gateway key doesn't fit: his tool talks to one gateway, and a local agent needs no key at all. Group.Accounts holds a group to some accounts or keys of the providers it names, in a gateway key's form and by the key's rule (#905, Identity.AllowsAccount). The asked group narrows the request's identity (access.Identity.HeldToGroup: the strict intersection with the key's own list; "<provider>/\x00" when they share none), so every gate a key's accounts go through holds the group's too: chat, responses, messages, count_tokens, embeddings, images and video, streamed or not. A group reached inside another, as a member or a fallback, is held in planLevel (hold, Member.Via): its candidates on an excluded account are Held rows with Weighed.HeldBy, which the Routing trace tells. Fallback stays within the group's entries; with every allowed account resting or out the group's usual error comes back, and a key and a group that share no account get a 403 naming the group, nothing asked upstream. SaveGroup resolves each entry (ResolveAccount, shared with the key's CleanAccounts); share and import drop them. A group without accounts is as before. GUI: the group editor's Accounts section, a row per member provider with two or more accounts, "Any of its accounts" until some are ticked in the app menu (openPicker multi). Every save sends accounts, since a save replaces the group. Strings in all five languages. Gateway keys stay as they are: Gateway › "Gateway keys are for other computers … added here once Share on local network is on" already says where, and this case needs none. Run (mote, through mote-run), at cafed0067 on origin/main9d08993c8: - gofmt -l internal/: clean. go vet of access, gateway, provider, gui; GOOS=linux -tags nogui and GOOS=windows go vet ./internal/...: ok. - go test -count=1 ./internal/access ./internal/provider ./internal/gateway ./internal/gui: access, provider, gateway ok; gui red only on TestMainWindowCorners/macOS_26_SDK, red on main too (#3949, mote's macOS 27). - node --test group-*.test.cjs routing-group-*.test.cjs routing-save*.test.cjs i18n-keys.test.cjs: 433/434. The one red is group-found-skip "webkit de 390px: a provider left out of found groups" (the clicks moved the page), filed as #4617 from main; the file alone passes 20/20 here and on main94f6f6092. group-accounts.test.cjs is 30/30 (Chromium and WebKit; en, zh, zh-TW, ja, de; 1100 and 420px; no scroll on the clicks, no sideways scroll, the save carries accounts). - Earlier, at base5a0c79ed9: go test -timeout 45m ./... all ok but TestVisionBridgePassesLines and TestSettingsSaveKeepsWhatItDoesNot- Send (fixed on main by0b783b1ddand b646a9127; both pass after the rebase) and TestMainWindowCorners (#3949). - The whole GUI suite was cut short twice (a wiped scratchpad, then a mote reboot). Its runs at load ~140-220 had about 35 reds, none in a file this change touches (account-mask, balance-fix, lan-*, the #4617 test among them); not chased here. - Sandbox HOME on mote, the built binary (`magpie serve`, MAGPIE_ADDR on a free port) with a fake upstream answering with the key it got: group/work and Work -> sk-work (3 of 3), group/mine and relay/m -> sk-mine. - Rebased again onto8826a15ea(no file in common): go vet of gui, provider, gateway; go test -run 'TestGroupAccounts|TestHeldToGroup| TestCleanAccounts|Budget|TestGroup' of gateway, access, provider, gui: ok; group-accounts and i18n-keys GUI files: 34/34. - Rebased ontoec104b862(trace.go and gateway-routing.md in common, merged clean): gofmt clean; go vet of gateway for darwin, windows, linux nogui; go test -count=1 ./internal/gateway: ok (640s). - Rebased onto2b52302dc, thenda275848b(no file in common): go vet ./internal/..., the TestGroupAccounts/TestHeldToGroup/Budget tests, group-accounts and i18n-keys GUI files: ok, 34/34. Broken by hand, each red, then restored: - serve's heldByGroup: three TestGroupAccounts* tests red (sk-mine spent). - count_tokens' heldByGroupAt: the count_tokens route red. - planLevel's hold: the nested "outer" group red. - the editor save without accounts: group-accounts.test.cjs red. Not tried: a real Codex or OpenAI account (the fake upstream stands in); a CLI `magpie group set accounts=` (no CLI for it yet); a provider's own fallback naming a held group has no test of its own (planFallbackGroup passes the group as hold, the same path as nested).
42 lines
1.8 KiB
Go
42 lines
1.8 KiB
Go
package access
|
|
|
|
import (
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// A routing group's accounts narrow whoever asks through it: a request
|
|
// with no key is held to the group's, a key's own list meets the group's
|
|
// (a provider both name keeps only the accounts both allow, and none
|
|
// when they share none), and a provider the group doesn't name is the
|
|
// key's as before. A group naming nothing changes nothing.
|
|
func TestHeldToGroup(t *testing.T) {
|
|
anyone := Identity{}
|
|
if got := anyone.HeldToGroup("Work", nil); got.Group != "" || len(got.Accounts) != 0 {
|
|
t.Fatalf("a group with no accounts: %+v", got)
|
|
}
|
|
got := anyone.HeldToGroup("Work", []string{"codex/work@x.com"})
|
|
if got.Group != "Work" || !got.AllowsAccount("codex", "work@x.com") || got.AllowsAccount("codex", "me@x.com") || !got.AllowsAccount("relay", "k") {
|
|
t.Fatalf("no key: %+v", got)
|
|
}
|
|
key := Identity{Accounts: []string{"codex/me@x.com", "codex/work@x.com", "relay/k1"}}
|
|
got = key.HeldToGroup("Work", []string{"codex/work@x.com", "codex/other@x.com"})
|
|
if !slices.Equal(got.Accounts, []string{"relay/k1", "codex/work@x.com"}) {
|
|
t.Fatalf("a key and a group: %v", got.Accounts)
|
|
}
|
|
if got.AllowsAccount("codex", "other@x.com") || got.AllowsAccount("relay", "k2") {
|
|
t.Fatalf("a key and a group allow too much: %v", got.Accounts)
|
|
}
|
|
apart := Identity{Accounts: []string{"codex/me@x.com"}}.HeldToGroup("Work", []string{"codex/work@x.com"})
|
|
if apart.AllowsAccount("codex", "me@x.com") || apart.AllowsAccount("codex", "work@x.com") || !apart.AllowsAccount("relay", "k") {
|
|
t.Fatalf("apart: %v", apart.Accounts)
|
|
}
|
|
if shown := apart.ShownAccounts(); len(shown) != 0 {
|
|
t.Fatalf("apart shows %v", shown)
|
|
}
|
|
// the key it was given is not changed
|
|
if len(key.Accounts) != 3 || key.Group != "" {
|
|
t.Fatalf("the key's identity changed: %+v", key)
|
|
}
|
|
}
|