Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(device-link): 对齐中断入口并释放离线订阅
Dashfaa3c60e319d
diff --git a/apps/desktop/src/renderer/__tests__/remoteContentRecoveryHook.test.ts b/apps/desktop/src/renderer/__tests__/remoteContentRecoveryHook.test.tsindex 5f013db0eb..3017c80226 100644--- a/apps/desktop/src/renderer/__tests__/remoteContentRecoveryHook.test.ts+++ b/apps/desktop/src/renderer/__tests__/remoteContentRecoveryHook.test.ts@@ -157,3 +157,30 @@ it('does not reset a recovered mounted task on its first busy presence update',expect(hook.result.current.contentState).toBe('syncing');hook.unmount();});++it.each(['relay', 'peer', 'disabled', 'unresponsive'])('releases the local topic on offline unmount (%s)', async (reason) => {+ vi.useFakeTimers();+ const unsubscribe = vi.fn(async () => {});+ let status!: (value: { status: string }) => void;+ let presence!: (value: { deviceId: string; online: boolean; remoteControlEnabled: boolean }) => void;+ let responsiveness!: (value: { deviceId: string; unresponsive: boolean }) => void;+ vi.stubGlobal('electronAPI', {+ deviceLink: {+ subscribe: vi.fn(async () => {}), unsubscribe,+ onStatusChanged: (cb: typeof status) => { status = cb; return () => {}; },+ onPresenceChanged: (cb: typeof presence) => { presence = cb; return () => {}; },+ onResponsivenessChanged: (cb: typeof responsiveness) => { responsiveness = cb; return () => {}; },+ },+ });+ mocks.running = false;+ mocks.reconcile.mockResolvedValue(true);+ const hook = renderHook(() => useRemoteSessionSync('session', 'host'));+ await act(async () => { await vi.advanceTimersByTimeAsync(0); });+ act(() => {+ if (reason === 'relay') status({ status: 'offline' });+ else if (reason === 'unresponsive') responsiveness({ deviceId: 'host', unresponsive: true });+ else presence({ deviceId: 'host', online: reason !== 'peer', remoteControlEnabled: reason !== 'disabled' });+ });+ hook.unmount();+ expect(unsubscribe).toHaveBeenCalledExactlyOnceWith('host', ['session:session']);+});diff --git a/apps/desktop/src/renderer/features/cc-agent/hooks/useRemoteSessionSync.ts b/apps/desktop/src/renderer/features/cc-agent/hooks/useRemoteSessionSync.tsindex 85d9848b0c..0916212321 100644--- a/apps/desktop/src/renderer/features/cc-agent/hooks/useRemoteSessionSync.ts+++ b/apps/desktop/src/renderer/features/cc-agent/hooks/useRemoteSessionSync.ts@@ -401,7 +401,6 @@ export function useRemoteSessionSync(.catch((err) => log.warn('device-link subscribe(session) failed', err));},unsubscribe: (d, topics) => {- if (!canRead()) return;return window.electronAPI.deviceLink.unsubscribe(d, topics).catch(() => {});},reconcile: (s) => {diff --git a/apps/mobile/app/devices/index.tsx b/apps/mobile/app/devices/index.tsxindex e977ac6cfd..24fa02aeea 100644--- a/apps/mobile/app/devices/index.tsx+++ b/apps/mobile/app/devices/index.tsx@@ -3843,7 +3843,7 @@ function HomeSessionRowInner({const primary = statusTarget;if (primary) onOpenSession(primary);};- const groupRowOpensPrimary = !!group && attention && !groupExpanded;+ const groupRowOpensPrimary = !!group && (attention || rightStatus === 'error') && !groupExpanded;const handlePress = selectionMode && onPressSelection? onPressSelection: groupdiff --git a/apps/mobile/src/__tests__/automationGroupPress.test.ts b/apps/mobile/src/__tests__/automationGroupPress.test.tsnew file mode 100644index 0000000000..49f4284bd1--- /dev/null+++ b/apps/mobile/src/__tests__/automationGroupPress.test.ts@@ -0,0 +1,53 @@+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';+import { describe, expect, it, vi } from 'vitest';+import type { RemoteSessionListItem } from '@cindy/maker-shared/session-list';+import { resolveMobileSessionRowStatus } from '../session/sessionRightStatus';++const source = readFileSync(resolve(process.cwd(), 'app/devices/index.tsx'), 'utf8').replace(/\r\n/g, '\n');+const start = source.indexOf(' const openGroupPrimary = () => {');+const body = source.slice(start, source.indexOf(' return (', start));+// Execute the actual row handler while keeping native rendering out of this unit test.+const handler = new Function('group', 'statusTarget', 'attention', 'rightStatus', 'groupExpanded',+ 'selectionMode', 'onPressSelection', 'onOpenSession', 'onToggleAutomationGroup', 'item',+ `${body}\nreturn handlePress;`);+const row = (id: string, time: number): RemoteSessionListItem => ({+ session: { id, status: 'active', createdAt: new Date(time).toISOString(), updatedAt: new Date(time).toISOString() },+ pendingInteractionCount: 0,+} as RemoteSessionListItem);++describe('automation group row press', () => {+ it.each([false, true])('opens the persisted interruption only while collapsed (expanded=%s)', (expanded) => {+ const interrupted = row('interrupted', 1000);+ Object.assign(interrupted.session, { activeTurnStartedAt: 1000, interruptedTurnStartedAt: 1000, lastTurnEndedAt: 900 });+ const latest = row('latest', 2000);+ const item = { ...latest, automationGroup: { key: 'group', items: [interrupted, latest], sessionCount: 2 } } as RemoteSessionListItem;+ const { status, target } = resolveMobileSessionRowStatus(item, false, expanded);+ const open = vi.fn(); const toggle = vi.fn();+ handler(item.automationGroup, target, false, status, expanded, false, undefined, open, toggle, item)();+ if (expanded) { expect(toggle).toHaveBeenCalledWith('group'); expect(open).not.toHaveBeenCalled(); }+ else { expect(open).toHaveBeenCalledWith(interrupted); expect(toggle).not.toHaveBeenCalled(); }+ Object.assign(interrupted.session, { lastTurnEndedAt: 1000 });+ const resolved = resolveMobileSessionRowStatus(item, false, false);+ open.mockClear(); toggle.mockClear();+ handler(item.automationGroup, resolved.target, false, resolved.status, false, false, undefined, open, toggle, item)();+ expect(toggle).toHaveBeenCalledWith('group'); expect(open).not.toHaveBeenCalled();+ });++ it.each(['time', 'running', 'done', 'awaiting', 'error'])('preserves selection, expansion and existing attention for %s', (status) => {+ const item = row('latest', 2000); const group = { key: 'group' };+ for (const attention of [false, true]) for (const expanded of [false, true]) {+ const open = vi.fn(); const toggle = vi.fn(); const select = vi.fn();+ handler(group, item, attention, status, expanded, true, select, open, toggle, item)();+ expect(select).toHaveBeenCalledOnce(); expect(open).not.toHaveBeenCalled(); expect(toggle).not.toHaveBeenCalled();+ handler(group, item, attention, status, expanded, false, select, open, toggle, item)();+ expect(open).toHaveBeenCalledTimes(!expanded && (attention || status === 'error') ? 1 : 0);+ expect(toggle).toHaveBeenCalledTimes(expanded || (!attention && status !== 'error') ? 1 : 0);+ }+ });++ it('keeps the arrow independent from row navigation', () => {+ const arrow = source.slice(source.indexOf('event.stopPropagation();', start));+ expect(arrow).toMatch(/^event.stopPropagation\(\);\s+onToggleAutomationGroup\?\.\(group.key\);/);+ });+});