GeezerVison is showing github.com — fix(gui): refresh every row on the shared Kimi login after logout or … · lidge-jun/opencodex@c3a1ec9
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: gui/src/pages/Providers.tsx +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -32,7 +32,7 @@ import { canCreateJevAutoFrom } from "../jev-decision-service"; | 32 | 32 | import { useProviderSettingsDeepLink } from "./providers-deep-link"; | 33 | 33 | import { subscribeKiroDeviceFinal } from "../kiro-device-login-finalizer"; | 34 | 34 | import type { BrowserLaunch } from "../oauth-browser-launch"; | 35 | | -import { oauthCredentialSlot } from "../../../src/oauth/credential-siblings"; | | 35 | +import { oauthCredentialSiblingsOf, oauthCredentialSlot } from "../../../src/oauth/credential-siblings"; | 36 | 36 |
| 37 | 37 | /** The page's real refresh tickets: only the captured report epoch and account read can settle them. */ | 38 | 38 | // oxlint-disable-next-line react/only-export-components -- keep the page-owned coordinator and its direct race tests in the authorized owner. | @@ -163,6 +163,13 @@ function useAccountSelectionEvents( | 163 | 163 | if (value.revision <= (revisions.get(key) ?? -1)) return; | 164 | 164 | revisions.set(key, value.revision); | 165 | 165 | pending.set(key, { provider: value.provider, kind: value.kind }); | | 166 | + // One login can serve several rows (kimi, kimi-responses); the event names the slot. | | 167 | + if (value.kind === "oauth") { | | 168 | + const slot = oauthCredentialSlot(value.provider); | | 169 | + for (const row of [slot, ...oauthCredentialSiblingsOf(slot)]) { | | 170 | + if (row !== value.provider) pending.set(`${value.kind}:${row}`, { provider: row, kind: value.kind }); | | 171 | + } | | 172 | + } | 166 | 173 | flush(); | 167 | 174 | } | 168 | 175 | }; | |
Collapse file Copy file name to clipboardExpand all lines: gui/src/pages/use-providers-oauth.ts +10-7Lines changed: 10 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -12,7 +12,7 @@ import { isApiTargetCaptureCurrent, targetFetch, type ApiTargetCapture } from ". | 12 | 12 | import { errorMessageFrom } from "../api-error"; | 13 | 13 | import { useRenderTargetCapture } from "../use-render-target-capture"; | 14 | 14 | import { confirmAction } from "../action-dialogs"; | 15 | | -import { oauthCredentialSlot } from "../../../src/oauth/credential-siblings"; | | 15 | +import { oauthCredentialSiblingsOf, oauthCredentialSlot } from "../../../src/oauth/credential-siblings"; | 16 | 16 |
| 17 | 17 | type AccountSet = { activeAccountId: string | null; accounts: OAuthAccount[] }; | 18 | 18 |
| @@ -333,6 +333,9 @@ export function useProvidersOAuth({ | 333 | 333 | const logoutTarget = targetKey ?? apiBase; | 334 | 334 | // A shared-login row (Kimi (Responses)) signs out the owner's Chat row too: say so first. | 335 | 335 | const sharedOwner = oauthCredentialSlot(provider) !== provider ? oauthCredentialSlot(provider) : undefined; | | 336 | + // Every other row on this login (kimi <-> kimi-responses): logout removes their active account too. | | 337 | + const sharedRows = [oauthCredentialSlot(provider), ...oauthCredentialSiblingsOf(oauthCredentialSlot(provider))] | | 338 | + .filter(row => row !== provider); | 336 | 339 | if (sharedOwner) { | 337 | 340 | const consented = await confirmAction({ | 338 | 341 | message: t("prov.logoutConfirmShared", { provider: oauthLabel(sharedOwner) }), | @@ -358,10 +361,10 @@ export function useProvidersOAuth({ | 358 | 361 | bumpLoginGeneration(provider); | 359 | 362 | setBusy(current => current === provider ? null : current); | 360 | 363 | setLoginInfo(current => current?.provider === provider ? null : current); | 361 | | - // The shared login's flows and status reads are keyed by the owner (kimi): fence those too, | 362 | | - // so a late owner status read or login poll cannot report the removed account as signed in. | | 364 | + // Fence the other rows on this login too, and the owner's login flows (keyed by kimi), so a | | 365 | + // late status read or login poll cannot report the removed account as signed in. | | 366 | + for (const row of sharedRows) invalidateOauthStatusReads?.(row); | 363 | 367 | if (sharedOwner) { | 364 | | - invalidateOauthStatusReads?.(sharedOwner); | 365 | 368 | bumpLoginGeneration(sharedOwner); | 366 | 369 | setBusy(current => current === sharedOwner ? null : current); | 367 | 370 | setLoginInfo(current => current?.provider === sharedOwner ? null : current); | @@ -384,16 +387,16 @@ export function useProvidersOAuth({ | 384 | 387 | // A read started while the server was processing logout can still describe | 385 | 388 | // the old account. Only a read started after settlement can verify status. | 386 | 389 | if (invalidateOauthStatusReads?.(provider, false) === false) return; | 387 | | - if (sharedOwner) invalidateOauthStatusReads?.(sharedOwner); | | 390 | + for (const row of sharedRows) invalidateOauthStatusReads?.(row); | 388 | 391 | clearStatus(); | 389 | 392 | if (!success) { | 390 | | - void fetchAccountSets([provider]).catch(() => {}); | | 393 | + void fetchAccountSets([provider, ...sharedRows]).catch(() => {}); | 391 | 394 | void fetchOauth(); | 392 | 395 | return; | 393 | 396 | } | 394 | 397 | try { | 395 | 398 | await Promise.all([ | 396 | | - fetchAccountSets(sharedOwner ? [provider, sharedOwner] : [provider]), fetchOauth(), fetchConfig(), fetchProviderQuotas(true), | | 399 | + fetchAccountSets([provider, ...sharedRows]), fetchOauth(), fetchConfig(), fetchProviderQuotas(true), | 397 | 400 | ]); | 398 | 401 | bumpModelsRefresh(); | 399 | 402 | if (targetKeyRef.current === logoutTarget && isApiTargetCaptureCurrent(capture)) | |
Collapse file Copy file name to clipboardExpand all lines: gui/tests/provider-revalidation-policy.test.tsx +31Lines changed: 31 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -227,6 +227,37 @@ for (const kind of ["oauth", "key", "codex"] as const) { | 227 | 227 | }); | 228 | 228 | } | 229 | 229 |
| | 230 | +test("a Kimi account selection event also re-reads the Kimi (Responses) accounts that share the login (#8087)", async () => { | | 231 | + let stream!: ReadableStreamDefaultController<Uint8Array>; | | 232 | + const reads: string[] = []; | | 233 | + const encoder = new TextEncoder(); | | 234 | + const send = (event: string, data: unknown) => { stream.enqueue(encoder.encode(`event: ${event}\r\ndata: ${JSON.stringify(data)}\r\n\r\n`)); }; | | 235 | + const kimiRow = { adapter: "openai-chat", authMode: "oauth", hasApiKey: false, baseUrl: "https://api.kimi.com/coding/v1" }; | | 236 | + Object.defineProperty(globalThis, "fetch", { configurable: true, value: async (input: RequestInfo | URL) => { | | 237 | + const url = new URL(String(input), "http://localhost"); | | 238 | + reads.push(url.pathname + url.search); | | 239 | + if (url.pathname === "/api/accounts/events") { | | 240 | + return new Response(new ReadableStream<Uint8Array>({ start(controller) { stream = controller; } }), { headers: { "Content-Type": "text/event-stream" } }); | | 241 | + } | | 242 | + if (url.pathname === "/api/config") return Response.json({ port: 10100, defaultProvider: "kimi", providers: { | | 243 | + kimi: kimiRow, "kimi-responses": { ...kimiRow, adapter: "openai-responses" } } }); | | 244 | + if (url.pathname === "/api/oauth/providers") return Response.json({ providers: ["kimi"] }); | | 245 | + if (url.pathname === "/api/oauth/status") return Response.json({ loggedIn: true }); | | 246 | + if (url.pathname === "/api/oauth/accounts") return Response.json({ activeAccountId: "a", accounts: [{ id: "a", active: true, quotaMode: "probe" }] }); | | 247 | + if (url.pathname === "/api/codex-auth/accounts") return Response.json({ accounts: [] }); | | 248 | + if (url.pathname === "/api/provider-quotas") return Response.json({ reports: [] }); | | 249 | + if (url.pathname === "/api/selected-models") return Response.json({ models: {} }); | | 250 | + if (url.pathname === "/api/usage") return Response.json({ providers: [], models: [] }); | | 251 | + return Response.json({}); | | 252 | + } }); | | 253 | + await act(async () => { root = createRoot(container); root.render(<LanguageProvider><Providers apiBase="" /></LanguageProvider>); }); | | 254 | + await act(async () => { send("ready", { revision: 0 }); }); | | 255 | + const siblingReads = () => reads.filter(path => path.startsWith("/api/oauth/accounts?") && path.includes("provider=kimi-responses")).length; | | 256 | + const before = siblingReads(); | | 257 | + await act(async () => { send("account-selection", { provider: "kimi", kind: "oauth", revision: 1 }); }); | | 258 | + expect(siblingReads()).toBeGreaterThan(before); | | 259 | +}); | | 260 | + | 230 | 261 | for (const kind of ["oauth", "api-key"] as const) { | 231 | 262 | test(`${kind} selection event updates the rendered active row without a poll tick or quota probe`, async () => { | 232 | 263 | const name = kind === "oauth" ? "cursor" : "deepseek"; | |
Collapse file Copy file name to clipboardExpand all lines: gui/tests/provider-shared-account-controls.test.tsx +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -170,6 +170,20 @@ test("logging out from Kimi (Responses) confirms that the Kimi Chat row is signe | 170 | 170 | } | 171 | 171 | }); | 172 | 172 |
| | 173 | +test("logging out from the Kimi row refreshes the Kimi (Responses) accounts too, without the sibling confirmation", async () => { | | 174 | + await mount(<LogoutHarness />); | | 175 | + const consent = spyOn(dialogs, "confirmAction").mockResolvedValue(true); | | 176 | + try { | | 177 | + await act(async () => { await logout("kimi"); }); | | 178 | + expect(consent).not.toHaveBeenCalled(); | | 179 | + expect(puts).toEqual([{ method: "POST", url: "/shared-hook/api/oauth/logout?provider=kimi", body: undefined }]); | | 180 | + expect(refetchedSets).toEqual(expect.arrayContaining(["kimi", "kimi-responses"])); | | 181 | + expect(invalidated).toContain("kimi-responses"); | | 182 | + } finally { | | 183 | + consent.mockRestore(); | | 184 | + } | | 185 | +}); | | 186 | + | 173 | 187 | test("a sibling logout also fences the owner's status reads and login hint", async () => { | 174 | 188 | await mount(<LogoutHarness />); | 175 | 189 | const consent = spyOn(dialogs, "confirmAction").mockResolvedValue(true); | |
Collapse file Copy file name to clipboardExpand all lines: structure/providers/oauth-credential-siblings.md +2-1Lines changed: 2 additions & 1 deletion - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -47,7 +47,8 @@ with `row: "kimi-responses"`. A sibling row's status and login buttons resolve t | 47 | 47 | login capture and Cancel, so a Kimi device login started from Kimi (Responses) shows its code there; a | 48 | 48 | login that settles selects the row it published. Selecting, pausing or deleting an account through either | 49 | 49 | row clears both rows' model caches, and a manual selection seeds both rows' rotation cursors | 50 | | -(`seedGenericPoolSelection`). | | 50 | +(`seedGenericPoolSelection`). In the dashboard, a logout from either row and an account-selection event for the | | 51 | +login refresh the accounts of every row on it. | 51 | 52 | Its Accounts panel lists the owner's accounts, and every control there acts on the shared account (owner | 52 | 53 | decision on #8087): the panel says so, and removing an account or pausing one (which stops the owner's | 53 | 54 | Chat row from using it too) asks for confirmation that names the owner's row | |
|