diff --git a/ui/desktop/src/__tests__/sessions.test.ts b/ui/desktop/src/__tests__/sessions.test.ts index 2970dd777d..3bb48febcf 100644 --- a/ui/desktop/src/__tests__/sessions.test.ts +++ b/ui/desktop/src/__tests__/sessions.test.ts @@ -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'); + }); +}); diff --git a/ui/desktop/src/hooks/useNavigationSessions.ts b/ui/desktop/src/hooks/useNavigationSessions.ts index 0c31eda802..bbbf7306f0 100644 --- a/ui/desktop/src/hooks/useNavigationSessions.ts +++ b/ui/desktop/src/hooks/useNavigationSessions.ts @@ -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; }