provider: a subscription's place in the order holds on a computer where its plugin has the other id (#1940, Sun1090)

Sun1090 put two plugin subscriptions first on one computer; the other
computer, synced, kept them where they were. The order is synced (the
providers part of WebDAV sync carries providers.json's order) and no
sign-in reorders it. But a built-in subscription served by its plugin is
"workbuddy-plugin" where the built-in isn't moved onto it and
"workbuddy" where it is (PluginID), and whether it is moved lives in
migrations.json, which isn't synced. The order from one computer named
ids the other doesn't have, and ordered() put those providers last.

ordered() now ranks a provider whose own id the order doesn't name by
its counterpart (id <-> id-plugin), only for the built-in subscription
ids (accountIDs), so a custom provider ending in -plugin is only itself.
An id the order names itself still wins.

Run: TestOrderKeepsAPluginsPlaceByEitherID passes; with the lookup taken
out it fails ("not moved here: [zhipu deepseek workbuddy-plugin
workbuddy-ai-plugin]"). go test ./internal/provider ok; gofmt -l clean;
go vet and GOOS=linux / GOOS=windows go vet -tags nogui
./internal/provider ok. Not tried across two real computers; the
reporter's ids are asked on the issue.
This commit is contained in:
yetone
2026-10-13 16:26:10 +08:00
parent 38bd14dbfd
commit 9c922b9f77
2 changed files with 67 additions and 0 deletions
+21
View File
@@ -3,6 +3,7 @@ package provider
import (
"fmt"
"slices"
"strings"
)
// ordered is ps in the order the user put them in (#499): those order
@@ -25,12 +26,32 @@ func ordered(ps []Provider, order []string) []Provider {
if i, ok := at[p.ID]; ok {
return i
}
if i, ok := at[samePlace(p.ID)]; ok {
return i
}
return len(order)
}
slices.SortStableFunc(ps, func(a, b Provider) int { return rank(a) - rank(b) })
return ps
}
// samePlace is the id the same subscription has on another computer: a
// built-in's plugin is id-plugin where the built-in isn't moved onto it
// and id where it is (PluginID), and whether it is moved is each
// computer's own (migrations.json isn't synced). An order synced from
// the other computer names it by the other id, and it keeps its place by
// that one (#1940, Sun1090: WorkBuddy and WorkBuddy AI, put first on one
// computer, weren't on the other).
func samePlace(id string) string {
if base, ok := strings.CutSuffix(id, "-plugin"); ok && slices.Contains(accountIDs, base) {
return base
}
if slices.Contains(accountIDs, id) {
return id + "-plugin"
}
return ""
}
// SetOrder saves the order the providers are listed and tried in, by id.
// Every id must be a provider's, once; the ones left out follow those
// named, as they are now, so a provider added later goes after them all.
+46
View File
@@ -100,3 +100,49 @@ func TestMirrorOrder(t *testing.T) {
t.Fatalf("listed: %v", listed)
}
}
// #1940 (Sun1090): WorkBuddy and WorkBuddy AI were put first on one
// computer, and the order synced to another kept them where they were. A
// subscription served by its plugin is workbuddy-plugin where the built-in
// isn't moved onto it and workbuddy where it is, and that is each
// computer's own, so the order synced names it by the other computer's id.
// It keeps its place by either.
func TestOrderKeepsAPluginsPlaceByEitherID(t *testing.T) {
ps := func(ids ...string) []Provider {
var out []Provider
for _, id := range ids {
out = append(out, Provider{ID: id})
}
return out
}
ids := func(ps []Provider) []string {
var out []string
for _, p := range ps {
out = append(out, p.ID)
}
return out
}
// put in order where both were moved: workbuddy-ai, workbuddy
order := []string{WorkBuddyAIID, "workbuddy", "zhipu", "deepseek"}
// here neither is moved, so the plugin signed in under its own id
got := ids(ordered(ps("zhipu", "deepseek", "workbuddy-plugin", WorkBuddyAIID+"-plugin"), order))
if want := []string{WorkBuddyAIID + "-plugin", "workbuddy-plugin", "zhipu", "deepseek"}; !slices.Equal(got, want) {
t.Fatalf("not moved here: %v, want %v", got, want)
}
// and the other way round
order = []string{"workbuddy-plugin", WorkBuddyAIID + "-plugin", "zhipu"}
got = ids(ordered(ps("zhipu", WorkBuddyAIID, "workbuddy"), order))
if want := []string{"workbuddy", WorkBuddyAIID, "zhipu"}; !slices.Equal(got, want) {
t.Fatalf("moved here: %v, want %v", got, want)
}
// an id the order names itself wins over its counterpart's place
got = ids(ordered(ps("zhipu", "workbuddy", "workbuddy-plugin"), []string{"workbuddy-plugin", "zhipu", "workbuddy"}))
if want := []string{"workbuddy-plugin", "zhipu", "workbuddy"}; !slices.Equal(got, want) {
t.Fatalf("both here: %v, want %v", got, want)
}
// a custom provider whose id ends in -plugin is only itself
got = ids(ordered(ps("zhipu", "my-plugin", "my"), []string{"my", "zhipu"}))
if want := []string{"my", "zhipu", "my-plugin"}; !slices.Equal(got, want) {
t.Fatalf("custom: %v, want %v", got, want)
}
}