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(mobile): 修复热更后整包版本回退

guyongca976212dbd8
diff --git a/apps/mobile/src/__tests__/clientEndpointStartup.test.ts b/apps/mobile/src/__tests__/clientEndpointStartup.test.ts
index 20022d8e60..85261cd5a2 100644
--- a/apps/mobile/src/__tests__/clientEndpointStartup.test.ts
+++ b/apps/mobile/src/__tests__/clientEndpointStartup.test.ts
@@ -97,10 +97,28 @@ describe('runStartupEndpointResolve(CDN 解析)', () => {
).resolves.toEqual({ ok: true, source: 'cdn' });
});
+ it('二进制版本优先读原生 0.1.2,不被 OTA manifest 的 0.1.0 覆盖', async () => {
+ vi.resetModules();
+ vi.doMock('expo-application', () => ({
+ nativeApplicationVersion: '0.1.2',
+ }));
+ vi.doMock('expo-constants', () => ({
+ default: { expoConfig: { version: '0.1.0' } },
+ }));
+ try {
+ const env = await import('@/config/env');
+ expect(env.APP_BINARY_VERSION).toBe('0.1.2');
+ } finally {
+ vi.doUnmock('expo-application');
+ vi.doUnmock('expo-constants');
+ vi.resetModules();
+ }
+ });
+
it('清单 review 命中二进制版本号且非 TestFlight → REVIEW_MODE=true', async () => {
vi.resetModules();
vi.doMock('expo-constants', () => ({
- default: { expoConfig: { version: '9.9.9' }, nativeAppVersion: '9.9.9' },
+ default: { expoConfig: { version: '9.9.9' } },
}));
try {
const env = await import('@/config/env');
diff --git a/apps/mobile/src/__tests__/expo-application.mock.ts b/apps/mobile/src/__tests__/expo-application.mock.ts
new file mode 100644
index 0000000000..34ca050bb4
--- /dev/null
+++ b/apps/mobile/src/__tests__/expo-application.mock.ts
@@ -0,0 +1 @@
+export const nativeApplicationVersion: string | null = null;
diff --git a/apps/mobile/src/config/env.ts b/apps/mobile/src/config/env.ts
index 89fe4fe946..66fc23d8b1 100644
--- a/apps/mobile/src/config/env.ts
+++ b/apps/mobile/src/config/env.ts
@@ -1,3 +1,4 @@
+import * as Application from 'expo-application';
import Constants from 'expo-constants';
import {
@@ -268,9 +269,10 @@ syncBuildTokenEndpointCache();
// 二进制版本号:审核模式匹配基准。优先原生层版本(iOS CFBundleShortVersionString /
// Android versionName,OTA 热更后不漂移),expoConfig.version 兜底(dev / 测试环境
-// 拿不到原生值)。与 mobileTapdb 的版本上报取值口径一致。
+// 拿不到原生值)。expo-application 已由现有 expo-auth-session / expo-notifications
+// 链进存量整包;这里只消费现成原生模块,不改 package.json / runtime fingerprint。
export const APP_BINARY_VERSION = (
- Constants.nativeAppVersion ??
+ Application.nativeApplicationVersion ??
Constants.expoConfig?.version ??
''
).trim();
diff --git a/apps/mobile/vitest.config.ts b/apps/mobile/vitest.config.ts
index 1da1cf3fd5..48a7406834 100644
--- a/apps/mobile/vitest.config.ts
+++ b/apps/mobile/vitest.config.ts
@@ -29,6 +29,9 @@ export default defineConfig({
// (checkout 路径含空格时 alias 指向不存在的 %20 路径,255 个测试文件整体
// TEST_COLLECT_FAILED);无空格路径下两者逐字节一致,CI 行为零变化。
'@': fileURLToPath(new URL('./src', import.meta.url)),
+ 'expo-application': fileURLToPath(
+ new URL('./src/__tests__/expo-application.mock.ts', import.meta.url),
+ ),
'expo-constants': fileURLToPath(new URL('./src/__tests__/expo-constants.mock.ts', import.meta.url)),
// expo-localization 同款处理:真模块拖 react-native(Flow 语法)依赖链;
// 需要控制语言的测试用 vi.mock 覆盖(优先于 alias)。