fix(ui): preserve user-set session name for recipe-based chats (#9079)

Signed-off-by: Douwe Osinga <douwe@squareup.com>
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
UGBOMEH OGOCHUKWU WILLIAMS
2026-05-13 00:43:58 +01:00
committed by GitHub
parent 66c89db942
commit 12604a8838
2 changed files with 26 additions and 0 deletions
+23
View File
@@ -1,5 +1,6 @@
import { describe, it, expect } from 'vitest';
import { shouldShowNewChatTitle } from '../sessions';
import { getSessionDisplayName } from '../hooks/useNavigationSessions';
import type { Session } from '../api';
// Helper to build a minimal Session object for testing.
@@ -105,3 +106,25 @@ describe('session reuse scoping (fix for #7601)', () => {
expect(windowAOld?.id).toBe('empty-a');
});
});
describe('getSessionDisplayName (fix for #8865)', () => {
it('returns the user-set name for a recipe session that has been renamed', () => {
const session = makeSession({
name: 'My Renamed Chat',
user_set_name: true,
message_count: 2,
recipe: { title: 'Some Recipe' } as unknown as Session['recipe'],
});
expect(getSessionDisplayName(session)).toBe('My Renamed Chat');
});
it('falls back to the recipe title when the user has not renamed', () => {
const session = makeSession({
name: 'auto-generated',
user_set_name: false,
message_count: 2,
recipe: { title: 'Some Recipe' } as unknown as Session['recipe'],
});
expect(getSessionDisplayName(session)).toBe('Some Recipe');
});
});
@@ -256,6 +256,9 @@ export function useNavigationSessions(options: UseNavigationSessionsOptions = {}
}
export function getSessionDisplayName(session: Session): string {
if (session.user_set_name) {
return session.name;
}
if (session.recipe?.title) {
return session.recipe.title;
}