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。

Merge pull request #6058 from fix/login-error-back-navigation

MagicLizia6421c843cea
diff --cc apps/desktop/src/renderer/components/login/LoginPage.tsx
index 3b7f8a899a,bfdc722d41..fdff529107
--- a/apps/desktop/src/renderer/components/login/LoginPage.tsx
+++ b/apps/desktop/src/renderer/components/login/LoginPage.tsx
@@@ -186,14 -188,9 +188,14 @@@ export function LoginPage(
* 未勾选时先弹协议弹窗,同意后才进主界面。调用方一律用
* `requireConsent(..., { deferConsentPersist: true })` 包裹:同意记录由**本函数**
* 在会话切过去之后落,不能由 requireConsent 提前落(竞态原因见那里的注释)。
+ *
- * 这里**不看 isLoading**:error 步的逃生入口在「返回 / 重试」请求进行中也必须可用,
++ * 登录方式请求等待期间仍允许从准备态、error 步和离线入口离开,
+ * 否则登录服务连不上时每点一次就把用户锁到超时。main 的 enter-local 会推进
+ * loginFlowEpoch,在途登录动作迟到时以 AUTH_FLOW_SUPERSEDED 作废,不会回写状态。
+ * 面板内入口仍由按钮 disabled 与协议门的 busy 复验挡住 in-flight。
*/
const openLocalMode = async () => {
- if (localModePendingRef.current || !enterLocalMode) return;
+ if ((isLoading && !canLeaveProviderLoad) || localModePendingRef.current || !enterLocalMode) return;
markLocalModeTransition(true);
try {
// 必须走 AuthContext.enterLocalMode():它调同一条 IPC,并用返回值立刻改
@@@ -268,15 -274,8 +279,12 @@@
* 会当场发出 device_login),等 enter-local 完成再广播 allowed:false 已经晚了。
* 于是「未登录态不上报」这条承诺在正式包上会被破一个窗口。让 openLocalMode
* 先切会话、再落同意即可关掉这个窗口(此时 allowed 恒为 false)。
- * @param options.allowDuringLoginRequest
- * true = 登录请求进行中也可过门续接。只有 error 步逃生入口用它:进入未登录状态
- * 不是登录派发,「in-flight 时不追加并发派发」那条复验不适用;照常复验的话,
- * 用户在重试转圈时点「跳过登录」并同意协议,动作会被静默丢弃。
++ * 登录方式等待期间的跳过入口不受登录派发的 busy 复验限制;其他入口仍照常复验。
*/
- const requireConsent = (action: () => void, options?: { deferConsentPersist?: boolean }) => {
+ const requireConsent = (
+ action: () => void,
- options?: { deferConsentPersist?: boolean; allowDuringLoginRequest?: boolean },
++ options?: { deferConsentPersist?: boolean },
+ ) => {
/* 会话切换进行中一律不接新的过门动作(codex 审查 P1 第二条,#907)。
`auth:enter-local` 的 handler 要 await waitForSessionInvalidation() 与
teardownAuthAccountBoundary(),这是一个真实可观测的窗口;窗口里 isLoading
@@@ -1423,12 -1454,7 +1463,11 @@@
type="button"
disabled={localModePending}
// error 步逃生入口与面板内文字按钮同口径:过协议门(2026-07-29 拍板)
- onClick={() => requireConsent(() => void openLocalMode(), { deferConsentPersist: true })}
+ onClick={() =>
+ requireConsent(() => void openLocalMode(), {
+ deferConsentPersist: true,
- allowDuringLoginRequest: true,
+ })
+ }
aria-describedby="login-local-mode-description"
className="select-none rounded-full border border-[var(--border-default)] bg-[var(--surface-elevated)] px-6 py-2.5 text-13 font-medium text-[var(--text-primary)] transition-colors hover:bg-[var(--surface-hover)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--focus-ring-soft)] disabled:cursor-not-allowed disabled:opacity-60"
style={{ minHeight: 40 }}
diff --cc apps/desktop/src/renderer/components/login/__tests__/LoginPage.consent.test.tsx
index 5dbbdd8790,1aae624a69..1cdaa11c8b
--- a/apps/desktop/src/renderer/components/login/__tests__/LoginPage.consent.test.tsx
+++ b/apps/desktop/src/renderer/components/login/__tests__/LoginPage.consent.test.tsx
@@@ -404,35 -404,37 +404,64 @@@ describe('consent guard(未勾选拦截
expect(screen.getByTestId('login-local-mode')).toBeTruthy();
});
- /* 「返回 / 重试」都要重新连登录服务,连不上时会一直等到超时。逃生入口若随这次
- 等待禁用,用户每点一次返回就被锁在 error 屏(0.1.104 实测:点返回 → 请稍候 →
- 超时 → 留在原地,期间跳过登录也点不了)。 */
++ /* 重试等待期间逃生入口仍可用,协议同意后不得因 in-flight 静默丢弃。 */
+ it('error 步重连登录服务期间逃生入口仍可用;同意后不因 in-flight 被丢弃', async () => {
+ mount(errorState, { errorCode: 'NETWORK_ERROR', isLoading: true });
+ const escape = screen.getByTestId('login-local-mode') as HTMLButtonElement;
+ expect(escape.disabled).toBe(false);
+ await act(async () => {
+ fireEvent.click(escape);
+ });
+ expect(screen.getByTestId('login-consent-dialog')).toBeTruthy();
+ await act(async () => {
+ fireEvent.click(screen.getByTestId('login-consent-agree'));
+ });
+ expect(enterLocalMode).toHaveBeenCalledTimes(1);
+ expect(enterLocalMode.mock.invocationCallOrder[0]).toBeLessThan(
+ acceptPrivacyConsent.mock.invocationCallOrder[0],
+ );
+ });
+
- it('面板内「跳过登录」在登录请求进行中仍禁用(只放开 error 步逃生入口)', async () => {
+ it.each([null, errorState])('keeps pending skip consent when providers finish from %j', async (initial) => {
+ const view = mount(initial, { isLoading: true });
+ fireEvent.click(screen.getByTestId('login-local-mode'));
+ loginHook.value.loginState = await identifierState('providers:cn-social');
+ loginHook.value.isLoading = false;
+ view.rerender(<LoginPage />);
+ expect(screen.getByTestId('login-consent-dialog')).toBeTruthy();
+ expect(acceptPrivacyConsent).not.toHaveBeenCalled();
+ await act(async () => { fireEvent.click(screen.getByTestId('login-consent-agree')); });
+ expect(enterLocalMode).toHaveBeenCalledOnce();
+ expect(acceptPrivacyConsent).toHaveBeenCalledOnce();
+ expect(enterLocalMode.mock.invocationCallOrder[0]).toBeLessThan(
+ acceptPrivacyConsent.mock.invocationCallOrder[0],
+ );
+ });
+
++ it('identifier 面板内「跳过登录」在登录请求进行中仍禁用', async () => {
+ mount(await identifierState('providers:cn-social'), { isLoading: true });
+ const entry = screen.getByTestId('login-skip-entry') as HTMLButtonElement;
+ expect(entry.disabled).toBe(true);
+ fireEvent.click(entry);
+ expect(screen.queryByTestId('login-consent-dialog')).toBeNull();
+ expect(enterLocalMode).not.toHaveBeenCalled();
+ });
+
+ it.each([
+ { step: 'completed' },
+ { step: 'browser-redirect', label: 'SSO' },
+ { step: 'error', code: 'CREDENTIAL_STORE_UNAVAILABLE', recoverTo: 'identifier' },
+ ])('abandons pending skip consent on an unrelated transition to %j', (state) => {
+ const view = mount(null, { isLoading: true });
+ fireEvent.click(screen.getByTestId('login-local-mode'));
+ loginHook.value.loginState = state;
+ loginHook.value.isLoading = false;
+ view.rerender(<LoginPage />);
+ expect(screen.queryByTestId('login-consent-dialog')).toBeNull();
+ expect(enterLocalMode).not.toHaveBeenCalled();
+ expect(acceptPrivacyConsent).not.toHaveBeenCalled();
+ });
+
it('旧游客圆钮入口已删除(圆钮行不再渲染 login-social-guest)', async () => {
mount(await identifierState('providers:cn-social'));
expect(screen.queryByTestId('login-social-guest')).toBeNull();
diff --cc docs/design-rules/DESIGN.md
index f59d45283d,7bbcaa7137..6fd05c93f9
--- a/docs/design-rules/DESIGN.md
+++ b/docs/design-rules/DESIGN.md
@@@ -1992,7 -1992,7 +1992,7 @@@ and media position (`ui/media-scrubber`
| `binding` | 身份未绑 membership,补绑 phone / email(`codeRequested` 两子态;**无重发钮**,桌面 harness 锁定) | `LoginInput` / `LoginSkinPhoneInput` → `LoginInput`(center) + `LoginPrimaryButton` |
| `account-deletion`(状态浮层) | 账号删除**状态展示**(发起流程在 Settings 的 `AccountDeletionSection`;登录页仅在存在删除回执时以**根层浮层气泡**展示 status,非主状态机 step;详见下方「注销状态浮层气泡」) | `AccountDeletionStatusPanel`(**登录皮容器外**的根层浮层,非面板内) |
| `browser-redirect` | 社交 / SSO 跳浏览器验证,等待回调 | `LoginLoadingRing` + Desktop `LoginBackButton`(`cancel-browser`;Mobile 保留原取消入口)+ `LoginTitleBlock` |
- | `completed` / `error` | 登录成功 / 失败(含 browser 回调终态页);`error` 步桌面另有面板下方 footer 的「跳过登录」**逃生入口**(登录服务不可用时仍能进未登录状态,与面板内入口同口径**过协议门**——2026-07-29 拍板;返回 / 重试重新连接登录服务期间**不禁用**,只在切换到未登录状态的过程中禁用) | 成功无面板(进主界面);error = `LoginBackButton`(仅桌面,复用 reset;普通登录与添加账号均重新加载登录入口)+ `LoginTitleBlock` + `LoginPrimaryButton`(重试)+ `LoginErrorText` + footer「跳过登录」按钮(桌面);browser 回调页 `oauthResultPage`(系统浏览器独立 HTML,main 侧内联常量,色值与 `--login-callback-*` token 同源——renderer CSS var 不可达,改值需两处同步) |
-| `completed` / `error` | 登录成功 / 失败(含 browser 回调终态页);`error` 步桌面另有面板下方 footer 的「跳过登录」**逃生入口**(登录服务不可用时仍能进未登录状态,与面板内入口同口径**过协议门**——2026-07-29 拍板) | 成功无面板(进主界面);error = `LoginBackButton`(仅桌面:普通登录网络错误取消当前等待,使用已取得的配置返回入口;配置尚未取得时显示「继续登录/跳过登录」的离线入口,不自动联网;添加账号则关闭流程)+ `LoginTitleBlock` + `LoginPrimaryButton`(重试)+ `LoginErrorText` + footer「跳过登录」按钮(桌面);browser 回调页 `oauthResultPage`(系统浏览器独立 HTML,main 侧内联常量,色值与 `--login-callback-*` token 同源——renderer CSS var 不可达,改值需两处同步) |
++| `completed` / `error` | 登录成功 / 失败(含 browser 回调终态页);`error` 步桌面另有面板下方 footer 的「跳过登录」**逃生入口**(登录服务不可用时仍能进未登录状态,与面板内入口同口径**过协议门**——2026-07-29 拍板;重试连接登录服务期间不禁用,只在切换到未登录状态的过程中禁用) | 成功无面板(进主界面);error = `LoginBackButton`(仅桌面:普通登录网络错误取消当前等待,使用已取得的配置返回入口;配置尚未取得时显示「继续登录/跳过登录」的离线入口,不自动联网;添加账号则关闭流程)+ `LoginTitleBlock` + `LoginPrimaryButton`(重试)+ `LoginErrorText` + footer「跳过登录」按钮(桌面);browser 回调页 `oauthResultPage`(系统浏览器独立 HTML,main 侧内联常量,色值与 `--login-callback-*` token 同源——renderer CSS var 不可达,改值需两处同步) |
**~~配置错误屏同样承载「跳过登录」逃生入口(移动端)~~〔已作废 2026-07-28:手机端整体剥离,配置错误屏无该入口〕**:`getMobileConfigIssues()` 命中(如 auth base URL 非法)时面板切到 config 提示态,该面板内仍渲染同一个 `LoginSkipLoginLink`(同槽 @(0,430)、同 handler、同 in-flight 门)——跳过登录不发任何网络请求,配置坏掉时恰恰最需要这个入口。