Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): register dev APNs tokens
DavidShenXDaccb10ad3d18
diff --git a/apps/mobile/src/__tests__/pushNotificationsRealm.test.ts b/apps/mobile/src/__tests__/pushNotificationsRealm.test.tsindex b9170b08c9..bb62038f77 100644--- a/apps/mobile/src/__tests__/pushNotificationsRealm.test.ts+++ b/apps/mobile/src/__tests__/pushNotificationsRealm.test.ts@@ -3,6 +3,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';const store = vi.hoisted(() => new Map<string, string>());const envState = vi.hoisted(() => ({activeRealm: 'cn' as 'cn' | 'global',+ buildRegion: 'cn' as 'cn' | 'global' | 'dev',endpointByRealm: {cn: 'https://relay.cn.example',global: 'https://relay.global.example',@@ -40,7 +41,9 @@ vi.mock('react-native', () => ({}));vi.mock('@/config/env', () => ({- AUTH_REGION: 'cn',+ get AUTH_REGION() {+ return envState.buildRegion;+ },BUILD_AUTH_REGION: 'cn',getActiveMobileSessionRealm: () => envState.activeRealm,loadMobileEndpointsForRealm: mocks.loadMobileEndpointsForRealm,@@ -73,6 +76,7 @@ describe('push notification realm routing', () => {vi.clearAllMocks();store.clear();envState.activeRealm = 'cn';+ envState.buildRegion = 'cn';mocks.getPermissionsAsync.mockResolvedValue({status: 'granted',canAskAgain: false,@@ -111,6 +115,28 @@ describe('push notification realm routing', () => {expect(readStoredRealms(REGISTERED_KEY)).toEqual(['global']);});+ it('dev 构建复用 cn 推送构建线向开发环境注册', async () => {+ envState.buildRegion = 'dev';+ expect((await import('@/config/env')).AUTH_REGION).toBe('dev');+ const apiFetch = vi.fn().mockResolvedValue({ registered: true });++ await expect(+ syncPushRegistration({ enabled: true, apiFetch }),+ ).resolves.toBe('registered');++ expect(apiFetch).toHaveBeenCalledWith(+ '/api/device-link/push-token',+ expect.objectContaining({+ baseUrl: 'https://relay.cn.example',+ method: 'PUT',+ body: expect.objectContaining({+ token: 'apns-device-token',+ appVariant: 'cn',+ }),+ }),+ );+ });+it('切换区域前用旧 token 向显式冻结的旧区域撤销', async () => {setStoredRealms(REGISTERED_KEY, ['global']);envState.activeRealm = 'cn';diff --git a/apps/mobile/src/__tests__/pushRegistrationModel.test.ts b/apps/mobile/src/__tests__/pushRegistrationModel.test.tsindex 53280673e1..4e2faf1a0b 100644--- a/apps/mobile/src/__tests__/pushRegistrationModel.test.ts+++ b/apps/mobile/src/__tests__/pushRegistrationModel.test.ts@@ -6,10 +6,10 @@ import {} from '@/notifications/pushRegistrationModel';describe('resolvePushAppVariant', () => {- it('cn / global 直通,dev 身份不注册', () => {+ it('cn / global 直通,dev 身份归 cn 推送构建线', () => {expect(resolvePushAppVariant('cn')).toBe('cn');expect(resolvePushAppVariant('global')).toBe('global');- expect(resolvePushAppVariant('dev')).toBeNull();+ expect(resolvePushAppVariant('dev')).toBe('cn');});});@@ -27,10 +27,12 @@ describe('buildPushTokenRegistrationBody', () => {expect(buildPushTokenRegistrationBody({ token: 'abc123', region: 'global', isDevBuild: false }),).toMatchObject({ appVariant: 'global', apnsEnv: 'prod' });+ expect(+ buildPushTokenRegistrationBody({ token: 'dev-token', region: 'dev', isDevBuild: true }),+ ).toMatchObject({ appVariant: 'cn', apnsEnv: 'sandbox' });});- it('dev 身份 / 空 token 返回 null', () => {- expect(buildPushTokenRegistrationBody({ token: 'abc', region: 'dev', isDevBuild: true })).toBeNull();+ it('空 token 返回 null', () => {expect(buildPushTokenRegistrationBody({ token: ' ', region: 'cn', isDevBuild: true })).toBeNull();});});diff --git a/apps/mobile/src/notifications/pushRegistrationModel.ts b/apps/mobile/src/notifications/pushRegistrationModel.tsindex 0d90efd647..9f72975d03 100644--- a/apps/mobile/src/notifications/pushRegistrationModel.ts+++ b/apps/mobile/src/notifications/pushRegistrationModel.ts@@ -10,10 +10,11 @@ export type PushAppVariant = 'cn' | 'global';/*** 构建线 → server 侧 appVariant(决定 APNs topic/bundleId)。- * dev 第三身份(com.xd.cindydev)没有对应 APNs topic,不注册(返回 null)。+ * dev 是内部开发身份且行为语义归 cn 系:开发环境用 APNS_TOPIC_CN+ * 配置 com.xd.cindydev,因此注册时复用 appVariant='cn'。*/-export function resolvePushAppVariant(region: 'cn' | 'global' | 'dev'): PushAppVariant | null {- return region === 'cn' || region === 'global' ? region : null;+export function resolvePushAppVariant(region: 'cn' | 'global' | 'dev'): PushAppVariant {+ return region === 'global' ? 'global' : 'cn';}export interface PushTokenRegistrationBody {@@ -25,7 +26,7 @@ export interface PushTokenRegistrationBody {}/**- * 组装 PUT /push-token 的 body;不可注册的场景(dev 身份 / 空 token)返回 null。+ * 组装 PUT /push-token 的 body;空 token 返回 null。* apnsEnv:dev client(Xcode debug 签名)走 sandbox APNs,TestFlight / App Store /* 自建 release 走 prod —— 与 __DEV__ 语义一致。*/@@ -35,7 +36,6 @@ export function buildPushTokenRegistrationBody(opts: {isDevBuild: boolean;}): PushTokenRegistrationBody | null {const appVariant = resolvePushAppVariant(opts.region);- if (!appVariant) return null;const token = opts.token.trim();if (!token) return null;return {