Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(worktree): 手动刷新被拒时显示原因提示
fmfsaisaibce8ecf5edf5
diff --git a/apps/desktop/src/renderer/components/new-chat/__tests__/BranchWorktreeChip.test.tsx b/apps/desktop/src/renderer/components/new-chat/__tests__/BranchWorktreeChip.test.tsxindex d29c8c9811..955ce4c01c 100644--- a/apps/desktop/src/renderer/components/new-chat/__tests__/BranchWorktreeChip.test.tsx+++ b/apps/desktop/src/renderer/components/new-chat/__tests__/BranchWorktreeChip.test.tsx@@ -23,10 +23,11 @@ const render = (element: React.ReactElement) =>});const mocks = vi.hoisted(() => ({toast: vi.fn(),+ warning: vi.fn(),t: (key: string, args?: object) => key + (args ? JSON.stringify(args) : ''),}));vi.mock('react-i18next', () => ({ useTranslation: () => ({ t: mocks.t }) }));-vi.mock('@/lib/toast', () => ({ toast: { error: mocks.toast } }));+vi.mock('@/lib/toast', () => ({ toast: { error: mocks.toast, warning: mocks.warning } }));vi.mock('../FolderPickerPopover', () => ({FolderPickerPopover: () => null,addRecentFolder: vi.fn(),@@ -149,11 +150,13 @@ it('explains a disabled conflict, then rechecks locally on hover', async () => {const button = await screen.findByRole('button', { name: /newChat.branchSync.conflict/ });expect(button.getAttribute('aria-disabled')).toBe('true');expect(button.parentElement?.tabIndex).toBe(0);+ expect(mocks.warning).not.toHaveBeenCalled();vi.useFakeTimers();fireEvent.mouseEnter(button.parentElement!);await act(async () => vi.advanceTimersByTime(250));expect(status).toHaveBeenCalledTimes(2);expect(refreshButton().hasAttribute('disabled')).toBe(false);+ expect(mocks.warning).not.toHaveBeenCalled();});it('reports failed fetches in a toast and permits retry without selecting anything', async () => {sync.mockRejectedValueOnce(new Error('[INTERNAL] Authentication failed'));@@ -199,11 +202,14 @@ it('keeps a fetched missing-remote result disabled across local rechecks, but clconst view = render(<BranchWorktreeChip {...props} />);await waitFor(() => expect(refreshButton().hasAttribute('disabled')).toBe(false));fireEvent.click(refreshButton());- await screen.findByRole('button', { name: /newChat.branchSync.missing-remote/ });+ const blocked = await screen.findByRole('button', { name: /newChat.branchSync.missing-remote/ });+ expect(mocks.warning).toHaveBeenCalledExactlyOnceWith(blocked.getAttribute('aria-label'));+ expect(mocks.toast).not.toHaveBeenCalled();await act(async () => {fireEvent.click(branchButton());});await waitFor(() => expect(status).toHaveBeenCalledTimes(2));+ expect(mocks.warning).toHaveBeenCalledOnce();expect(screen.getByRole('button', { name: /newChat.branchSync.missing-remote/ })@@ -212,3 +218,21 @@ it('keeps a fetched missing-remote result disabled across local rechecks, but clview.rerender(<BranchWorktreeChip {...props} branchLabel="other" />);await waitFor(() => expect(refreshButton().hasAttribute('disabled')).toBe(false));});++// F01: a rejected user action should notify only its current target. Existing+// stale-read coverage cannot catch a delayed mutation response causing a toast.+it('does not warn for a blocked click result after changing branch or project', async () => {+ let resolve!: (value: unknown) => void;+ sync.mockReturnValue(+ new Promise((done) => {+ resolve = done;+ }),+ );+ const view = render(<BranchWorktreeChip {...props} />);+ await waitFor(() => expect(refreshButton().hasAttribute('disabled')).toBe(false));+ fireEvent.click(refreshButton());+ view.rerender(<BranchWorktreeChip {...props} baseRepo="/other" branchLabel="other" />);+ await act(async () => resolve({ status: { ...baseStatus, blocked: 'conflict' }, updated: 0 }));+ expect(mocks.warning).not.toHaveBeenCalled();+ expect(mocks.toast).not.toHaveBeenCalled();+});diff --git a/apps/desktop/src/renderer/hooks/useBranchSync.ts b/apps/desktop/src/renderer/hooks/useBranchSync.tsindex 1188bebbd0..cdb3aef829 100644--- a/apps/desktop/src/renderer/hooks/useBranchSync.ts+++ b/apps/desktop/src/renderer/hooks/useBranchSync.ts@@ -93,6 +93,12 @@ export function useBranchSync(clearTimeout(doneTimer.current);};}, [key, refresh]);+ const blockedHint = (status: BranchSyncStatus) =>+ t(`newChat.branchSync.${status.blocked}`, {+ branch,+ remote: status.remote ?? 'origin',+ remoteBranch: status.remoteBranch ?? branch,+ });const sync = async () => {if (!baseRepo || busy.current) return;busy.current = true;@@ -101,6 +107,7 @@ export function useBranchSync(try {const result = (await invoke(true)) as BranchSyncResult;if (currentKey.current !== key || id !== request.current) return;+ if (result.status.blocked) toast.warning(blockedHint(result.status));setSnapshot({key,status: result.status,@@ -141,7 +148,7 @@ export function useBranchSync(if (status?.remoteOnly) hint = t('newChat.branchSync.remoteAction', vars);if (status?.checkoutPath)hint += `\n${t('newChat.branchSync.checkedOut', { ...vars, directory: status.checkoutPath.split(/[\\/]/).filter(Boolean).at(-1) })}`;- if (status?.blocked) hint = t(`newChat.branchSync.${status.blocked}`, vars);+ if (status?.blocked) hint = blockedHint(status);if (state.result && !status?.blocked)hint = state.result.updated? t('newChat.branchSync.updated', { count: state.result.updated })