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
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -95,7 +91,6 @@ export function useChatTitleGenerator(taskId: string): void {
getSessionService().updateSessionTaskTitle(taskId, title);
log.debug("Updated task title from conversation", {
taskId,
title,
promptCount,
});
}
Expand All @@ -108,7 +103,6 @@ export function useChatTitleGenerator(taskId: string): void {

log.debug("Updated task summary from conversation", {
taskId,
summary,
promptCount,
});
}
Expand Down
Loading