fix(assistant): remove stale localStorage cache read in session launcher

This commit is contained in:
Chris Scott committed 2026-06-05 18:27:36 -04:00
1 parent cc89a524c4
commit 51ebfabb3d
2 files changed
+1 -81

No files matched your search

@@ -6,7 +6,6 @@ import { initializeAssistantMode } from '@/api/repos'
const mocks = vi.hoisted(() => ({
listSessions: vi.fn(),
getSession: vi.fn(),
createSession: vi.fn(),
sendPromptAsync: vi.fn(),
initializeAssistantMode: vi.fn(),
@@ -19,7 +18,6 @@ vi.mock('@/api/repos', () => ({
vi.mock('@/api/opencode', () => ({
OpenCodeClient: vi.fn(() => ({
listSessions: mocks.listSessions,
getSession: mocks.getSession,
createSession: mocks.createSession,
sendPromptAsync: mocks.sendPromptAsync,
})),
@@ -36,25 +34,6 @@ describe('useAssistantSessionLauncher', () => {
mocks.initializeAssistantMode.mockResolvedValue({ directory: '/assistant' })
})
it('opens the cached assistant session without listing sessions', async () => {
localStorage.setItem('ocm:assistant:last-session:123:/assistant', 'cached')
mocks.getSession.mockResolvedValue({ id: 'cached', directory: '/assistant', time: { updated: 20 } })
const onNavigate = vi.fn()
const { result } = renderHook(() => useAssistantSessionLauncher({
repoId: 123,
opcodeUrl: 'http://localhost:5551',
onNavigate,
}))
await act(async () => {
await result.current.openAssistant()
})
expect(mocks.getSession).toHaveBeenCalledWith('cached')
expect(mocks.listSessions).not.toHaveBeenCalled()
expect(onNavigate).toHaveBeenCalledWith('cached')
})
it('opens the latest root session in the assistant directory', async () => {
mocks.listSessions.mockResolvedValue([
{ id: 'older', directory: '/assistant', time: { updated: 10 } },
@@ -82,29 +61,6 @@ describe('useAssistantSessionLauncher', () => {
expect(mocks.sendPromptAsync).not.toHaveBeenCalled()
})
it('falls back to latest lookup when the cached session is stale', async () => {
localStorage.setItem('ocm:assistant:last-session:123:/assistant', 'stale')
mocks.getSession.mockRejectedValueOnce(new Error('not found'))
mocks.listSessions.mockResolvedValue([
{ id: 'latest', directory: '/assistant', time: { updated: 30 } },
])
const onNavigate = vi.fn()
const { result } = renderHook(() => useAssistantSessionLauncher({
repoId: 123,
opcodeUrl: 'http://localhost:5551',
onNavigate,
}))
await act(async () => {
await result.current.openAssistant()
})
expect(mocks.getSession).toHaveBeenCalledWith('stale')
expect(mocks.listSessions).toHaveBeenCalledWith({ limit: 1, roots: true })
expect(onNavigate).toHaveBeenCalledWith('latest')
expect(localStorage.getItem('ocm:assistant:last-session:123:/assistant')).toBe('latest')
})
it('notifies an existing assistant session when some generated updates were preserved', async () => {
mocks.initializeAssistantMode.mockResolvedValue({
directory: '/assistant',