Files
magpie/internal/provider/zcode_startmodels_test.go
yetone 96446806bd zcode: a Start Plan account neither lists nor offers GLM-5.3, and the move to the plugin doesn't count it lost (悠悠哥 on Discord: "仍使用内置:插件不提供 GLM-5.3" moving ZCode onto its plugin) — GLM-5.3 is the Coding Plan's alone (ZCode's builtin config lists GLM-5.3-Flash, GLM-5.2 and GLM-5-Turbo for account:zai-start-plan), and the plugin serves a Start Plan account what ZCode does. But a Z.ai account with a key made and no Coding Plan bought, whose requests go to the Start Plan, was taken for a Coding Plan account until a request found its route (zcodeOnStart with no context said the Coding Plan), and afterwards was listed whatever list was fetched last (the Coding Plan's, another account's or its own before), so GLM-5.3 was listed, could be ticked, and the move found the plugin "short" of it. Now: before a route is found, the plan the account showed at sign-in says it (zcodeOnStartAs, zcodeStartNamed: "Start Plan"); on the Start Plan, a model the plan doesn't serve (zcodeStartServes: ZCode's config on the machine, else zcodeStartModels) is unusable, taken out of a fetched list and out of the picks, with a list fetched or not (Exposed); and a mover may say which models the built-in served on an account (mover.builtin), ZCode's saying a Start Plan account was never served GLM-5.3, so one the built-in didn't serve either is no loss. A model really lost is named with the account and its plan: "the plugin doesn't serve GLM-5.3 for a@x (GLM Coding Pro), though the built-in does" (插件没有为 … 提供 …(内置提供)), the why's args carrying user. TestZCodeStartPlanHasNoGLM53 (a Start Plan account before and after the Coding Plan's list was fetched, GLM-5.3 ticked or not; a Coding Plan account still has it; the mover's builtin) fails without the change (it listed GLM-5.3 GLM-5.3-Flash GLM-5.2 GLM-5-Turbo); TestMoveToPlugin's new case (a model the built-in didn't serve moves; one it did is named with "a@fake (Fake Start)"); plugin-move-unserved.test.cjs (WebKit, en and zh, with an account and without) fails without the app.js change and passes with it, plugin-move.test.cjs passes. No ZCode request or sign-in was made. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME, go test ./internal/gui pass.
2026-10-02 22:00:34 +08:00

85 lines
3.4 KiB
Go

package provider
import (
"context"
"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. And the move doesn't count it as one the plugin drops.
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))
}
// 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))})
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()))
}
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")
}
}