fix: avoid stale project binding for new sessions

Keeps implicit new sessions tied to the current directory
Prevents unmatched directories from inheriting the active project
Adds regression coverage for draft project selection
This commit is contained in:
Bohdan Triapitsyn
2026-06-24 10:56:54 +03:00
parent 604bb97258
commit a9dfd32347
2 changed files with 14 additions and 4 deletions
@@ -255,6 +255,17 @@ describe('openNewSessionDraft project binding', () => {
expect(draft.directoryOverride).toBe(projectB.path);
});
test('does not attach active project when current directory is unmatched', () => {
useDirectoryStore.getState().setDirectory('/external/worktree', { showOverlay: false });
useSessionUIStore.getState().openNewSessionDraft();
const draft = useSessionUIStore.getState().newSessionDraft;
expect(draft.open).toBe(true);
expect(draft.selectedProjectId).toBeNull();
expect(draft.directoryOverride).toBe('/external/worktree');
});
test('respects explicit directoryOverride over active project', () => {
useSessionUIStore.getState().openNewSessionDraft({ directoryOverride: '/projects/beta/src' });
const draft = useSessionUIStore.getState().newSessionDraft;
+3 -4
View File
@@ -623,10 +623,9 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
const currentDirProject = resolveDraftProjectForDirectory(projects, availableWorktreesByProject, currentDirectory)
const selectedProject = (() => {
if (explicitProject || explicitDirectory !== null) {
return explicitProject ?? inferredProjectFromDir ?? fallbackProject
}
if (currentDirectory) return currentDirProject ?? fallbackProject
if (explicitProject) return explicitProject
if (explicitDirectory !== null) return inferredProjectFromDir
if (currentDirectory) return currentDirProject
return persistedProjectByDir ?? persistedProjectById ?? fallbackProject
})()