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): 阻断屏重新核对时刷新强更目标,不再固守旧安装地址

guyongd13c7156dda7
diff --git a/apps/mobile/src/__tests__/forcedUpdateGate.test.ts b/apps/mobile/src/__tests__/forcedUpdateGate.test.ts
index 0841d7efa2..f0d916b6b0 100644
--- a/apps/mobile/src/__tests__/forcedUpdateGate.test.ts
+++ b/apps/mobile/src/__tests__/forcedUpdateGate.test.ts
@@ -62,9 +62,11 @@ describe('强更阻断闸门', () => {
expect(layout).toContain("from '@/update/useForcedUpdateRecheck'");
expect(layout).toContain('useForcedUpdateRecheck();');
// 解除方向 fail-closed:只有成功拉到 /latest 且判定不再强更才解除,
- // 拉取失败维持阻断,不能靠断网 / 飞行模式绕过。
- expect(recheck).toContain('if (evaluation.forced) return \'still-forced\';');
+ // 拉取失败 / 记录解析不出 / 拿不到本机 version 一律维持阻断,不能靠断网绕过。
+ expect(recheck).toContain("if (!record || !currentVersion) return 'error';");
expect(recheck).toContain("return 'error'");
+ // 仍强更时必须刷新 target:服务端可能只修正了坏掉的安装地址。
+ expect(recheck).toContain('deps.onStillForced(evaluation.target)');
});
it('阻断态只存内存,不持久化(服务端撤回门槛后用户不能被本地缓存锁死)', () => {
diff --git a/apps/mobile/src/update/forcedUpdateRecheck.test.ts b/apps/mobile/src/update/forcedUpdateRecheck.test.ts
index fcffbf0ae1..c0cdadc4a6 100644
--- a/apps/mobile/src/update/forcedUpdateRecheck.test.ts
+++ b/apps/mobile/src/update/forcedUpdateRecheck.test.ts
@@ -24,6 +24,7 @@ function makeDeps(overrides: Partial<ForcedUpdateRecheckDeps> = {}) {
getCurrentRuntimeVersion: () => '1',
getCurrentVersion: () => '1.0.0',
onCleared: vi.fn(),
+ onStillForced: vi.fn(),
now: () => nowMs,
advance: (ms: number) => { nowMs += ms; },
...overrides,
@@ -86,22 +87,50 @@ describe('createForcedUpdateRechecker 解除判定', () => {
expect(deps.onCleared).toHaveBeenCalledOnce();
});
- it('门槛仍在 → 维持阻断', async () => {
+ it('门槛仍在 → 维持阻断,并把最新 target 写回', async () => {
const deps = makeDeps();
await expect(runOnce(deps)).resolves.toBe('still-forced');
expect(deps.onCleared).not.toHaveBeenCalled();
+ expect(deps.onStillForced).toHaveBeenCalledOnce();
+ });
+
+ it('门槛仍在但服务端修正了安装地址 → 刷新 target(否则按钮一直打开旧链接)', async () => {
+ const deps = makeDeps({
+ fetchLatest: vi.fn(async () => latestRecord({
+ installUrl: 'https://cdn.example/fixed',
+ itmsUrl: 'itms-services://?action=download-manifest&url=https://cdn.example/fixed.plist',
+ })),
+ });
+ await expect(runOnce(deps)).resolves.toBe('still-forced');
+ expect(deps.onStillForced).toHaveBeenCalledWith(expect.objectContaining({
+ installUrl: 'https://cdn.example/fixed',
+ itmsUrl: 'itms-services://?action=download-manifest&url=https://cdn.example/fixed.plist',
+ }));
+ });
+
+ it('门槛仍在且换了更高的强更目标 → 刷新 target', async () => {
+ const deps = makeDeps({
+ fetchLatest: vi.fn(async () => latestRecord({ version: '3.0.0', runtimeVersion: '3', minVersion: '3.0.0' })),
+ });
+ await expect(runOnce(deps)).resolves.toBe('still-forced');
+ expect(deps.onStillForced).toHaveBeenCalledWith(expect.objectContaining({
+ version: '3.0.0',
+ runtimeVersion: '3',
+ }));
});
it('/latest 拉取失败 → 维持阻断(不能靠断网绕过强更)', async () => {
const deps = makeDeps({ fetchLatest: vi.fn(async () => { throw new Error('offline'); }) });
await expect(runOnce(deps)).resolves.toBe('error');
expect(deps.onCleared).not.toHaveBeenCalled();
+ expect(deps.onStillForced).not.toHaveBeenCalled();
});
it('/latest 记录解析不出 → 维持阻断(一条坏记录不得放行所有被强更装机)', async () => {
const deps = makeDeps({ fetchLatest: vi.fn(async () => ({})) });
await expect(runOnce(deps)).resolves.toBe('error');
expect(deps.onCleared).not.toHaveBeenCalled();
+ expect(deps.onStillForced).not.toHaveBeenCalled();
});
it('记录有效但缺 runtimeVersion / 安装地址 → 维持阻断', async () => {
@@ -110,6 +139,7 @@ describe('createForcedUpdateRechecker 解除判定', () => {
});
await expect(runOnce(deps)).resolves.toBe('error');
expect(deps.onCleared).not.toHaveBeenCalled();
+ expect(deps.onStillForced).not.toHaveBeenCalled();
});
it('拿不到本机 version → 维持阻断(比不出来不放行)', async () => {
@@ -119,6 +149,7 @@ describe('createForcedUpdateRechecker 解除判定', () => {
});
await expect(runOnce(deps)).resolves.toBe('error');
expect(deps.onCleared).not.toHaveBeenCalled();
+ expect(deps.onStillForced).not.toHaveBeenCalled();
});
it('/latest 挂起 → withTimeout 兜底为 error,维持阻断', async () => {
diff --git a/apps/mobile/src/update/forcedUpdateRecheck.ts b/apps/mobile/src/update/forcedUpdateRecheck.ts
index ffdade73f4..dc26809545 100644
--- a/apps/mobile/src/update/forcedUpdateRecheck.ts
+++ b/apps/mobile/src/update/forcedUpdateRecheck.ts
@@ -25,6 +25,18 @@ export interface ForcedUpdateRecheckDeps {
getCurrentVersion: () => string | null | undefined;
/** 判定不再强更时调用(实参为 clearForcedUpdate),之后业务树重新挂载。 */
onCleared: () => void;
+ /**
+ * 仍然强更时把**最新**目标写回(实参为 enterForcedUpdate,对等值目标幂等)。
+ * 必须刷新而不是原样保留:服务端修正 installUrl / itmsUrl(坏链接正是最需要救的那种
+ * 故障),或发布更高的强更目标时,阻断屏的「去更新」不能继续打开旧链接。
+ */
+ onStillForced: (target: {
+ version: string;
+ runtimeVersion: string;
+ installUrl: string;
+ itmsUrl: string;
+ releaseNotes?: string;
+ }) => void;
now: () => number;
/** 阻断屏卸载后使迟到结果失效。 */
isCurrent?: () => boolean;
@@ -78,9 +90,13 @@ export function createForcedUpdateRechecker(
currentVersion,
latest,
});
- // 仍然强更(门槛还在,或换了更高的目标)→ 维持阻断,不动 store:
- // 目标信息的刷新交给下次冷启动,阻断屏本身不需要热更文案。
- if (evaluation.forced) return 'still-forced';
+ // 仍然强更(门槛还在,或换了更高的目标)→ 维持阻断,但把最新 target 写回:
+ // 服务端可能只修正了 installUrl / itmsUrl(坏链接恰恰是最需要救的故障),
+ // 或发布了更高的强更目标 —— 继续用旧 target 会让「去更新」一直打开旧链接。
+ if (evaluation.forced) {
+ if (evaluation.target) deps.onStillForced(evaluation.target);
+ return 'still-forced';
+ }
deps.onCleared();
return 'cleared';
} catch {
diff --git a/apps/mobile/src/update/useForcedUpdateRecheck.ts b/apps/mobile/src/update/useForcedUpdateRecheck.ts
index 63d4825f94..53b8c7b6e2 100644
--- a/apps/mobile/src/update/useForcedUpdateRecheck.ts
+++ b/apps/mobile/src/update/useForcedUpdateRecheck.ts
@@ -10,7 +10,7 @@ import Constants from 'expo-constants';
import * as Updates from 'expo-updates';
import { fetchLatestRelease } from './fetchLatestRelease';
import { createForcedUpdateRechecker } from './forcedUpdateRecheck';
-import { clearForcedUpdate } from './forcedUpdateStore';
+import { clearForcedUpdate, enterForcedUpdate } from './forcedUpdateStore';
import { isCanaryChannel } from './canaryChannelStore';
export function useForcedUpdateRecheck(isCanary = isCanaryChannel()): void {
@@ -26,6 +26,8 @@ export function useForcedUpdateRecheck(isCanary = isCanaryChannel()): void {
getCurrentRuntimeVersion: () => Updates.runtimeVersion,
getCurrentVersion: () => Constants.expoConfig?.version ?? null,
onCleared: clearForcedUpdate,
+ // 仍强更时刷新目标(等值时 enterForcedUpdate 幂等,不会引发重渲染)。
+ onStillForced: enterForcedUpdate,
now: () => Date.now(),
isCurrent: () => current,
});