mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
section 12: Phase 12: One shared flattened stream event type; delete the
This commit is contained in:
1 parent
0b2303a870
commit
717536c5a6
15 files changed
+122
-125
No files matched your search
@@ -164,6 +164,7 @@ const childSessionForm: FormInfo = {
|
||||
function Harness() {
|
||||
const { current, pendingCount, syncForSession, navigateToCurrent, cancel, reply, getForSession } = useForms()
|
||||
const permissions = usePermissions()
|
||||
const { sshHostKey } = useEventContext()
|
||||
const location = useLocation()
|
||||
const [rejection, setRejection] = useState('none')
|
||||
const recordRejection = (action: Promise<void>) => {
|
||||
@@ -192,6 +193,7 @@ function Harness() {
|
||||
<div data-testid="path">{location.pathname}</div>
|
||||
<div data-testid="search">{location.search}</div>
|
||||
<div data-testid="location-key">{location.key}</div>
|
||||
<div data-testid="ssh-host">{sshHostKey.request?.host ?? 'none'}</div>
|
||||
<button onClick={() => syncForSession('/repo', 'session-1')}>Sync</button>
|
||||
<button onClick={() => permissions.syncForSession('/repo', 'session-1')}>Sync Permissions</button>
|
||||
<button onClick={navigateToCurrent}>Navigate</button>
|
||||
@@ -941,6 +943,36 @@ describe('EventProvider permissions and forms', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('exposes an SSH host key request received via the global monitor onEvent', 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: 'ssh.host-key-request',
|
||||
properties: {
|
||||
id: 'host-key-1',
|
||||
host: 'example.com:22',
|
||||
ip: '203.0.113.10',
|
||||
keyType: 'ssh-ed25519',
|
||||
fingerprint: 'SHA256:abc',
|
||||
timestamp: Date.now(),
|
||||
isKeyChanged: false,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByTestId('ssh-host')).toHaveTextContent('example.com:22')
|
||||
})
|
||||
})
|
||||
|
||||
it('adds a pending permission received via the global monitor onEvent', async () => {
|
||||
mocks.listRepos.mockResolvedValue([{ id: 123, fullPath: '/repo' }])
|
||||
|
||||
|
||||
@@ -14,13 +14,19 @@ import {
|
||||
} from '@/api/opencode'
|
||||
import { listRepos } from '@/api/repos'
|
||||
import { FetchError } from '@opencode-manager/shared'
|
||||
import { buildServerDirectoryKey, LOCAL_OPENCODE_SERVER_ID, parseServerDirectoryKey } from '@opencode-manager/shared/schemas'
|
||||
import {
|
||||
buildServerDirectoryKey,
|
||||
LOCAL_OPENCODE_SERVER_ID,
|
||||
parseServerDirectoryKey,
|
||||
type OpenCodeStreamEvent,
|
||||
type SSHHostKeyRequest,
|
||||
} from '@opencode-manager/shared/schemas'
|
||||
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, V2Event } from '@opencode-manager/shared/opencode'
|
||||
import type { PermissionResponse, SSHHostKeyRequest, Repo } from '@/api/types'
|
||||
import type { FormAnswer, FormInfo, PermissionRequest } from '@opencode-manager/shared/opencode'
|
||||
import type { PermissionResponse, Repo } from '@/api/types'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { openCodeEventStream, type EventStreamHealthState } from '@/lib/opencode-event-stream'
|
||||
import { addToSessionKeyedState, removeFromSessionKeyedState } from '@/lib/sessionKeyedState'
|
||||
@@ -53,9 +59,6 @@ type PendingForm = ServerScoped<FormInfo>
|
||||
type PermissionsBySession = Record<string, PendingPermission[]>
|
||||
type FormsBySession = Record<string, PendingForm[]>
|
||||
type SSEHealthState = Pick<EventStreamHealthState, 'isConnected' | 'isHealthy' | 'isStalled'>
|
||||
type StreamEvent =
|
||||
| (V2Event & { directory?: string; serverId?: string })
|
||||
| { type: 'ssh.host-key-request'; properties: SSHHostKeyRequest }
|
||||
|
||||
type SessionScopedItem = { id: string; sessionID: string }
|
||||
|
||||
@@ -1046,11 +1049,8 @@ export function EventProvider({ children }: { children: React.ReactNode }) {
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) return
|
||||
|
||||
const handleSSEMessage = (data: unknown) => {
|
||||
if (!data || typeof data !== 'object' || !('type' in data)) return
|
||||
|
||||
const event = data as StreamEvent
|
||||
const serverId = (event as { serverId?: string }).serverId ?? LOCAL_OPENCODE_SERVER_ID
|
||||
const handleSSEMessage = (event: OpenCodeStreamEvent) => {
|
||||
const serverId = event.serverId ?? LOCAL_OPENCODE_SERVER_ID
|
||||
|
||||
const goalEvent = { type: event.type, data: 'data' in event ? event.data : null }
|
||||
if (applySessionGoalEvent(queryClient, goalEvent, serverId)) return
|
||||
|
||||
Reference in new issue
Block a user