plugin: a lapsed account kept first doesn't say the provider fell back (#4917)

The provider's own row took fellBack and listError from its first
account's listing, whatever stood first in the sign-ins. With a lapsed
sign-in kept under the provider's own key beside a live account (a Kiro
oauth the vendor turned away beside the API key in use), the provider
said its list had fallen back although the live account's list told it:
the models are the accounts' union, so the provider falls back only when
no account tells a list of its own. Reading that row, keepListed put the
last list told over the fresh one and the relist stopped dropping the
picks of models the vendor no longer lists, for as long as the lapsed
account stood first; magpie plugin list said the provider fell back.

The last list told is still kept where every account fell back.

Review: applied as ggbdpq posted it (patch sha256 checked against the
issue's). Broken by hand at the reviewed head: host.js reverted to its
parent, TestLapsedFirstAccountKeepsTheProvidersList red; restored,
green.

Run at the pushed tree (this stack of nine on origin/main 3c2dceb34),
on mote (macOS arm64, Go 1.26.8):
- go test -count=1 -timeout 45m ./internal/catalog/...
  ./internal/plugin/... ./internal/davsync/... ./internal/gateway/...:
  catalog, plugin and davsync ok; gateway red on one test only,
  TestCodexPoolSaysTheClientsVersion, the open #4807 (another test's
  Codex identity reaches it in a full package run). It passes run
  alone at this tree, 3 of 3.
- go vet ./... (darwin); GOOS=linux and GOOS=windows go vet -tags
  nogui ./...: ok. gofmt -l on every tracked .go file: clean.
- The hand breaks above ran on this stack before its rebase onto
  3c2dceb34. That commit changed member.go only, nothing these tests
  reach.
Not tried: the GUI suite, since no GUI file changed. Windows and Linux
test runs (the Claude bridge tests use a shell fake and skip on
Windows). No real vendor, Claude Code or network was used; every
case runs against fakes.

Generated-by: GLM-5.3-Flash (ZCode)
This commit is contained in:
ggbdpq
2026-11-03 07:43:18 +08:00
committed by yetone
parent d97e52aea5
commit 29bd947c62
2 changed files with 83 additions and 2 deletions
+8 -2
View File
@@ -2149,6 +2149,12 @@ function rowOf(id, a, keys, stored, p, own) {
for (const q of own) for (const [k, m] of Object.entries(q?.models ?? {})) models[k] ??= m
const ids = (q) => Object.values(q.models).filter((m) => m.status !== "deprecated").map((m) => m.id)
const first = stored[keys[0]]
// the provider's list is its accounts' union, so it fell back only when
// no account told a list of its own: a lapsed account kept first beside
// a live one doesn't say the provider fell back, and its list goes on
// moving (the last one told is kept for a provider whose every account
// fell back) (#4917)
const fellBack = keys.length > 0 && !!p.fellBack && own.every((q) => !q || q.fellBack || q.failed)
return {
id,
spec: a.spec,
@@ -2168,8 +2174,8 @@ function rowOf(id, a, keys, stored, p, own) {
signedIn: keys.length > 0,
authType: first?.type ?? "",
accountId: whoOf(first),
fellBack: keys.length > 0 && !!p.fellBack,
listError: keys.length > 0 && p.fellBack ? p.listError ?? "" : "",
fellBack,
listError: fellBack ? p.listError ?? "" : "",
accounts: keys.map((k, i) => ({
key: k,
type: stored[k]?.type ?? "",
+75
View File
@@ -5,6 +5,7 @@ import (
"net/http"
"net/http/httptest"
"path/filepath"
"slices"
"sync/atomic"
"testing"
"time"
@@ -79,3 +80,77 @@ func listSaysWhy(t *testing.T, throws string) {
}
}
}
// A lapsed account kept first in the sign-ins (#4917) fails its own list,
// but one it stands beside lists fine: the provider's list is the accounts'
// union, so the provider hasn't fallen back, and the list it told goes
// when its vendor's changes — the last one told is kept for a provider
// whose every account fell back, not for one whose list was told.
func TestLapsedFirstAccountKeepsTheProvidersList(t *testing.T) {
sandbox(t)
Restart()
provMu.Lock()
provCache = nil
provMu.Unlock()
var name atomic.Value
name.Store("extra")
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(name.Load().(string)))
}))
defer srv.Close()
t.Setenv("FAKE_MODELS", srv.URL+"/models")
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel()
abs, _ := filepath.Abs("testdata/fake/index.js")
if _, err := Add(ctx, abs); err != nil {
t.Fatal(err)
}
// a lapsed sign-in under the provider's own key, a live one beside it,
// as a Kiro oauth the vendor turned away kept first beside an API key
if _, err := Import(ctx, "fakeco", map[string]any{"type": "oauth", "refresh": "r-dead", "access": "stale", "expires": time.Now().Add(time.Hour).UnixMilli(), "accountId": "Lapsed"}); err != nil {
t.Fatal(err)
}
if _, err := APIKey(ctx, "fakeco", 0, nil, "live", NewAccount); err != nil {
t.Fatal(err)
}
has := func(ps []Provider, id string) bool {
t.Helper()
if len(ps) != 1 || len(ps[0].Accounts) != 2 {
t.Fatalf("Providers = %+v", ps)
}
return slices.ContainsFunc(ps[0].Models, func(m Model) bool { return m.ID == id })
}
ps, err := Providers(ctx)
if err != nil || !has(ps, "fake-extra") {
t.Fatalf("with the vendor up, Providers = %+v, %v", ps, err)
}
// the lapsed account fell back; the provider, listing by the live one,
// didn't
if ps[0].FellBack || ps[0].ListError != "" {
t.Fatalf("a lapsed first account said the provider fell back saying %q (fellBack %v)", ps[0].ListError, ps[0].FellBack)
}
var lapsed, live *Account
for i := range ps[0].Accounts {
if ps[0].Accounts[i].Type == "oauth" {
lapsed = &ps[0].Accounts[i]
} else {
live = &ps[0].Accounts[i]
}
}
if lapsed == nil || !lapsed.FellBack || lapsed.ListError == "" {
t.Fatalf("the lapsed account says %+v", lapsed)
}
if live == nil || live.FellBack || live.ListError != "" {
t.Fatalf("the live account says %+v", live)
}
// the vendor's list changes: the provider's follows it, though its
// first account stays lapsed
name.Store("newer")
if ps, err = Providers(ctx); err != nil || !has(ps, "fake-newer") || has(ps, "fake-extra") {
t.Fatalf("with the vendor's list changed, Providers = %+v, %v", ps, err)
}
if ps[0].FellBack {
t.Fatalf("a lapsed first account says the provider fell back")
}
}