diff --git a/apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.test.ts b/apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.test.ts index 061244159..ee11f6323 100644 --- a/apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.test.ts +++ b/apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.test.ts @@ -103,25 +103,45 @@ describe("useChatTitleGenerator", () => { }); }); - it("allows first generation even when title_manually_set", async () => { - mockGetCachedTask.mockReturnValue({ - id: TASK_ID, - title_manually_set: true, - }); - mockGenerateTitle.mockResolvedValue({ - title: "Auto title", - summary: "", - }); - mockPrompts.value = ["some prompt"]; + it.each([ + { name: "no summary", summary: "", expectsSummaryUpdate: false }, + { + name: "with summary", + summary: "User wants to fix auth", + expectsSummaryUpdate: true, + }, + ])( + "skips title update when title_manually_set ($name)", + async ({ summary, expectsSummaryUpdate }) => { + mockGetCachedTask.mockReturnValue({ + id: TASK_ID, + title_manually_set: true, + }); + mockGenerateTitle.mockResolvedValue({ + title: "Auto title", + summary, + }); + mockPrompts.value = ["fix auth"]; - renderHook(() => useChatTitleGenerator(TASK_ID)); + renderHook(() => useChatTitleGenerator(TASK_ID)); - await waitFor(() => { - expect(mockUpdateTask).toHaveBeenCalledWith(TASK_ID, { - title: "Auto title", + await waitFor(() => { + expect(mockGenerateTitle).toHaveBeenCalled(); }); - }); - }); + expect(mockUpdateTask).not.toHaveBeenCalled(); + + if (expectsSummaryUpdate) { + await waitFor(() => { + expect(mockSessionStoreSetters.updateSession).toHaveBeenCalledWith( + "run-1", + { conversationSummary: summary }, + ); + }); + } else { + expect(mockSessionStoreSetters.updateSession).not.toHaveBeenCalled(); + } + }, + ); it("calls enrichDescriptionWithFileContent before generating", async () => { mockEnrichDescription.mockResolvedValue("enriched content"); diff --git a/apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.ts b/apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.ts index 3cab24164..048436046 100644 --- a/apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.ts +++ b/apps/code/src/renderer/features/sessions/hooks/useChatTitleGenerator.ts @@ -73,15 +73,11 @@ export function useChatTitleGenerator(taskId: string): void { const result = await generateTitleAndSummary(content); if (result) { const { title, summary } = result; - if (title) { - const isFirstGeneration = lastGeneratedAtCount.current === 0; - if ( - !isFirstGeneration && - getCachedTask(taskId)?.title_manually_set - ) { - log.debug("Skipping auto-title, user renamed task", { taskId }); - return; - } + const titleLocked = !!getCachedTask(taskId)?.title_manually_set; + + if (title && titleLocked) { + log.debug("Skipping auto-title, user renamed task", { taskId }); + } else if (title) { const client = await getAuthenticatedClient(); if (client) { await client.updateTask(taskId, { title }); @@ -95,7 +91,6 @@ export function useChatTitleGenerator(taskId: string): void { getSessionService().updateSessionTaskTitle(taskId, title); log.debug("Updated task title from conversation", { taskId, - title, promptCount, }); } @@ -108,7 +103,6 @@ export function useChatTitleGenerator(taskId: string): void { log.debug("Updated task summary from conversation", { taskId, - summary, promptCount, }); }