fix(web): share picker titles match sidebar (name before summary) (#1219)

The /share route used a local getSessionTitle that preferred summary.text
over metadata.name, so Android share-target rows disagreed with the
session sidebar. Reuse @/lib/sessionTitle and lock the precedence with a
unit test. Closes tiann/hapi#1218 once upstream PR lands after dogfood.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
HeavyGee
2026-07-29 10:06:05 +08:00
committed by GitHub
co-authored by Cursor
parent d8aa8736cd
commit 5eae68d237
2 changed files with 39 additions and 7 deletions
+38
View File
@@ -0,0 +1,38 @@
import { describe, expect, it } from 'vitest'
import { getSessionTitle } from './sessionTitle'
describe('getSessionTitle', () => {
it('prefers metadata.name over summary.text (sidebar / share picker parity)', () => {
expect(getSessionTitle({
id: 'abcdef0123456789',
metadata: {
name: 'hub runner version governance',
summary: { text: 'HAPI Skill Lookup' },
path: '/tmp/share-title-parity',
},
})).toBe('hub runner version governance')
})
it('falls back to summary when name is absent', () => {
expect(getSessionTitle({
id: 'abcdef0123456789',
metadata: {
summary: { text: 'HAPI Skill Lookup' },
path: '/tmp/share-title-parity',
},
})).toBe('HAPI Skill Lookup')
})
it('falls back to the last path segment when name and summary are absent', () => {
expect(getSessionTitle({
id: 'abcdef0123456789',
metadata: {
path: '/tmp/share-title-parity',
},
})).toBe('share-title-parity')
})
it('falls back to a short id when metadata is empty', () => {
expect(getSessionTitle({ id: 'abcdef0123456789' })).toBe('abcdef01')
})
})
+1 -7
View File
@@ -10,6 +10,7 @@ import {
type ShareTransferPayload,
} from '@/lib/shareTransfer'
import { setSharePendingTransfer } from '@/lib/sharePendingState'
import { getSessionTitle } from '@/lib/sessionTitle'
import type { SessionSummary } from '@/types/api'
type LoadState =
@@ -29,13 +30,6 @@ function formatBytes(n: number): string {
return `${(n / (1024 * 1024)).toFixed(1)} MB`
}
function getSessionTitle(session: SessionSummary): string {
return session.metadata?.summary?.text
?? session.metadata?.name
?? session.metadata?.path
?? session.id.slice(0, 8)
}
function SharePreview(props: { payload: ShareTransferPayload }) {
const { payload } = props
const { t } = useTranslation()