From f4e52659a8b4449a4676c59c3c65e33c414a023e Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 4 Nov 2026 11:56:29 +0800 Subject: [PATCH] plugins: a pick listed as another id leaves with its model (axelburks) A plugin's model the user lists as another id ("list as", SetModelID) is picked under that id, but pluginListedIDs held the plugin's own ids. The hourly relist and Refresh compared the pick with a list that never had it, so "in the old list, not in the new one" was false, and a model the plugin dropped stayed picked and on, as if typed in by hand. The built-in providers' liveIDs already mapped through modelIDsOf; the plugin path now does too. The list-as stays in settings, so when the plugin lists the model again relistPicks puts the pick back under the same id. Run: TestListedAsPickLeavesWithItsModel (new: aaa listed as claude-opus-5.5 and picked, next list lacks aaa -> pick set aside, alias kept, a hand-typed pick stays; aaa back -> pick back, alias intact), on mote. Broken by hand: with pluginListedIDs returning the raw ids the test fails ("dropped []"). go test internal/provider, internal/plugin: ok. internal/gui: TestCoreScriptBudget (1535230 > 1533802) and TestMainWindowCorners (mote's macOS) red, neither touched by this change. Not tried: a real plugin sign-in. --- internal/provider/plugin_delisted_test.go | 60 +++++++++++++++++++++++ internal/provider/plugin_relist.go | 6 ++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/internal/provider/plugin_delisted_test.go b/internal/provider/plugin_delisted_test.go index 4d1f7e9fa..783327e34 100644 --- a/internal/provider/plugin_delisted_test.go +++ b/internal/provider/plugin_delisted_test.go @@ -338,3 +338,63 @@ func TestPicksGoneForGoodServeTheList(t *testing.T) { t.Fatalf("served %v once the pick is listed again", got) } } + +// A plugin's model the user lists as another id (SetModelID, "list as") +// is picked under that id, but the plugin's list names it by its own. The +// pick left with the model all the same (axelburks on Discord: aaa listed +// as claude-opus-5.5 stayed picked and on after its plugin dropped aaa), +// its "list as" stayed, and both are back when the plugin lists aaa again. +// A pick typed by hand, listed by neither list, stays throughout. +func TestListedAsPickLeavesWithItsModel(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) + } + } + before := ourFree("aaa", "bbb") + plugin.UseCached(before) + t.Cleanup(func() { plugin.UseCached(nil) }) + s := settings.Load() + s.ModelIDs = map[string]string{"our-free-model/claude-opus-5.5": "aaa"} + if err := settings.Save(s); err != nil { + t.Fatal(err) + } + if err := Save(Provider{ID: "our-free-model", Models: []string{"claude-opus-5.5", "bbb", "typed-by-hand"}}); err != nil { + t.Fatal(err) + } + now := ourFree("bbb") + plugin.UseCached(now) + if got := dropGonePluginPicks(before, now)["our-free-model"]; !slices.Equal(got, []string{"claude-opus-5.5"}) { + t.Fatalf("dropped %v, want the pick listed as claude-opus-5.5", got) + } + p, _ := Find("our-free-model") + if !slices.Equal(p.Models, []string{"bbb", "typed-by-hand"}) || !slices.Equal(p.Delisted, []string{"claude-opus-5.5"}) { + t.Fatalf("picks %v, set aside %v", p.Models, p.Delisted) + } + if got := settings.Load().ModelIDs["our-free-model/claude-opus-5.5"]; got != "aaa" { + t.Fatalf("the list-as is %q after the model left", got) + } + // the next relist compares the same lists: nothing more happens + if got := dropGonePluginPicks(now, now)["our-free-model"]; len(got) != 0 { + t.Fatalf("dropped %v again", got) + } + back := ourFree("aaa", "bbb") + plugin.UseCached(back) + dropGonePluginPicks(now, back) + p, _ = Find("our-free-model") + if !slices.Equal(p.Models, []string{"bbb", "typed-by-hand", "claude-opus-5.5"}) || len(p.Delisted) != 0 { + t.Fatalf("aaa listed again: picks %v, set aside %v", p.Models, p.Delisted) + } + if got := settings.Load().ModelIDs["our-free-model/claude-opus-5.5"]; got != "aaa" { + t.Fatalf("the list-as is %q after the model came back", got) + } +} diff --git a/internal/provider/plugin_relist.go b/internal/provider/plugin_relist.go index 5d488a197..d14fe29a9 100644 --- a/internal/provider/plugin_relist.go +++ b/internal/provider/plugin_relist.go @@ -79,7 +79,8 @@ func KeepPluginsListed(ctx context.Context) { } // pluginListedIDs is the ids each plugin provider lists, by magpie's id for -// it, those that fell back left out: their list wasn't read. +// it, those that fell back left out: their list wasn't read. A model the +// user lists as another id is there under that one, as a pick is. func pluginListedIDs(ps []plugin.Provider) map[string]map[string]bool { out := map[string]map[string]bool{} for _, p := range ps { @@ -90,7 +91,8 @@ func pluginListedIDs(ps []plugin.Provider) map[string]map[string]bool { for _, m := range p.Models { ids[m.ID] = true } - out[PluginID(p.ID)] = ids + // picks are of the ids the user lists them by (SetModelID) + out[PluginID(p.ID)] = modelIDsOf(PluginID(p.ID)).ids(ids) } return out }