diff --git a/internal/provider/migrate.go b/internal/provider/migrate.go index 24928cd6d..a7988bda4 100644 --- a/internal/provider/migrate.go +++ b/internal/provider/migrate.go @@ -379,10 +379,12 @@ func Moved(id string) bool { } // movedAgent is whether the logins.json agent's accounts are a moved -// built-in's, its plugin's now. +// built-in's, its plugin's now. Retired is not enough: a retired +// built-in's own account, the agent's own sign-in, still has to be listed +// for its mover to take it (MoveRetiring, MoveCandidates). func movedAgent(agent string) bool { for id, mv := range movers { - if slices.Contains(mv.agents, agent) && PluginServes(id) { + if slices.Contains(mv.agents, agent) && Moved(id) { return true } } diff --git a/internal/provider/migrate_movers_c_test.go b/internal/provider/migrate_movers_c_test.go index ad326ca12..e18e29713 100644 --- a/internal/provider/migrate_movers_c_test.go +++ b/internal/provider/migrate_movers_c_test.go @@ -47,7 +47,7 @@ func movingOf(t *testing.T, id string) map[string]Moving { return out } -// Kiro's own sign-in stays the plugin's to read, an account magpie signed in whole, +// Kiro's own sign-in goes as a marker, an account magpie signed in whole, // the provider's key as an API key account (off the provider while the // plugin has it); back, a renewed sign-in is written into its home, one // signed in since gets a home, and the key goes back onto the provider. @@ -70,10 +70,10 @@ func TestKiroMover(t *testing.T) { if k := ms["Kiro API key"]; !k.First || k.Auth["type"] != "api" || k.Auth["key"] != "ksk_1" || k.Auth["accountId"] != "Kiro API key" { t.Fatalf("the key: %+v", k) } - // with the built-in retired, kiro-cli's or the IDE's own sign-in is the - // plugin's to read (movedAgent): nothing of it goes in the move - if own, ok := ms["Kiro account"]; ok { - t.Fatalf("Kiro's own went along: %+v", own) + // retired and not moved, the own sign-in still goes, as a marker + own := ms["Kiro account"] + if !own.Own || own.First || own.Auth["source"] != "kiro" || own.Auth["access"] != "" { + t.Fatalf("Kiro's own: %+v", own) } // with the key, the built-in used nothing else: b goes along off b := ms["b@x"] @@ -112,8 +112,8 @@ func TestKiroMover(t *testing.T) { if c, ok := readKiroFile(filepath.Join(nx.Home, kiroTokenFile)); !ok || c.access != "n-a" || !c.social { t.Fatalf("n@x's home: %+v", c) } - // Kiro's own, as the plugin marks it: nothing to write - if ls2, user, err := movers["kiro"].back(ls, "Kiro account", map[string]any{"type": "oauth", "source": "kiro", "accountId": "Kiro account"}); err != nil || user != "Kiro account" || len(ls2) != n+1 { + // Kiro's own: nothing to write + if ls2, user, err := movers["kiro"].back(ls, "Kiro account", own.Auth); err != nil || user != "Kiro account" || len(ls2) != n+1 { t.Fatalf("Kiro's own back: %v %q", err, user) } // the key: back onto the provider once logins.json is let go, saving diff --git a/internal/provider/migrate_retired_test.go b/internal/provider/migrate_retired_test.go index fb0ded2ce..d91a5db8a 100644 --- a/internal/provider/migrate_retired_test.go +++ b/internal/provider/migrate_retired_test.go @@ -1,6 +1,7 @@ package provider import ( + "path/filepath" "strings" "testing" ) @@ -37,3 +38,24 @@ func TestRetiredBuiltinIsThePlugins(t *testing.T) { t.Fatalf("signing in to the retired built-in: %v", err) } } + +// A retired built-in's accounts not moved yet are its mover's to take, +// the agent's own sign-in too: listed as the agent's own, not left out as +// the plugin's, until the move has run. +func TestRetiredOwnAccountStillMoves(t *testing.T) { + home := signIn(t) + was := retiredBuiltins["zcode"] + retiredBuiltins["zcode"] = true + t.Cleanup(func() { retiredBuiltins["zcode"] = was }) + t.Setenv("ZCODE_CREDENTIAL_SECRET", "test-secret") + writeFile(t, filepath.Join(home, ".zcode", "v2", "credentials.json"), map[string]any{ + "oauth:zai:user_info": zcodeEncrypt(t, `{"user_id":"u1","email":"own@example.com"}`), + "account-provider:coding-plan:account:zai-individual-coding-plan:account:abc:api-key": zcodeEncrypt(t, "own.secret"), + }) + if own := movingOf(t, "zcode")["own@example.com"]; !own.Own { + t.Fatalf("ZCode's own, retired and not moved: %+v", own) + } + if c := MoveCandidates(); len(c) != 1 || c[0].ID != "zcode" || c[0].Accounts != 1 { + t.Fatalf("candidates: %+v", c) + } +}