Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(devices): refresh locale labels and disambiguate mobile rows
Chris4a7b7aeba308
diff --git a/apps/desktop/src/renderer/__tests__/useProjectGroups.test.tsx b/apps/desktop/src/renderer/__tests__/useProjectGroups.test.tsxindex 4f98bafc71..55eb1ee1c7 100644--- a/apps/desktop/src/renderer/__tests__/useProjectGroups.test.tsx+++ b/apps/desktop/src/renderer/__tests__/useProjectGroups.test.tsx@@ -1,8 +1,9 @@// @vitest-environment jsdom-import { cleanup, renderHook } from '@testing-library/react';+import { act, cleanup, renderHook } from '@testing-library/react';import { afterEach, beforeEach, expect, it, vi } from 'vitest';import type { Session } from '@/lib/ccAgent.types';import { useProjectGroups } from '@/features/cc-agent/hooks/useProjectGroups';+import i18n from '@/i18n';const registry = vi.hoisted(() => ({ hosts: [] as RemoteHostSnapshot[], bots: [] }));vi.mock('@/hooks/useRemoteSshHosts', () => ({ useRemoteSshHosts: () => registry.hosts }));@@ -67,3 +68,25 @@ it('updates collision labels when another device starts or stops sharing the namrerender({ rows });expect(result.current.projects[0].remoteMachineIdentity?.detail).toBeNull();});++it('refreshes cached unnamed labels and reused results when the language changes', async () => {+ const previousLanguage = i18n.language;+ await i18n.changeLanguage('en');+ const rows = [task('a', { deviceLinkDeviceId: 'one', deviceLinkDeviceName: 'one' })];+ try {+ const { result } = renderHook(() => {+ const all = useProjectGroups(rows);+ const filtered = useProjectGroups(rows, undefined, false, undefined, '', all);+ return { all, filtered };+ });+ const before = result.current.all;+ expect(before.projects[0].remoteMachineIdentity?.label).toBe('another computer');+ await act(async () => { await i18n.changeLanguage('zh-CN'); });+ expect(result.current.all.projects[0].remoteMachineIdentity?.label).toBe('另一台电脑');+ expect(result.current.all).not.toBe(before);+ expect(result.current.filtered).toBe(result.current.all);+ } finally {+ cleanup();+ await i18n.changeLanguage(previousLanguage);+ }+});diff --git a/apps/desktop/src/renderer/features/cc-agent/hooks/useProjectGroups.ts b/apps/desktop/src/renderer/features/cc-agent/hooks/useProjectGroups.tsindex dca4c82976..7948b1ab9d 100644--- a/apps/desktop/src/renderer/features/cc-agent/hooks/useProjectGroups.ts+++ b/apps/desktop/src/renderer/features/cc-agent/hooks/useProjectGroups.ts@@ -7,6 +7,7 @@*/import { useMemo, useSyncExternalStore } from 'react';+import { useStableTranslation } from '@/hooks/useStableTranslation';import { createProjectGroupsSelector } from '../lib/projectGroupsSelector';import { useProvisionalDraftProjectTaskId } from './useProvisionalDraftProjectTaskId';@@ -35,6 +36,8 @@ export function useProjectGroups(equivalentResult?: ProjectGroupsResult,projectAliasMembers?: readonly Session[],): ProjectGroupsResult {+ const { i18n } = useStableTranslation();+ const language = i18n.resolvedLanguage ?? i18n.language;const sshHosts = useRemoteSshHosts();const hostProjectAliases = useSyncExternalStore(remoteProjectAliases.subscribe, remoteProjectAliases.getSnapshot);const selectGroups = useMemo(() => createProjectGroupsSelector(), []);@@ -76,11 +79,11 @@ export function useProjectGroups([groups.projects],);const ambiguityKey = JSON.stringify(projectDevices);- // Weak keys keep only live grouping nodes. Registry/collision changes must+ // Weak keys keep only live grouping nodes. Registry/collision/language changes must// re-enrich even unchanged nodes so remote labels never retain stale names.const enrichedProjects = useMemo(() => new WeakMap<ProjectNode, ProjectNode>(),- [sshHosts, ambiguityKey],+ [sshHosts, ambiguityKey, language],);return useMemo(() => {if (equivalentResult) return equivalentResult;@@ -99,5 +102,5 @@ export function useProjectGroups(return enriched;}),};- }, [groups, equivalentResult, enrichedProjects, sshHosts, projectDevices]);+ }, [groups, equivalentResult, enrichedProjects, sshHosts, projectDevices, language]);}diff --git a/apps/mobile/src/__tests__/deviceManagementAndroid.test.tsx b/apps/mobile/src/__tests__/deviceManagementAndroid.test.tsxindex b8f1198f87..822f452747 100644--- a/apps/mobile/src/__tests__/deviceManagementAndroid.test.tsx+++ b/apps/mobile/src/__tests__/deviceManagementAndroid.test.tsx@@ -55,11 +55,26 @@ vi.mock("@/platform/gestureHandler", () => ({vi.mock("@expo/ui", () => ({ListItem: (props: Captured) => {captured.listItems.push(props);- return null;+ return createElement("div", null, props.children as ReactNode);},+ Host: ({ children }: { children?: ReactNode }) => createElement("div", null, children),Text: ({ children }: { children?: ReactNode }) => createElement("span", null, children),}));-vi.mock("react-i18next", () => ({ useTranslation: () => ({ t: (key: string) => key }) }));+vi.mock("@expo/ui/swift-ui", () => {+ const container = ({ children }: { children?: ReactNode }) => createElement("div", null, children);+ const SwipeActions = Object.assign(container, { Actions: container });+ return { Button: container, Circle: () => null, HStack: container, List: container, Section: container, SwipeActions, Text: container };+});+vi.mock("@expo/ui/swift-ui/modifiers", () => {+ const modifier = () => ({});+ return { accessibilityLabel: (label: string) => ({ label }), disabled: modifier, font: modifier,+ foregroundStyle: modifier, frame: modifier, labelStyle: modifier, listRowBackground: modifier,+ listStyle: modifier, refreshable: modifier, scrollContentBackground: modifier, tint: modifier };+});+vi.mock("react-i18next", async (importOriginal) => ({+ ...await importOriginal<typeof import("react-i18next")>(),+ useTranslation: () => ({ t: (key: string, options?: { name?: string }) => options?.name ? `${key}: ${options.name}` : key }),+}));vi.mock("@/theme", async () => {const tokens = await import("@/theme/tokens");return {@@ -76,6 +91,8 @@ vi.mock("@/session/SettingsGroupRows", () => ({import { DeviceInformationFields } from "@/device-link/DeviceInformationFields";import { DeviceManagementList } from "@/device-link/DeviceManagementList";+import { DeviceManagementList as IOSDeviceManagementList } from "@/device-link/DeviceManagementList.ios";+import i18n from "@/i18n";function device(id: string, online: boolean): DeviceView {return { deviceId: id, name: `Mac ${id}`, online, lastSeenAt: null } as DeviceView;@@ -170,4 +187,31 @@ describe("Android device management follows iOS interactions", () => {textAlign: "right",});});++ // Regression: passing no roster made two cached ID-as-name devices indistinguishable.+ // Both production lists must label across sections without changing their action targets.+ it.each([['android', DeviceManagementList], ['ios', IOSDeviceManagementList]] as const)(+ '%s disambiguates unnamed rows and their screen-reader labels using the complete list',+ (platform, List) => {+ const first = { ...device('a', true), name: 'a' };+ const second = { ...device('b', false), name: 'b' };+ const onOpen = vi.fn();+ const html = renderToStaticMarkup(createElement(List, {+ busy: false, rows: [row(first, 'Online', 'just now'), row(second, 'Offline', '2h ago')],+ onOpen, onRename: vi.fn(), onDelete: vi.fn(), onRefresh: vi.fn(async () => undefined),+ }));+ const fallback = i18n.t('devices.cloudCompanion.unknownDevice');+ for (const [index, target] of [first, second].entries()) {+ const name = `${fallback} (${index + 1})`;+ expect(html).toContain(name);+ const item = (platform === 'android' ? captured.pressables : captured.listItems)+ .find((props) => props.testID === `deviceManagement.open.${target.deviceId}`);+ const label = `devices.management.openDevice: ${name}`;+ if (platform === 'android') expect(item?.accessibilityLabel).toBe(label);+ else expect(item?.modifiers).toContainEqual({ label: `${label}, ${target.online ? 'Online · just now' : '2h ago'}` });+ (item?.onPress as () => void)();+ expect(onOpen).toHaveBeenLastCalledWith(target);+ }+ },+ );});diff --git a/apps/mobile/src/device-link/DeviceManagementList.ios.tsx b/apps/mobile/src/device-link/DeviceManagementList.ios.tsxindex 772829d226..420913a645 100644--- a/apps/mobile/src/device-link/DeviceManagementList.ios.tsx+++ b/apps/mobile/src/device-link/DeviceManagementList.ios.tsx@@ -3,6 +3,7 @@ import { useMemo, useState } from 'react';import { Host, ListItem } from '@expo/ui';import { Button, Circle, HStack, List, Section, SwipeActions, Text } from '@expo/ui/swift-ui';import {+ accessibilityLabel,disabled,font,foregroundStyle,@@ -43,12 +44,17 @@ export function DeviceManagementList({const { t } = useTranslation();const [offlineExpanded, setOfflineExpanded] = useState(false);const sections = useMemo(() => buildDeviceManagementSections(rows), [rows]);+ const devices = useMemo(() => rows.map((row) => row.device), [rows]);const offlineRows = visibleOfflineDeviceRows(sections.offline, offlineExpanded);const renderRow = (row: DeviceManagementListProps['rows'][number]) => {const { device } = row;+ const name = deviceDisplayName(device.deviceId, device.name, devices);return (<SwipeActions key={device.deviceId} modifiers={[listRowBackground(colors.surfaceElevated)]}><ListItem+ modifiers={[accessibilityLabel([+ t('devices.management.openDevice', { name }), deviceManagementStatusText(row),+ ].filter(Boolean).join(', '))]}onPress={() => onOpen(device)}leading={<Monitor@@ -87,7 +93,7 @@ export function DeviceManagementList({foregroundStyle({ type: 'hierarchical', style: 'primary' }),]}>- {deviceDisplayName(device.deviceId, device.name)}+ {name}</Text></ListItem><SwipeActions.Actions edge="leading" allowsFullSwipe={false}>diff --git a/apps/mobile/src/device-link/DeviceManagementList.tsx b/apps/mobile/src/device-link/DeviceManagementList.tsxindex d679b0e27c..1f4058322d 100644--- a/apps/mobile/src/device-link/DeviceManagementList.tsx+++ b/apps/mobile/src/device-link/DeviceManagementList.tsx@@ -35,6 +35,7 @@ export function DeviceManagementList(props: DeviceManagementListProps) {const [offlineExpanded, setOfflineExpanded] = useState(false);const [refreshing, setRefreshing] = useState(false);const sections = useMemo(() => buildDeviceManagementSections(props.rows), [props.rows]);+ const devices = useMemo(() => props.rows.map((row) => row.device), [props.rows]);const offlineRows = visibleOfflineDeviceRows(sections.offline, offlineExpanded);const { onRefresh } = props;const refresh = useCallback(() => {@@ -46,7 +47,8 @@ export function DeviceManagementList(props: DeviceManagementListProps) {openRow.current = ref;};const renderRow = (row: DeviceManagementListProps['rows'][number]) => (- <DeviceRow key={row.device.deviceId} {...props} row={row} onWillOpen={onWillOpen} />+ <DeviceRow key={row.device.deviceId} {...props} row={row}+ name={deviceDisplayName(row.device.deviceId, row.device.name, devices)} onWillOpen={onWillOpen} />);return (<ScrollView@@ -96,6 +98,7 @@ export function DeviceManagementList(props: DeviceManagementListProps) {function DeviceRow({row,+ name,busy,onOpen,onRename,@@ -103,6 +106,7 @@ function DeviceRow({onWillOpen,}: DeviceManagementListProps & {row: DeviceManagementListProps['rows'][number];+ name: string;onWillOpen(ref: ClassicSwipeableMethods | null): void;}) {const ref = useRef<ClassicSwipeableMethods | null>(null);@@ -147,7 +151,7 @@ function DeviceRow({onSwipeableWillOpen={() => onWillOpen(ref.current)}><Pressable- accessibilityLabel={t('devices.management.openDevice', { name: deviceDisplayName(row.device.deviceId, row.device.name) })}+ accessibilityLabel={t('devices.management.openDevice', { name })}accessibilityRole="button"onPress={() => onOpen(row.device)}testID={`deviceManagement.open.${row.device.deviceId}`}@@ -159,7 +163,7 @@ function DeviceRow({color={colors.textSecondary}/><View style={styles.labels}>- <Text numberOfLines={1} style={styles.name}>{deviceDisplayName(row.device.deviceId, row.device.name)}</Text>+ <Text numberOfLines={1} style={styles.name}>{name}</Text><View style={styles.status}>{/* 状态点:可控用品牌 teal,其余(离线 / 未开远控 / 已撤销)用 muted(borderStrong)。 */}<StatusDot tone={row.canOpen ? 'ready' : 'muted'} />