Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions packages/ui/src/features/task-detail/BranchMismatchDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,14 @@ export function BranchMismatchDialog({
Continue anyway
</Button>

<AlertDialog.Action>
<Button
variant="solid"
size="1"
onClick={onSwitch}
loading={isSwitching}
>
Switch branch
</Button>
</AlertDialog.Action>
<Button
variant="solid"
size="1"
onClick={onSwitch}
loading={isSwitching}
>
Switch branch
</Button>
</Flex>
</AlertDialog.Content>
</AlertDialog.Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ let capturedMutationOptions: {
onError?: (e: Error) => void;
} = {};
const mockMutate = vi.fn();
let mockIsPending = false;

vi.mock("@tanstack/react-query", () => ({
useMutation: (opts: Record<string, unknown>) => {
capturedMutationOptions = opts as typeof capturedMutationOptions;
return { mutate: mockMutate, isPending: false };
return { mutate: mockMutate, isPending: mockIsPending };
},
}));

Expand Down Expand Up @@ -89,6 +90,7 @@ describe("useBranchMismatchDialog", () => {
vi.clearAllMocks();
capturedMutationOptions = {};
mockShouldWarn = false;
mockIsPending = false;
});

describe("handleBeforeSubmit", () => {
Expand Down Expand Up @@ -184,6 +186,34 @@ describe("useBranchMismatchDialog", () => {
},
);
});

it("does nothing while a switch is in flight, so a dismiss can't drop the pending message", () => {
mockIsPending = true;
const { result, onSendPrompt } = renderDialog({ shouldWarn: true });
const clearEditor = vi.fn();

act(() => {
result.current.handleBeforeSubmit("hello", clearEditor);
});

act(() => {
result.current.dialogProps?.onSwitch();
});

mockTrack.mockClear();
act(() => {
result.current.dialogProps?.onCancel();
});

expect(mockTrack).not.toHaveBeenCalled();
expect(result.current.dialogProps?.open).toBe(true);

act(() => {
capturedMutationOptions.onSuccess?.();
});

expect(onSendPrompt).toHaveBeenCalledWith("hello");
});
});

describe("handleSwitch", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,13 @@ export function useBranchMismatchDialog({
}, [dismissWarning, emitAction]);

const handleCancel = useCallback(() => {
if (isSwitching) return;
emitAction("cancel");
setPendingMessage(null);
pendingMessageRef.current = null;
pendingClearRef.current = null;
setSwitchError(null);
}, [emitAction]);
}, [emitAction, isSwitching]);

const dialogProps =
linkedBranch && currentBranch
Expand Down
Loading