providers: a built-in moved onto its plugin keeps its place among the accounts — the plugins' accounts were listed after every built-in, so a moved one dropped to the end of the providers list, and of the order routing and the agents' model lists follow. One a built-in was moved onto now stands where the built-in stood; a plugin's own provider still goes last. TestMovedAccountKeepsItsPlace fails without the change.

This commit is contained in:
yetone
2026-10-01 03:41:46 +08:00
parent 8756ece70c
commit aed5e30d43
2 changed files with 48 additions and 1 deletions
+29 -1
View File
@@ -847,7 +847,35 @@ func Accounts() []Provider {
}
// a built-in moved onto its plugin is the plugin's now (migrate.go)
out = slices.DeleteFunc(out, func(p Provider) bool { return Moved(p.ID) })
return append(out, pluginAccounts()...)
return placeMoved(out, pluginAccounts())
}
// builtinOrder is the built-ins' ids in the order Accounts lists them.
var builtinOrder = slices.Concat([]string{"claude", "codex", "copilot", "cursor", "grok", "devin", "kiro", "zcode",
"workbuddy", WorkBuddyAIID, CommandCodePlanID}, qoderAgents, []string{"zed", "factory", MiMoID, "gemini", "antigravity"})
// placeMoved adds the plugins' accounts to the built-ins': one a built-in
// was moved onto stands where the built-in stood, the others go last.
func placeMoved(out, plugins []Provider) []Provider {
at := func(id string) int {
if i := slices.Index(builtinOrder, id); i >= 0 {
return i
}
return len(builtinOrder)
}
var rest []Provider
for _, p := range plugins {
if !Moved(p.ID) || !slices.Contains(builtinOrder, p.ID) {
rest = append(rest, p)
continue
}
i := slices.IndexFunc(out, func(q Provider) bool { return !q.IsPlugin() && at(q.ID) > at(p.ID) })
if i < 0 {
i = len(out)
}
out = slices.Insert(out, i, p)
}
return append(out, rest...)
}
func readJSON(path string, v any) bool {
+19
View File
@@ -1,6 +1,7 @@
package provider
import (
"slices"
"testing"
"github.com/yetone/magpie/internal/catalog"
@@ -74,3 +75,21 @@ func TestPluginCatalogPriceAndImages(t *testing.T) {
t.Errorf("a model not said of: %v", *in)
}
}
// A built-in moved onto its plugin stands where the built-in stood among
// the accounts; a plugin's own provider goes last.
func TestMovedAccountKeepsItsPlace(t *testing.T) {
_, grok := movedGrok(t)
fake := pluginProvider(plugin.Provider{ID: "fakeco"}, pluginLogin{})
out := placeMoved([]Provider{{ID: "claude"}, {ID: "codex"}, {ID: "zed"}, {ID: "gemini"}}, []Provider{fake, grok})
var ids []string
for _, p := range out {
ids = append(ids, p.ID)
}
if want := []string{"claude", "codex", "grok", "zed", "gemini", "fakeco"}; !slices.Equal(ids, want) {
t.Fatalf("accounts %v, want %v", ids, want)
}
if !out[2].IsPlugin() {
t.Fatal("the moved Grok isn't its plugin's")
}
}