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): 清除旧范围错误并统一列表恢复状态

Dash0ec567a53996
diff --git a/apps/mobile/app/devices/[deviceId].tsx b/apps/mobile/app/devices/[deviceId].tsx
index 5153f59a7f..c63b00dfe5 100644
--- a/apps/mobile/app/devices/[deviceId].tsx
+++ b/apps/mobile/app/devices/[deviceId].tsx
@@ -18,6 +18,7 @@ import { SafeAreaView, useSafeAreaInsets } from 'react-native-safe-area-context'
import { useTranslation } from 'react-i18next';
import type { TFunction } from 'i18next';
import { ConnectionBanner, useShowConnectionBanner } from '@/components/ConnectionBanner';
+import { resolveEffectiveConnectionError } from '@/components/connectionBannerVisibility';
import { unresponsiveDevicesStore, useUnresponsiveDevices } from '@/device-link/unresponsiveDevicesStore';
import { goBackGuarded } from '@/utils/backGuard';
import { useGuardedPush } from '@/utils/useGuardedPush';
@@ -220,6 +221,7 @@ function DeviceDetailScreenContent() {
// 熔断 open(电脑端未响应):relay 可能仍 online,可见性与 banner 文案单独入参。
const unresponsiveDevices = useUnresponsiveDevices();
const deviceUnresponsive = !!deviceId && unresponsiveDevices.has(deviceId);
+ const effectiveError = resolveEffectiveConnectionError(error, deviceUnresponsive);
const searchOrigins = useMemo(() => (deviceId ? [{
deviceId,
deviceName,
@@ -505,7 +507,7 @@ function DeviceDetailScreenContent() {
itemCount: 0,
hasSyncedThisOpen: syncedListQueryScope === listQueryScope,
loading: loading || indexedSearch.status === 'searching',
- failed: !!error,
+ failed: !!effectiveError,
});
useEffect(() => {
setSelectedSessionIds((prev) => {
@@ -760,7 +762,7 @@ function DeviceDetailScreenContent() {
/>
)}
ListEmptyComponent={suppressListEmptyState ? (
- error ? null : <RemoteListSyncingPlaceholder testID="deviceDetail.automationSyncing" />
+ effectiveError ? null : <RemoteListSyncingPlaceholder testID="deviceDetail.automationSyncing" />
) : (
<MainWindowEmptyState
centered
@@ -898,7 +900,7 @@ function DeviceDetailScreenContent() {
/>
)}
ListEmptyComponent={suppressListEmptyState ? (
- error ? null : <RemoteListSyncingPlaceholder testID="deviceDetail.projectSyncing" />
+ effectiveError ? null : <RemoteListSyncingPlaceholder testID="deviceDetail.projectSyncing" />
) : (
<MainWindowEmptyState
centered
@@ -1231,7 +1233,7 @@ function DeviceDetailScreenContent() {
section.title ? <Text style={styles.sectionTitle}>{section.title}</Text> : null
)}
ListEmptyComponent={suppressListEmptyState ? (
- error ? null : <RemoteListSyncingPlaceholder testID="deviceDetail.syncing" />
+ effectiveError ? null : <RemoteListSyncingPlaceholder testID="deviceDetail.syncing" />
) : (
<MainWindowEmptyState
centered
diff --git a/apps/mobile/src/__tests__/deviceDetailProjectHeaderLayout.test.ts b/apps/mobile/src/__tests__/deviceDetailProjectHeaderLayout.test.ts
index c20a5e9ba1..c3e7949069 100644
--- a/apps/mobile/src/__tests__/deviceDetailProjectHeaderLayout.test.ts
+++ b/apps/mobile/src/__tests__/deviceDetailProjectHeaderLayout.test.ts
@@ -39,7 +39,7 @@ function renderProject(searchOpen: boolean) {
const inset = { contentInsetAdjustmentBehavior: 'automatic' };
const scope: Record<string, unknown> = {
createElement, projectWorkingDir: '/project', sections: [], displaySections: [],
- showConnectionBanner: false, loading: false, status: 'connected', styles: {},
+ showConnectionBanner: false, loading: false, status: 'connected', styles: {}, effectiveError: null,
simpleScrollScreenSafeAreaEdges: () => ['left', 'right', 'bottom'],
simpleScrollInsetProps: inset, usesNativeStackHeader: () => true, headerHeight: 88,
t: (key: string) => key, projectName: 'Project', deviceName: 'Computer', deviceId: 'device',
diff --git a/apps/mobile/src/__tests__/homeDesktopFirst.test.ts b/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
index 1456befb52..fda0d1f905 100644
--- a/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
+++ b/apps/mobile/src/__tests__/homeDesktopFirst.test.ts
@@ -17,7 +17,15 @@ function readSource(relativePath: string): string {
const homeSource = ts.createSourceFile('HomeSurface.tsx', readSource('src/session/HomeSurface.tsx'), ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
const feedbackExpressions = new Map<string, string>();
const feedbackNames = new Set(['homeListScopePending', 'initialHomeLoading', 'initialHomeError', 'healthCopy', 'showConnectionRow', 'showHomeSyncAction', 'showHomeRecoveryProgress', 'connectionTitle']);
+let listScopeEffect = '';
function collectFeedback(node: ts.Node) {
+ if (ts.isExpressionStatement(node) && ts.isCallExpression(node.expression)
+ && node.expression.expression.getText(homeSource) === 'useLayoutEffect'
+ && node.expression.arguments[0]?.getText(homeSource).includes('homeListFilterRef.current === requestedListFilter')) {
+ listScopeEffect = ts.transpileModule(node.getText(homeSource), {
+ compilerOptions: { target: ts.ScriptTarget.ES2022 },
+ }).outputText;
+ }
if (ts.isVariableDeclaration(node) && feedbackNames.has(node.name.getText(homeSource)) && node.initializer) {
feedbackExpressions.set(node.name.getText(homeSource), ts.transpileModule(`const result = ${node.initializer.getText(homeSource)};`, {
compilerOptions: { target: ts.ScriptTarget.ES2022 },
@@ -46,6 +54,33 @@ function homeFeedback(overrides: Record<string, unknown>) {
}
describe('mobile Home connection feedback', () => {
+ // PR #6381: an error from A masked B's loading state. Existing feedback tests
+ // never changed the selection after an error. Unit: run the production layout
+ // effect with React's dependency comparison, before deriving the next frame.
+ it('retires the previous computer error before painting a new selection', () => {
+ let previousDeps: unknown[] = [];
+ let error: string | null = null;
+ const bindings = {
+ useLayoutEffect: (effect: () => void, deps: unknown[]) => {
+ if (deps.some((value, index) => value !== previousDeps[index])) effect();
+ previousDeps = deps;
+ },
+ setError: (value: string | null) => { error = value; },
+ homeListFilterRef: { current: 'active' }, requestedListFilter: 'active',
+ selectedDeviceId: 'a', advanceHomeSyncGeneration: () => undefined,
+ };
+ const render = () => new Function(...Object.keys(bindings), listScopeEffect)(...Object.values(bindings));
+ render();
+ error = 'A failed';
+ render();
+ expect(error).toBe('A failed');
+ bindings.selectedDeviceId = 'b';
+ render();
+ expect(homeFeedback({
+ connectionError: error, homeListOwnedDeviceIdsRef: { current: new Set() },
+ })).toMatchObject({ initialHomeLoading: true, initialHomeError: false });
+ });
+
// Unit regression for the reported active/archive flash: run Home's actual
// presentation expressions after startup has already settled. Existing tests
// only exercised connection banners and never a new list scope or search.
diff --git a/apps/mobile/src/__tests__/sessionEmptyState.test.ts b/apps/mobile/src/__tests__/sessionEmptyState.test.ts
index 49011d7997..72ee878846 100644
--- a/apps/mobile/src/__tests__/sessionEmptyState.test.ts
+++ b/apps/mobile/src/__tests__/sessionEmptyState.test.ts
@@ -1,7 +1,9 @@
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import ts from 'typescript';
+import * as React from 'react';
import { describe, expect, it, vi } from 'vitest';
+import { resolveEffectiveConnectionError } from '@/components/connectionBannerVisibility';
import {
shouldSuppressEmptyMessageState,
shouldSuppressRemoteListEmptyState,
@@ -14,7 +16,23 @@ const detailSource = ts.createSourceFile('detail.tsx', readFileSync(
resolve(process.cwd(), 'app/devices/[deviceId].tsx'), 'utf8',
), ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);
let syncCode = '';
+const presentation = new Map<string, string>();
+const pendingPlaceholders: string[] = [];
+function compileExpression(expression: ts.Expression) {
+ return ts.transpileModule(`const result = ${expression.getText(detailSource)};`, {
+ compilerOptions: { target: ts.ScriptTarget.ES2022, jsx: ts.JsxEmit.React },
+ }).outputText + '\nreturn result;';
+}
function findSync(node: ts.Node) {
+ if (ts.isVariableDeclaration(node) && node.initializer
+ && ['effectiveError', 'suppressListEmptyState'].includes(node.name.getText(detailSource))) {
+ presentation.set(node.name.getText(detailSource), compileExpression(node.initializer));
+ }
+ if (ts.isJsxAttribute(node) && node.name.getText(detailSource) === 'ListEmptyComponent'
+ && node.initializer && ts.isJsxExpression(node.initializer)
+ && node.initializer.expression && ts.isConditionalExpression(node.initializer.expression)) {
+ pendingPlaceholders.push(compileExpression(node.initializer.expression.whenTrue));
+ }
if (ts.isVariableDeclaration(node) && node.name.getText(detailSource) === 'syncSessions'
&& node.initializer && ts.isCallExpression(node.initializer)) {
syncCode = ts.transpileModule(`const sync = ${node.initializer.arguments[0].getText(detailSource)};`, {
@@ -25,6 +43,30 @@ function findSync(node: ts.Node) {
}
findSync(detailSource);
+// PR #6381: the banner expires DEVICE_UNRESPONSIVE after recovery, while all
+// three list modes still hid feedback using the raw error. Existing policy
+// tests did not exercise those render branches. Unit: execute their real JSX
+// expressions through failure → recovery, with a previously synced empty list.
+it('uses the same effective failure for empty-state suppression and every pending placeholder', () => {
+ const bindings: Record<string, unknown> = {
+ error: '[DEVICE_UNRESPONSIVE] circuit open', deviceUnresponsive: true,
+ resolveEffectiveConnectionError, shouldSuppressRemoteListEmptyState,
+ syncedListQueryScope: 'current', listQueryScope: 'current', loading: false,
+ indexedSearch: { status: 'idle' }, React, RemoteListSyncingPlaceholder: 'syncing',
+ };
+ const evaluate = (code: string) => new Function(...Object.keys(bindings), code)(...Object.values(bindings));
+ for (const recovering of [true, false]) {
+ bindings.deviceUnresponsive = recovering;
+ bindings.effectiveError = evaluate(presentation.get('effectiveError')!);
+ expect(evaluate(presentation.get('suppressListEmptyState')!)).toBe(recovering);
+ for (const code of pendingPlaceholders) {
+ const element = evaluate(code);
+ expect(element === null).toBe(recovering);
+ if (element) expect(element.type).toBe('syncing');
+ }
+ }
+});
+
it.each(['resolve', 'reject'])('keeps a new filter pending when the old request settles with %s', async (outcome) => {
const firstScope = { deviceId: 'mac', filter: 'active' };
const listQueryScopeRef = { current: firstScope };
diff --git a/apps/mobile/src/session/HomeSurface.tsx b/apps/mobile/src/session/HomeSurface.tsx
index 1a461bfab7..aea8c1fa6c 100644
--- a/apps/mobile/src/session/HomeSurface.tsx
+++ b/apps/mobile/src/session/HomeSurface.tsx
@@ -812,6 +812,9 @@ function HomeScreenContent({ active = true, onModeChange, width, newSessionInSys
}, [advanceHomeSyncGeneration, releaseHomeListOwner]);
useLayoutEffect(() => {
+ // Neither the previous computer's error nor the previous filter's error
+ // describes the new list scope. Clear it before painting its loading state.
+ setError(null);
if (homeListFilterRef.current === requestedListFilter) return;
homeListFilterRef.current = requestedListFilter;
// A new filter is a new list scope even on the same computer. Reuse the
@@ -825,8 +828,7 @@ function HomeScreenContent({ active = true, onModeChange, width, newSessionInSys
for (const deviceId of homeSyncTargetDeviceIdsRef.current) next[deviceId] = 'syncing';
return next;
});
- setError(null);
- }, [advanceHomeSyncGeneration, requestedListFilter]);
+ }, [advanceHomeSyncGeneration, requestedListFilter, selectedDeviceId]);
useEffect(() => () => {
const owned = [...homeListOwnedDeviceIdsRef.current];