Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(auth): release account switch state

xd-boboa41c6f34e35b
diff --git a/apps/desktop/src/renderer/components/sidebar/AccountSwitcherDialog.tsx b/apps/desktop/src/renderer/components/sidebar/AccountSwitcherDialog.tsx
index a225aa1cfa..6eb2d2245f 100644
--- a/apps/desktop/src/renderer/components/sidebar/AccountSwitcherDialog.tsx
+++ b/apps/desktop/src/renderer/components/sidebar/AccountSwitcherDialog.tsx
@@ -104,10 +104,7 @@ export function AccountSwitcherDialog({
if (hasRunningTask) {
// Full app windows always provide the shared confirmation host. Standalone
// story/test mounts fail closed instead of switching without consent.
- if (!confirmDialog) {
- setSwitchingKey(null);
- return;
- }
+ if (!confirmDialog) return;
const confirmed = await confirmDialog.confirm({
title: t('sidebar.accountSwitcher.runningTaskTitle'),
description: t('sidebar.accountSwitcher.runningTaskDescription'),
@@ -115,10 +112,7 @@ export function AccountSwitcherDialog({
cancelText: t('logic.confirm.cancel'),
confirmVariant: 'destructive',
});
- if (!confirmed) {
- setSwitchingKey(null);
- return;
- }
+ if (!confirmed) return;
}
// Main owns the account boundary: it stops and drains the outgoing runtime
@@ -127,6 +121,7 @@ export function AccountSwitcherDialog({
onOpenChange(false);
} catch {
toast.error(t('sidebar.accountSwitcher.switchFailed'));
+ } finally {
setSwitchingKey(null);
}
};
diff --git a/apps/desktop/src/renderer/components/sidebar/__tests__/AccountSwitcherDialog.test.tsx b/apps/desktop/src/renderer/components/sidebar/__tests__/AccountSwitcherDialog.test.tsx
index 545df189f2..8ca372f779 100644
--- a/apps/desktop/src/renderer/components/sidebar/__tests__/AccountSwitcherDialog.test.tsx
+++ b/apps/desktop/src/renderer/components/sidebar/__tests__/AccountSwitcherDialog.test.tsx
@@ -1,6 +1,6 @@
// @vitest-environment jsdom
-import { createRef } from 'react';
+import { createRef, useState } from 'react';
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
@@ -199,4 +199,40 @@ describe('AccountSwitcherDialog', () => {
await waitFor(() => expect(switchAccount).toHaveBeenCalledWith('org-key'));
expect(onOpenChange).toHaveBeenCalledWith(false);
});
+
+ it('releases the switching state after success so the dialog can be used again', async () => {
+ function Harness() {
+ const [open, setOpen] = useState(true);
+ return (
+ <>
+ <button type="button" onClick={() => setOpen(true)}>
+ reopen
+ </button>
+ <AccountSwitcherDialog
+ open={open}
+ onOpenChange={setOpen}
+ onAddAccount={vi.fn()}
+ triggerRef={createRef<HTMLButtonElement>()}
+ />
+ </>
+ );
+ }
+
+ render(<Harness />);
+
+ fireEvent.click(await screen.findByRole('button', { name: /Example CorpOrganization Cindy/ }));
+ await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull());
+
+ fireEvent.click(screen.getByRole('button', { name: 'reopen' }));
+
+ const switchButton = await screen.findByRole('button', {
+ name: /Example CorpOrganization Cindy/,
+ });
+ expect((switchButton as HTMLButtonElement).disabled).toBe(false);
+ expect(
+ (screen.getByRole('button', {
+ name: 'sidebar.accountSwitcher.addAccount',
+ }) as HTMLButtonElement).disabled,
+ ).toBe(false);
+ });
});