provider: a retired built-in's own account is still listed for its mover

movedAgent asked PluginServes(id) since cfa262509, so once a built-in
is retired sideLogins leaves the agent's own sign-in out as the
plugin's, though nothing has moved it. The mover's out() then never
lists it: MoveRetiring doesn't move it and MoveCandidates doesn't show
it in the Move line, so a user whose only account is the agent's own
(ZCode's, Kiro's, Grok's, ...) would be served by nothing once that
built-in is retired. movedAgent asks Moved(id) again: the own row is
set aside only after a real move.

New: TestRetiredOwnAccountStillMoves retires zcode in the test and
checks ZCode's own account is in its mover's list and in
MoveCandidates.

Run in this worktree (at 488ed5895 plus this change):
  go test -tags nogui -count=1 -run TestRetiredOwnAccountStillMoves
    ./internal/provider: red with movedAgent back on PluginServes
    ("ZCode's own, retired and not moved: {User: ... Own:false}"),
    green with the fix.
  go test -tags nogui -count=1 -run 'Retired|Mover|Migrat|Move|
    SideLogin|Own' ./internal/provider ./internal/gateway ./internal/cli
    ./internal/gui: ok (all four)
  gofmt -l internal: nothing; go vet -tags nogui ./internal/provider
    for darwin, linux, windows: clean.
Not run: whole packages, the full suite, the GUI suite (machine load
~300).
This commit is contained in:
yetone
2026-10-17 23:11:00 +08:00
parent 30fcbf684b
commit b98f906b10
3 changed files with 33 additions and 9 deletions
+4 -2
View File
@@ -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
}
}
+7 -7
View File
@@ -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
+22
View File
@@ -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)
}
}