fix: unblock initial new session prompts

This commit is contained in:
Bohdan Triapitsyn
2026-06-03 14:51:17 +03:00
parent 2163c2e3f7
commit a649ba8df4
3 changed files with 66 additions and 13 deletions
@@ -0,0 +1,53 @@
import { beforeEach, describe, expect, mock, test } from 'bun:test';
const bootstrapStatusCalls: string[] = [];
let bootstrapStatusResult = { status: 'ready' as const, error: null, updatedAt: 1 };
mock.module('@/contexts/runtimeAPIRegistry', () => ({
getRegisteredRuntimeAPIs: () => ({
git: {
worktree: {
bootstrapStatus: (directory: string) => {
bootstrapStatusCalls.push(directory);
return Promise.resolve(bootstrapStatusResult);
},
},
},
}),
}));
mock.module('@/lib/gitApiHttp', () => ({
getGitWorktreeBootstrapStatus: (directory: string) => {
bootstrapStatusCalls.push(directory);
return Promise.resolve(bootstrapStatusResult);
},
}));
const {
clearWorktreeBootstrapState,
markWorktreeBootstrapPending,
waitForWorktreeBootstrap,
} = await import('./worktreeBootstrap');
describe('worktreeBootstrap.waitForWorktreeBootstrap', () => {
beforeEach(() => {
bootstrapStatusCalls.length = 0;
bootstrapStatusResult = { status: 'ready', error: null, updatedAt: 1 };
clearWorktreeBootstrapState('/repo');
clearWorktreeBootstrapState('/repo-wt');
});
test('does not poll directories that were not marked pending', async () => {
await waitForWorktreeBootstrap('/repo');
expect(bootstrapStatusCalls).toEqual([]);
});
test('polls when the directory was explicitly marked pending', async () => {
markWorktreeBootstrapPending('/repo-wt');
await waitForWorktreeBootstrap('/repo-wt');
expect(bootstrapStatusCalls).toEqual(['/repo-wt']);
});
});
@@ -93,6 +93,10 @@ export const waitForWorktreeBootstrap = async (directory: string, timeoutMs = DE
}
const current = state.get(key);
if (!current) {
return;
}
if (current?.status === 'ready') {
return;
}
+9 -13
View File
@@ -832,28 +832,24 @@ export const useSessionUIStore = create<SessionUIState>()((set, get) => ({
})
const draftSyntheticParts = draft.syntheticParts
await activateConfigForDirectory(draftDirectoryOverride ?? created.directory ?? null)
const createdDirectory = normalizePath(draftDirectoryOverride ?? created.directory ?? null)
const configState = useConfigStore.getState()
const draftAgentName = configState.currentAgentName
const effectiveDraftAgent = trimmedAgent ?? draftAgentName
void activateConfigForDirectory(createdDirectory).catch((error) => {
console.warn("Failed to activate directory after creating session:", error)
})
if (configState.currentProviderId && configState.currentModelId) {
useSelectionStore.getState().saveSessionModelSelection(created.id, configState.currentProviderId, configState.currentModelId)
}
const effectiveDraftAgent = trimmedAgent ?? configState.currentAgentName
useSelectionStore.getState().saveSessionModelSelection(created.id, providerID, modelID)
if (effectiveDraftAgent) {
useSelectionStore.getState().saveSessionAgentSelection(created.id, effectiveDraftAgent)
if (configState.currentProviderId && configState.currentModelId) {
useSelectionStore.getState().saveAgentModelForSession(created.id, effectiveDraftAgent, configState.currentProviderId, configState.currentModelId)
useSelectionStore.getState().saveAgentModelVariantForSession(created.id, effectiveDraftAgent, configState.currentProviderId, configState.currentModelId, variant)
}
useSelectionStore.getState().saveAgentModelForSession(created.id, effectiveDraftAgent, providerID, modelID)
useSelectionStore.getState().saveAgentModelVariantForSession(created.id, effectiveDraftAgent, providerID, modelID, variant)
}
get().initializeNewOpenChamberSession(created.id, configState.agents ?? [])
const createdDirectory = normalizePath(draftDirectoryOverride ?? created.directory ?? null)
get().closeNewSessionDraft()
get().setCurrentSession(created.id, createdDirectory)