Files
opencode-manager/frontend/src/components/navigation/NotificationsSheet.test.tsx
T
Chris Scott dacde879d6 feat(opencode): migrate OpenCode Manager to OpenCode 2 (#359)
* feat(opencode): migrate OpenCode Manager to OpenCode 2

Port the backend lifecycle, generated plugins, event aggregation,
schedules, worktrees, provider credentials, MCP, config handling, the
frontend chat model, and the ocm CLI to OpenCode 2.

Adopt @opencode/client 2.0.15 as the single typed V2 API contract,
require OpenCode 2.0.0 or newer (pinned 2.0.15), and delete every
V1-only code path.

* refactor(opencode): reload config in place and drop v1 compatibility shims

Route config/skill/AGENTS.md changes through the OpenCode location reload
API instead of a full server restart, stop auto-resuming interrupted
sessions, remove the restart coordinator and v1 MCP/version shims, and pin
support to OpenCode >=2.0.15 <3.0.0. Adds integration-ready retries,
service-mode launch, ocm-cli repo proxy, and new frontend form/MCP helpers.

* refactor(opencode): consolidate v2 migration helpers and harden install, proxy, and session flows

- extract shared semver and model-ref utilities, reuse across version checks
- share the OpenCode release download script across Docker, entrypoint, dev setup
- unify install/upgrade failure recovery and guard externally managed OPENCODE_BIN
- scope the repo proxy location rewrite and surface ocm proxy errors
- rework frontend session projection, permission lookup, and cache invalidation

* fix(schedules): reject unavailable agents before creating a session

* feat(opencode): add ocm install, schedule agent fallback, and session move guards
2026-09-26 13:16:45 -04:00

182 lines
5.4 KiB
TypeScript

import { render, screen, fireEvent } from '@testing-library/react'
import { describe, it, expect, vi } from 'vitest'
import { MemoryRouter } from 'react-router-dom'
import { NotificationsSheet } from './NotificationsSheet'
import { usePermissions, useForms } from '@/contexts/EventContext'
vi.mock('@/contexts/EventContext')
describe('NotificationsSheet', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('renders empty state when both counts are 0', () => {
vi.mocked(usePermissions).mockReturnValue({
pendingCount: 0,
setShowDialog: vi.fn(),
navigateToCurrent: vi.fn(),
current: null,
respond: vi.fn(),
dismiss: vi.fn(),
hasForSession: vi.fn(),
})
vi.mocked(useForms).mockReturnValue({
pendingCount: 0,
navigateToCurrent: vi.fn(),
current: null,
reply: vi.fn(),
cancel: vi.fn(),
dismiss: vi.fn(),
hasForSession: vi.fn(),
})
const handleClose = vi.fn()
render(
<NotificationsSheet isOpen onClose={handleClose} />,
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
)
expect(screen.getAllByText("You're all caught up").length).toBe(2)
})
it('renders permission section with pending count', () => {
vi.mocked(usePermissions).mockReturnValue({
pendingCount: 2,
setShowDialog: vi.fn(),
navigateToCurrent: vi.fn(),
current: {
id: 'perm-1',
sessionID: 'session-1',
action: 'shell',
resources: ['/test/pattern'],
metadata: {},
},
respond: vi.fn(),
dismiss: vi.fn(),
hasForSession: vi.fn(),
})
vi.mocked(useForms).mockReturnValue({
pendingCount: 0,
navigateToCurrent: vi.fn(),
current: null,
reply: vi.fn(),
cancel: vi.fn(),
dismiss: vi.fn(),
hasForSession: vi.fn(),
})
const handleClose = vi.fn()
render(
<NotificationsSheet isOpen onClose={handleClose} />,
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
)
expect(screen.getByText('Pending permissions')).toBeInTheDocument()
expect(screen.getByText('Run Command')).toBeInTheDocument()
expect(screen.getByText('+1 more')).toBeInTheDocument()
})
it('renders form section with pending count', () => {
vi.mocked(usePermissions).mockReturnValue({
pendingCount: 0,
setShowDialog: vi.fn(),
navigateToCurrent: vi.fn(),
current: null,
respond: vi.fn(),
dismiss: vi.fn(),
hasForSession: vi.fn(),
})
vi.mocked(useForms).mockReturnValue({
pendingCount: 1,
navigateToCurrent: vi.fn(),
current: {
id: 'form-1',
sessionID: 'session-1',
title: 'Test question',
fields: [{ key: 'q0', type: 'string', options: [] }],
},
reply: vi.fn(),
cancel: vi.fn(),
dismiss: vi.fn(),
hasForSession: vi.fn(),
})
const handleClose = vi.fn()
render(
<NotificationsSheet isOpen onClose={handleClose} />,
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
)
expect(screen.getByText('Pending forms')).toBeInTheDocument()
expect(screen.getByText('Test question')).toBeInTheDocument()
})
it('calls setShowDialog and onClose when permission is clicked', () => {
const setShowDialogMock = vi.fn()
const navigateToPermissionMock = vi.fn()
const handleClose = vi.fn()
vi.mocked(usePermissions).mockReturnValue({
pendingCount: 1,
setShowDialog: setShowDialogMock,
navigateToCurrent: navigateToPermissionMock,
current: {
id: 'perm-1',
sessionID: 'session-1',
action: 'shell',
resources: ['/test/pattern'],
metadata: {},
},
respond: vi.fn(),
dismiss: vi.fn(),
hasForSession: vi.fn(),
})
vi.mocked(useForms).mockReturnValue({
pendingCount: 0,
navigateToCurrent: vi.fn(),
current: null,
reply: vi.fn(),
cancel: vi.fn(),
dismiss: vi.fn(),
hasForSession: vi.fn(),
})
render(
<NotificationsSheet isOpen onClose={handleClose} />,
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
)
fireEvent.click(screen.getByText('/test/pattern'))
expect(navigateToPermissionMock).toHaveBeenCalled()
expect(setShowDialogMock).toHaveBeenCalled()
expect(handleClose).toHaveBeenCalled()
})
it('calls navigateToCurrent and onClose when form is clicked', () => {
const navigateToFormMock = vi.fn()
const handleClose = vi.fn()
vi.mocked(usePermissions).mockReturnValue({
pendingCount: 0,
setShowDialog: vi.fn(),
navigateToCurrent: vi.fn(),
current: null,
respond: vi.fn(),
dismiss: vi.fn(),
hasForSession: vi.fn(),
})
vi.mocked(useForms).mockReturnValue({
pendingCount: 1,
navigateToCurrent: navigateToFormMock,
current: {
id: 'form-1',
sessionID: 'session-1',
title: 'Test question',
fields: [{ key: 'q0', type: 'string', options: [] }],
},
reply: vi.fn(),
cancel: vi.fn(),
dismiss: vi.fn(),
hasForSession: vi.fn(),
})
render(
<NotificationsSheet isOpen onClose={handleClose} />,
{ wrapper: ({ children }) => <MemoryRouter>{children}</MemoryRouter> },
)
fireEvent.click(screen.getByText('Test question'))
expect(navigateToFormMock).toHaveBeenCalled()
expect(handleClose).toHaveBeenCalled()
})
})