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(desktop): 修复 ChatGPT 失效后的重新登录入口 (#2192)

Chris Zhang72f5b4def154
diff --git a/apps/desktop/src/renderer/__tests__/providersSectionDeepLink.test.tsx b/apps/desktop/src/renderer/__tests__/providersSectionDeepLink.test.tsx
index ff577c0dc7..8a28bb1e7e 100644
--- a/apps/desktop/src/renderer/__tests__/providersSectionDeepLink.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/providersSectionDeepLink.test.tsx
@@ -178,7 +178,7 @@ afterEach(() => {
});
describe('ProvidersSection — 深链定位', () => {
- it('ChatGPT 系统共享登录失效时显示来源说明并打开 ChatGPT App', async () => {
+ it('ChatGPT 系统共享登录失效时显示来源说明并在 Cindy 中重新登录', async () => {
codexAuthState.state = {
kind: 'reconnect-required',
reason: 'token_revoked',
@@ -201,13 +201,13 @@ describe('ProvidersSection — 深链定位', () => {
'var(--remote-status-failed)',
);
expect(await screen.findByText('chatgptAuthRecovery.systemSharedInvalidated')).not.toBeNull();
- fireEvent.click(screen.getByRole('button', { name: 'chatgptAuthRecovery.openApp' }));
+ fireEvent.click(screen.getByRole('button', { name: 'chatgptAuthRecovery.relogin' }));
- await waitFor(() => expect(window.electronAPI.openChatGPTApp).toHaveBeenCalledOnce());
- expect(codexAuthActions.triggerLogin).not.toHaveBeenCalled();
+ await waitFor(() => expect(codexAuthActions.triggerLogin).toHaveBeenCalledOnce());
+ expect(window.electronAPI.openChatGPTApp).not.toHaveBeenCalled();
});
- it('ChatGPT App 打开失败时保留恢复入口并提示用户', async () => {
+ it('ChatGPT 系统共享重新登录被取消时保留恢复入口', async () => {
codexAuthState.state = {
kind: 'reconnect-required',
reason: 'token_revoked',
@@ -222,18 +222,15 @@ describe('ProvidersSection — 深链定位', () => {
models: { codex: [], 'claude-code': [] },
}),
];
- vi.mocked(window.electronAPI.openChatGPTApp).mockRejectedValueOnce(
- new Error('bridge unavailable'),
- );
+ codexAuthActions.triggerLogin.mockResolvedValueOnce('cancelled');
renderAt('?tab=providers&connect=openai');
- fireEvent.click(await screen.findByRole('button', { name: 'chatgptAuthRecovery.openApp' }));
+ fireEvent.click(await screen.findByRole('button', { name: 'chatgptAuthRecovery.relogin' }));
- await waitFor(() =>
- expect(toastError).toHaveBeenCalledWith('chatgptAuthRecovery.openAppFailed'),
- );
- expect(screen.getByRole('button', { name: 'chatgptAuthRecovery.openApp' })).not.toBeNull();
- expect(codexAuthActions.triggerLogin).not.toHaveBeenCalled();
+ await waitFor(() => expect(codexAuthActions.triggerLogin).toHaveBeenCalledOnce());
+ expect(toastError).not.toHaveBeenCalled();
+ expect(screen.getByRole('button', { name: 'chatgptAuthRecovery.relogin' })).not.toBeNull();
+ expect(window.electronAPI.openChatGPTApp).not.toHaveBeenCalled();
});
it('connect=anthropic(未占行内置渠道)→ 向导 builtin 直达;参数消费后清除', async () => {
diff --git a/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx b/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx
index 6d7616e7f4..be945bd252 100644
--- a/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx
+++ b/apps/desktop/src/renderer/components/chat/ErrorBanner.tsx
@@ -408,15 +408,6 @@ export function ErrorBanner({
await refreshOpenAiAuth();
return;
}
- if (openAiCredentialScope === 'system-shared') {
- try {
- const result = await window.electronAPI.openChatGPTApp();
- if (!result.success) toast.error(t('chatgptAuthRecovery.openAppFailed'));
- } catch {
- toast.error(t('chatgptAuthRecovery.openAppFailed'));
- }
- return;
- }
promptCodexSessionExpired(error);
};
@@ -541,8 +532,8 @@ export function ErrorBanner({
)}
</div>
{openAiReconnectRequired && (
- // 系统共享凭证必须回 ChatGPT App 修复;Cindy 独立凭证才启动 Cindy OAuth。
- // 登录候选出现后先走账号级服务端探测,探测成功前继续隐藏请求 Retry。
+ // 所有凭证来源都由 Cindy 启动可产生新 Codex 凭据的登录流程;登录候选出现后
+ // 先走账号级服务端探测,探测成功前继续隐藏请求 Retry。
<button
type="button"
onClick={() => void handleOpenAiRecovery()}
@@ -558,9 +549,7 @@ export function ErrorBanner({
? 'chatgptAuthRecovery.recheck'
: openAiRecoveryBusy
? 'chatgptAuthRecovery.checking'
- : openAiCredentialScope === 'system-shared'
- ? 'chatgptAuthRecovery.openApp'
- : 'chatgptAuthRecovery.relogin',
+ : 'chatgptAuthRecovery.relogin',
)}
>
<Spinner icon={RefreshCw} size={12} spinning={openAiRecoveryBusy} />
@@ -569,9 +558,7 @@ export function ErrorBanner({
? 'chatgptAuthRecovery.checking'
: openAiRecoveryCheck === 'failed'
? 'chatgptAuthRecovery.recheck'
- : openAiCredentialScope === 'system-shared'
- ? 'chatgptAuthRecovery.openApp'
- : 'chatgptAuthRecovery.relogin',
+ : 'chatgptAuthRecovery.relogin',
)}
</button>
)}
diff --git a/apps/desktop/src/renderer/components/chat/__tests__/ErrorBannerCodexOAuth.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/ErrorBannerCodexOAuth.test.tsx
index 0ea263c7e5..1f11412408 100644
--- a/apps/desktop/src/renderer/components/chat/__tests__/ErrorBannerCodexOAuth.test.tsx
+++ b/apps/desktop/src/renderer/components/chat/__tests__/ErrorBannerCodexOAuth.test.tsx
@@ -148,7 +148,7 @@ describe('ErrorBanner OpenAI connection recovery', () => {
expect(screen.queryByText(error)).toBeNull();
});
- it('opens the ChatGPT App for an invalidated system-shared login', async () => {
+ it('starts Cindy login for an invalidated system-shared login', async () => {
mocks.getState.mockResolvedValue({
authenticated: false,
errorReason: 'token_revoked',
@@ -166,11 +166,12 @@ describe('ErrorBanner OpenAI connection recovery', () => {
);
expect(await screen.findByText('chatgptAuthRecovery.systemSharedInvalidated')).toBeTruthy();
- fireEvent.click(screen.getByRole('button', { name: 'chatgptAuthRecovery.openApp' }));
+ fireEvent.click(screen.getByRole('button', { name: 'chatgptAuthRecovery.relogin' }));
- await waitFor(() => expect(mocks.openChatGPTApp).toHaveBeenCalledOnce());
- expect(mocks.triggerLogin).not.toHaveBeenCalled();
- expect(screen.queryByRole('button', { name: 'chat.errorBanner.retry' })).toBeNull();
+ await waitFor(() => expect(mocks.triggerLogin).toHaveBeenCalledOnce());
+ expect(mocks.openChatGPTApp).not.toHaveBeenCalled();
+ expect(await screen.findByText('chatgptAuthRecovery.recovered')).toBeTruthy();
+ expect(screen.getByRole('button', { name: 'chat.errorBanner.retry' })).toBeTruthy();
});
it('keeps the recovery action disabled until the credential source is known', async () => {
@@ -204,7 +205,7 @@ describe('ErrorBanner OpenAI connection recovery', () => {
});
await initialState.promise;
});
- expect(await screen.findByRole('button', { name: 'chatgptAuthRecovery.openApp' })).toBeTruthy();
+ expect(await screen.findByRole('button', { name: 'chatgptAuthRecovery.relogin' })).toBeTruthy();
});
it('does not restore retry on a fresh mount until the replacement account probe succeeds', async () => {
@@ -247,13 +248,16 @@ describe('ErrorBanner OpenAI connection recovery', () => {
expect(screen.getByRole('button', { name: 'chat.errorBanner.retry' })).toBeTruthy();
});
- it('keeps the recovery action available when the ChatGPT App cannot be opened', async () => {
+ it('keeps the system-shared recovery action after user cancellation', async () => {
mocks.getState.mockResolvedValue({
authenticated: false,
errorReason: 'token_revoked',
credentialScope: 'system-shared',
});
- mocks.openChatGPTApp.mockResolvedValueOnce({ success: false });
+ mocks.triggerLogin.mockResolvedValueOnce({
+ authenticated: false,
+ errorReason: 'login_cancelled',
+ });
render(
<ErrorBanner
error="token_revoked"
@@ -265,23 +269,25 @@ describe('ErrorBanner OpenAI connection recovery', () => {
/>,
);
- fireEvent.click(await screen.findByRole('button', { name: 'chatgptAuthRecovery.openApp' }));
+ fireEvent.click(await screen.findByRole('button', { name: 'chatgptAuthRecovery.relogin' }));
- await waitFor(() => {
- expect(mocks.toastError).toHaveBeenCalledWith('chatgptAuthRecovery.openAppFailed');
- });
- expect(mocks.triggerLogin).not.toHaveBeenCalled();
- expect(screen.getByRole('button', { name: 'chatgptAuthRecovery.openApp' })).toBeTruthy();
+ await waitFor(() => expect(mocks.triggerLogin).toHaveBeenCalledOnce());
+ expect(mocks.toastError).not.toHaveBeenCalled();
+ expect(mocks.openChatGPTApp).not.toHaveBeenCalled();
+ expect(screen.getByRole('button', { name: 'chatgptAuthRecovery.relogin' })).toBeTruthy();
expect(screen.queryByRole('button', { name: 'chat.errorBanner.retry' })).toBeNull();
});
- it('keeps the recovery action available when opening the ChatGPT App rejects', async () => {
+ it('keeps the system-shared recovery action after login failure', async () => {
mocks.getState.mockResolvedValue({
authenticated: false,
errorReason: 'token_revoked',
credentialScope: 'system-shared',
});
- mocks.openChatGPTApp.mockRejectedValueOnce(new Error('bridge unavailable'));
+ mocks.triggerLogin.mockResolvedValueOnce({
+ authenticated: false,
+ errorReason: 'login_timeout',
+ });
render(
<ErrorBanner
error="token_revoked"
@@ -293,13 +299,14 @@ describe('ErrorBanner OpenAI connection recovery', () => {
/>,
);
- fireEvent.click(await screen.findByRole('button', { name: 'chatgptAuthRecovery.openApp' }));
+ fireEvent.click(await screen.findByRole('button', { name: 'chatgptAuthRecovery.relogin' }));
await waitFor(() => {
- expect(mocks.toastError).toHaveBeenCalledWith('chatgptAuthRecovery.openAppFailed');
+ expect(mocks.toastError).toHaveBeenCalledWith('settings.connections.codex.toast.loginFailed');
});
- expect(mocks.triggerLogin).not.toHaveBeenCalled();
- expect(screen.getByRole('button', { name: 'chatgptAuthRecovery.openApp' })).toBeTruthy();
+ expect(mocks.triggerLogin).toHaveBeenCalledOnce();
+ expect(mocks.openChatGPTApp).not.toHaveBeenCalled();
+ expect(screen.getByRole('button', { name: 'chatgptAuthRecovery.relogin' })).toBeTruthy();
expect(screen.queryByRole('button', { name: 'chat.errorBanner.retry' })).toBeNull();
});
@@ -728,7 +735,7 @@ describe('ErrorBanner OpenAI connection recovery', () => {
expect(mocks.cancelLogin).not.toHaveBeenCalled();
});
- it('uses the system-shared voice recovery copy and opens the ChatGPT App', async () => {
+ it('uses the system-shared voice recovery copy and starts Cindy login', async () => {
mocks.getState.mockResolvedValue({
authenticated: false,
errorReason: 'token_revoked',
@@ -745,16 +752,16 @@ describe('ErrorBanner OpenAI connection recovery', () => {
expect(mocks.confirm).toHaveBeenCalledWith({
title: 'chatgptAuthRecovery.title',
description: 'chatgptAuthRecovery.systemSharedInvalidated',
- confirmText: 'chatgptAuthRecovery.openApp',
+ confirmText: 'chatgptAuthRecovery.relogin',
cancelText: 'chatgptAuthRecovery.later',
autoFocusConfirm: true,
}),
);
- await waitFor(() => expect(mocks.openChatGPTApp).toHaveBeenCalledOnce());
- expect(mocks.triggerLogin).not.toHaveBeenCalled();
+ await waitFor(() => expect(mocks.triggerLogin).toHaveBeenCalledOnce());
+ expect(mocks.openChatGPTApp).not.toHaveBeenCalled();
});
- it('keeps the original shared recovery flow when an authenticated hint cannot be verified', async () => {
+ it('starts Cindy login when an authenticated system-shared hint cannot be verified', async () => {
mocks.getState.mockResolvedValue({
authenticated: true,
identity: '[email protected]',
@@ -773,14 +780,16 @@ describe('ErrorBanner OpenAI connection recovery', () => {
expect(mocks.confirm).toHaveBeenCalledWith({
title: 'chatgptAuthRecovery.title',
description: 'chatgptAuthRecovery.systemSharedInvalidated',
- confirmText: 'chatgptAuthRecovery.openApp',
+ confirmText: 'chatgptAuthRecovery.relogin',
cancelText: 'chatgptAuthRecovery.later',
autoFocusConfirm: true,
}),
);
- await waitFor(() => expect(mocks.openChatGPTApp).toHaveBeenCalledOnce());
- expect(mocks.toastSuccess).not.toHaveBeenCalled();
- expect(mocks.triggerLogin).not.toHaveBeenCalled();
+ await waitFor(() => expect(mocks.triggerLogin).toHaveBeenCalledOnce());
+ expect(mocks.openChatGPTApp).not.toHaveBeenCalled();
+ await waitFor(() =>
+ expect(mocks.toastSuccess).toHaveBeenCalledWith('logic.toasts.codexConnected'),
+ );
});
it('localizes event-loop terminal errors from the stable reason key', () => {
diff --git a/apps/desktop/src/renderer/components/settings/ProvidersSection.tsx b/apps/desktop/src/renderer/components/settings/ProvidersSection.tsx
index ff9737c131..26c0b3eec6 100644
--- a/apps/desktop/src/renderer/components/settings/ProvidersSection.tsx
+++ b/apps/desktop/src/renderer/components/settings/ProvidersSection.tsx
@@ -591,17 +591,8 @@ function OpenAiHeader({ provider, onChanged }: { provider?: ProviderView; onChan
await refresh();
return;
}
- if (credentialScope === 'system-shared') {
- try {
- const result = await window.electronAPI.openChatGPTApp();
- if (!result.success) toast.error(t('chatgptAuthRecovery.openAppFailed'));
- } catch {
- toast.error(t('chatgptAuthRecovery.openAppFailed'));
- }
- return;
- }
await handleLogin();
- }, [credentialScope, handleLogin, loggingIn, recoveryCheck, refresh, t]);
+ }, [handleLogin, loggingIn, recoveryCheck, refresh]);
const recoveryDetail = reconnectRequired ? (
<p className="text-12 leading-relaxed text-[var(--settings-integration-subtitle)]">
@@ -632,9 +623,7 @@ function OpenAiHeader({ provider, onChanged }: { provider?: ProviderView; onChan
? 'chatgptAuthRecovery.checking'
: recoveryCheck === 'failed'
? 'chatgptAuthRecovery.recheck'
- : credentialScope === 'system-shared'
- ? 'chatgptAuthRecovery.openApp'
- : 'chatgptAuthRecovery.relogin',
+ : 'chatgptAuthRecovery.relogin',
)}
onClick={() => void handleRecovery()}
disabled={recoveryCheck === 'checking' || loggingIn}
diff --git a/apps/desktop/src/renderer/hooks/useCodexSessionExpiredPrompt.ts b/apps/desktop/src/renderer/hooks/useCodexSessionExpiredPrompt.ts
index 97c3cb9604..d4dcf3bfc9 100644
--- a/apps/desktop/src/renderer/hooks/useCodexSessionExpiredPrompt.ts
+++ b/apps/desktop/src/renderer/hooks/useCodexSessionExpiredPrompt.ts
@@ -18,7 +18,7 @@ function reconnectCopyForScope(scope: CodexCredentialScope): {
if (scope === 'system-shared') {
return {
description: 'chatgptAuthRecovery.systemSharedInvalidated',
- confirmText: 'chatgptAuthRecovery.openApp',
+ confirmText: 'chatgptAuthRecovery.relogin',
};
}
return {
@@ -113,22 +113,6 @@ export function useCodexSessionExpiredPrompt(options?: {
}
}
- if (credentialScope === 'system-shared') {
- try {
- const result = await window.electronAPI.openChatGPTApp();
- if (mountedRef.current && !result.success) {
- toast.error(t('chatgptAuthRecovery.openAppFailed'));
- }
- } catch {
- if (mountedRef.current) {
- toast.error(t('chatgptAuthRecovery.openAppFailed'));
- }
- } finally {
- if (mountedRef.current) closePrompt();
- }
- return;
- }
-
try {
const result = await triggerOwnedLogin();
if (!mountedRef.current) return;
diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.json
index 9ee8499a2b..4c67e3f899 100644
--- a/apps/desktop/src/renderer/i18n/locales/en/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json
@@ -5629,7 +5629,7 @@
},
"chatgptAuthRecovery": {
"title": "ChatGPT Sign-In Is No Longer Valid",
- "systemSharedInvalidated": "Cindy is currently using this computer’s ChatGPT sign-in. That sign-in is no longer valid. Open the ChatGPT App, sign in again, then retry.",
+ "systemSharedInvalidated": "Cindy is currently using this computer’s ChatGPT sign-in. That sign-in is no longer valid. Sign in again in Cindy, then retry.",
"instanceIsolatedInvalidated": "Cindy is currently using a separately signed-in ChatGPT account. That sign-in is no longer valid. Sign in again in Cindy, then retry.",
"unknownInvalidated": "Cindy’s current ChatGPT sign-in is no longer valid. Sign in again, then retry.",
"recovered": "ChatGPT sign-in has been restored. Please retry.",
diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.json
index 839c3fdb77..a8ce2a466c 100644
--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json
@@ -5627,7 +5627,7 @@
},
"chatgptAuthRecovery": {
"title": "ChatGPT のログインが無効になりました",
- "systemSharedInvalidated": "Cindy は現在、このコンピューターの ChatGPT ログインを使用しています。このログインは無効になりました。ChatGPT App を開いて再度ログインしてから、再試行してください。",
+ "systemSharedInvalidated": "Cindy は現在、このコンピューターの ChatGPT ログインを使用しています。このログインは無効になりました。Cindy で再度ログインしてから、再試行してください。",
"instanceIsolatedInvalidated": "Cindy は現在、個別にログインした ChatGPT アカウントを使用しています。このログインは無効になりました。Cindy で再度ログインしてから、再試行してください。",
"unknownInvalidated": "Cindy の現在の ChatGPT ログインは無効になりました。再度ログインしてから、再試行してください。",
"recovered": "ChatGPT ログインが復旧しました。再試行してください。",
diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.json
index 92b0d39cd6..c6b1a0f479 100644
--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json
@@ -5627,7 +5627,7 @@
},
"chatgptAuthRecovery": {
"title": "ChatGPT 로그인이 더 이상 유효하지 않습니다",
- "systemSharedInvalidated": "Cindy는 현재 이 컴퓨터의 ChatGPT 로그인을 사용하고 있습니다. 이 로그인이 만료되었습니다. ChatGPT App을 열어 다시 로그인한 후 재시도하세요.",
+ "systemSharedInvalidated": "Cindy는 현재 이 컴퓨터의 ChatGPT 로그인을 사용하고 있습니다. 이 로그인이 만료되었습니다. Cindy에서 다시 로그인한 후 재시도하세요.",
"instanceIsolatedInvalidated": "Cindy는 현재 별도로 로그인한 ChatGPT 계정을 사용하고 있습니다. 이 로그인이 만료되었습니다. Cindy에서 다시 로그인한 후 재시도하세요.",
"unknownInvalidated": "Cindy의 현재 ChatGPT 로그인이 만료되었습니다. 다시 로그인한 후 재시도하세요.",
"recovered": "ChatGPT 로그인이 복구되었습니다. 다시 시도하세요.",
diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
index 137aae25c7..699fe89fdd 100644
--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json
@@ -5627,7 +5627,7 @@
},
"chatgptAuthRecovery": {
"title": "ChatGPT 登录已失效",
- "systemSharedInvalidated": "Cindy 当前沿用了本机的 ChatGPT 登录。该登录已失效。请打开 ChatGPT App 重新登录后重试。",
+ "systemSharedInvalidated": "Cindy 当前沿用了本机的 ChatGPT 登录。该登录已失效。请在 Cindy 中重新登录后重试。",
"instanceIsolatedInvalidated": "Cindy 当前使用的是单独登录的 ChatGPT 账号。该登录已失效。请在 Cindy 中重新登录后重试。",
"unknownInvalidated": "Cindy 当前的 ChatGPT 登录已失效。请重新登录后重试。",
"recovered": "ChatGPT 登录已恢复,请重试。",