fix(sessions): preflight every worktree move

This commit is contained in:
mattv8
2026-08-27 18:43:37 -06:00
parent 8fc08853b3
commit 26d6d72551
5 changed files with 45 additions and 80 deletions
@@ -204,7 +204,6 @@ const {
cancelSessionTreeMove,
useSessionTreeMoveConfirmation,
getSessionTreeMoveConfirmation,
startSessionTreeWorktreeMove,
} = await import('./sessionWorktreeMove');
const makeSession = (id: string, directory = '/source'): Session => ({
@@ -659,16 +658,10 @@ describe('moveSessionTreeToExistingWorktree', () => {
throw new Error('git-ready failed');
};
startSessionTreeWorktreeMove({
root: makeSession('root'),
descendants: [],
sourceDirectory: '/source',
successMessage: 'success',
failureMessage: 'failed',
});
requestSessionTreeMove(makeQuickIntent());
await waitFor(() => toastErrors.length === 1);
expect(toastErrors).toEqual([{ title: 'failed', description: 'git-ready failed' }]);
expect(toastErrors).toEqual([{ title: 'move failed', description: 'git-ready failed' }]);
expect(removeWorktreeCalls).toEqual([{
projectDirectory: '/repo',
directory: '/created-worktree',
@@ -683,13 +676,7 @@ describe('moveSessionTreeToExistingWorktree', () => {
setStatuses('/source', { root: 'busy' });
};
startSessionTreeWorktreeMove({
root: makeSession('root'),
descendants: [],
sourceDirectory: '/source',
successMessage: 'success',
failureMessage: 'failed',
});
requestSessionTreeMove(makeQuickIntent());
await waitFor(() => toastErrors.length === 1);
expect(removeWorktreeCalls).toEqual([{
@@ -1020,16 +1007,10 @@ describe('moveSessionTreeToExistingWorktree', () => {
setStatuses('/source', { root: 'idle' });
resolveProjectRefImplementation = () => null;
startSessionTreeWorktreeMove({
root: makeSession('root'),
descendants: [],
sourceDirectory: '/source',
successMessage: 'success',
failureMessage: 'failed',
});
requestSessionTreeMove(makeQuickIntent());
await waitFor(() => toastErrors.length === 1);
expect(toastErrors).toEqual([{ title: 'failed', description: 'Unable to find the project for this session' }]);
expect(toastErrors).toEqual([{ title: 'move failed', description: 'Unable to find the project for this session' }]);
expect(removeWorktreeCalls).toEqual([]);
expect(moveCalls).toEqual([]);
});
@@ -405,47 +405,3 @@ export const requestSessionTreeMove = (intent: SessionTreeMoveIntent): void => {
}
})();
};
export const startSessionTreeExistingWorktreeMove = (input: {
root: Session;
descendants: Session[];
sourceDirectory: string;
destination: WorktreeMetadata;
successMessage: string;
failureMessage: string;
}): void => {
requestSessionTreeMove({
kind: 'existing',
root: input.root,
descendants: input.descendants,
sourceDirectory: input.sourceDirectory,
destination: input.destination,
messages: {
success: input.successMessage,
failure: input.failureMessage,
sourceVerificationFailed: input.failureMessage,
applyChangesFailed: input.failureMessage,
},
});
};
export const startSessionTreeWorktreeMove = (input: {
root: Session;
descendants: Session[];
sourceDirectory: string;
successMessage: string;
failureMessage: string;
}): void => {
requestSessionTreeMove({
kind: 'quick',
root: input.root,
descendants: input.descendants,
sourceDirectory: input.sourceDirectory,
messages: {
success: input.successMessage,
failure: input.failureMessage,
sourceVerificationFailed: input.failureMessage,
applyChangesFailed: input.failureMessage,
},
});
};