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.
75 lines
2.8 KiB
Go
75 lines
2.8 KiB
Go
package provider
|
|
|
|
import (
|
|
"encoding/json"
|
|
"slices"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/catalog"
|
|
)
|
|
|
|
func zcodeIDs(ms []catalog.Model) []string {
|
|
var out []string
|
|
for _, m := range ms {
|
|
out = append(out, m.ID)
|
|
}
|
|
return out
|
|
}
|
|
|
|
// 悠悠哥's move to the plugin was held back by GLM-5.3 on a Start Plan
|
|
// (体验套餐) account: a Z.ai account with a key made and no Coding Plan
|
|
// bought, its requests going to the Start Plan, was shown the Coding
|
|
// Plan's models until a request found where it goes, and the list fetched
|
|
// 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.
|
|
func TestZCodeStartPlanHasNoGLM53(t *testing.T) {
|
|
signIn(t)
|
|
old := zcodeBuiltinFiles
|
|
zcodeBuiltinFiles = func() []string { return nil } // not this machine's ZCode
|
|
t.Cleanup(func() { zcodeBuiltinFiles = old })
|
|
zcodeRoutes.Lock()
|
|
zcodeRoutes.m = map[string]zcodeRoute{}
|
|
zcodeRoutes.Unlock()
|
|
jwt := zcodeTestJWT(time.Now().Add(24 * time.Hour))
|
|
start := zcodeKey{Key: "made.key", Base: ZCodeZaiBase, JWT: jwt}
|
|
saveLogins(t, savedLogin{Agent: "zcode", User: "trial@x", Plan: "Start Plan", First: true, On: true, Auth: json.RawMessage(jsonText(start))})
|
|
|
|
has53 := func(ms []catalog.Model) bool { return slices.Contains(zcodeIDs(ms), "GLM-5.3") }
|
|
p, ok := zcodeAccount()
|
|
if !ok {
|
|
t.Fatal("no ZCode account")
|
|
}
|
|
// before any request: its plan's name says the Start Plan
|
|
if ms := p.Available(); has53(ms) || len(ms) == 0 {
|
|
t.Fatalf("a Start Plan account before its route is found lists %v", zcodeIDs(ms))
|
|
}
|
|
p.Models = []string{"GLM-5.3", "GLM-5.2"}
|
|
if ms := p.Exposed(); has53(ms) || !slices.Contains(zcodeIDs(ms), "GLM-5.2") {
|
|
t.Fatalf("a Start Plan account with GLM-5.3 ticked exposes %v", zcodeIDs(ms))
|
|
}
|
|
// with the Coding Plan's list fetched last
|
|
if err := catalog.SaveLive("zcode", ZCodeZaiBase, zcodeModels); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p.Models = nil
|
|
if ms := p.Available(); has53(ms) || len(ms) == 0 {
|
|
t.Fatalf("a Start Plan account under the Coding Plan's list lists %v", zcodeIDs(ms))
|
|
}
|
|
p.Models = []string{"GLM-5.3", "GLM-5.2"}
|
|
if ms := p.Exposed(); has53(ms) || !slices.Contains(zcodeIDs(ms), "GLM-5.2") {
|
|
t.Fatalf("a Start Plan account under the Coding Plan's list exposes %v", zcodeIDs(ms))
|
|
}
|
|
|
|
// 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))})
|
|
p, _ = zcodeAccount()
|
|
p.Models = []string{"GLM-5.3"}
|
|
if !has53(p.Available()) || !has53(p.Exposed()) {
|
|
t.Fatalf("a Coding Plan account lists %v", zcodeIDs(p.Available()))
|
|
}
|
|
}
|