From 41f32899640b4a461e14e645873d54ddf46557e2 Mon Sep 17 00:00:00 2001 From: Jinjing <6427696+AmethystLiang@users.noreply.github.com> Date: Fri, 15 May 2026 21:38:19 -0700 Subject: [PATCH] fix: address review findings (#2059) --- .../CommitArea.chevron-spinner.test.tsx | 1 + .../CommitArea.generate.test.tsx | 1 + .../CommitArea.primary-icons.test.tsx | 1 + .../right-sidebar/CommitArea.test.tsx | 9 +++ .../right-sidebar/SourceControl.tsx | 57 ++++++++++++++++--- src/renderer/src/store/slices/editor.test.ts | 35 +++++++++++- src/renderer/src/store/slices/editor.ts | 25 +++++++- 7 files changed, 117 insertions(+), 12 deletions(-) diff --git a/src/renderer/src/components/right-sidebar/CommitArea.chevron-spinner.test.tsx b/src/renderer/src/components/right-sidebar/CommitArea.chevron-spinner.test.tsx index bf85b0365..6091979b4 100644 --- a/src/renderer/src/components/right-sidebar/CommitArea.chevron-spinner.test.tsx +++ b/src/renderer/src/components/right-sidebar/CommitArea.chevron-spinner.test.tsx @@ -84,6 +84,7 @@ function baseProps(overrides: Partial = {}) { return { commitMessage: 'feat: add commit area', commitError: null as string | null, + remoteActionError: null as string | null, isCommitting: inputs.isCommitting, aiEnabled: false, aiAgentConfigured: false, diff --git a/src/renderer/src/components/right-sidebar/CommitArea.generate.test.tsx b/src/renderer/src/components/right-sidebar/CommitArea.generate.test.tsx index 83c9c0872..90fdeca70 100644 --- a/src/renderer/src/components/right-sidebar/CommitArea.generate.test.tsx +++ b/src/renderer/src/components/right-sidebar/CommitArea.generate.test.tsx @@ -102,6 +102,7 @@ function baseProps(overrides: Partial = {}) { return { commitMessage: 'feat: add commit area', commitError: null as string | null, + remoteActionError: null as string | null, isCommitting: inputs.isCommitting, aiEnabled: false, aiAgentConfigured: false, diff --git a/src/renderer/src/components/right-sidebar/CommitArea.primary-icons.test.tsx b/src/renderer/src/components/right-sidebar/CommitArea.primary-icons.test.tsx index 4cf98fcef..3f0099934 100644 --- a/src/renderer/src/components/right-sidebar/CommitArea.primary-icons.test.tsx +++ b/src/renderer/src/components/right-sidebar/CommitArea.primary-icons.test.tsx @@ -72,6 +72,7 @@ function baseProps(overrides: Partial = {}) { return { commitMessage: 'feat: add commit area', commitError: null as string | null, + remoteActionError: null as string | null, isCommitting: inputs.isCommitting, aiEnabled: false, aiAgentConfigured: false, diff --git a/src/renderer/src/components/right-sidebar/CommitArea.test.tsx b/src/renderer/src/components/right-sidebar/CommitArea.test.tsx index cf37df70c..c362b2d4e 100644 --- a/src/renderer/src/components/right-sidebar/CommitArea.test.tsx +++ b/src/renderer/src/components/right-sidebar/CommitArea.test.tsx @@ -125,6 +125,7 @@ function baseProps(overrides: Partial = {}) { return { commitMessage: 'feat: add commit area', commitError: null as string | null, + remoteActionError: null as string | null, isCommitting: inputs.isCommitting, aiEnabled: false, aiAgentConfigured: false, @@ -282,6 +283,14 @@ describe('CommitArea', () => { expect(hasText(element, 'pre-commit hook failed')).toBe(true) }) + it('shows an inline error message when a remote action fails', () => { + const element = CommitArea({ + ...baseProps(), + remoteActionError: 'Fetch failed. network timeout' + }) + expect(hasText(element, 'Fetch failed. network timeout')).toBe(true) + }) + it('keeps the primary button labelled Commit when the tree is staged, even with commits to push', () => { // Why: the primary never compounds ("Commit & Push"). Users commit first, // then the primary rotates to Push. Compound flows remain in the dropdown, diff --git a/src/renderer/src/components/right-sidebar/SourceControl.tsx b/src/renderer/src/components/right-sidebar/SourceControl.tsx index 13b490239..1a5c1c894 100644 --- a/src/renderer/src/components/right-sidebar/SourceControl.tsx +++ b/src/renderer/src/components/right-sidebar/SourceControl.tsx @@ -32,6 +32,7 @@ import { type LucideIcon } from 'lucide-react' import { useAppStore } from '@/store' +import { resolveRemoteOperationErrorMessage } from '@/store/slices/editor' import { useActiveWorktree, useRepoById, useWorktreeMap } from '@/store/selectors' import { getHostedReviewCacheKey } from '@/store/slices/hosted-review' import { detectLanguage } from '@/lib/language-detect' @@ -139,6 +140,7 @@ import { type SourceControlScope = 'all' | 'uncommitted' type SourceControlViewMode = 'list' | 'tree' +type RemoteActionError = { kind: RemoteOpKind; message: string } // Why: directional signifiers ahead of each primary action label. Commit // (✓) is affirmative; Push (↑) points in the direction data flows; Sync @@ -267,6 +269,15 @@ function hostedReviewStateClass(review: HostedReviewInfo): string { return 'text-muted-foreground/50' } +function resolveRemoteActionError(kind: RemoteOpKind, error: unknown): string { + return resolveRemoteOperationErrorMessage(error, { + publish: kind === 'publish', + isPush: kind === 'push', + isSync: kind === 'sync', + isFetch: kind === 'fetch' + }) +} + function HostedReviewIcon({ review, className @@ -467,6 +478,9 @@ function SourceControlInner(): React.JSX.Element { // so switching worktrees restores each draft instead of wiping it. const [commitDrafts, setCommitDrafts] = useState({}) const [commitErrors, setCommitErrors] = useState>({}) + const [remoteActionErrors, setRemoteActionErrors] = useState< + Record + >({}) // Why: keep commit-in-flight state per-worktree. A single boolean would be // cleared when the user switched worktrees, letting them double-click Commit // on worktree A after briefly navigating to B and back while A's original @@ -496,6 +510,7 @@ function SourceControlInner(): React.JSX.Element { const filterInputRef = useRef(null) const commitMessage = readCommitDraftForWorktree(commitDrafts, activeWorktreeId) const commitError = commitErrors[activeWorktreeId ?? ''] ?? null + const remoteActionError = remoteActionErrors[activeWorktreeId ?? ''] ?? null const isFolder = activeRepo ? isFolderRepo(activeRepo) : false const worktreePath = activeWorktree?.path ?? null @@ -839,6 +854,7 @@ function SourceControlInner(): React.JSX.Element { } setCommitDrafts((prev) => pruneRecord(prev)) setCommitErrors((prev) => pruneRecord(prev)) + setRemoteActionErrors((prev) => pruneRecord(prev)) setCommitInFlightByWorktree((prev) => pruneRecord(prev)) setGenerateInFlightByWorktree((prev) => pruneRecord(prev)) setGenerateErrors((prev) => pruneRecord(prev)) @@ -1079,6 +1095,7 @@ function SourceControlInner(): React.JSX.Element { return } const connectionId = getConnectionId(activeWorktreeId) ?? undefined + setRemoteActionErrors((prev) => ({ ...prev, [activeWorktreeId]: null })) try { if (kind === 'publish') { await pushBranch( @@ -1109,9 +1126,19 @@ function SourceControlInner(): React.JSX.Element { return } await syncBranch(activeWorktreeId, worktreePath, connectionId, activeWorktree?.pushTarget) - } catch { + setRemoteActionErrors((prev) => ({ ...prev, [activeWorktreeId]: null })) + } catch (error) { // Why: remote action failures are surfaced by editor-slice actions to keep // one consistent toast path and avoid duplicate notifications in the UI. + // Keep the latest failure inline too: dropdown-only actions like Fetch can + // otherwise look like nothing happened once the menu closes. + setRemoteActionErrors((prev) => ({ + ...prev, + [activeWorktreeId]: { + kind, + message: resolveRemoteActionError(kind, error) + } + })) } }, [ @@ -2492,6 +2519,7 @@ function SourceControlInner(): React.JSX.Element { 0 + const describedBy = [ + commitError ? 'commit-area-error' : null, + remoteActionError ? 'commit-area-remote-error' : null, + generateError ? 'commit-area-generate-error' : null + ] + .filter(Boolean) + .join(' ') // Why: only render the Generate button when the user has opted into the // feature. Mounting a perma-disabled button would leak space and add noise @@ -3036,13 +3073,7 @@ export function CommitArea({ onChange={(e) => onCommitMessageChange(e.target.value)} placeholder="Message" aria-label="Commit message" - aria-describedby={ - commitError - ? 'commit-area-error' - : generateError - ? 'commit-area-generate-error' - : undefined - } + aria-describedby={describedBy || undefined} // Why: reserve right padding so typed text does not slide under the // absolute-positioned Generate icon in the top-right corner. className={`mt-0.5 w-full resize-none rounded-md border border-border bg-background px-2 py-1.5 text-xs text-foreground outline-none placeholder:text-muted-foreground/70 focus-visible:ring-1 focus-visible:ring-ring ${ @@ -3181,6 +3212,16 @@ export function CommitArea({ {commitError}

)} + {remoteActionError && ( + + )} {generateError && (

{ ) }) + it('surfaces an explicit toast when pull stops on merge conflicts', async () => { + const store = createEditorStore() + gitPullMock.mockRejectedValueOnce( + new Error( + 'Auto-merging src/app.ts\nCONFLICT (content): Merge conflict in src/app.ts\nAutomatic merge failed; fix conflicts and then commit the result.' + ) + ) + + await expect(store.getState().pullBranch('wt-1', '/repo')).rejects.toThrow() + + expect(toastErrorMock).toHaveBeenCalledWith( + 'Pull stopped with merge conflicts. Resolve them in Source Control, then commit the merge.' + ) + }) + it('runs publish branch through push with publish=true', async () => { // Why: pushBranch no longer awaits a post-op git status / upstream // refresh. The 3s git-status poll and the upstream-status effect in the @@ -1160,7 +1175,7 @@ describe('createEditorSlice remote branch actions', () => { await expect(store.getState().fetchBranch('wt-1', '/repo')).rejects.toThrow('network timeout') - expect(toastErrorMock).toHaveBeenCalledWith('network timeout') + expect(toastErrorMock).toHaveBeenCalledWith('Fetch failed. network timeout') expect(gitUpstreamStatusMock).not.toHaveBeenCalled() expect(store.getState().isRemoteOperationActive).toBe(false) }) @@ -1335,6 +1350,24 @@ describe('createEditorSlice remote branch actions', () => { expect(gitPushMock).not.toHaveBeenCalled() expect(store.getState().isRemoteOperationActive).toBe(false) }) + + it('surfaces a sync-labeled toast when syncBranch stops on merge conflicts', async () => { + const store = createEditorStore() + gitPullMock.mockRejectedValueOnce( + new Error( + 'Auto-merging src/app.ts\nCONFLICT (content): Merge conflict in src/app.ts\nAutomatic merge failed; fix conflicts and then commit the result.' + ) + ) + + await expect(store.getState().syncBranch('wt-1', '/repo')).rejects.toThrow() + + expect(toastErrorMock).toHaveBeenCalledTimes(1) + expect(toastErrorMock).toHaveBeenCalledWith( + 'Sync stopped with merge conflicts. Resolve them in Source Control, then commit the merge.' + ) + expect(gitPushMock).not.toHaveBeenCalled() + expect(store.getState().isRemoteOperationActive).toBe(false) + }) }) describe('createEditorSlice activateMarkdownLink', () => { diff --git a/src/renderer/src/store/slices/editor.ts b/src/renderer/src/store/slices/editor.ts index e955b243f..7c18af097 100644 --- a/src/renderer/src/store/slices/editor.ts +++ b/src/renderer/src/store/slices/editor.ts @@ -470,14 +470,26 @@ function extractPublishFailureDetail(message: string): string | null { return null } -function resolveRemoteOperationErrorMessage( +export function resolveRemoteOperationErrorMessage( error: unknown, - options?: { publish?: boolean; isPush?: boolean; isSync?: boolean } + options?: { publish?: boolean; isPush?: boolean; isSync?: boolean; isFetch?: boolean } ): string { if (!(error instanceof Error)) { return REMOTE_OPERATION_FAILED_MESSAGE } + if (/unmerged files|needs merge|you have not concluded your merge/i.test(error.message)) { + return options?.isSync + ? 'Sync blocked — resolve existing merge conflicts first.' + : 'Pull blocked — resolve existing merge conflicts first.' + } + + if (/automatic merge failed|CONFLICT \(|fix conflicts/i.test(error.message)) { + return options?.isSync + ? 'Sync stopped with merge conflicts. Resolve them in Source Control, then commit the merge.' + : 'Pull stopped with merge conflicts. Resolve them in Source Control, then commit the merge.' + } + // Why: under sync, the inner push runs *after* a successful pull, so a // non-fast-forward at that point means the remote raced ahead between // fetch and push — not "user forgot to pull". Saying "Pull first" would @@ -539,6 +551,13 @@ function resolveRemoteOperationErrorMessage( return 'Push failed. Check your connection and try again.' } + if (options?.isFetch) { + const detail = + extractPublishFailureDetail(error.message) ?? + truncateDetail(stripCredentialsFromMessage(error.message)) + return `Fetch failed. ${detail}` + } + return error.message } @@ -2126,7 +2145,7 @@ export const createEditorSlice: StateCreator = (s try { await fetchRuntimeGit({ settings: get().settings, worktreeId, worktreePath, connectionId }) } catch (error) { - toast.error(resolveRemoteOperationErrorMessage(error)) + toast.error(resolveRemoteOperationErrorMessage(error, { isFetch: true })) throw error } finally { get().endRemoteOperation()