mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
feat: add session status store with optimistic active state and SSE polling (#272)
* feat: add session status store with optimistic active state and SSE polling - Adds sessionStatusStore with setOptimisticActive (auto-timeout), statusCache deduplication, and replaceStatuses/clearStatus - Integrates store in useSendPrompt (set optimistic on send, clear on error) - Adds session.status SSE event handling in useSSE with 5s polling fallback - Refactors test to mock the store instead of using real store instance - Fixes repoId null check in useRepoActivity * feat: replace event-source-polyfill with native SSE for PromptInput * fix: keep stop button visible and hide clear prompt button during active session * feat: restore failed queued prompts and preserve optimistic active status during poll * test: add MessageThread tests for optimistic editing state and resend flow * fix: handle queued prompt edge cases during pending submission and SSE errors
This commit is contained in:
1 parent
931f1215e6
commit
4e32fd5b00
16 files changed
+833
-61
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { MessageThread } from './MessageThread'
|
||||
import { useUIState } from '@/stores/uiStateStore'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
useSessionStatus: vi.fn(),
|
||||
@@ -8,6 +9,8 @@ const mocks = vi.hoisted(() => ({
|
||||
useSettings: vi.fn(),
|
||||
usePermissions: vi.fn(),
|
||||
useQuestions: vi.fn(),
|
||||
useRefreshMessage: vi.fn(),
|
||||
useSessionAgent: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/stores/sessionStatusStore', () => ({
|
||||
@@ -27,6 +30,14 @@ vi.mock('@/contexts/EventContext', () => ({
|
||||
useQuestions: () => mocks.useQuestions(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useRemoveMessage', () => ({
|
||||
useRefreshMessage: () => mocks.useRefreshMessage(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSessionAgent', () => ({
|
||||
useSessionAgent: () => mocks.useSessionAgent(),
|
||||
}))
|
||||
|
||||
interface MockSettingsReturn {
|
||||
preferences: {
|
||||
simpleChatMode: boolean
|
||||
@@ -147,6 +158,12 @@ describe('MessageThread', () => {
|
||||
mocks.useQuestions.mockReturnValue({
|
||||
getForCallID: vi.fn(() => null),
|
||||
})
|
||||
mocks.useRefreshMessage.mockReturnValue({
|
||||
isPending: false,
|
||||
mutate: vi.fn(),
|
||||
})
|
||||
mocks.useSessionAgent.mockReturnValue({ agent: 'test-agent' })
|
||||
useUIState.getState().setIsEditingMessage(false)
|
||||
})
|
||||
|
||||
it('renders assistant message with only subtask part as standalone row without header', () => {
|
||||
@@ -397,4 +414,74 @@ describe('MessageThread', () => {
|
||||
expect(screen.getByText('Hello')).toBeInTheDocument()
|
||||
expect(screen.getByText('You')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('keeps global editing state active when edit textarea blurs', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
})
|
||||
|
||||
const messages = [
|
||||
createUserMessage('1', 'Hello'),
|
||||
createAssistantMessage('2', [createTextPart('This is a response', '2')]),
|
||||
]
|
||||
|
||||
const { unmount } = render(
|
||||
<MessageThread
|
||||
opcodeUrl="http://localhost:5551"
|
||||
sessionID="test-session"
|
||||
messages={messages as any}
|
||||
/>
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByTitle('Edit message'))
|
||||
const textarea = screen.getByPlaceholderText('Edit your message...')
|
||||
fireEvent.focus(textarea)
|
||||
expect(useUIState.getState().isEditingMessage).toBe(true)
|
||||
|
||||
fireEvent.blur(textarea)
|
||||
expect(useUIState.getState().isEditingMessage).toBe(true)
|
||||
|
||||
unmount()
|
||||
expect(useUIState.getState().isEditingMessage).toBe(false)
|
||||
})
|
||||
|
||||
it('resends an edited prompt after the edit textarea blurs', () => {
|
||||
setupSettings({
|
||||
simpleChatMode: false,
|
||||
showReasoning: false,
|
||||
})
|
||||
const mutate = vi.fn()
|
||||
mocks.useRefreshMessage.mockReturnValue({
|
||||
isPending: false,
|
||||
mutate,
|
||||
})
|
||||
|
||||
const messages = [
|
||||
createUserMessage('1', 'Hello'),
|
||||
createAssistantMessage('2', [createTextPart('This is a response', '2')]),
|
||||
]
|
||||
|
||||
render(
|
||||
<MessageThread
|
||||
opcodeUrl="http://localhost:5551"
|
||||
sessionID="test-session"
|
||||
messages={messages as any}
|
||||
/>
|
||||
)
|
||||
|
||||
fireEvent.click(screen.getByTitle('Edit message'))
|
||||
const textarea = screen.getByPlaceholderText('Edit your message...')
|
||||
fireEvent.change(textarea, { target: { value: 'Updated prompt' } })
|
||||
fireEvent.blur(textarea)
|
||||
fireEvent.click(screen.getByRole('button', { name: /resend/i }))
|
||||
|
||||
expect(mutate).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
assistantMessageID: '2',
|
||||
userMessageContent: 'Updated prompt',
|
||||
}),
|
||||
expect.any(Object),
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user