Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
feat(desktop): 更新重启前提示运行中任务风险 (#765)
DavidShenXDb6a3b452249a
diff --git a/apps/desktop/src/main/__tests__/clientEndpointsService.test.ts b/apps/desktop/src/main/__tests__/clientEndpointsService.test.tsindex 5e8c2f00ce..7511332912 100644--- a/apps/desktop/src/main/__tests__/clientEndpointsService.test.ts+++ b/apps/desktop/src/main/__tests__/clientEndpointsService.test.ts@@ -1209,8 +1209,13 @@ describe('netlog 产物事后核对(verifyEndpointNetLogCapture)', () => {// 它能抓住 symlink / 类型变化,抓不住"号被回收后重建"。const capture = prepareEndpointNetLogFile(logDir)!;fs.writeFileSync(capture.file, '{}', 'utf8');- expect(verifyEndpointNetLogCapture({ ...capture, dirIno: capture.dirIno + 1 })).toBe(false);- expect(verifyEndpointNetLogCapture({ ...capture, dirDev: capture.dirDev + 1 })).toBe(false);+ // Windows 可能把 ino 暴露为 0;生产逻辑会有意跳过无法执行的 inode 身份核对。+ if (!capture.dirIno) return;+ // 不用 +1:Windows 的 inode 可能超过 Number.MAX_SAFE_INTEGER,+1 后数值仍相等。+ const otherIno = capture.dirIno === 1 ? 2 : 1;+ const otherDev = capture.dirDev === 1 ? 2 : 1;+ expect(verifyEndpointNetLogCapture({ ...capture, dirIno: otherIno })).toBe(false);+ expect(verifyEndpointNetLogCapture({ ...capture, dirDev: otherDev })).toBe(false);});it('目标被换成 symlink → 不通过', () => {diff --git a/apps/desktop/src/renderer/__tests__/updateBannerBusyHint.test.tsx b/apps/desktop/src/renderer/__tests__/updateBannerBusyHint.test.tsxnew file mode 100644index 0000000000..2ea2ca9fef--- /dev/null+++ b/apps/desktop/src/renderer/__tests__/updateBannerBusyHint.test.tsx@@ -0,0 +1,108 @@+// @vitest-environment jsdom++import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';++const { anySessionInTurn, relaunchToUpdate } = vi.hoisted(() => ({+ anySessionInTurn: vi.fn<() => Promise<boolean>>(),+ relaunchToUpdate: vi.fn(),+}));++vi.mock('react-i18next', () => ({+ useTranslation: () => ({+ t: (key: string) => key,+ }),+}));++vi.mock('@/hooks/useUpdateStatus', () => ({+ useUpdateStatus: () => ({+ status: 'ready',+ version: '1.2.3',+ errorCode: null,+ }),+}));++vi.mock('@/hooks/useUpdateBannerDismiss', () => ({+ useUpdateBannerDismiss: () => ({+ dismissed: false,+ dismiss: vi.fn(),+ restore: vi.fn(),+ isNewUpdateAfterDismiss: vi.fn(() => false),+ }),+}));++vi.mock('@/components/ui/tooltip', () => ({+ Tip: ({ children }: { children: React.ReactNode }) => children,+}));++import { UpdateBanner } from '@/components/sidebar/UpdateBanner';++beforeEach(() => {+ anySessionInTurn.mockReset();+ relaunchToUpdate.mockReset();+ Object.defineProperty(window, 'electronAPI', {+ configurable: true,+ value: {+ anySessionInTurn,+ relaunchToUpdate,+ clientEndpoints: { websiteUrl: 'https://cindy.ai' },+ } as unknown as Window['electronAPI'],+ });+});++afterEach(cleanup);++describe('UpdateBanner busy-turn restart hint', () => {+ it('shows the warning hint in the semantic warning color while any turn is running', async () => {+ anySessionInTurn.mockResolvedValue(true);+ render(<UpdateBanner isCollapsed={false} />);++ fireEvent.click(screen.getByRole('button', { name: 'update.banner.ariaExpanded' }));++ const hint = await screen.findByText('update.banner.confirmBusyHint');+ expect(anySessionInTurn).toHaveBeenCalledTimes(1);+ expect(hint.className).toContain('text-[var(--warning-fg)]');+ });++ it('keeps the existing neutral hint when no turn is running', async () => {+ anySessionInTurn.mockResolvedValue(false);+ render(<UpdateBanner isCollapsed={false} />);++ fireEvent.click(screen.getByRole('button', { name: 'update.banner.ariaExpanded' }));++ await waitFor(() => expect(anySessionInTurn).toHaveBeenCalledTimes(1));+ const hint = screen.getByText('update.banner.confirmHint');+ expect(hint.className).toContain('text-sidebar-muted');+ expect(hint.className).not.toContain('text-[var(--warning-fg)]');+ });++ it('keeps relaunch behavior unchanged while the text-only snapshot is pending', async () => {+ let resolveTurnCheck!: (busy: boolean) => void;+ anySessionInTurn.mockImplementation(+ () => new Promise<boolean>((resolve) => { resolveTurnCheck = resolve; }),+ );+ render(<UpdateBanner isCollapsed={false} />);++ fireEvent.click(screen.getByRole('button', { name: 'update.banner.ariaExpanded' }));+ await waitFor(() => expect(anySessionInTurn).toHaveBeenCalledTimes(1));++ const confirmButton = screen.getByRole('button', { name: 'update.banner.confirmAria' });+ expect((confirmButton as HTMLButtonElement).disabled).toBe(false);+ fireEvent.click(confirmButton);+ expect(relaunchToUpdate).toHaveBeenCalledTimes(1);++ resolveTurnCheck(false);+ });++ it('keeps the neutral hint when the one-shot probe throws synchronously', async () => {+ anySessionInTurn.mockImplementation(() => {+ throw new Error('electron bridge is not registered');+ });+ render(<UpdateBanner isCollapsed={false} />);++ fireEvent.click(screen.getByRole('button', { name: 'update.banner.ariaExpanded' }));++ await waitFor(() => expect(anySessionInTurn).toHaveBeenCalledTimes(1));+ expect(screen.getByText('update.banner.confirmHint')).toBeTruthy();+ });+});diff --git a/apps/desktop/src/renderer/components/sidebar/UpdateBanner.tsx b/apps/desktop/src/renderer/components/sidebar/UpdateBanner.tsxindex ed09de6a9e..c3d834052b 100644--- a/apps/desktop/src/renderer/components/sidebar/UpdateBanner.tsx+++ b/apps/desktop/src/renderer/components/sidebar/UpdateBanner.tsx@@ -65,6 +65,9 @@ export function UpdateBanner({ isCollapsed, onOpenVersionNotice }: UpdateBannerPconst { dismissed, dismiss, restore, isNewUpdateAfterDismiss } = useUpdateBannerDismiss();// 就地确认态:替代原先的屏幕中央 ConfirmDialog。const [confirming, setConfirming] = useState(false);+ // 复用关闭窗口保护链路的权威 busy 探针:只统计仍在执行的逻辑 turn,+ // 不把 keepalive、已结束但仍在渲染收尾的状态误判为运行中任务。+ const [hasSessionInTurn, setHasSessionInTurn] = useState(false);// 进入确认态后把焦点移到「取消」按钮 —— 键盘用户点入口键后原触发元素会卸载,// 若不主动聚焦,焦点会丢失、无法继续操作。刻意聚焦「取消」而非「确认」:让默认落在// 安全动作上,避免再按一次 Enter/Space 就直接更新的误操作(即 Radix 对破坏性操作@@ -103,6 +106,33 @@ export function UpdateBanner({ isCollapsed, onOpenVersionNotice }: UpdateBannerPif (status !== 'ready') setConfirming(false);}, [status]);+ // 每次进入确认态都重新查询,避免沿用上一次打开弹层时的 busy 结果。+ // handler 在 splash / login 阶段尚未注册时可能 reject;此 banner 只会在+ // ready 主界面出现,但仍与 WindowControls 保持同样的安全兜底语义。+ useEffect(() => {+ if (!confirming) {+ setHasSessionInTurn(false);+ return;+ }++ let cancelled = false;+ setHasSessionInTurn(false);+ // Start the probe in a microtask so a synchronously unavailable IPC bridge+ // is converted into a rejected promise and handled by the same fallback.+ void Promise.resolve()+ .then(() => window.electronAPI.anySessionInTurn())+ .then((busy) => {+ if (!cancelled) setHasSessionInTurn(busy);+ })+ .catch(() => {+ if (!cancelled) setHasSessionInTurn(false);+ });++ return () => {+ cancelled = true;+ };+ }, [confirming]);+// 新更新到达时自动 restore:isNewUpdateAfterDismiss 先检查当前 status 是否为// active update 态(ready / superseding),再对比 dismiss 时的快照——两个条件// 都满足才 restore(),从而避免 remount 时 useUpdateStatus() 经历 idle→ready@@ -351,11 +381,22 @@ export function UpdateBanner({ isCollapsed, onOpenVersionNotice }: UpdateBannerP延伸而不是第三段独立文案;没有链接时这个 wrapper 只有一个子元素,布局与加链接前完全一致。 */}<div className="flex flex-col items-center gap-1">- <p className="text-xs text-sidebar-muted">+ <p+ className={cn(+ 'text-center text-xs',+ !isPreparing && confirming && hasSessionInTurn+ ? 'text-[var(--warning-fg)]'+ : 'text-sidebar-muted',+ )}+ >{isPreparing? t('update.banner.preparingSubtitle'): confirming- ? t('update.banner.confirmHint')+ ? t(+ hasSessionInTurn+ ? 'update.banner.confirmBusyHint'+ : 'update.banner.confirmHint',+ ): t('update.banner.subtitle')}</p>{notesVersion && (diff --git a/apps/desktop/src/renderer/i18n/locales/en/common.json b/apps/desktop/src/renderer/i18n/locales/en/common.jsonindex 0e8a4ebe27..14b136ecee 100644--- a/apps/desktop/src/renderer/i18n/locales/en/common.json+++ b/apps/desktop/src/renderer/i18n/locales/en/common.json@@ -3909,6 +3909,7 @@"preparingAria": "Preparing newer version, please wait","confirmTitle": "Restart to update?","confirmHint": "The app will restart automatically",+ "confirmBusyHint": "A task is still running. Restarting will interrupt it","confirmButton": "Restart now","cancel": "Cancel","confirmTooltip": "Confirm restart to apply the update",diff --git a/apps/desktop/src/renderer/i18n/locales/ja/common.json b/apps/desktop/src/renderer/i18n/locales/ja/common.jsonindex d993f90fcb..bdca1d0c5d 100644--- a/apps/desktop/src/renderer/i18n/locales/ja/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ja/common.json@@ -3908,6 +3908,7 @@"preparingAria": "新しいバージョンを準備中、お待ちください","confirmTitle": "再起動して更新?","confirmHint": "アプリが自動的に再起動します",+ "confirmBusyHint": "実行中のタスクがあります。再起動すると中断されます","confirmButton": "再起動","cancel": "キャンセル","confirmTooltip": "再起動して更新を適用",diff --git a/apps/desktop/src/renderer/i18n/locales/ko/common.json b/apps/desktop/src/renderer/i18n/locales/ko/common.jsonindex 6e34d2a1b8..818ad828c1 100644--- a/apps/desktop/src/renderer/i18n/locales/ko/common.json+++ b/apps/desktop/src/renderer/i18n/locales/ko/common.json@@ -3908,6 +3908,7 @@"preparingAria": "새 버전 준비 중입니다. 잠시만 기다려 주세요","confirmTitle": "재시작하여 업데이트?","confirmHint": "앱이 자동으로 재시작됩니다",+ "confirmBusyHint": "아직 실행 중인 작업이 있습니다. 재시작하면 작업이 중단됩니다","confirmButton": "재시작","cancel": "취소","confirmTooltip": "재시작하여 업데이트 적용",diff --git a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.jsonindex 3298aaaba8..5ca3fc44f8 100644--- a/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json+++ b/apps/desktop/src/renderer/i18n/locales/zh-CN/common.json@@ -3908,6 +3908,7 @@"preparingAria": "正在准备新版本,请稍候","confirmTitle": "确认重启更新?","confirmHint": "应用会自动重启",+ "confirmBusyHint": "当前仍有任务在执行,重启会直接中断","confirmButton": "确认重启","cancel": "取消","confirmTooltip": "确认重启并应用更新",diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.mdindex c9a58999f1..1261d05293 100644--- a/docs/design-rules/DESIGN.md+++ b/docs/design-rules/DESIGN.md@@ -412,6 +412,7 @@ Theme switching: `useTheme.ts` provides `theme` (System / Light / Dark mode) plu| `--perm-bypass-selected-text` | `#EA6B17` | `#EA6B17` | Heart Orange, permission semantics (auto-follows `var(--warning-accent)`, finalized 2026-07-17) || `--settings-integration-warning` | `#EA6B17` | `#EA6B17` | Warning semantics (auto-follows `var(--warning-accent)`, finalized 2026-07-17) || `--warning-bg-soft` | rgba(234,107,23,0.12) | rgba(234,107,23,0.18) | Warning alpha surface (alpha recomputed against `#EA6B17`, 2026-07-17) |+| `--warning-fg` | `#F3A115` | `#F3A115` | Warning text/icons, including the update-restart busy-turn interruption hint || `--focus-ring` / `--focus-ring-soft` | `#417CDD` / @50% | same | A11y focus ring, finalized 2026-07-17 (replaces #3b82f6), theme-invariant || `--shadow-menu` / `--cmd-palette-shadow` / `--confirm-shadow` | rgba | rgba (deeper) | Shadows, theme-invariant || `--overlay-modal` / `--overlay-lightbox` | rgba | rgba (deeper) | Modal / lightbox backdrop |