provider: a move onto the plugin takes every account, and no model holds it back
The built-ins are retired (the owner, 10-16: 一定要下线完毕), so a move
can't be held back by something only the built-in could fix. Before, a
move failed when every account was lapsed, when one account's check
failed (the vendor unreachable through the plugin), when the vendor
refused every account, or when a model in use wasn't in the plugin's
list. Each of those left the user on a built-in that is going away.
Now Move installs the plugin and imports every account:
- one the vendor refuses goes along marked lapsed, as before;
- one already lapsed, or whose check fails otherwise, goes along untried
and unmarked, for the plugin's own reads to judge, and is logged;
- no model is checked against the plugin's list.
Only an install failure, the plugin not serving the id, or a sign-in the
plugin won't import fails the move, which puts everything back and is
tried again after moveRetry. The movers' served (Devin, Cursor) and
builtin (ZCode) hooks, modelsInUse, modelNames, lapsedAll and devinBase
had no other use and are gone, with the tests of the hooks. The page still
translates an older magpie's lapsed, unserved and account whys, which
migrations.json can hold.
Tests:
- TestMoveEveryAccountLapsed and TestMoveTriesEachAccount are new, and
TestMoveToPlugin's first case is now a refused account that moves.
importAuth is a seam: the fake mover's "r-noimport" sign-in fails part
way, so TestMoveToPlugin, TestMoveTidiesItsPlugin and TestMoveCutShort
still test putting back.
- TestMoveCutShort's cut-short record now carries the sent sign-in's
hash, as a real move writes it. Without it putBack took the built-in's
sign-in as renewed. The old test passed only because the check renewed
the token a second time.
- Broken by hand: with a failed check or a refusal returning an error
again, TestMoveToPlugin and TestMoveTriesEachAccount go red.
What was run:
- go test -tags nogui ./internal/provider -run
'Move|HandOver|Lapse|PutBack|Retir|Adopt|KeepMoved|ReleasePlugin|
ZCodeStartPlan|Devin|Cursor' passes.
- go vet passes and gofmt -l is clean.
- At ab7b28510 on ba132d68b: go test -tags nogui ./... -count=1
-timeout 90m, 66 packages ok, no FAIL; GOOS=linux and windows go vet
of provider, gui and cli pass.
- Rebased onto origin/main with the next commit; the suite at that head
is in its body.
This commit is contained in:
@@ -125,7 +125,7 @@ Migration records use four states:
|
||||
| `back` | Ownership returned to the built-in. `MoveRetiring` moves it again, unless `Left` says the user removed or turned off the plugin. |
|
||||
| `failed` | Migration failed and the built-in continues serving. Automatic retry waits six hours. |
|
||||
|
||||
The editor's "Move to plugin" action calls `provider.Adopt`. With accounts, adoption delegates to `Move`, which imports and validates accounts and model coverage before committing plugin ownership. With no accounts, adoption verifies the package and the provider it serves, then records plugin ownership without account checks.
|
||||
The editor's "Move to plugin" action calls `provider.Adopt`. With accounts, adoption delegates to `Move`, which installs the plugin, imports every account and commits plugin ownership. Each account is tried through the plugin, and none holds the move back, since the built-in is retired: one the vendor refuses goes along marked lapsed, and one already lapsed or that fails its check otherwise (its vendor unreachable) goes along untried, for the plugin's own reads to judge. No model the built-in served is checked against the plugin's list. Only an install failure, the plugin not serving the id, or a sign-in the plugin won't import fails the move, which then puts everything back (`putBack`) and is tried again after six hours. A `why` from an older magpie's failed move (`lapsed`, `unserved`, `account`) is still read and translated by the page. With no accounts, adoption verifies the package and the provider it serves, then records plugin ownership without account checks.
|
||||
|
||||
Installing the plugin independently can also hand over ownership through `provider.HandOver`. The package must be enabled, meet the mover's minimum version, and serve the expected provider. After add, update, or upgrade, the GUI calls `HandOver(ctx, false)`, which can adopt a built-in with no accounts. Existing built-in accounts wait for `HandOver(ctx, true)` in gateway maintenance.
|
||||
|
||||
|
||||
@@ -917,35 +917,6 @@ func devinTierOf(id string) (tier, level string) {
|
||||
return "", devinLevel(id)
|
||||
}
|
||||
|
||||
// devinBase is the model a Devin variant id is a variant of: the id less
|
||||
// its tier and effort words (claude-opus-5-5-low-fast is claude-opus-5-5,
|
||||
// swe-2-high swe-2); an id at no effort is itself.
|
||||
func devinBase(id string) string {
|
||||
tier, level := devinTierOf(id)
|
||||
if level == "" {
|
||||
return id
|
||||
}
|
||||
low := strings.ToLower(id)
|
||||
cut := func(word string) bool {
|
||||
for _, sep := range []string{"-", "_"} {
|
||||
if strings.HasSuffix(low, sep+word) {
|
||||
low, id = low[:len(low)-len(sep+word)], id[:len(low)-len(sep+word)]
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
if tier != "" {
|
||||
cut(tier)
|
||||
}
|
||||
for _, l := range devinLevels {
|
||||
if l.level == level && cut(l.word) {
|
||||
break
|
||||
}
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// devinEffortOf is the effort a Devin id runs at, in a tier or not.
|
||||
func devinEffortOf(id string) string {
|
||||
_, l := devinTierOf(id)
|
||||
|
||||
@@ -204,32 +204,3 @@ func TestDevinTiers(t *testing.T) {
|
||||
t.Errorf("offered to the agent: %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
// The built-in's Devin picks from before the families were one model
|
||||
// (swe-2-high, claude-opus-5-5-low-fast) are variants of a model the plugin
|
||||
// lists, which it passes to Devin as they are: moving loses none of them,
|
||||
// nor Adaptive, which the built-in never served. A variant of a model the
|
||||
// plugin doesn't list, and a model of its own, are lost (moving Devin named every
|
||||
// level the user had picked was named as one the plugin doesn't serve).
|
||||
func TestDevinMoveKeepsVariants(t *testing.T) {
|
||||
for id, want := range map[string]string{
|
||||
"swe-2-high": "swe-2", "claude-opus-5-5-low-fast": "claude-opus-5-5", "swe-1-7-lightning-medium": "swe-1-7-lightning",
|
||||
"GPT-6-Sol_HIGH": "GPT-6-Sol", "claude-fable-5-1-xhigh": "claude-fable-5-1", "swe-1-6-fast": "swe-1-6-fast", "glm-5-2-1m": "glm-5-2-1m", "swe-2": "swe-2",
|
||||
} {
|
||||
if got := devinBase(id); got != want {
|
||||
t.Errorf("devinBase(%q) = %q, want %q", id, got, want)
|
||||
}
|
||||
}
|
||||
served := movers["devin"].served
|
||||
listed := []string{"swe-2", "claude-opus-5-5", "claude-opus-5-5-fast", "swe-1-7-lightning"}
|
||||
for _, m := range []string{"swe-2-high", "swe-2-max", "claude-opus-5-5-medium-fast", "swe-1-7-lightning-medium", "Adaptive", "adaptive"} {
|
||||
if !served(m, listed) {
|
||||
t.Errorf("moving loses %s", m)
|
||||
}
|
||||
}
|
||||
for _, m := range []string{"claude-fable-5-1-high", "gpt-6-luna", "swe-2"} {
|
||||
if served(m, listed) {
|
||||
t.Errorf("%s counts as served", m)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,14 @@ package provider
|
||||
// 2. each account's sign-in is kept as the plugin keeps one, in the order
|
||||
// and on or off as the user had it;
|
||||
// 3. each is tried as a request would try it (the plugin's loader and its
|
||||
// model list for that account), and every model the built-in has in use
|
||||
// must be one the plugin serves;
|
||||
// 4. only then does the id change hands: the built-in's saved accounts go
|
||||
// out of logins.json into migrations.json, kept for going back.
|
||||
// model list for that account): one the vendor refuses is marked, and
|
||||
// one that fails otherwise goes along untried, since the built-in is
|
||||
// retired and the plugin is where the account is fixed now;
|
||||
// 4. the id changes hands: the built-in's saved accounts go out of
|
||||
// logins.json into migrations.json, kept for going back.
|
||||
//
|
||||
// Anything short of that puts everything back as it was — the plugin's
|
||||
// A failure on the way (the install, the plugin not serving the id, a
|
||||
// sign-in it won't import) puts everything back as it was — the plugin's
|
||||
// newer tokens included, since a refresh token used once is spent — and
|
||||
// the built-in carries on. MoveBack undoes a move the same way.
|
||||
|
||||
@@ -93,10 +95,10 @@ type Migration struct {
|
||||
//
|
||||
// offline magpie couldn't reach npm (or Bun's download) to install the plugin
|
||||
// install npm couldn't install it: line
|
||||
// lapsed every account of name needs signing in again
|
||||
// unserved the plugin doesn't serve models (their names) for user (with
|
||||
// its plan), though the built-in does
|
||||
// account user doesn't work through the plugin: error
|
||||
//
|
||||
// An older magpie also failed a move for an account (lapsed, unserved,
|
||||
// account), which the page still reads from migrations.json; since the
|
||||
// built-ins are retired every account goes along.
|
||||
type MoveWhy struct {
|
||||
Code string `json:"code"`
|
||||
Args map[string]string `json:"args,omitempty"`
|
||||
@@ -227,14 +229,6 @@ type mover struct {
|
||||
// what else of the built-in's they carry (a key onto its provider),
|
||||
// whose saving syncs the agents, which read the accounts.
|
||||
settle func(auths map[string]map[string]any) error
|
||||
// served is whether the plugin, listing listed, still serves model, one
|
||||
// of the built-in's picks it doesn't list; nil for none.
|
||||
served func(model string, listed []string) bool
|
||||
// builtin is whether the built-in served model on account a, by the
|
||||
// plan a is on; nil for every model on every account. One it didn't
|
||||
// (a ZCode Start Plan account's GLM-5.3) is no loss when the plugin
|
||||
// doesn't list it either.
|
||||
builtin func(ctx context.Context, a Moving, model string) bool
|
||||
}
|
||||
|
||||
// movers are the deprecated built-ins and their plugins, by id. Once one
|
||||
@@ -479,23 +473,10 @@ var (
|
||||
// so a test can read what it is handed
|
||||
addPlugin = plugin.Add
|
||||
upgradePlugin = plugin.Upgrade
|
||||
// importAuth keeps a built-in's sign-in as one of the plugin's
|
||||
importAuth = plugin.Import
|
||||
)
|
||||
|
||||
// modelsInUse are the models the built-in id serves now: the ones agents,
|
||||
// picks and routing can name.
|
||||
var modelsInUse = func(id string) []string {
|
||||
for _, p := range All() {
|
||||
if p.ID == id && !p.IsPlugin() {
|
||||
var out []string
|
||||
for _, m := range p.Exposed() {
|
||||
out = append(out, m.ID)
|
||||
}
|
||||
return out
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Move puts the built-in id's accounts onto its plugin (see above). An
|
||||
// error leaves the built-in as it was.
|
||||
func Move(ctx context.Context, id string) error {
|
||||
@@ -575,7 +556,6 @@ func Adopt(ctx context.Context, id string) error {
|
||||
}
|
||||
|
||||
func move(ctx context.Context, id string, mv *mover) (err error) {
|
||||
inUse := modelsInUse(id)
|
||||
var host string
|
||||
if p, err := Find(id); err == nil && !p.IsPlugin() {
|
||||
host = p.Host()
|
||||
@@ -587,11 +567,6 @@ func move(ctx context.Context, id string, mv *mover) (err error) {
|
||||
if len(accts) == 0 {
|
||||
return fmt.Errorf("no %s account to move", id)
|
||||
}
|
||||
// every account lapsed: nothing to try the plugin with, so nothing is
|
||||
// installed for it
|
||||
if !slices.ContainsFunc(accts, func(a Moving) bool { return !a.Lapsed }) {
|
||||
return lapsedAll(id)
|
||||
}
|
||||
had := pluginListed(mv.pkg)
|
||||
if err := installPlugin(ctx, mv.pkg, mv.min); err != nil {
|
||||
return installFailed(mv.pkg, err)
|
||||
@@ -635,7 +610,7 @@ func move(ctx context.Context, id string, mv *mover) (err error) {
|
||||
}()
|
||||
var moved []movedAccount
|
||||
for _, a := range accts {
|
||||
key, err := plugin.Import(ctx, id, a.Auth)
|
||||
key, err := importAuth(ctx, id, a.Auth)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s: %w", a.User, err)
|
||||
}
|
||||
@@ -648,54 +623,27 @@ func move(ctx context.Context, id string, mv *mover) (err error) {
|
||||
if err := keepOrder(pp, accts, moved); err != nil {
|
||||
return err
|
||||
}
|
||||
tried := false
|
||||
// the built-in is retired, so every account goes: one the vendor
|
||||
// refuses is marked, as the built-in marked it; one that is lapsed,
|
||||
// or that the plugin couldn't prove (its vendor unreachable, its sign-in
|
||||
// gone in words), goes untried and unmarked, and the plugin's own reads
|
||||
// judge it from now on. No model the built-in served holds it back.
|
||||
for i, a := range accts {
|
||||
if a.Lapsed {
|
||||
continue
|
||||
}
|
||||
// through the account's proxy, as its requests go
|
||||
c, err := plugin.Check(ViaLogin(ctx, id, a.User), id, moved[i].Key)
|
||||
if err == nil && (c.Refused != "" || refused(c.Usage)) {
|
||||
// the vendor turned the sign-in away: marked, as the built-in
|
||||
// marked it, and along untried, as a lapsed one goes
|
||||
switch {
|
||||
case err == nil && (c.Refused != "" || refused(c.Usage)):
|
||||
notePluginLapse(pp, moved[i].Key, http.StatusUnauthorized)
|
||||
continue
|
||||
case err != nil:
|
||||
log.Printf("moving %s's %s to its plugin untried: %s", id, a.User, err)
|
||||
}
|
||||
if err != nil && signInGone.MatchString(err.Error()) {
|
||||
// the plugin says in words the sign-in is gone (Grok's past
|
||||
// its time): it moves along untried, as a lapsed one does, and
|
||||
// unmarked, as the plugin's own reads leave its accounts
|
||||
continue
|
||||
}
|
||||
if err != nil {
|
||||
return &moveError{MoveWhy{Code: "account", Args: map[string]string{"user": a.User, "error": err.Error()}}, fmt.Sprintf("%s doesn't work through the plugin: %s", a.User, err), err}
|
||||
}
|
||||
if !tried {
|
||||
if missing := slices.DeleteFunc(slices.Clone(inUse), func(m string) bool {
|
||||
return slices.Contains(c.Models, m) || mv.served != nil && mv.served(m, c.Models) ||
|
||||
mv.builtin != nil && !mv.builtin(ctx, a, m)
|
||||
}); len(missing) > 0 {
|
||||
names := strings.Join(modelNames(id, missing), ", ")
|
||||
who := a.User
|
||||
if a.Plan != "" {
|
||||
who += " (" + a.Plan + ")"
|
||||
}
|
||||
return &moveError{MoveWhy{Code: "unserved", Args: map[string]string{"models": names, "user": who}}, fmt.Sprintf("the plugin doesn't serve %s for %s, though the built-in does. Untick them under Models, or keep the built-in.", names, who), nil}
|
||||
}
|
||||
tried = true
|
||||
}
|
||||
}
|
||||
if !tried {
|
||||
return lapsedAll(id)
|
||||
}
|
||||
return commitMove(id, mv, moved, installed, host)
|
||||
}
|
||||
|
||||
func lapsedAll(id string) error {
|
||||
name := nameOf(id)
|
||||
return &moveError{MoveWhy{Code: "lapsed", Args: map[string]string{"name": name}}, fmt.Sprintf("every %s account needs signing in again. Sign one in, then move.", name), nil}
|
||||
}
|
||||
|
||||
// refused is a check's usage read saying the vendor turned the account's
|
||||
// sign-in away, read as the usage page reads it: a models hook may fall
|
||||
// back to a list it keeps, but the read asks the vendor of the account.
|
||||
@@ -703,28 +651,6 @@ func refused(u *plugin.Usage) bool {
|
||||
return u != nil && (u.SignIn == "expired" || u.SignIn == "" && signInGone.MatchString(u.Error))
|
||||
}
|
||||
|
||||
// modelNames are the ids' names, as the built-in id lists them.
|
||||
func modelNames(id string, ids []string) []string {
|
||||
names := map[string]string{}
|
||||
for _, p := range All() {
|
||||
if p.ID == id && !p.IsPlugin() {
|
||||
for _, m := range p.Available() {
|
||||
names[m.ID] = m.Name
|
||||
}
|
||||
}
|
||||
}
|
||||
var out []string
|
||||
for _, m := range ids {
|
||||
if names[m] != "" {
|
||||
m = names[m]
|
||||
}
|
||||
if !slices.Contains(out, m) {
|
||||
out = append(out, m)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// pluginListed is whether the package is in the plugin list already.
|
||||
func pluginListed(pkg string) bool {
|
||||
return slices.ContainsFunc(plugin.Load().Plugins, func(e plugin.Entry) bool { return plugin.PackageName(e.Spec) == pkg })
|
||||
|
||||
@@ -14,8 +14,7 @@ import (
|
||||
// signed in to under its own id already stays as it is, as does one the
|
||||
// user moved back, and nothing happens while the plugin isn't installed.
|
||||
func TestHandOver(t *testing.T) {
|
||||
inUse := []string{"fake-1"}
|
||||
ctx, abs, installs := fakePlugin(t, &inUse)
|
||||
ctx, abs, installs := fakePlugin(t)
|
||||
reset := func(ls ...savedLogin) {
|
||||
t.Helper()
|
||||
_ = plugin.SignOut(ctx, "fakeco", "")
|
||||
|
||||
@@ -32,8 +32,7 @@ func TestMoveBackKeepsLapse(t *testing.T) {
|
||||
if _, err := plugin.Providers(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inUse := []string{"fake-1"}
|
||||
fakeMover(t, &inUse)
|
||||
fakeMover(t)
|
||||
mv := movers["fakeco"]
|
||||
mv.pkg = abs
|
||||
back := mv.back
|
||||
@@ -87,8 +86,7 @@ func TestMoveRefusedWhileListing(t *testing.T) {
|
||||
if _, err := plugin.Providers(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inUse := []string{"fake-1"}
|
||||
fakeMover(t, &inUse)
|
||||
fakeMover(t)
|
||||
movers["fakeco"].pkg = abs
|
||||
loginsMu.Lock()
|
||||
if err := writeLogins([]savedLogin{fakeLogin("a@fake", "r-a", true, true), fakeLogin("g@fake", "r-models-gone", false, true)}); err != nil {
|
||||
@@ -131,8 +129,7 @@ func TestMoveExpiredInWords(t *testing.T) {
|
||||
if _, err := plugin.Providers(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inUse := []string{"fake-1"}
|
||||
fakeMover(t, &inUse)
|
||||
fakeMover(t)
|
||||
movers["fakeco"].pkg = abs
|
||||
loginsMu.Lock()
|
||||
if err := writeLogins([]savedLogin{fakeLogin("a@fake", "r-a", true, true), fakeLogin("x@fake", "r-models-expired", false, true)}); err != nil {
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@@ -20,16 +19,6 @@ func init() {
|
||||
pkg: "@magpie-community/opencode-devin-auth",
|
||||
min: "0.1.20", // a tool result's images go to Devin on the tool message that answers the call, as the built-in sent them; 0.1.19: Devin answers in JSON when the request asks for it (response_format into the instructions, as the built-in); 0.1.18: a tool whose parameters have a root anyOf, oneOf or allOf goes as a plain object (#1196), a branch that is a union itself folded too (#1271); a turn's parallel calls split over two assistant messages keep their results (#1275); a temperature or top_p of 0 goes as 1e-6, which Devin takes (plugins #50); a call id with ":" or "#" goes to the agent as one Claude Code takes, and back to Devin as it was (#1304); a week used up, its share left out of GetUserStatus, is 100% and holds the account until its reset (面条); SWE-2, which Devin's quota doesn't count (its Free cost tier), is left out of the day and week and listed free, so a used-up quota no longer holds it (太陽と向日葵); a tool schema with a list type, an array with no items, or properties or an enum with no type goes to a Gemini model in a shape it takes, not "There is an issue with this request" (7eleven); each model carries the price Devin lists for it, and SWE-2 stays free beside the -lightning variants Devin now files under it (太陽と向日葵, Usage showed no cost)
|
||||
agents: []string{"devin"},
|
||||
// a variant picked before the families were one model (swe-2-high)
|
||||
// goes to Devin as it is, through the plugin too, which keeps the
|
||||
// picks it is given; Adaptive and Fusion the built-in never served
|
||||
served: func(model string, listed []string) bool {
|
||||
if id := strings.ToLower(model); id == "adaptive" || id == "fusion" {
|
||||
return true
|
||||
}
|
||||
base := devinBase(model)
|
||||
return base != model && slices.Contains(listed, base)
|
||||
},
|
||||
out: func() ([]Moving, error) {
|
||||
var out []Moving
|
||||
for _, l := range devinLogins() {
|
||||
@@ -223,7 +212,6 @@ func init() {
|
||||
pkg: "@magpie-community/opencode-cursor-auth",
|
||||
min: "0.2.18", // a failed tool result reaches Cursor as failed on the stateless path too; the keychain token is read once per 10s and, after a refused read, not asked again for 10 minutes, as the built-in; 0.2.17: a tool-result continuation in a Run's last minute rebuilds from the supplied history before writing results, not a 502 "native Run lifetime expired" (plugins #157); 0.2.16: a multi-step native turn's last step reports its own share of the turn's usage, the rest billed as usage.magpie_deferred, so Codex doesn't read 1.1M as a 61K context and compact at once (plugins #156); a step's calls get the batch wait from the latest one, so a step of many long calls isn't failed as "did not complete its declared native tool batch" (plugins #155); 0.2.15: calls the plugin answers itself (a tool the request doesn't have, get_mcp_tools) count toward Cursor's tool count, so a step with one isn't failed as "inconsistent native tool count" or a batch never completed, and a long history's blob burst waits for a slow link instead of failing as "native outbound messages limit reached" (plugins #142); 0.2.14: a Run tool call stays on one native Cursor session across its result, and a tool that outlasts Cursor resumes stateless, not as a failed turn (plugins #135); 0.2.13: a Run cancelled while it opens is closed upstream, not left streaming for nobody (plugins #130), and dashboard usage is collected per account, so one account never takes another's event as its debt (plugins #131); 0.2.12: Grok Bot is among the panel's three rings ahead of an On-demand with no limit, which is only a dollar figure (#2213); 0.2.11: a step's usage is its own, and what it collected of earlier steps goes as usage.magpie_deferred, billed with it but never told as its prompt, so pi's context isn't inflated (#1053, plugins #101); 0.2.10: a Team member with no limit of their own spends the team's on-demand pool, which is shown and counted as the limit, not as unlimited (#1868); 0.2.9: a default model whose own branch stops short of the asked effort goes to its nearest effort, so the id and its parameters agree (plugins #55); 0.2.8: a failure's status and its sign-in mark as the built-in's; Max Mode models retried in Max Mode; glm-5.3 listed; catalog entries written as CallDynamicTool calls, an empty turn retried (plugins #11); a tool step's usage from the dashboard's usage event, cache included (#676); far from Cursor a step whose event shows late is counted by the conversation's next steps instead of guessed (#1053); a turn's parallel calls split over two assistant messages keep their results (#1275); the list is Cursor's picker, a model once per context size with that window, effort and fast sent as the variant's parameters, and an id 0.1.x listed still runs as the variant it stood for (plugins #51); an id 0.1.x listed, at an effort only its other branch has, goes as that branch's nearest effort, not as the default's id with parameters that contradict it (plugins #54); a model listed at a size Cursor has a fast variant of says fast, for magpie's Fast switch (#1360); a Run HTTP/2 can't open (a proxy or network that blocks it, "h2 is not supported") goes over HTTP/1.1 as RunSSE + BidiAppend on api2 (plugins #59); a model asked for by its bare name (grok-4.7) counts in the pool its sized ids (grok-4.7@256k) are in (Will on Discord); an account with a Grok Bot allowance shows it on its Usage card, aside, so a spent Bot never stops Cursor requests (plugins #64); an account that may spend on-demand (a team or enterprise that pays past the included usage) is not used up when its included pools are, its On-demand spend is (fottencity on Discord, #1476); an assistant turn's reasoning_content is kept across a tool continuation (plugins #82); an empty reply says what Cursor's Run sent before it, so the next report shows why (plugins #60)
|
||||
agents: []string{"cursor"},
|
||||
served: cursorServed,
|
||||
out: func() ([]Moving, error) {
|
||||
if CursorExecutable() == "" || cursorSignedOut() {
|
||||
return nil, nil
|
||||
@@ -255,33 +243,6 @@ const (
|
||||
cursorCLIMark = "cursor-agent" // the Cursor plugin's sign-in that reads cursor-agent's token
|
||||
)
|
||||
|
||||
// cursorServed is whether the Cursor plugin, listing listed, runs model,
|
||||
// an id the built-in listed. Since 0.2.0 (plugins #51) the plugin lists
|
||||
// Cursor's picker, a model once per context size (grok-4.7@256k) with
|
||||
// effort and fast as the request's parameters, and runs an id 0.1.x or
|
||||
// the built-in listed as the variant it stood for (its named()): the
|
||||
// built-in's grok-4.7-fast, claude-opus-5-thinking, cursor-grok-4.5 or a
|
||||
// stale grok-4.7-low. Such an id is served when its family, without effort,
|
||||
// thinking or fast, is a model the picker lists, with or without Cursor's
|
||||
// "cursor-" before it; Auto is the picker's default (#1656). A family the
|
||||
// picker hasn't got is still refused. The list is flat, so a fast id of a
|
||||
// family listed counts as served though the account may lack fast; the
|
||||
// plugin runs it as the family's nearest variant the account has.
|
||||
func cursorServed(model string, listed []string) bool {
|
||||
names := map[string]bool{}
|
||||
for _, l := range listed {
|
||||
n, _, _ := strings.Cut(l, "@")
|
||||
names[n] = true
|
||||
}
|
||||
if model == "default" || model == "auto" {
|
||||
return names["auto"] || names["default"]
|
||||
}
|
||||
fam, _ := splitCursorID(model)
|
||||
fam = strings.TrimSuffix(fam, "-fast")
|
||||
fam = strings.TrimSuffix(fam, "-thinking")
|
||||
return fam != "" && (names[fam] || names[strings.TrimPrefix(fam, "cursor-")] || names["cursor-"+fam])
|
||||
}
|
||||
|
||||
// ownUser is the account the agent's own sign-in is saved as, else user.
|
||||
func ownUser(ls []savedLogin, agent, user string) string {
|
||||
for _, l := range ls {
|
||||
|
||||
@@ -265,39 +265,3 @@ func TestMoveCursor(t *testing.T) {
|
||||
t.Fatalf("signed out: %+v", out)
|
||||
}
|
||||
}
|
||||
|
||||
// The Cursor plugin lists Cursor's picker, a model once per context size,
|
||||
// and runs the ids the built-in listed as the variants they stood for: a
|
||||
// move doesn't fail on those (#1656). The list is what the plugin's 0.2.7
|
||||
// lists for its own test picker (context.test.mjs PICKER); each id said
|
||||
// served here is one that plugin's request() resolves to a variant of
|
||||
// Cursor's (grok-4.7-fast to grok-4.7-high-fast, cursor-grok-4.6 to
|
||||
// cursor-grok-4.6-high), run against it.
|
||||
func TestCursorMoverServesBuiltinIDs(t *testing.T) {
|
||||
listed := []string{"claude-opus-5-5@300k", "claude-opus-5-5@1m", "claude-haiku-5-5@300k", "claude-haiku-5-5@1m", "grok-4.7@256k", "grok-4.7@500k", "grok-4.6", "composer-2.5", "auto", "max-only"}
|
||||
served := movers["cursor"].served
|
||||
if served == nil {
|
||||
t.Fatal("the Cursor mover has no served hook")
|
||||
}
|
||||
for _, id := range []string{
|
||||
"grok-4.7", "grok-4.7-fast", "grok-4.7-low", "grok-4.7-high-fast", // a family, fast, a stale effort
|
||||
"claude-opus-5-5", "claude-opus-5-5-fast", "claude-opus-5-5-high",
|
||||
"claude-haiku-5-5-thinking", "claude-haiku-5-5-thinking-low",
|
||||
"cursor-grok-4.6", "cursor-grok-4.6-high", // Cursor's own prefix the picker's name hasn't
|
||||
"composer-2.5-fast", "default", "auto", "max-only",
|
||||
} {
|
||||
if !served(id, listed) {
|
||||
t.Errorf("%s: not served, though the plugin runs it", id)
|
||||
}
|
||||
}
|
||||
// a family the picker hasn't got is still refused
|
||||
for _, id := range []string{"claude-fable-5-thinking-no-zdr", "codex-5.3-fast", "grok-4.5", "gpt-5.5-high", "claude-opus-5", "fast", "-fast"} {
|
||||
if served(id, listed) {
|
||||
t.Errorf("%s: served, though the plugin lists nothing of it", id)
|
||||
}
|
||||
}
|
||||
// Auto only when the plugin lists it
|
||||
if served("default", []string{"grok-4.7@256k"}) {
|
||||
t.Error("default served by a list without Auto")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package provider
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
@@ -18,7 +19,7 @@ import (
|
||||
// fakeMover moves a made-up built-in, "fakeco", whose accounts keep a
|
||||
// token in logins.json, onto the test plugin: the token is the plugin's
|
||||
// refresh token.
|
||||
func fakeMover(t *testing.T, inUse *[]string) {
|
||||
func fakeMover(t *testing.T) {
|
||||
t.Helper()
|
||||
movers["fakeco"] = &mover{
|
||||
pkg: "fake",
|
||||
@@ -41,12 +42,19 @@ func fakeMover(t *testing.T, inUse *[]string) {
|
||||
return ls, ls[i].User, nil
|
||||
},
|
||||
}
|
||||
oldInstall, oldInUse := installPlugin, modelsInUse
|
||||
oldInstall, oldImport := installPlugin, importAuth
|
||||
installPlugin = func(context.Context, string, string) error { return nil }
|
||||
modelsInUse = func(string) []string { return *inUse }
|
||||
// a sign-in "r-noimport" is one the plugin won't keep, failing the
|
||||
// move part way, after the accounts before it went over
|
||||
importAuth = func(ctx context.Context, id string, auth map[string]any) (string, error) {
|
||||
if auth["refresh"] == "r-noimport" {
|
||||
return "", errors.New("FakeCo won't keep this sign-in")
|
||||
}
|
||||
return plugin.Import(ctx, id, auth)
|
||||
}
|
||||
t.Cleanup(func() {
|
||||
delete(movers, "fakeco")
|
||||
installPlugin, modelsInUse = oldInstall, oldInUse
|
||||
installPlugin, importAuth = oldInstall, oldImport
|
||||
})
|
||||
}
|
||||
|
||||
@@ -90,8 +98,7 @@ func TestMoveToPlugin(t *testing.T) {
|
||||
if _, err := plugin.Providers(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inUse := []string{"fake-1", "fake-claude"}
|
||||
fakeMover(t, &inUse)
|
||||
fakeMover(t)
|
||||
movers["fakeco"].pkg = abs
|
||||
reset := func(ls ...savedLogin) {
|
||||
t.Helper()
|
||||
@@ -122,78 +129,44 @@ func TestMoveToPlugin(t *testing.T) {
|
||||
return out
|
||||
}
|
||||
|
||||
// an account the vendor refuses: nothing moves, and the other's token,
|
||||
// spent by the plugin, comes back renewed
|
||||
// an account the vendor refuses goes along: the built-in is retired,
|
||||
// so nothing an account does holds the move back
|
||||
reset(fakeLogin("a@fake", "rot-a", false, true), fakeLogin("c@fake", "r-dead", false, true))
|
||||
if err := Move(ctx, "fakeco"); err != nil || !Moved("fakeco") {
|
||||
t.Fatalf("Move with a refused account = %v", err)
|
||||
}
|
||||
if got := strings.Join(pluginUsers(), " "); got != "a@fake+ c@fake+" {
|
||||
t.Fatalf("the plugin's accounts after moving a refused one: %s", got)
|
||||
}
|
||||
|
||||
// a sign-in the plugin won't keep: nothing moves, and the one that went
|
||||
// over before it comes back
|
||||
reset(fakeLogin("a@fake", "rot-a", false, true), fakeLogin("c@fake", "r-noimport", false, true))
|
||||
err := Move(ctx, "fakeco")
|
||||
if err == nil || !strings.Contains(err.Error(), "c@fake") {
|
||||
t.Fatalf("Move with a refused account = %v", err)
|
||||
t.Fatalf("Move with a sign-in the plugin won't keep = %v", err)
|
||||
}
|
||||
if m, _ := MigrationOf("fakeco"); m.State != MoveFailed || Moved("fakeco") {
|
||||
t.Fatalf("after a failed move: %+v", m)
|
||||
}
|
||||
if s := fakeSaved(t); !strings.HasPrefix(fakeToken(s["a@fake"]), "rot-a+") || fakeToken(s["c@fake"]) != "r-dead" {
|
||||
if s := fakeSaved(t); !strings.HasPrefix(fakeToken(s["a@fake"]), "rot-a") || fakeToken(s["c@fake"]) != "r-noimport" {
|
||||
t.Fatalf("the built-in's accounts after a failed move: %+v", s)
|
||||
}
|
||||
if plugin.SignedIn("fakeco") {
|
||||
t.Fatal("the plugin kept an account of a failed move")
|
||||
}
|
||||
|
||||
// a model in use the plugin doesn't serve: nothing moves
|
||||
reset(fakeLogin("a@fake", "r-a", false, true))
|
||||
inUse = []string{"fake-1", "gone-model"}
|
||||
if err := Move(ctx, "fakeco"); err == nil || !strings.Contains(err.Error(), "gone-model") {
|
||||
t.Fatalf("Move with a model the plugin lacks = %v", err)
|
||||
}
|
||||
if len(fakeSaved(t)) != 1 || plugin.SignedIn("fakeco") {
|
||||
t.Fatal("a move short of a model moved")
|
||||
}
|
||||
// one the mover says the plugin serves though it doesn't list it (a
|
||||
// Devin variant) isn't named, nor is a name twice
|
||||
movers["fakeco"].served = func(m string, listed []string) bool { return m == "fake-1-high" && slices.Contains(listed, "fake-1") }
|
||||
reset(fakeLogin("a@fake", "r-a", false, true))
|
||||
inUse = []string{"fake-1", "fake-1-high", "gone-model", "gone-model"}
|
||||
if err := Move(ctx, "fakeco"); err == nil || strings.Contains(err.Error(), "fake-1-high") || strings.Count(err.Error(), "gone-model") != 1 {
|
||||
t.Fatalf("Move with a served variant and a model the plugin lacks = %v", err)
|
||||
}
|
||||
movers["fakeco"].served = nil
|
||||
// one the built-in never served on the account either (a ZCode Start
|
||||
// Plan account's GLM-5.3) is no loss and isn't named; one it did is,
|
||||
// with the account and its plan
|
||||
movers["fakeco"].builtin = func(_ context.Context, a Moving, m string) bool { return a.User != "a@fake" || m != "never-model" }
|
||||
reset(func() savedLogin { l := fakeLogin("a@fake", "r-a", false, true); l.Plan = "Fake Start"; return l }())
|
||||
inUse = []string{"fake-1", "never-model"}
|
||||
if err := Move(ctx, "fakeco"); err != nil {
|
||||
t.Fatalf("Move with a model the built-in didn't serve either = %v", err)
|
||||
}
|
||||
if err := MoveBack(ctx, "fakeco"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reset(func() savedLogin { l := fakeLogin("a@fake", "r-a", false, true); l.Plan = "Fake Start"; return l }())
|
||||
inUse = []string{"fake-1", "never-model", "gone-model"}
|
||||
err = Move(ctx, "fakeco")
|
||||
if err == nil || strings.Contains(err.Error(), "never-model") || !strings.Contains(err.Error(), "gone-model for a@fake (Fake Start)") {
|
||||
t.Fatalf("Move with a model the built-in served on the account = %v", err)
|
||||
}
|
||||
if w := WhyOf(err); w == nil || w.Code != "unserved" || w.Args["user"] != "a@fake (Fake Start)" || w.Args["models"] != "gone-model" {
|
||||
t.Fatalf("its why: %+v", w)
|
||||
}
|
||||
movers["fakeco"].builtin = nil
|
||||
inUse = []string{"fake-1", "fake-claude"}
|
||||
|
||||
// an account signed in through the plugin already gets back what it had
|
||||
reset(fakeLogin("a@fake", "r-a", false, true))
|
||||
reset(fakeLogin("a@fake", "r-a", false, true), fakeLogin("c@fake", "r-noimport", false, true))
|
||||
if _, err := plugin.Import(ctx, "fakeco", map[string]any{"type": "oauth", "refresh": "r-mine", "access": "a", "expires": 9e15, "accountId": "a@fake"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inUse = []string{"gone-model"}
|
||||
if err := Move(ctx, "fakeco"); err == nil {
|
||||
t.Fatal("moved short of a model")
|
||||
t.Fatal("moved a sign-in the plugin won't keep")
|
||||
}
|
||||
if a := plugin.Auths("fakeco"); len(a) != 1 || a["fakeco"]["refresh"] != "r-mine" {
|
||||
t.Fatalf("the plugin's own account after a failed move: %v", a)
|
||||
}
|
||||
inUse = []string{"fake-1", "fake-claude"}
|
||||
|
||||
// a move through: b first, a on behind it, d off; a lapsed one goes
|
||||
// along untried
|
||||
@@ -292,8 +265,7 @@ func TestMoveCutShort(t *testing.T) {
|
||||
if _, err := plugin.Providers(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inUse := []string{"fake-1"}
|
||||
fakeMover(t, &inUse)
|
||||
fakeMover(t)
|
||||
movers["fakeco"].pkg = abs
|
||||
retiring = func() []string { return []string{"fakeco"} }
|
||||
t.Cleanup(func() { retiring = MovableIDs })
|
||||
@@ -306,23 +278,29 @@ func TestMoveCutShort(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// as a move records it: the sign-in sent, which the built-in still has
|
||||
out, _ := movers["fakeco"].out()
|
||||
_ = setMigration("fakeco", func(m *Migration) {
|
||||
*m = Migration{State: MoveMoving, At: time.Now(), Accounts: []movedAccount{{Key: key, User: "a@fake"}}}
|
||||
*m = Migration{State: MoveMoving, At: time.Now(), Accounts: []movedAccount{{Key: key, User: "a@fake", Sent: signinHash(out[0].Auth)}}}
|
||||
})
|
||||
if movingNow("fakeco") && len(pluginAccounts()) != 0 {
|
||||
t.Fatal("a plugin provider mid-move is listed")
|
||||
}
|
||||
// the built-in fails now (its models aren't the plugin's): put back,
|
||||
// the move fails now (a sign-in the plugin won't keep): put back,
|
||||
// with the renewed token
|
||||
inUse = []string{"gone-model"}
|
||||
loginsMu.Lock()
|
||||
_ = writeLogins(append(readLogins(), fakeLogin("n@fake", "r-noimport", false, true)))
|
||||
loginsMu.Unlock()
|
||||
if errs := MoveRetiring(ctx); errs["fakeco"] == nil {
|
||||
t.Fatal("moved short of a model")
|
||||
t.Fatal("moved a sign-in the plugin won't keep")
|
||||
}
|
||||
if s := fakeSaved(t); !strings.HasPrefix(fakeToken(s["a@fake"]), "rot-a+") || plugin.SignedIn("fakeco") {
|
||||
t.Fatalf("after putting back a move cut short: %+v", s)
|
||||
}
|
||||
// failed just now: not tried again by itself until moveRetry has gone
|
||||
inUse = []string{"fake-1"}
|
||||
loginsMu.Lock()
|
||||
_ = writeLogins(slices.DeleteFunc(readLogins(), func(l savedLogin) bool { return l.User == "n@fake" }))
|
||||
loginsMu.Unlock()
|
||||
if errs := MoveRetiring(ctx); len(errs) != 0 || Moved("fakeco") {
|
||||
t.Fatalf("tried again at once: %v", errs)
|
||||
}
|
||||
@@ -368,8 +346,7 @@ func TestPutBackKeepsNewer(t *testing.T) {
|
||||
if _, err := plugin.Providers(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inUse := []string{"fake-1"}
|
||||
fakeMover(t, &inUse)
|
||||
fakeMover(t)
|
||||
mv := movers["fakeco"]
|
||||
sent := func(tok, user string) string {
|
||||
return signinHash(map[string]any{"type": "oauth", "refresh": tok, "access": "a", "expires": 9e15, "accountId": user})
|
||||
@@ -437,8 +414,7 @@ func TestMovedBuiltinQuiet(t *testing.T) {
|
||||
// the built-in came up to date with magpie; one moved back isn't touched.
|
||||
func TestKeepMovedCurrent(t *testing.T) {
|
||||
claudeHome(t)
|
||||
var inUse []string
|
||||
fakeMover(t, &inUse)
|
||||
fakeMover(t)
|
||||
movers["fakeco"].min = "0.2.0"
|
||||
var asked []string
|
||||
installPlugin = func(_ context.Context, pkg, min string) error {
|
||||
@@ -565,8 +541,7 @@ func TestReleasePlugin(t *testing.T) {
|
||||
if _, err := plugin.Providers(ctx); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inUse := []string{"fake-1"}
|
||||
fakeMover(t, &inUse)
|
||||
fakeMover(t)
|
||||
movers["fakeco"].pkg = abs
|
||||
loginsMu.Lock()
|
||||
if err := writeLogins([]savedLogin{fakeLogin("a@fake", "r-a", true, true), fakeLogin("b@fake", "r-b", false, true)}); err != nil {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
|
||||
// fakePlugin readies the test plugin's host for a move of fakeco, with
|
||||
// the plugin not yet installed: the move's install adds it.
|
||||
func fakePlugin(t *testing.T, inUse *[]string) (context.Context, string, *int) {
|
||||
func fakePlugin(t *testing.T) (context.Context, string, *int) {
|
||||
t.Helper()
|
||||
bun := testenv.Bun(t)
|
||||
claudeHome(t)
|
||||
@@ -25,7 +25,7 @@ func fakePlugin(t *testing.T, inUse *[]string) (context.Context, string, *int) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||
t.Cleanup(cancel)
|
||||
abs, _ := filepath.Abs("../plugin/testdata/fake/index.js")
|
||||
fakeMover(t, inUse)
|
||||
fakeMover(t)
|
||||
movers["fakeco"].pkg = abs
|
||||
installs := 0
|
||||
installPlugin = func(ctx context.Context, pkg, _ string) error {
|
||||
@@ -48,23 +48,18 @@ func setFakeLogins(t *testing.T, ls ...savedLogin) {
|
||||
}
|
||||
}
|
||||
|
||||
// Every account lapsed: there's nothing to try the plugin with, so the
|
||||
// move says so before installing anything.
|
||||
func TestMoveNeedsAWorkingAccount(t *testing.T) {
|
||||
claudeHome(t)
|
||||
inUse := []string{"fake-1"}
|
||||
fakeMover(t, &inUse)
|
||||
installs := 0
|
||||
installPlugin = func(context.Context, string, string) error { installs++; return nil }
|
||||
// Every account lapsed: the built-in is retired, so the plugin is
|
||||
// installed and they go along marked, to sign in again through it.
|
||||
func TestMoveEveryAccountLapsed(t *testing.T) {
|
||||
ctx, _, installs := fakePlugin(t)
|
||||
l := fakeLogin("a@fake", "r-a", true, true)
|
||||
l.Lapsed = "expired"
|
||||
setFakeLogins(t, l)
|
||||
err := Move(context.Background(), "fakeco")
|
||||
if w := WhyOf(err); w == nil || w.Code != "lapsed" || installs != 0 {
|
||||
t.Fatalf("Move with every account lapsed = %v (why %+v), %d installs", err, w, installs)
|
||||
if err := Move(ctx, "fakeco"); err != nil || !Moved("fakeco") || *installs != 1 {
|
||||
t.Fatalf("Move with every account lapsed = %v, moved %v, %d installs", err, Moved("fakeco"), *installs)
|
||||
}
|
||||
if m, _ := MigrationOf("fakeco"); m.State != MoveFailed || m.Why == nil || m.Why.Code != "lapsed" {
|
||||
t.Fatalf("the failed move's record: %+v", m)
|
||||
if ls := pluginLogins(mustPlugin(t)); len(ls) != 1 || ls[0].Lapsed == "" {
|
||||
t.Fatalf("the lapsed account on the plugin: %+v", ls)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,12 +68,10 @@ func TestMoveNeedsAWorkingAccount(t *testing.T) {
|
||||
// keeps it, and going back takes it away when it serves nothing else. A
|
||||
// plugin the user had installed stays either way.
|
||||
func TestMoveTidiesItsPlugin(t *testing.T) {
|
||||
inUse := []string{"fake-1", "gone-model"}
|
||||
ctx, abs, _ := fakePlugin(t, &inUse)
|
||||
setFakeLogins(t, fakeLogin("a@fake", "r-a", true, true))
|
||||
err := Move(ctx, "fakeco")
|
||||
if w := WhyOf(err); w == nil || w.Code != "unserved" || !strings.Contains(err.Error(), "gone-model") {
|
||||
t.Fatalf("Move short of a model = %v (why %+v)", err, w)
|
||||
ctx, abs, _ := fakePlugin(t)
|
||||
setFakeLogins(t, fakeLogin("a@fake", "r-a", true, true), fakeLogin("n@fake", "r-noimport", false, true))
|
||||
if err := Move(ctx, "fakeco"); err == nil || !strings.Contains(err.Error(), "won't keep") {
|
||||
t.Fatalf("Move with a sign-in the plugin won't keep = %v", err)
|
||||
}
|
||||
if pluginListed(abs) {
|
||||
t.Fatal("a failed move left the plugin it installed")
|
||||
@@ -87,7 +80,7 @@ func TestMoveTidiesItsPlugin(t *testing.T) {
|
||||
t.Fatalf("the built-in's account after a failed move: %+v", s)
|
||||
}
|
||||
|
||||
inUse = []string{"fake-1"}
|
||||
setFakeLogins(t, fakeLogin("a@fake", "r-a", true, true))
|
||||
if err := Move(ctx, "fakeco"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -108,11 +101,11 @@ func TestMoveTidiesItsPlugin(t *testing.T) {
|
||||
if _, err := plugin.Add(ctx, abs); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
inUse = []string{"gone-model"}
|
||||
setFakeLogins(t, fakeLogin("a@fake", "r-a", true, true), fakeLogin("n@fake", "r-noimport", false, true))
|
||||
if err := Move(ctx, "fakeco"); err == nil || !pluginListed(abs) {
|
||||
t.Fatalf("a failed move onto the user's plugin: %v, listed %v", err, pluginListed(abs))
|
||||
}
|
||||
inUse = []string{"fake-1"}
|
||||
setFakeLogins(t, fakeLogin("a@fake", "r-a", true, true))
|
||||
os.Remove(migrationsPath())
|
||||
if err := Move(ctx, "fakeco"); err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -122,47 +115,36 @@ func TestMoveTidiesItsPlugin(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// The move proves each account through the vendor: one whose usage read
|
||||
// the vendor refuses goes along marked and untried, as a lapsed one does,
|
||||
// and the move fails when that leaves none tried; one the plugin couldn't
|
||||
// reach its vendor for (its models hook keeping a list of its own) stops
|
||||
// the move, as nothing proved it works.
|
||||
func TestMoveProvesEachAccount(t *testing.T) {
|
||||
inUse := []string{"fake-1"}
|
||||
ctx, abs, _ := fakePlugin(t, &inUse)
|
||||
// The move tries each account through the vendor, and none holds it
|
||||
// back: one whose usage read the vendor refuses goes along marked, as a
|
||||
// lapsed one does; one the plugin couldn't reach its vendor for (its
|
||||
// models hook keeping a list of its own) goes along unmarked, for the
|
||||
// plugin's own reads to judge.
|
||||
func TestMoveTriesEachAccount(t *testing.T) {
|
||||
ctx, abs, _ := fakePlugin(t)
|
||||
if _, err := plugin.Add(ctx, abs); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
setFakeLogins(t, fakeLogin("z@fake", "r-gone", true, true))
|
||||
if err := Move(ctx, "fakeco"); WhyOf(err) == nil || WhyOf(err).Code != "lapsed" || Moved("fakeco") {
|
||||
if err := Move(ctx, "fakeco"); err != nil || !Moved("fakeco") {
|
||||
t.Fatalf("Move with its one account refused = %v", err)
|
||||
}
|
||||
if ls := pluginLogins(mustPlugin(t)); len(ls) != 1 || ls[0].Lapsed == "" {
|
||||
t.Fatalf("the refused account on the plugin: %+v", ls)
|
||||
}
|
||||
|
||||
setFakeLogins(t, fakeLogin("a@fake", "r-a", true, true), fakeLogin("z@fake", "r-unreachable", false, true))
|
||||
err := Move(ctx, "fakeco")
|
||||
w := WhyOf(err)
|
||||
if w == nil || w.Code != "account" || w.Args["user"] != "z@fake" || !strings.Contains(err.Error(), "couldn't reach FakeCo") {
|
||||
t.Fatalf("Move with the vendor unreachable = %v (why %+v)", err, w)
|
||||
}
|
||||
if Moved("fakeco") || plugin.SignedIn("fakeco") || len(fakeSaved(t)) != 2 {
|
||||
t.Fatal("a move with an account unproven moved")
|
||||
}
|
||||
loginsMu.Lock()
|
||||
for _, l := range readLogins() {
|
||||
if l.Agent == "plugin:fakeco" {
|
||||
t.Errorf("a failed move left the plugin's row of %s", l.User)
|
||||
}
|
||||
}
|
||||
loginsMu.Unlock()
|
||||
|
||||
setFakeLogins(t, fakeLogin("a@fake", "r-a", true, true), fakeLogin("z@fake", "r-gone", false, true))
|
||||
if err := Move(ctx, "fakeco"); err != nil {
|
||||
t.Fatalf("an account refused stopped the move: %v", err)
|
||||
_ = plugin.SignOut(ctx, "fakeco", "")
|
||||
os.Remove(migrationsPath())
|
||||
setFakeLogins(t, fakeLogin("a@fake", "r-a", true, true), fakeLogin("z@fake", "r-unreachable", false, true), fakeLogin("g@fake", "r-gone", false, true))
|
||||
if err := Move(ctx, "fakeco"); err != nil || !Moved("fakeco") {
|
||||
t.Fatalf("Move with the vendor unreachable for one account = %v", err)
|
||||
}
|
||||
users := map[string]string{}
|
||||
for _, l := range pluginLogins(mustPlugin(t)) {
|
||||
if (l.User == "z@fake") != (l.Lapsed != "") {
|
||||
t.Fatalf("moved %s: lapsed %q", l.User, l.Lapsed)
|
||||
}
|
||||
users[l.User] = l.Lapsed
|
||||
}
|
||||
if len(users) != 3 || users["a@fake"] != "" || users["z@fake"] != "" || users["g@fake"] == "" {
|
||||
t.Fatalf("moved accounts, user → lapsed: %v", users)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,8 +207,7 @@ func TestMovedShowsBuiltinHost(t *testing.T) {
|
||||
// sign-in is the plugin's. Going back takes the plugin it installed away.
|
||||
// One with an account is moved.
|
||||
func TestAdoptBeforeSigningIn(t *testing.T) {
|
||||
inUse := []string{"fake-1"}
|
||||
ctx, abs, installs := fakePlugin(t, &inUse)
|
||||
ctx, abs, installs := fakePlugin(t)
|
||||
if err := Adopt(ctx, "fakeco"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strings"
|
||||
@@ -23,19 +22,6 @@ func init() {
|
||||
pkg: "@magpie-community/opencode-zcode-auth",
|
||||
min: "0.1.19", // the personal plan's resets, and the team's, carry each reset's end and window; a Start Plan refusal carries the built-in's hint; 0.1.18: the ZCode app's sign-in reads ZCode 3.15's GLM Coding Plan key from config.json (provider["builtin:*-coding-plan"].options.apiKey), so a valid plan no longer reads as "no plan", as the built-in does since 1d8e83a79 (#2130); 0.1.17: the ZCode app's sign-in reads credentials.json from the folder ZCode's data was moved to in its settings (数据存储路径, dataBaseDir in the home folder's setting.json), as the built-in does since 41972b25f (flower on Discord); 0.1.16's ZCode app's sign-in follows ZCode only while it is signed in to the same account, so an entry added for one account never sends with another's credentials after ZCode switched (LingYi_Stu on X); 0.1.15's Start Plan request says the agent's folder and git repository as magpie tells them, never magpie's own folder, and leaves out what it doesn't know (plugins #86); 0.1.14's gift-only account lists its gift's models by their own names, as ZCode does, so a Start Plan GLM-5.3 bucket's model is listed as GLM-5.3, not only GLM-5.3-Trial (#1261, plugins aca7c59); 0.1.13's claim line has one fixed name, which the GUI translates, so it no longer shares the "ZCode Trust Build" bucket window's name (plugins #43); 0.1.12's counted window carries its amount and limit, so the card's count follows used/left (#659, plugins #35); 0.1.11's gift plan ZCode holds but hasn't granted is named on the card, to claim in the ZCode app (plugins #30, #1001); 0.1.10's gift-only buckets and 0.1.9's trial entries (plugins #21) kept
|
||||
agents: []string{"zcode"},
|
||||
// the built-in never served GLM-5.3 to a Start Plan account, so
|
||||
// its pick is no loss when the plugin doesn't list it (the plugin
|
||||
// lists it, as ZCode does, only while a gift bucket serves it);
|
||||
// its plan as its requests found it, else as it showed it, nothing
|
||||
// asked of Z.ai
|
||||
builtin: func(_ context.Context, a Moving, model string) bool {
|
||||
for _, l := range zcodeLogins() {
|
||||
if strings.EqualFold(l.User, a.User) {
|
||||
return !zcodeOnStartAs(nil, l.key, l.Plan) || zcodeStartServes()(model)
|
||||
}
|
||||
}
|
||||
return true
|
||||
},
|
||||
out: func() ([]Moving, error) {
|
||||
var out []Moving
|
||||
for _, l := range zcodeLogins() {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"slices"
|
||||
"testing"
|
||||
@@ -25,7 +24,7 @@ func zcodeIDs(ms []catalog.Model) []string {
|
||||
// last (the Coding Plan's) after that, so GLM-5.3 was listed and could be
|
||||
// ticked, though neither ZCode nor the built-in serves it there. Now such an
|
||||
// account neither lists nor exposes it, picked or not; a Coding Plan one
|
||||
// still does. And the move doesn't count it as one the plugin drops.
|
||||
// still does.
|
||||
func TestZCodeStartPlanHasNoGLM53(t *testing.T) {
|
||||
signIn(t)
|
||||
old := zcodeBuiltinFiles
|
||||
@@ -64,12 +63,6 @@ func TestZCodeStartPlanHasNoGLM53(t *testing.T) {
|
||||
t.Fatalf("a Start Plan account under the Coding Plan's list exposes %v", zcodeIDs(ms))
|
||||
}
|
||||
|
||||
// the move: GLM-5.3 the built-in didn't serve on it, GLM-5.2 it did
|
||||
a := Moving{User: "trial@x", Plan: "Start Plan"}
|
||||
if b := movers["zcode"].builtin; b(context.Background(), a, "GLM-5.3") || !b(context.Background(), a, "GLM-5.2") {
|
||||
t.Fatal("the move counts GLM-5.3 as served on a Start Plan account")
|
||||
}
|
||||
|
||||
// a Coding Plan account still has it
|
||||
coding := zcodeKey{Key: "plan.key", Base: ZCodeZaiBase, JWT: jwt}
|
||||
saveLogins(t, savedLogin{Agent: "zcode", User: "pro@x", Plan: "GLM Coding Pro", First: true, On: true, Auth: json.RawMessage(jsonText(coding))})
|
||||
@@ -78,7 +71,4 @@ func TestZCodeStartPlanHasNoGLM53(t *testing.T) {
|
||||
if !has53(p.Available()) || !has53(p.Exposed()) {
|
||||
t.Fatalf("a Coding Plan account lists %v", zcodeIDs(p.Available()))
|
||||
}
|
||||
if !movers["zcode"].builtin(context.Background(), Moving{User: "pro@x", Plan: "GLM Coding Pro"}, "GLM-5.3") {
|
||||
t.Fatal("the move counts GLM-5.3 as not served on a Coding Plan account")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user