Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): captcha 加载失败文案补网络指引 (#3205)
lengjingxub7b56bc4137a
diff --git a/apps/mobile/src/auth/__tests__/loginSkinErrorCopy.test.ts b/apps/mobile/src/auth/__tests__/loginSkinErrorCopy.test.tsindex b6a2f5f880..3bb6d4d6b6 100644--- a/apps/mobile/src/auth/__tests__/loginSkinErrorCopy.test.ts+++ b/apps/mobile/src/auth/__tests__/loginSkinErrorCopy.test.ts@@ -2,7 +2,9 @@ import { describe, expect, it, vi } from "vitest";/*** PR4a 错误文案行测试(SC-7 slice pr4a error-copy 族):- * inventory §4.5 移动具名 14 码 + REGION_MISMATCH + UNKNOWN_CODE 兜底,+ * inventory §4.5 移动具名码 + REGION_MISMATCH + 发码路径常见码+ * (RATE_LIMITED / SSO_LOGIN_REQUIRED / INVALID_RESPONSE / AUTH_SERVICE_UNAVAILABLE)+ * + UNKNOWN_CODE 兜底,* 逐码断言 5 语 catalog verbatim 路由(vi.mock expo-localization 轮换系统 locale,* authErrorText 走真实解析链)。皮肤层错误条消费 authErrorText 输出,* 文案权威在 loginMessages catalog(translation-review SHA 绑定)。@@ -169,6 +171,43 @@ describe("loginSkin 错误文案 5 语(catalog verbatim 路由)", () => {);});+ it("RATE_LIMITED:5 语 catalog verbatim 路由", () => {+ expectCodeRoutedVerbatim("RATE_LIMITED");+ expect(authErrorMessages.RATE_LIMITED["zh-CN"]).toBe(+ "操作过于频繁,请稍后再试。",+ );+ });++ it("SSO_LOGIN_REQUIRED:5 语 catalog verbatim 路由", () => {+ expectCodeRoutedVerbatim("SSO_LOGIN_REQUIRED");+ expect(authErrorMessages.SSO_LOGIN_REQUIRED["zh-CN"]).toBe(+ "该邮箱所属企业要求通过 SSO 登录。",+ );+ });++ it("AUTH_SERVICE_UNAVAILABLE:5 语 catalog verbatim 路由", () => {+ expectCodeRoutedVerbatim("AUTH_SERVICE_UNAVAILABLE");+ expect(authErrorMessages.AUTH_SERVICE_UNAVAILABLE["zh-CN"]).toBe(+ "登录服务暂不可用,请稍后重试。",+ );+ });++ it("INVALID_RESPONSE:5 语 catalog verbatim 路由(zod 契约漂移,不在 scenario error 值域)", () => {+ const perLocale = authErrorMessages.INVALID_RESPONSE;+ expect(perLocale).toBeTruthy();+ expect(Object.keys(perLocale).sort()).toEqual([...LOCALES].sort());+ for (const locale of LOCALES) {+ mockLanguageTag.current = LOCALE_TAGS[locale];+ const text = authErrorText("INVALID_RESPONSE");+ expect(text, locale).toBe(perLocale[locale]);+ expect(text, locale).not.toBe(loginMessages[locale].errorFallback);+ }+ mockLanguageTag.current = "zh-Hans-CN";+ expect(authErrorMessages.INVALID_RESPONSE["zh-CN"]).toBe(+ "登录服务返回了无法识别的结果,请稍后重试。",+ );+ });+it("UNKNOWN_CODE:未注册 wire code 逐 locale 回退 errorFallback,null 返回 null", () => {expect(authErrorMessages.UNKNOWN_CODE).toBeUndefined();for (const locale of LOCALES) {diff --git a/apps/mobile/src/auth/loginMessages.ts b/apps/mobile/src/auth/loginMessages.tsindex 8820541903..ce5329ff17 100644--- a/apps/mobile/src/auth/loginMessages.ts+++ b/apps/mobile/src/auth/loginMessages.ts@@ -59,7 +59,7 @@ const messages = {signIn: "登入",resendCode: "重新發送驗證碼",captchaTitle: "安全驗證",- captchaFailed: "安全驗證載入失敗",+ captchaFailed: "安全驗證載入失敗,請檢查網路後重試。",captchaRetry: "重試",captchaCancel: "取消",resendCountdown: "{n} 秒後可重新發送",@@ -174,7 +174,7 @@ const messages = {signIn: "登录",resendCode: "重新发送验证码",captchaTitle: "安全验证",- captchaFailed: "安全验证加载失败",+ captchaFailed: "安全验证加载失败,请检查网络后重试。",captchaRetry: "重试",captchaCancel: "取消",resendCountdown: "{n} 秒后可重新发送",@@ -291,7 +291,7 @@ const messages = {signIn: "Sign in",resendCode: "Resend code",captchaTitle: "Security check",- captchaFailed: "Failed to load the security check.",+ captchaFailed: "Couldn't load the security check. Check your network and try again.",captchaRetry: "Retry",captchaCancel: "Cancel",resendCountdown: "Resend available in {n}s",@@ -420,7 +420,7 @@ const messages = {signIn: "ログイン",resendCode: "認証コードを再送信",captchaTitle: "セキュリティチェック",- captchaFailed: "セキュリティチェックを読み込めませんでした。",+ captchaFailed: "セキュリティチェックを読み込めませんでした。ネットワークを確認して再試行してください。",captchaRetry: "再試行",captchaCancel: "キャンセル",resendCountdown: "{n} 秒後に再送信できます",@@ -547,7 +547,7 @@ const messages = {signIn: "로그인",resendCode: "인증 코드 재전송",captchaTitle: "보안 확인",- captchaFailed: "보안 확인을 불러오지 못했습니다.",+ captchaFailed: "보안 확인을 불러오지 못했습니다. 네트워크를 확인한 후 다시 시도해 주세요.",captchaRetry: "다시 시도",captchaCancel: "취소",resendCountdown: "{n}초 후 재전송 가능",@@ -695,6 +695,34 @@ export const authErrorMessages: Record<string, Record<LoginLocale, string>> = {ja: "入力内容の形式が正しくありません。",ko: "입력한 내용의 형식이 올바르지 않습니다.",},+ RATE_LIMITED: {+ "zh-CN": "操作过于频繁,请稍后再试。",+ "zh-TW": "操作過於頻繁,請稍後再試。",+ en: "Too many attempts. Please wait and try again.",+ ja: "操作が多すぎます。しばらく待ってから再試行してください。",+ ko: "요청이 너무 많습니다. 잠시 후 다시 시도해 주세요.",+ },+ SSO_LOGIN_REQUIRED: {+ "zh-CN": "该邮箱所属企业要求通过 SSO 登录。",+ "zh-TW": "該電子郵件所屬企業要求透過 SSO 登入。",+ en: "This organization requires SSO sign-in.",+ ja: "この組織は SSO ログインが必要です。",+ ko: "이 조직은 SSO 로그인이 필요합니다.",+ },+ INVALID_RESPONSE: {+ "zh-CN": "登录服务返回了无法识别的结果,请稍后重试。",+ "zh-TW": "登入服務返回了無法識別的結果,請稍後再試。",+ en: "The sign-in service returned an unrecognized result. Try again later.",+ ja: "ログインサービスから認識できない結果が返されました。しばらくしてから再試行してください。",+ ko: "로그인 서비스에서 알 수 없는 결과를 반환했습니다. 잠시 후 다시 시도해 주세요.",+ },+ AUTH_SERVICE_UNAVAILABLE: {+ "zh-CN": "登录服务暂不可用,请稍后重试。",+ "zh-TW": "登入服務暫不可用,請稍後再試。",+ en: "The sign-in service is temporarily unavailable. Try again later.",+ ja: "ログインサービスは一時的に利用できません。しばらくしてからお試しください。",+ ko: "로그인 서비스를 일시적으로 사용할 수 없습니다. 잠시 후 다시 시도해 주세요.",+ },CAPTCHA_REQUIRED: {"zh-CN": "请先完成安全验证。","zh-TW": "請先完成安全驗證。",diff --git a/packages/auth-client/src/__tests__/client.test.ts b/packages/auth-client/src/__tests__/client.test.tsindex 52bd4c3c0c..d2192e82c7 100644--- a/packages/auth-client/src/__tests__/client.test.ts+++ b/packages/auth-client/src/__tests__/client.test.ts@@ -130,6 +130,26 @@ describe("CindyAuthClient", () => {expect(legacy.captcha).toBeUndefined();});+ it("keeps recognized discovery methods when the server appends an unknown type", async () => {+ const fetch = vi.fn(async () =>+ response(200, {+ methods: [{ type: "email_code" }, { type: "passkey", id: "future-1" }],+ }),+ );+ await expect(client(fetch).discover("[email protected]")).resolves.toEqual([+ { type: "email_code" },+ ]);+ });++ it("fails closed when discovery returns only unrecognized methods", async () => {+ const fetch = vi.fn(async () =>+ response(200, { methods: [{ type: "passkey", id: "future-1" }] }),+ );+ await expect(client(fetch).discover("[email protected]")).rejects.toMatchObject({+ code: "INVALID_RESPONSE",+ });+ });+it("carries captchaToken in the email request-code body only when provided", async () => {const fetch = vi.fn(async () => response(200, { status: "sent" }));await client(fetch).requestCode("email", "[email protected]");diff --git a/packages/auth-client/src/client.ts b/packages/auth-client/src/client.tsindex 32aaa64432..bf43abc546 100644--- a/packages/auth-client/src/client.ts+++ b/packages/auth-client/src/client.ts@@ -8,8 +8,8 @@ import {accountTokenPairSchema,authRegionSchema,desktopAuthorizationPollSchema,- loginMethodSchema,loginOutcomeSchema,+ recognizeLoginMethods,meResponseSchema,providerConfigSchema,ssoOrgDiscoverySchema,@@ -116,10 +116,28 @@ export class CindyAuthClient {async discover(email: string): Promise<LoginMethod[]> {const result = await this.request("/api/auth/discovery",- z.object({ methods: z.array(loginMethodSchema) }),+ z.object({ methods: z.array(z.unknown()) }),{ email },);- return result.methods;+ let methods: LoginMethod[];+ try {+ methods = recognizeLoginMethods(result.methods);+ } catch {+ throw new AuthApiError(+ "INVALID_RESPONSE",+ 200,+ "Authentication server returned a malformed known login method",+ );+ }+ // 列表非空却没有一项能识别:仍按契约漂移失败,避免空 method-choice 假成功。+ if (result.methods.length > 0 && methods.length === 0) {+ throw new AuthApiError(+ "INVALID_RESPONSE",+ 200,+ "Authentication server returned no recognized login methods",+ );+ }+ return methods;}/** 企业 SSO 入口:组织 ID、slug 或已验证域名 → 已启用的 SSO 连接。 */diff --git a/packages/auth-client/src/index.ts b/packages/auth-client/src/index.tsindex 7bf26a22fe..f1e8a81e2f 100644--- a/packages/auth-client/src/index.ts+++ b/packages/auth-client/src/index.ts@@ -56,6 +56,7 @@ export {desktopAuthorizationPollSchema,loginMethodSchema,loginOutcomeSchema,+ recognizeLoginMethods,meResponseSchema,membershipSchema,providerConfigSchema,diff --git a/packages/auth-client/src/types.ts b/packages/auth-client/src/types.tsindex de27fbf58a..37cd47ff7e 100644--- a/packages/auth-client/src/types.ts+++ b/packages/auth-client/src/types.ts@@ -104,6 +104,32 @@ export const loginMethodSchema = z.discriminatedUnion("type", []);export type LoginMethod = z.infer<typeof loginMethodSchema>;+/**+ * Discovery 允许服务端 append-only 增加未知登录方式。未知项丢弃,避免整份+ * `methods` 校验失败变成 INVALID_RESPONSE,把已经认识的 email_code / sso+ * 一起挡掉(移动端会落到「登录未完成」兜底,验证码发不出去)。+ */+const knownLoginMethodTypes = new Set(["email_code", "sso"]);++export function recognizeLoginMethods(items: readonly unknown[]): LoginMethod[] {+ return items.flatMap((item) => {+ // 有 string type 且不在已知集 = 服务端新增方式,向前兼容丢弃。+ if (+ typeof item === "object" &&+ item !== null &&+ "type" in item &&+ typeof item.type === "string" &&+ item.type.length > 0 &&+ !knownLoginMethodTypes.has(item.type)+ ) {+ return [];+ }+ // 其余(已知 type、缺 type、type 非字符串)一律严格 parse,+ // 字段残缺抛错由调用方转为 INVALID_RESPONSE,不静默丢弃。+ return [loginMethodSchema.parse(item)];+ });+}+/*** 把企业 SSO discovery 结果映射成 LoginMethod 列表。* 多连接时复用 method-choice 让用户选 IdP;唯一连接由