fix(permissions): clear expired permission requests

This commit is contained in:
Chris Scott committed 2026-10-07 09:05:21 -04:00
1 parent bf9903862b
commit 83e8650949
2 files changed
+26 -1

No files matched your search

@@ -5,6 +5,7 @@ import type { ReactNode } from 'react'
import { MemoryRouter, useLocation } from 'react-router-dom'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { FormInfo, PermissionRequest } from '@opencode-manager/shared/opencode'
import { FetchError } from '@opencode-manager/shared'
import { useSessionStatus } from '@/stores/sessionStatusStore'
import { changeWalkthroughQueryKey } from '@/hooks/useChangeWalkthrough'
import { EventProvider, useEventContext, useForms, usePermissions, useSSEHealth } from './EventContext'
@@ -248,6 +249,24 @@ describe('EventProvider permissions and forms', () => {
})
})
it('removes a permission the server no longer knows about when replying', async () => {
mocks.listPendingPermissions.mockResolvedValue([pendingPermission])
mocks.replyPermission.mockRejectedValue(new FetchError('Permission request not found', 404, 'PermissionNotFoundError'))
render(<Harness />, { wrapper: createWrapper() })
await userEvent.click(screen.getByRole('button', { name: 'Sync Permissions' }))
await waitFor(() => expect(screen.getByTestId('permission-count')).toHaveTextContent('1'))
await userEvent.click(screen.getByRole('button', { name: 'Reject Permission' }))
await waitFor(() => {
expect(screen.getByTestId('permission-count')).toHaveTextContent('0')
expect(screen.getByTestId('permission-current')).toHaveTextContent('none')
})
})
it('forwards an optional rejection message to the facade', async () => {
mocks.listPendingPermissions.mockResolvedValue([pendingPermission])
+7 -1
View File
@@ -11,6 +11,7 @@ import {
replyPermission,
} from '@/api/opencode'
import { listRepos } from '@/api/repos'
import { FetchError } from '@opencode-manager/shared'
import type { FormAnswer, FormInfo, PermissionRequest, V2Event } from '@opencode-manager/shared/opencode'
import type { PermissionResponse, SSHHostKeyRequest, Repo } from '@/api/types'
import { showToast } from '@/lib/toast'
@@ -284,7 +285,12 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
response: PermissionResponse,
message?: string,
) => {
await replyPermission(sessionID, permissionID, response, message)
try {
await replyPermission(sessionID, permissionID, response, message)
} catch (error) {
if (!(error instanceof FetchError && error.statusCode === 404)) throw error
showToast.info('Permission request expired')
}
removePermission(permissionID, sessionID)
}, [removePermission])