mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
section 13: Phase 13: Session status from the client type, compaction-dr
This commit is contained in:
1 parent
717536c5a6
commit
2d4abe79e1
21 files changed
+194
-100
No files matched your search
@@ -1929,6 +1929,58 @@ describe('EventProvider permissions and forms', () => {
|
||||
expect(useSessionStatus.getState().getStatus('session-9')).toEqual({ type: 'busy' })
|
||||
})
|
||||
|
||||
it('shows compaction from compaction events and restores the previous status', async () => {
|
||||
render(<Harness />, { wrapper: createWrapper() })
|
||||
|
||||
await waitFor(() => expect(mocks.subscribeGlobalMonitor).toHaveBeenCalled())
|
||||
|
||||
const lastSubscribeCall = mocks.subscribeGlobalMonitor.mock.calls[mocks.subscribeGlobalMonitor.mock.calls.length - 1]
|
||||
const onEvent = lastSubscribeCall[0].onEvent as (data: unknown) => void
|
||||
|
||||
act(() => {
|
||||
onEvent({ type: 'session.execution.started', data: { sessionID: 'session-compact' }, directory: '/repo' })
|
||||
onEvent({
|
||||
type: 'session.compaction.started',
|
||||
data: { sessionID: 'session-compact', reason: 'manual' },
|
||||
directory: '/repo',
|
||||
})
|
||||
})
|
||||
expect(useSessionStatus.getState().getStatus('session-compact')).toEqual({ type: 'compact' })
|
||||
|
||||
act(() => {
|
||||
onEvent({
|
||||
type: 'session.compaction.ended',
|
||||
data: { sessionID: 'session-compact', reason: 'manual', text: 'summary' },
|
||||
directory: '/repo',
|
||||
})
|
||||
})
|
||||
expect(useSessionStatus.getState().getStatus('session-compact')).toEqual({ type: 'busy' })
|
||||
|
||||
act(() => {
|
||||
onEvent({
|
||||
type: 'session.compaction.started',
|
||||
data: { sessionID: 'session-compact', reason: 'auto' },
|
||||
directory: '/repo',
|
||||
})
|
||||
onEvent({
|
||||
type: 'session.status',
|
||||
data: { sessionID: 'session-compact', status: { type: 'retry', attempt: 1, message: 'rate limited', next: 5 } },
|
||||
directory: '/repo',
|
||||
})
|
||||
onEvent({
|
||||
type: 'session.compaction.failed',
|
||||
data: { sessionID: 'session-compact', reason: 'auto', error: { message: 'boom' } },
|
||||
directory: '/repo',
|
||||
})
|
||||
})
|
||||
expect(useSessionStatus.getState().getStatus('session-compact')).toEqual({
|
||||
type: 'retry',
|
||||
attempt: 1,
|
||||
message: 'rate limited',
|
||||
next: 5,
|
||||
})
|
||||
})
|
||||
|
||||
it('applies execution lifecycle and idle events from the global monitor to the status store', async () => {
|
||||
render(<Harness />, { wrapper: createWrapper() })
|
||||
|
||||
|
||||
@@ -25,8 +25,8 @@ import { isLocalOpenCodeServer } from '@/contexts/OpenCodeServerContext'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useOpenCodeServers } from '@/hooks/useOpenCodeServers'
|
||||
import { remoteProjectsQueryOptions } from '@/hooks/useRemoteProjects'
|
||||
import type { FormAnswer, FormInfo, PermissionRequest } from '@opencode-manager/shared/opencode'
|
||||
import type { PermissionResponse, Repo } from '@/api/types'
|
||||
import type { FormAnswer, FormInfo, PermissionReply, PermissionRequest } from '@opencode-manager/shared/opencode'
|
||||
import type { Repo } from '@/api/types'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { openCodeEventStream, type EventStreamHealthState } from '@/lib/opencode-event-stream'
|
||||
import { addToSessionKeyedState, removeFromSessionKeyedState } from '@/lib/sessionKeyedState'
|
||||
@@ -238,7 +238,7 @@ interface EventContextValue {
|
||||
respond: (
|
||||
permissionID: string,
|
||||
sessionID: string,
|
||||
response: PermissionResponse,
|
||||
response: PermissionReply,
|
||||
message?: string,
|
||||
) => Promise<void>
|
||||
dismiss: (permissionID: string, sessionID?: string) => void
|
||||
@@ -626,7 +626,7 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
|
||||
const replyToPermission = useCallback(async (
|
||||
permissionID: string,
|
||||
sessionID: string,
|
||||
response: PermissionResponse,
|
||||
response: PermissionReply,
|
||||
message?: string,
|
||||
) => {
|
||||
const permission = allPermissions.find(candidate => candidate.id === permissionID)
|
||||
@@ -1098,6 +1098,15 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
|
||||
useSessionStatus.getState().setStatus(event.data.sessionID, { type: 'idle' })
|
||||
break
|
||||
}
|
||||
case 'session.compaction.started': {
|
||||
useSessionStatus.getState().beginCompaction(event.data.sessionID)
|
||||
break
|
||||
}
|
||||
case 'session.compaction.ended':
|
||||
case 'session.compaction.failed': {
|
||||
useSessionStatus.getState().endCompaction(event.data.sessionID)
|
||||
break
|
||||
}
|
||||
case 'session.execution.started': {
|
||||
useSessionStatus.getState().setSessionServer(event.data.sessionID, serverId)
|
||||
rememberSessionDirectory(event.data.sessionID, event.directory, serverId)
|
||||
|
||||
Reference in new issue
Block a user