mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
* 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
174 lines
5.1 KiB
TypeScript
174 lines
5.1 KiB
TypeScript
import { describe, it, expect, vi } from 'vitest'
|
|
import { render, screen } from '@testing-library/react'
|
|
import userEvent from '@testing-library/user-event'
|
|
import { McpServerCard } from './McpServerCard'
|
|
import type { McpServerConfig, McpStatus } from '@/api/mcp'
|
|
|
|
const serverId = 'my-test-server'
|
|
const serverConfig: McpServerConfig = { type: 'remote', url: 'https://example.com/mcp' }
|
|
const status: McpStatus = { status: 'connected' }
|
|
|
|
describe('McpServerCard', () => {
|
|
it('renders display name and description', () => {
|
|
render(
|
|
<McpServerCard
|
|
serverId={serverId}
|
|
serverConfig={serverConfig}
|
|
status={status}
|
|
isConnected={true}
|
|
errorMessage={null}
|
|
isAnyOperationPending={false}
|
|
togglingServerId={null}
|
|
isRemovingAuth={false}
|
|
onToggleServer={vi.fn()}
|
|
onDeleteServer={vi.fn()}
|
|
onAuthenticate={vi.fn()}
|
|
onRemoveAuth={vi.fn()}
|
|
/>,
|
|
)
|
|
|
|
expect(screen.getByText('My test server')).toBeInTheDocument()
|
|
expect(screen.getByText('Remote server: https://example.com/mcp')).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders the Connected status badge', () => {
|
|
render(
|
|
<McpServerCard
|
|
serverId={serverId}
|
|
serverConfig={serverConfig}
|
|
status={status}
|
|
isConnected={true}
|
|
errorMessage={null}
|
|
isAnyOperationPending={false}
|
|
togglingServerId={null}
|
|
isRemovingAuth={false}
|
|
onToggleServer={vi.fn()}
|
|
onDeleteServer={vi.fn()}
|
|
onAuthenticate={vi.fn()}
|
|
onRemoveAuth={vi.fn()}
|
|
/>,
|
|
)
|
|
|
|
expect(screen.getByText('Connected')).toBeInTheDocument()
|
|
})
|
|
|
|
it('renders the toggle Switch when not awaiting auth', () => {
|
|
render(
|
|
<McpServerCard
|
|
serverId={serverId}
|
|
serverConfig={serverConfig}
|
|
status={status}
|
|
isConnected={true}
|
|
errorMessage={null}
|
|
isAnyOperationPending={false}
|
|
togglingServerId={null}
|
|
isRemovingAuth={false}
|
|
onToggleServer={vi.fn()}
|
|
onDeleteServer={vi.fn()}
|
|
onAuthenticate={vi.fn()}
|
|
onRemoveAuth={vi.fn()}
|
|
/>,
|
|
)
|
|
|
|
const switches = screen.getAllByRole('switch')
|
|
expect(switches.length).toBeGreaterThanOrEqual(1)
|
|
})
|
|
|
|
it('calls onDeleteServer when Delete Server is clicked from overflow menu', async () => {
|
|
const user = userEvent.setup()
|
|
const onDeleteServer = vi.fn()
|
|
|
|
render(
|
|
<McpServerCard
|
|
serverId={serverId}
|
|
serverConfig={serverConfig}
|
|
status={status}
|
|
isConnected={true}
|
|
errorMessage={null}
|
|
isAnyOperationPending={false}
|
|
togglingServerId={null}
|
|
isRemovingAuth={false}
|
|
onToggleServer={vi.fn()}
|
|
onDeleteServer={onDeleteServer}
|
|
onAuthenticate={vi.fn()}
|
|
onRemoveAuth={vi.fn()}
|
|
/>,
|
|
)
|
|
|
|
await user.click(screen.getByLabelText('Actions for My test server'))
|
|
await user.click(screen.getByText('Delete Server'))
|
|
|
|
expect(onDeleteServer).toHaveBeenCalledTimes(1)
|
|
expect(onDeleteServer).toHaveBeenCalledWith('my-test-server', 'My test server')
|
|
})
|
|
|
|
it('renders the Connecting badge for a pending server', () => {
|
|
render(
|
|
<McpServerCard
|
|
serverId={serverId}
|
|
serverConfig={serverConfig}
|
|
status={{ status: 'pending' }}
|
|
isConnected={false}
|
|
errorMessage={null}
|
|
isAnyOperationPending={false}
|
|
togglingServerId={null}
|
|
isRemovingAuth={false}
|
|
onToggleServer={vi.fn()}
|
|
onDeleteServer={vi.fn()}
|
|
onAuthenticate={vi.fn()}
|
|
onRemoveAuth={vi.fn()}
|
|
/>,
|
|
)
|
|
|
|
expect(screen.getByText('Connecting')).toBeInTheDocument()
|
|
})
|
|
|
|
it('offers auth for an OAuth integration even without an error message', () => {
|
|
render(
|
|
<McpServerCard
|
|
serverId={serverId}
|
|
serverConfig={serverConfig}
|
|
status={{ status: 'failed', error: 'MCP error -32000', integrationID: 'int-1' }}
|
|
isConnected={false}
|
|
errorMessage="MCP error -32000"
|
|
isAnyOperationPending={false}
|
|
togglingServerId={null}
|
|
isRemovingAuth={false}
|
|
onToggleServer={vi.fn()}
|
|
onDeleteServer={vi.fn()}
|
|
onAuthenticate={vi.fn()}
|
|
onRemoveAuth={vi.fn()}
|
|
/>,
|
|
)
|
|
|
|
expect(screen.getByRole('button', { name: /Auth/ })).toBeInTheDocument()
|
|
})
|
|
|
|
it('offers remove auth for a connected OAuth integration', async () => {
|
|
const user = userEvent.setup()
|
|
const onRemoveAuth = vi.fn()
|
|
|
|
render(
|
|
<McpServerCard
|
|
serverId={serverId}
|
|
serverConfig={serverConfig}
|
|
status={{ status: 'connected', integrationID: 'int-1' }}
|
|
isConnected={true}
|
|
errorMessage={null}
|
|
isAnyOperationPending={false}
|
|
togglingServerId={null}
|
|
isRemovingAuth={false}
|
|
onToggleServer={vi.fn()}
|
|
onDeleteServer={vi.fn()}
|
|
onAuthenticate={vi.fn()}
|
|
onRemoveAuth={onRemoveAuth}
|
|
/>,
|
|
)
|
|
|
|
await user.click(screen.getByLabelText('Actions for My test server'))
|
|
await user.click(screen.getByText('Remove Auth'))
|
|
|
|
expect(onRemoveAuth).toHaveBeenCalledWith('my-test-server')
|
|
})
|
|
})
|