provider: a model off for an agent stays off while the vendor's list lacks it; zcode min 0.1.59 (WJaunita45604 on X)
ZCode's GLM-5.3-Flash-Trial is listed only from about 23:00. SetHiddenModels
rebuilt the agent's off list from the models listed right now, so an off
choice for an absent model was dropped on the next Save, and the model came
back on at 23:00. It now keeps hidden ids that ListedFor no longer lists.
(Provider picks and per-agent PickedModels already survive a relist; a
3-day flip test with an editor Save in between guards that.)
The display half is in the plugin, zcode 0.1.59 (npm checked): a reply the
gift answered names the -Trial entry, so Usage, sessions and the request log
show the model served. The mover min is raised to 0.1.59.
Run: go test ./internal/provider (wsl, ok); gateway zcode/trial tests ok;
gofmt clean; go vet linux, windows, darwin ok. Plugin: bun test in
packages/zcode 243 pass.
Broken by hand: SetHiddenModels reverted -> TestHiddenModelAbsentStaysHidden
red ("an unlisted model's off choice lost"); plugin trialNamed removed -> the
2 new gift tests red.
Not tried: a real Start Plan reply or live account; mote was out of disk, so
tests ran on wsl. GUI not touched.
This commit is contained in:
@@ -219,3 +219,49 @@ func TestOnlyPickedModels(t *testing.T) {
|
||||
t.Fatal("picks set for an agent shown every model")
|
||||
}
|
||||
}
|
||||
|
||||
// A model taken out of an agent's lists that its provider's list lacks for
|
||||
// part of the day (ZCode's GLM-5.3-Flash-Trial is listed from 23:00) stays
|
||||
// taken out when the editor saves the hidden models meanwhile, as a pick of
|
||||
// it stays picked (SetPickedModels): it is still off when it is listed again
|
||||
// (WJaunita45604 on X).
|
||||
func TestHiddenModelAbsentStaysHidden(t *testing.T) {
|
||||
isolate(t)
|
||||
t.Setenv("HOME", t.TempDir())
|
||||
t.Setenv("USERPROFILE", t.TempDir())
|
||||
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
||||
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
||||
save := func(models ...string) {
|
||||
t.Helper()
|
||||
if err := Save(Provider{ID: "daily", Name: "Daily", Key: "k", Chat: "http://127.0.0.1:1/v1", Models: models}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
save("m1", "trial")
|
||||
if err := SetHiddenModels("codex", []string{"daily/trial"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// the day: the model isn't listed, and the editor sends the hidden
|
||||
// models it can show, none
|
||||
save("m1")
|
||||
if err := SetHiddenModels("codex", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := settings.Load().HiddenModels["codex"]; !slices.Equal(got, []string{"daily/trial"}) {
|
||||
t.Fatalf("an unlisted model's off choice lost: %v", got)
|
||||
}
|
||||
// 23:00: it is listed again, still off
|
||||
save("m1", "trial")
|
||||
if slices.Contains(ids(shownOf("codex")), "daily/trial") {
|
||||
t.Fatal("the model came back on")
|
||||
}
|
||||
// listed, the editor's word is the user's: turning it on works
|
||||
if err := SetHiddenModels("codex", nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !slices.Contains(ids(shownOf("codex")), "daily/trial") {
|
||||
t.Fatal("turning a listed model on did nothing")
|
||||
}
|
||||
}
|
||||
|
||||
func shownOf(agent string) []Entry { s, _ := CatalogFor(agent); return s }
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -398,3 +398,55 @@ func TestListedAsPickLeavesWithItsModel(t *testing.T) {
|
||||
t.Fatalf("the list-as is %q after the model came back", got)
|
||||
}
|
||||
}
|
||||
|
||||
// A model its plugin lists for part of the day only (ZCode's
|
||||
// GLM-5.3-Flash-Trial, from 23:00) comes back picked on every day, also
|
||||
// when the user saves the provider's picks meanwhile with the editor, which
|
||||
// shows the models listed then (WJaunita45604 on X).
|
||||
func TestDailyPluginModelStaysPicked(t *testing.T) {
|
||||
claudeHome(t)
|
||||
t.Setenv("MAGPIE_BUN", "")
|
||||
if err := os.MkdirAll(settings.Dir(), 0o700); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for name, v := range map[string]any{
|
||||
"plugins.json": map[string]any{"plugins": []map[string]any{{"spec": "magpie-our-free-model"}}},
|
||||
"plugin-auth.json": map[string]any{"our-free-model": map[string]any{"type": "api", "key": "managed"}},
|
||||
} {
|
||||
b, _ := json.Marshal(v)
|
||||
if err := os.WriteFile(filepath.Join(settings.Dir(), name), b, 0o600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
night := ourFree("pool-a", "pool-b", "daily-trial")
|
||||
day := ourFree("pool-a", "pool-b")
|
||||
plugin.UseCached(night)
|
||||
t.Cleanup(func() { plugin.UseCached(nil) })
|
||||
if err := Save(Provider{ID: "our-free-model", Models: []string{"pool-a", "daily-trial"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for d := 0; d < 3; d++ {
|
||||
plugin.UseCached(day)
|
||||
if got := dropGonePluginPicks(night, day)["our-free-model"]; !slices.Equal(got, []string{"daily-trial"}) {
|
||||
t.Fatalf("day %d: dropped %v", d, got)
|
||||
}
|
||||
// the editor lists pool-a and pool-b: the user ticks pool-b
|
||||
p, _ := Find("our-free-model")
|
||||
p.Models = []string{"pool-a", "pool-b"}
|
||||
if d == 1 {
|
||||
p.Models = []string{"pool-a"}
|
||||
}
|
||||
if err := Save(*p); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
plugin.UseCached(night)
|
||||
dropGonePluginPicks(day, night)
|
||||
p, _ = Find("our-free-model")
|
||||
if !slices.Contains(p.Models, "daily-trial") || len(p.Delisted) != 0 {
|
||||
t.Fatalf("day %d: back, picks %v, set aside %v", d, p.Models, p.Delisted)
|
||||
}
|
||||
if got := servedIDs(t, "our-free-model"); !slices.Contains(got, "daily-trial") {
|
||||
t.Fatalf("day %d: not served: %v", d, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,6 +276,22 @@ func SetHiddenModels(agent string, ids []string) error {
|
||||
keep = append(keep, id)
|
||||
}
|
||||
}
|
||||
// a model taken out that its provider's list lacks now (ZCode's
|
||||
// -Trial entries are listed from 23:00 only) isn't in the list the
|
||||
// editor sent, so it stays taken out for when it is listed again, as
|
||||
// SetPickedModels keeps a pick of it
|
||||
if was := HiddenModels(agent); len(was) > 0 {
|
||||
listed, _ := ListedFor(agent)
|
||||
now := map[string]bool{}
|
||||
for _, e := range listed {
|
||||
now[e.ID] = true
|
||||
}
|
||||
for id := range was {
|
||||
if !now[id] && !slices.Contains(keep, id) {
|
||||
keep = append(keep, id)
|
||||
}
|
||||
}
|
||||
}
|
||||
slices.Sort(keep)
|
||||
s := settings.Load()
|
||||
if slices.Equal(s.HiddenModels[agent], keep) {
|
||||
|
||||
Reference in New Issue
Block a user