mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
fix: preserve prompt text on network error and allow offline typing (#276)
* fix: preserve prompt text on network error and allow offline typing * fix: preserve prompt on network error, swallow 524 to avoid duplicate sends * feat: add service worker precaching with app shell and runtime cache strategies * fix: copy frontend/plugins into Docker build context * fix: improve service worker update checks with visibility and focus handlers * fix: add connect timeout to event stream to recover from failed connections * fix: remove optimistic message insert, keep prompt in input until server confirms
This commit is contained in:
1 parent
a7d0c13f9a
commit
3e617c2df8
18 files changed
+569
-57
No files matched your search
@@ -4,6 +4,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { createElement } from 'react'
|
||||
import { useSendPrompt } from './useOpenCode'
|
||||
import { FetchError } from '../api/fetchWrapper'
|
||||
import { messagesQueryKey } from '../lib/queryInvalidation'
|
||||
|
||||
const mockSendPrompt = vi.fn()
|
||||
const mockSendPromptAsync = vi.fn()
|
||||
@@ -40,6 +41,7 @@ vi.mock('../lib/opencode-errors', () => ({
|
||||
message: err.message,
|
||||
isRetryable: false,
|
||||
})),
|
||||
isGatewayTimeout: vi.fn((err) => err?.statusCode === 524),
|
||||
}))
|
||||
|
||||
const mockClearError = vi.fn()
|
||||
@@ -264,4 +266,68 @@ describe('useSendPrompt', () => {
|
||||
|
||||
expect(mockClearError).toHaveBeenCalledWith('session-2')
|
||||
})
|
||||
|
||||
it('rolls back optimistic prompt and stores failed prompt on network failure', async () => {
|
||||
const queryKey = messagesQueryKey('http://localhost:5551', 'session-lost', '/test')
|
||||
queryClient.setQueryData(queryKey, [])
|
||||
mockSendPrompt.mockRejectedValueOnce(new TypeError('Failed to fetch'))
|
||||
|
||||
const { result } = renderHookWithProviders()
|
||||
|
||||
await expect(
|
||||
result.current.mutateAsync({
|
||||
sessionID: 'session-lost',
|
||||
prompt: 'keep this prompt',
|
||||
})
|
||||
).rejects.toThrow('Failed to fetch')
|
||||
|
||||
expect(mockClearStatus).toHaveBeenCalledWith('session-lost')
|
||||
expect(mockSetError).toHaveBeenCalledWith(expect.objectContaining({
|
||||
sessionID: 'session-lost',
|
||||
failedPrompt: 'keep this prompt',
|
||||
}))
|
||||
expect(queryClient.getQueryData(queryKey)).toEqual([])
|
||||
})
|
||||
|
||||
it('stores failed prompt when queued async request fails before reaching OpenCode', async () => {
|
||||
mockSendPromptAsync.mockRejectedValueOnce(new TypeError('Failed to fetch'))
|
||||
|
||||
const { result } = renderHookWithProviders()
|
||||
|
||||
await expect(
|
||||
result.current.mutateAsync({
|
||||
sessionID: 'session-queued-lost',
|
||||
prompt: 'queued while disconnected',
|
||||
queued: true,
|
||||
})
|
||||
).rejects.toThrow('Failed to fetch')
|
||||
|
||||
expect(mockClearQueuedPrompt).toHaveBeenCalledWith('session-queued-lost')
|
||||
expect(mockClearStatus).toHaveBeenCalledWith('session-queued-lost')
|
||||
expect(mockSetError).toHaveBeenCalledWith(expect.objectContaining({
|
||||
sessionID: 'session-queued-lost',
|
||||
failedPrompt: 'queued while disconnected',
|
||||
}))
|
||||
})
|
||||
|
||||
it('rolls back optimistic message but keeps status and surfaces no error on gateway timeout', async () => {
|
||||
const queryKey = messagesQueryKey('http://localhost:5551', 'session-524', '/test')
|
||||
queryClient.setQueryData(queryKey, [
|
||||
{ info: { id: 'optimistic_user_1' }, parts: [] },
|
||||
])
|
||||
mockSendPrompt.mockRejectedValueOnce(new FetchError('Gateway timeout', 524))
|
||||
|
||||
const { result } = renderHookWithProviders()
|
||||
|
||||
await expect(
|
||||
result.current.mutateAsync({
|
||||
sessionID: 'session-524',
|
||||
prompt: 'long running prompt',
|
||||
})
|
||||
).rejects.toThrow('Gateway timeout')
|
||||
|
||||
expect(queryClient.getQueryData(queryKey)).toEqual([])
|
||||
expect(mockClearStatus).not.toHaveBeenCalled()
|
||||
expect(mockSetError).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user