fix: verify Cursor chat store before reopen (#1037)

* test: reproduce issue #841

* test: cover Cursor chat store discovery

* fix: verify Cursor chat store before resume (closes #841)

* test: preserve non-Cursor resume behavior

* test: cover conservative Cursor resume gating

* fix: gate Cursor reopen until store verification

* test: cover legacy Cursor drawer fallback

* fix: scan unique legacy Cursor store drawer

* test: preserve raw Cursor workspace path hashing

* fix: hash raw Cursor workspace path

* test: pin Cursor probe owner and machine

* fix: probe Cursor store on recorded owner

* test: normalize Cursor probe owner home

* fix: normalize Cursor probe owner home
This commit is contained in:
SSU-WEI HUANG
2026-07-16 12:34:41 +08:00
committed by GitHub
parent adb6f41858
commit 520c3f511a
27 changed files with 955 additions and 34 deletions
@@ -52,6 +52,23 @@ describe('SessionActionMenu - Reopen action', () => {
expect(screen.getByRole('menuitem', { name: /Delete/ })).toBeInTheDocument()
})
it('renders a disabled Reopen item with an explanation when resume data is missing', () => {
const onClose = vi.fn()
renderMenu({
sessionActive: false,
onReopen: undefined,
reopenDisabledReason: 'Cursor chat data is no longer available on this machine.',
onClose,
})
const reopen = screen.getByRole('menuitem', { name: /Reopen/ })
expect(reopen).toHaveAttribute('aria-disabled', 'true')
expect(screen.getByRole('tooltip')).toHaveTextContent('Cursor chat data is no longer available')
fireEvent.click(reopen)
expect(onClose).not.toHaveBeenCalled()
})
it('fires onReopen and closes the menu when the Reopen item is clicked', () => {
const onReopen = vi.fn()
const onClose = vi.fn()
+26 -9
View File
@@ -8,6 +8,7 @@ import {
type CSSProperties
} from 'react'
import { useTranslation } from '@/lib/use-translation'
import { HoverTooltip } from '@/components/HoverTooltip'
type SessionActionMenuProps = {
isOpen: boolean
@@ -17,6 +18,7 @@ type SessionActionMenuProps = {
onExport?: () => void
onArchive: () => void
onReopen?: () => void
reopenDisabledReason?: string
onDelete: () => void
anchorPoint: { x: number; y: number }
menuId?: string
@@ -143,6 +145,7 @@ export function SessionActionMenu(props: SessionActionMenuProps) {
onExport,
onArchive,
onReopen,
reopenDisabledReason,
onDelete,
anchorPoint,
menuId
@@ -318,16 +321,30 @@ export function SessionActionMenu(props: SessionActionMenuProps) {
</button>
) : (
<>
{onReopen ? (
<button
type="button"
role="menuitem"
className={`${baseItemClassName} hover:bg-[var(--app-subtle-bg)]`}
onClick={handleReopen}
{onReopen || reopenDisabledReason ? (
<HoverTooltip
id={`${resolvedMenuId}-reopen-tooltip`}
className="w-full [&>span:first-child]:w-full"
align="start"
revealOnParentFocusClass="group-focus-within:opacity-100 group-focus-within:visible"
target={(
<button
type="button"
role="menuitem"
aria-disabled={reopenDisabledReason ? true : undefined}
aria-describedby={reopenDisabledReason ? `${resolvedMenuId}-reopen-tooltip` : undefined}
className={`${baseItemClassName} ${reopenDisabledReason
? 'cursor-not-allowed opacity-50'
: 'hover:bg-[var(--app-subtle-bg)]'}`}
onClick={reopenDisabledReason ? undefined : handleReopen}
>
<ReopenIcon className="text-[var(--app-hint)]" />
{t('session.action.reopen')}
</button>
)}
>
<ReopenIcon className="text-[var(--app-hint)]" />
{t('session.action.reopen')}
</button>
{reopenDisabledReason ?? t('session.action.reopen')}
</HoverTooltip>
) : null}
<button
type="button"
+9 -1
View File
@@ -395,6 +395,8 @@ function hasAbortableAgentRun(blocks: readonly ChatBlock[]): boolean {
type SessionChatProps = {
api: ApiClient
session: Session
cursorChatOnDisk?: boolean
reopenDisabledReason?: string
messages: DecryptedMessage[]
pendingMessages?: DecryptedMessage[]
messagesWarning: string | null
@@ -452,7 +454,11 @@ function SessionChatInner(props: SessionChatProps) {
const { t } = useTranslation()
const navigate = useNavigate()
const sessionInactive = !props.session.active
const inactiveCanResume = inactiveSessionCanResume(props.session, props.messages.length)
const inactiveCanResume = inactiveSessionCanResume(
props.session,
props.messages.length,
props.cursorChatOnDisk
)
const terminalSupported = isRemoteTerminalSupported(props.session.metadata)
const normalizedCacheRef = useRef<Map<string, { source: DecryptedMessage; normalized: NormalizedMessage | null }>>(new Map())
const blocksByIdRef = useRef<Map<string, ChatBlock>>(new Map())
@@ -1217,6 +1223,8 @@ function SessionChatInner(props: SessionChatProps) {
onToggleOutline={handleToggleOutline}
outlineActive={outlineOpen}
api={props.api}
canReopen={inactiveCanResume}
reopenDisabledReason={props.reopenDisabledReason}
onSessionDeleted={props.onBack}
onSessionReopened={(newSessionId) => {
navigate({
+4 -1
View File
@@ -92,6 +92,8 @@ export function SessionHeader(props: {
onToggleOutline?: () => void
outlineActive?: boolean
api: ApiClient | null
canReopen?: boolean
reopenDisabledReason?: string
onSessionDeleted?: () => void
onSessionReopened?: (newSessionId: string) => void
}) {
@@ -258,7 +260,8 @@ export function SessionHeader(props: {
onRename={() => setRenameOpen(true)}
onExport={() => setExportOpen(true)}
onArchive={() => setArchiveOpen(true)}
onReopen={handleReopen}
onReopen={props.canReopen === false ? undefined : handleReopen}
reopenDisabledReason={props.reopenDisabledReason}
onDelete={() => setDeleteOpen(true)}
anchorPoint={menuAnchorPoint}
menuId={menuId}
+19 -1
View File
@@ -26,6 +26,7 @@ import { getSessionTitle } from '@/lib/sessionTitle'
import type { Machine } from '@/types/api'
import { getMachinePlatform, presentMachineHealth } from '@/lib/machineHealth'
import { MachineGroupHeader } from '@/components/MachineGroupHeader'
import { useCursorChatStoreStatus } from '@/hooks/queries/useCursorChatStoreStatus'
type SessionGroup = {
key: string
@@ -596,6 +597,22 @@ function SessionItem(props: {
const [renameOpen, setRenameOpen] = useState(false)
const [archiveOpen, setArchiveOpen] = useState(false)
const [deleteOpen, setDeleteOpen] = useState(false)
const {
status: cursorChatStoreStatus,
isApplicable: cursorChatStoreApplicable,
error: cursorChatStoreError,
} = useCursorChatStoreStatus({
api,
session: s,
enabled: menuOpen
})
const cursorReopenDisabledReason = cursorChatStoreApplicable && cursorChatStoreStatus?.onDisk !== true
? cursorChatStoreError
? t('session.action.reopenCursorCheckFailed')
: cursorChatStoreStatus?.onDisk === false
? t('session.action.reopenCursorMissing')
: t('session.action.reopenCursorChecking')
: undefined
const { archiveSession, reopenSession, renameSession, deleteSession, isPending } = useSessionActions(
api,
@@ -732,7 +749,8 @@ function SessionItem(props: {
sessionActive={s.active}
onRename={() => setRenameOpen(true)}
onArchive={() => setArchiveOpen(true)}
onReopen={handleReopen}
onReopen={cursorReopenDisabledReason ? undefined : handleReopen}
reopenDisabledReason={cursorReopenDisabledReason}
onDelete={() => setDeleteOpen(true)}
anchorPoint={menuAnchorPoint}
/>