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): keep project connection icons tied to shared connection state

Dash5ba5f401fd9e
diff --git a/apps/mobile/src/__tests__/homeProjectMachineIdentity.test.ts b/apps/mobile/src/__tests__/homeProjectMachineIdentity.test.ts
index c92f3314cd..3d1003b905 100644
--- a/apps/mobile/src/__tests__/homeProjectMachineIdentity.test.ts
+++ b/apps/mobile/src/__tests__/homeProjectMachineIdentity.test.ts
@@ -2,6 +2,13 @@ import { describe, expect, it } from 'vitest';
import type { MobileHomeDeviceFilterItem, MobileHomeProjectGroup } from '@/session/mobileHome';
import { buildHomeProjectMachineIdentities } from '@/session/homeProjectMachineIdentity';
+const connected = {
+ status: 'online' as const,
+ getPresenceAvailability: (_deviceId: string): boolean | null => true,
+ unresponsiveDevices: new Set<string>(),
+ revokedDevices: new Set<string>(),
+};
+
function project(key: string, deviceId: string | null, deviceName: string): MobileHomeProjectGroup {
return {
key, deviceId, deviceName, title: 'folder', workingDir: '/folder',
@@ -23,7 +30,7 @@ describe('project machine identity parity with Desktop', () => {
projects: [project('a', 'win', 'Windows'), project('b', 'mac', 'MacBook'), project('c', 'mac', 'MacBook')],
deviceFilters: [device('win', 'Windows'), device('mac', 'MacBook')],
selectedDeviceId: null,
- });
+ }, connected);
expect([...result.values()].map((item) => item.displayLabel)).toEqual(['Windows', 'MacBook', 'MacBook']);
expect(result.get('a')).toEqual({ displayLabel: 'Windows', disconnected: false, hideLabel: false });
});
@@ -33,12 +40,12 @@ describe('project machine identity parity with Desktop', () => {
const result = buildHomeProjectMachineIdentities({
projects: [project('a', 'one', 'MacBook'), project('b', 'two', 'macbook')],
deviceFilters, selectedDeviceId: null,
- });
+ }, connected);
expect(result.get('a')?.displayLabel).toBe('MacBook · one');
expect(result.get('b')?.displayLabel).toBe('macbook · two');
const onlyOneVisible = buildHomeProjectMachineIdentities({
projects: [project('a', 'one', 'MacBook')], deviceFilters, selectedDeviceId: null,
- });
+ }, connected);
expect(onlyOneVisible.get('a')?.displayLabel).toBe('MacBook');
});
@@ -46,24 +53,62 @@ describe('project machine identity parity with Desktop', () => {
const result = buildHomeProjectMachineIdentities({
projects: [project('a', 'mac', 'MacBook')],
deviceFilters: [device('mac', 'MacBook', false)], selectedDeviceId: 'mac',
- });
+ }, { ...connected, getPresenceAvailability: () => false });
expect(result.get('a')).toEqual({ displayLabel: 'MacBook', disconnected: true, hideLabel: true });
});
- it('reflects a failed connection and a later recovery without hiding the machine label', () => {
+ // Regression: reopening a task list first paints cached tasks without its local
+ // device roster. Unit coverage previously equated that unknown/failed list state
+ // with disconnection; exercise the production icon projection across the gap.
+ it('keeps the project connected across roster loading, stale offline rows and refreshed rows', () => {
+ const home = {
+ projects: [project('a', 'mac', 'MacBook')],
+ selectedDeviceId: null,
+ };
+ for (const deviceFilters of [
+ [],
+ [{ ...device('mac', 'MacBook', false), state: 'unknown' as const }],
+ [device('mac', 'MacBook', false)],
+ [device('mac', 'MacBook')],
+ ]) {
+ expect(buildHomeProjectMachineIdentities({ ...home, deviceFilters }, connected).get('a'))
+ .toEqual({ displayLabel: 'MacBook', disconnected: false, hideLabel: false });
+ }
+ });
+
+ it.each([
+ ['unknown presence', { getPresenceAvailability: (): boolean | null => null }, false],
+ ['offline or remote disabled', { getPresenceAvailability: (): boolean | null => false }, true],
+ ['relay reconnecting', { status: 'connecting' as const }, true],
+ ['relay stopped', { status: 'stopped' as const }, true],
+ ['unresponsive host', { unresponsiveDevices: new Set(['mac']) }, true],
+ ['revoked host', { revokedDevices: new Set(['mac']) }, true],
+ ] as const)('uses shared evidence for %s even while the roster says ready', (_label, evidence, disconnected) => {
const home = {
projects: [project('a', 'mac', 'MacBook')],
deviceFilters: [device('mac', 'MacBook')], selectedDeviceId: null,
};
- expect(buildHomeProjectMachineIdentities(home, { mac: 'failed' }).get('a')?.disconnected).toBe(true);
- expect(buildHomeProjectMachineIdentities(home, { mac: 'idle' }).get('a')?.disconnected).toBe(false);
+ expect(buildHomeProjectMachineIdentities(home, { ...connected, ...evidence }).get('a')?.disconnected).toBe(disconnected);
+ expect(buildHomeProjectMachineIdentities(home, connected).get('a')?.disconnected).toBe(false);
+ });
+
+ it('keeps failures scoped to their computer and reads current presence with unchanged list inputs', () => {
+ const home = {
+ projects: [project('a', 'mac', 'MacBook'), project('b', 'win', 'Windows')],
+ deviceFilters: [], selectedDeviceId: null,
+ };
+ let macAvailable = false;
+ const evidence = { ...connected, getPresenceAvailability: (id: string) => id !== 'mac' || macAvailable };
+ expect([...buildHomeProjectMachineIdentities(home, evidence).values()].map(row => row.disconnected)).toEqual([true, false]);
+ macAvailable = true;
+ expect([...buildHomeProjectMachineIdentities(home, evidence).values()].map(row => row.disconnected)).toEqual([false, false]);
});
it('uses the current device name, falls back to ID for empty names, and skips unowned folders', () => {
const result = buildHomeProjectMachineIdentities({
projects: [project('a', 'mac', 'Old name'), project('b', 'win', ''), project('c', null, '')],
deviceFilters: [device('mac', 'Renamed Mac'), device('win', ' ')], selectedDeviceId: null,
- });
+ }, connected);
expect(result.get('a')?.displayLabel).toBe('Renamed Mac');
expect(result.get('b')?.displayLabel).toBe('win');
expect(result.has('c')).toBe(false);
diff --git a/apps/mobile/src/session/HomeSurface.tsx b/apps/mobile/src/session/HomeSurface.tsx
index 97881ca50b..2dc5eb6e4d 100644
--- a/apps/mobile/src/session/HomeSurface.tsx
+++ b/apps/mobile/src/session/HomeSurface.tsx
@@ -530,6 +530,7 @@ function HomeScreenContent({ active = true, onModeChange, width, newSessionInSys
getPresenceAvailability,
invoke,
lastPresenceSnapshot,
+ presenceVersion,
recoveringDeviceIds,
readDeviceList,
status,
@@ -2046,8 +2047,12 @@ function HomeScreenContent({ active = true, onModeChange, width, newSessionInSys
[deviceModels, scheduleIndex, selectedDeviceId, homeSessions, t],
);
const projectMachineIdentities = useMemo(
- () => buildHomeProjectMachineIdentities(home, deviceConnectionStates),
- [home, deviceConnectionStates],
+ () => buildHomeProjectMachineIdentities(home, {
+ status, getPresenceAvailability, unresponsiveDevices, revokedDevices,
+ }),
+ // Presence is read through a stable getter; its version/connection epoch must
+ // refresh icons even when the page-local device list has not changed.
+ [home, status, getPresenceAvailability, presenceVersion, connectionEpoch, unresponsiveDevices, revokedDevices],
);
const runningSessionIds = useMemo(() => {
const ids = new Set<string>();
diff --git a/apps/mobile/src/session/homeProjectMachineIdentity.ts b/apps/mobile/src/session/homeProjectMachineIdentity.ts
index 96fa0a79be..e956354084 100644
--- a/apps/mobile/src/session/homeProjectMachineIdentity.ts
+++ b/apps/mobile/src/session/homeProjectMachineIdentity.ts
@@ -1,3 +1,4 @@
+import type { DeviceLinkContextValue } from '@/device-link/DeviceLinkContext';
import type { MobileHomePresentation } from './mobileHome';
export interface HomeProjectMachineIdentity {
@@ -6,10 +7,15 @@ export interface HomeProjectMachineIdentity {
hideLabel: boolean;
}
+type HomeProjectConnection = Pick<DeviceLinkContextValue, 'status' | 'getPresenceAvailability'> & {
+ unresponsiveDevices: ReadonlySet<string>;
+ revokedDevices: ReadonlySet<string>;
+};
+
/** Mirrors Desktop remoteProjectIdentity: only visible, distinct devices disambiguate names. */
export function buildHomeProjectMachineIdentities(
home: Pick<MobileHomePresentation, 'projects' | 'deviceFilters' | 'selectedDeviceId'>,
- connectionStates: Readonly<Record<string, string>> = {},
+ connection: HomeProjectConnection,
): ReadonlyMap<string, HomeProjectMachineIdentity> {
const filters = new Map(home.deviceFilters.map((device) => [device.deviceId, device]));
const deviceName = (project: MobileHomePresentation['projects'][number]) =>
@@ -27,10 +33,14 @@ export function buildHomeProjectMachineIdentities(
if (!project.deviceId) continue;
const name = deviceName(project);
const ambiguous = name && (idsByName.get(name.toLowerCase())?.size ?? 0) > 1;
- const device = filters.get(project.deviceId);
identities.set(project.key, {
displayLabel: ambiguous ? `${name} · ${project.deviceId}` : name || project.deviceId,
- disconnected: !device?.available || connectionStates[project.deviceId] === 'failed',
+ // A remounted list paints cached projects before its device roster arrives.
+ // Missing/stale roster rows and failed list reads are not connection evidence.
+ disconnected: connection.status !== 'online'
+ || connection.getPresenceAvailability(project.deviceId) === false
+ || connection.unresponsiveDevices.has(project.deviceId)
+ || connection.revokedDevices.has(project.deviceId),
// As on Desktop, an explicit device heading makes the inline label redundant.
hideLabel: home.selectedDeviceId === project.deviceId,
});
diff --git a/docs/dev-rules/remote-and-mobile-adaptation.md b/docs/dev-rules/remote-and-mobile-adaptation.md
index 3de73ad311..92f9ba3aad 100644
--- a/docs/dev-rules/remote-and-mobile-adaptation.md
+++ b/docs/dev-rules/remote-and-mobile-adaptation.md
@@ -399,6 +399,11 @@ Mobile 历史读取在 relay 已在线且目标 presence 不是明确不可用
历史控制器与页面同步;也不能为了放行读取伪造在线快照。明确离线/停用或 relay 未在线时
仍只展示缓存,授权、撤权和旧代结果拦截继续由原链路处理。
+Mobile 项目标题的电脑图标同样使用共享连接状态、当前 presence、无响应与撤权证据,
+不从页面局部设备清单的缺失、旧快照或列表读取失败推导断连。首页、任务抽屉与宽屏常驻列表
+共用此判据;重建列表与普通同步不会重置连接图标,真实断连与恢复仍随共享状态更新。
+实现与回归见 `homeProjectMachineIdentity.ts`、`HomeSurface.tsx` 与 `homeProjectMachineIdentity.test.ts`。
+
Mobile 返回任务或恢复网络时,历史视图只恢复展示,由页面既有同步协调器发起快照,
不再由视图激活另读一页。已有缓存且订阅尚未确认时,最多等待 2 秒合并本次列表/详情
订阅确认;以当前 ACK 表为准,不复用前一次聚焦/连接已完成的 Promise。等待期间只