Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

provider: the WorkBuddy mover tells two accounts of one nickname apart by uid

yetonea30aed01627d
diff --git a/internal/provider/migrate.go b/internal/provider/migrate.go
index a041009df..212738222 100644
--- a/internal/provider/migrate.go
+++ b/internal/provider/migrate.go
@@ -181,6 +181,9 @@ type movedAccount struct {
Key string `json:"key"`
User string `json:"user"`
Own bool `json:"own,omitempty"`
+ // ID is the vendor's id of the account (WorkBuddy's uid), where the
+ // mover reads one: two accounts of one name are told apart by it.
+ ID string `json:"id,omitempty"`
// Was is what the plugin kept at Key before, when the user had signed
// in to the same account through the plugin already.
Was map[string]any `json:"was,omitempty"`
@@ -199,28 +202,39 @@ func signinHash(a map[string]any) string {
// sent: the built-in renewed them while the move went on (a request, a
// refresh) and, a refresh token being spent once used, the plugin's copy
// may be dead.
-func renewedSince(mv *mover, moved []movedAccount) []string {
+func renewedSince(mv *mover, moved []movedAccount) []movedAccount {
now, err := mv.out()
if err != nil {
return nil
}
- var out []string
+ var out []movedAccount
for _, ma := range moved {
if ma.Own {
continue
}
- for _, a := range now {
- if strings.EqualFold(a.User, ma.User) && signinHash(a.Auth) != ma.Sent {
- out = append(out, ma.User)
- }
+ if slices.ContainsFunc(now, func(a Moving) bool { return !a.Own && a.same(ma) && signinHash(a.Auth) != ma.Sent }) {
+ out = append(out, ma)
}
}
return out
}
+// same is whether a is the account moved as ma: by the vendor's id where
+// both have one, a name being no one's own (wakkana on Discord), else by
+// name.
+func (a Moving) same(ma movedAccount) bool {
+ if a.ID != "" && ma.ID != "" {
+ return a.ID == ma.ID
+ }
+ return strings.EqualFold(a.User, ma.User)
+}
+
// Moving is one of a built-in's accounts on its way to the plugin.
type Moving struct {
- User string
+ User string
+ // ID is the vendor's id of the account, where the built-in kept one
+ // (WorkBuddy's uid).
+ ID string
First, On bool
// Lapsed is an account the vendor already refused: it goes along, but
// isn't tried.
@@ -695,7 +709,7 @@ func move(ctx context.Context, id string, mv *mover) (err error) {
if err != nil {
return fmt.Errorf("%s: %w", a.User, err)
}
- ma := movedAccount{Key: key, User: a.User, Own: a.Own, Was: before[key], Sent: signinHash(a.Auth)}
+ ma := movedAccount{Key: key, User: a.User, Own: a.Own, ID: a.ID, Was: before[key], Sent: signinHash(a.Auth)}
moved = append(moved, ma)
if err := setMigration(id, func(m *Migration) { m.Accounts = moved }); err != nil {
return err
@@ -776,7 +790,11 @@ func keepOrder(pp plugin.Provider, accts []Moving, moved []movedAccount) error {
// commitMove hands the id over: the built-in's accounts go aside.
func commitMove(id string, mv *mover, moved []movedAccount, installed bool, host string) error {
if r := renewedSince(mv, moved); len(r) > 0 {
- return fmt.Errorf("%s renewed while moving; tried again later", strings.Join(r, ", "))
+ var users []string
+ for _, ma := range r {
+ users = append(users, ma.User)
+ }
+ return fmt.Errorf("%s renewed while moving; tried again later", strings.Join(users, ", "))
}
var kept json.RawMessage
if mv.take != nil {
@@ -855,7 +873,7 @@ func putBack(ctx context.Context, id string, mv *mover, why string) {
}
renewed := renewedSince(mv, m.Accounts)
skip := func(ma movedAccount, a map[string]any) bool {
- return signinHash(a) == ma.Sent || slices.ContainsFunc(renewed, func(u string) bool { return strings.EqualFold(u, ma.User) })
+ return signinHash(a) == ma.Sent || slices.ContainsFunc(renewed, func(r movedAccount) bool { return r.Key == ma.Key })
}
_, _, _ = handBack(ctx, id, mv, m.Accounts, keys, skip, nil, func(ls []savedLogin, _ map[string]string) []savedLogin { return ls })
for _, ma := range m.Accounts {
diff --git a/internal/provider/migrate_movers_c_test.go b/internal/provider/migrate_movers_c_test.go
index e18e29713..ea43545e5 100644
--- a/internal/provider/migrate_movers_c_test.go
+++ b/internal/provider/migrate_movers_c_test.go
@@ -2,6 +2,7 @@ package provider
import (
"encoding/json"
+ "fmt"
"github.com/yetone/magpie/internal/catalog"
"github.com/yetone/magpie/internal/update"
"os"
@@ -193,6 +194,40 @@ func TestWorkBuddyMover(t *testing.T) {
}
}
+// Two WorkBuddy accounts of one nickname are two accounts, told apart by
+// uid: the desktop's goes beside one magpie signed in under its name, and
+// neither reads as renewed by the other (wakkana on Discord). The same uid
+// under the desktop's name is the desktop's account, moved once.
+func TestWorkBuddyMoverSameNameOtherUID(t *testing.T) {
+ home := signIn(t)
+ wbWriteOwn(t, home, "own-access") // "Me", u1
+ other := wbCreds{UID: "u9", Access: "a9", Refresh: "r9", ExpiresAt: 1_900_000_000_000}
+ saveLogins(t, savedLogin{Agent: "workbuddy", User: "Me", On: true, Auth: json.RawMessage(jsonText(other))})
+ ms, err := movers["workbuddy"].out()
+ if err != nil {
+ t.Fatal(err)
+ }
+ uids := map[string]bool{}
+ var moved []movedAccount
+ for i, m := range ms {
+ uids[str(m.Auth["uid"])+map[bool]string{true: " desktop"}[m.Own]] = true
+ moved = append(moved, movedAccount{Key: fmt.Sprint("k", i), User: m.User, Own: m.Own, ID: m.ID, Sent: signinHash(m.Auth)})
+ }
+ if len(ms) != 2 || !uids["u1 desktop"] || !uids["u9"] {
+ t.Fatalf("moving %+v", ms)
+ }
+ if r := renewedSince(movers["workbuddy"], moved); len(r) != 0 {
+ t.Fatalf("read as renewed: %+v", r)
+ }
+
+ same := other
+ same.UID = "u1"
+ saveLogins(t, savedLogin{Agent: "workbuddy", User: "Me", On: true, Auth: json.RawMessage(jsonText(same))})
+ if ms := movingOf(t, "workbuddy"); len(ms) != 1 || ms["Me"].Auth["access"] != "a9" {
+ t.Fatalf("the same uid: %+v", ms)
+ }
+}
+
// wbWriteOwn signs WorkBuddy desktop in under home, as its app does.
func wbWriteOwn(t *testing.T, home string, access any) {
t.Helper()
diff --git a/internal/provider/migrate_workbuddy.go b/internal/provider/migrate_workbuddy.go
index 90126ee0b..0ac91e0bd 100644
--- a/internal/provider/migrate_workbuddy.go
+++ b/internal/provider/migrate_workbuddy.go
@@ -21,7 +21,7 @@ func init() {
out: func() ([]Moving, error) {
var out []Moving
for _, a := range wbLogins(w) {
- m := Moving{User: a.User, First: a.Active, On: a.On, Lapsed: a.Lapsed != "", Own: a.own, Plan: a.Plan}
+ m := Moving{User: a.User, ID: a.creds.UID, First: a.Active, On: a.On, Lapsed: a.Lapsed != "", Own: a.own, Plan: a.Plan}
if a.own {
m.Auth = map[string]any{"type": "oauth", "source": "desktop", "access": "", "refresh": "", "expires": 0,
"accountId": a.User, "uid": a.creds.UID}
diff --git a/internal/provider/workbuddy.go b/internal/provider/workbuddy.go
index abd8298e7..4d848c96c 100644
--- a/internal/provider/workbuddy.go
+++ b/internal/provider/workbuddy.go
@@ -230,6 +230,16 @@ func wbLogins(w *wbSite) []wbAccount {
}
out = append(out, a)
}
+ // one magpie signed in under the desktop's name stands for the
+ // desktop's only when it is the same uid: a nickname is no one's own, so
+ // another account of that name leaves the desktop's its own place
+ // (wakkana on Discord), as the plugin keeps both
+ // (one removed in magpie stays out)
+ if hasOwn && !slices.ContainsFunc(out, func(a wbAccount) bool { return a.own || a.creds.UID == own.UID }) &&
+ slices.ContainsFunc(out, func(a wbAccount) bool { return strings.EqualFold(a.User, ownUser) }) &&
+ !slices.ContainsFunc(readLogins(), func(l savedLogin) bool { return l.Agent == w.id && l.own() && l.Hidden != "" }) {
+ out = append(out, wbAccount{Login: Login{Agent: w.id, User: ownUser, On: true, Own: true}, site: w, own: true, creds: own})
+ }
return out
}