mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(servers): run Manager automation on linked servers
This commit is contained in:
1 parent
c591c15743
commit
a9bdb8358f
131 files changed
+6568
-949
No files matched your search
@@ -81,18 +81,21 @@ export function DesktopSidebar() {
|
||||
)}
|
||||
|
||||
{collapsed ? (
|
||||
<div className="flex flex-col gap-1 p-2 pt-0">
|
||||
{collapsedItems.map((item: MoreDrawerItem) => (
|
||||
<SidebarItem
|
||||
key={item.key}
|
||||
icon={item.icon}
|
||||
label={item.label}
|
||||
collapsed={collapsed}
|
||||
onClick={() => handleItemClick(item)}
|
||||
danger={item.danger}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<>
|
||||
<div className="flex flex-col gap-1 p-2 pt-0">
|
||||
{collapsedItems.map((item: MoreDrawerItem) => (
|
||||
<SidebarItem
|
||||
key={item.key}
|
||||
icon={item.icon}
|
||||
label={item.label}
|
||||
collapsed={collapsed}
|
||||
onClick={() => handleItemClick(item)}
|
||||
danger={item.danger}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
<LinkedServersNav variant="rail" />
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<LinkedServersNav />
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import { MemoryRouter } from 'react-router-dom'
|
||||
import { LinkedServersNav } from './LinkedServersNav'
|
||||
|
||||
@@ -34,6 +34,14 @@ function renderNav(pathname = '/') {
|
||||
)
|
||||
}
|
||||
|
||||
function renderRail(pathname = '/') {
|
||||
return render(
|
||||
<MemoryRouter initialEntries={[pathname]}>
|
||||
<LinkedServersNav variant="rail" />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
}
|
||||
|
||||
describe('LinkedServersNav', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
@@ -75,4 +83,38 @@ describe('LinkedServersNav', () => {
|
||||
expect(screen.getByRole('link', { name: /Kitchen/ })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('link', { name: /Office/ })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders enabled servers as icon links in the collapsed rail', () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen], isLoading: false })
|
||||
|
||||
renderRail('/servers/srv_kitchen/sessions/abc')
|
||||
|
||||
expect(screen.getByRole('link', { name: 'Kitchen' })).toHaveAttribute(
|
||||
'aria-current',
|
||||
'page',
|
||||
)
|
||||
expect(screen.queryByText('Servers')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('renders nothing in the collapsed rail when no linked servers exist', () => {
|
||||
const { container } = renderRail()
|
||||
|
||||
expect(container).toBeEmptyDOMElement()
|
||||
})
|
||||
|
||||
it('hands navigation to the caller in the sheet variant', () => {
|
||||
mocks.useOpenCodeServers.mockReturnValue({ servers: [kitchen], isLoading: false })
|
||||
const onNavigate = vi.fn()
|
||||
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<LinkedServersNav variant="sheet" onNavigate={onNavigate} />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'Servers' })).toBeInTheDocument()
|
||||
fireEvent.click(screen.getByRole('button', { name: /Kitchen/ }))
|
||||
|
||||
expect(onNavigate).toHaveBeenCalledWith('/servers/srv_kitchen')
|
||||
})
|
||||
})
|
||||
@@ -5,7 +5,33 @@ import { SidebarSection } from '@/components/ui/sidebar'
|
||||
import { getServerPath } from '@/lib/navigation'
|
||||
import { cn } from '@/lib/utils'
|
||||
|
||||
export function LinkedServersNav() {
|
||||
export type LinkedServersVariant = 'sidebar' | 'rail' | 'sheet'
|
||||
|
||||
interface LinkedServersNavProps {
|
||||
/** `sidebar` renders the labelled section, `rail` the collapsed icon column, `sheet` the mobile sheet group. */
|
||||
variant?: LinkedServersVariant
|
||||
/** When provided, each row is a button that hands navigation to the caller instead of rendering a link. */
|
||||
onNavigate?: (path: string) => void
|
||||
}
|
||||
|
||||
function isActiveServerPath(pathname: string, path: string) {
|
||||
return pathname === path || pathname.startsWith(`${path}/`)
|
||||
}
|
||||
|
||||
function ServerConnectionDot({ connected }: { connected: boolean }) {
|
||||
const label = connected ? 'Connected' : 'Disconnected'
|
||||
|
||||
return (
|
||||
<span
|
||||
role="img"
|
||||
aria-label={label}
|
||||
title={label}
|
||||
className={cn('h-2 w-2 shrink-0 rounded-full', connected ? 'bg-success' : 'bg-muted-foreground/40')}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export function LinkedServersNav({ variant = 'sidebar', onNavigate }: LinkedServersNavProps) {
|
||||
const location = useLocation()
|
||||
const { servers, isLoading } = useOpenCodeServers()
|
||||
const { statusById } = useOpenCodeServerStatuses()
|
||||
@@ -15,37 +41,87 @@ export function LinkedServersNav() {
|
||||
return null
|
||||
}
|
||||
|
||||
if (variant === 'rail') {
|
||||
return (
|
||||
<div className="flex flex-col gap-1 px-2">
|
||||
{enabledServers.map((server) => {
|
||||
const path = getServerPath(server.id)
|
||||
const active = isActiveServerPath(location.pathname, path)
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={server.id}
|
||||
to={path}
|
||||
title={server.name}
|
||||
aria-current={active ? 'page' : undefined}
|
||||
className={cn(
|
||||
'flex items-center justify-center rounded-md p-2.5 transition-colors duration-150',
|
||||
'focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
|
||||
active ? 'bg-accent text-accent-foreground' : 'text-foreground hover:bg-accent/50',
|
||||
)}
|
||||
>
|
||||
<Server className="h-5 w-5 shrink-0" />
|
||||
<span className="sr-only">{server.name}</span>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const rows = enabledServers.map((server) => {
|
||||
const path = getServerPath(server.id)
|
||||
const active = isActiveServerPath(location.pathname, path)
|
||||
const connected = statusById[server.id]?.connected ?? false
|
||||
const className = cn(
|
||||
'flex items-center gap-3 rounded-md p-2.5 text-sm transition-colors duration-150',
|
||||
'focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
|
||||
active ? 'bg-accent text-accent-foreground' : 'text-foreground hover:bg-accent/50',
|
||||
variant === 'sheet' && 'mx-2 p-2 text-left',
|
||||
)
|
||||
const content = (
|
||||
<>
|
||||
<Server className="h-5 w-5 shrink-0" />
|
||||
<span className="min-w-0 flex-1 truncate">{server.name}</span>
|
||||
<ServerConnectionDot connected={connected} />
|
||||
</>
|
||||
)
|
||||
|
||||
if (onNavigate) {
|
||||
return (
|
||||
<button
|
||||
key={server.id}
|
||||
type="button"
|
||||
onClick={() => onNavigate(path)}
|
||||
aria-current={active ? 'page' : undefined}
|
||||
className={className}
|
||||
>
|
||||
{content}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Link key={server.id} to={path} className={className}>
|
||||
{content}
|
||||
</Link>
|
||||
)
|
||||
})
|
||||
|
||||
if (variant === 'sheet') {
|
||||
return (
|
||||
<section aria-label="Servers" className="flex flex-col border-b border-border pb-1">
|
||||
<h2 className="px-4 pt-2 pb-0.5 text-xs font-medium uppercase tracking-wider text-muted-foreground">
|
||||
Servers
|
||||
</h2>
|
||||
{rows}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<SidebarSection label="Servers" collapsed={false}>
|
||||
{enabledServers.map((server) => {
|
||||
const path = getServerPath(server.id)
|
||||
const active = location.pathname === path || location.pathname.startsWith(`${path}/`)
|
||||
const connected = statusById[server.id]?.connected ?? false
|
||||
|
||||
return (
|
||||
<Link
|
||||
key={server.id}
|
||||
to={path}
|
||||
className={cn(
|
||||
'flex items-center gap-3 rounded-md p-2.5 text-sm transition-colors duration-150',
|
||||
'focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background',
|
||||
active ? 'bg-accent text-accent-foreground' : 'text-foreground hover:bg-accent/50',
|
||||
)}
|
||||
>
|
||||
<Server className="h-5 w-5 shrink-0" />
|
||||
<span className="min-w-0 flex-1 truncate">{server.name}</span>
|
||||
<span
|
||||
role="img"
|
||||
aria-label={connected ? 'Connected' : 'Disconnected'}
|
||||
title={connected ? 'Connected' : 'Disconnected'}
|
||||
className={cn(
|
||||
'h-2 w-2 shrink-0 rounded-full',
|
||||
connected ? 'bg-success' : 'bg-muted-foreground/40',
|
||||
)}
|
||||
/>
|
||||
</Link>
|
||||
)
|
||||
})}
|
||||
{rows}
|
||||
</SidebarSection>
|
||||
)
|
||||
}
|
||||
@@ -361,7 +361,7 @@ describe('MoreDrawer', () => {
|
||||
expect(handleClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('offers only account items on a linked-server route', () => {
|
||||
it('offers the terminal plus account items on a linked-server route', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
setActivityGroups({ recent: [createActiveWorkItem()] })
|
||||
@@ -373,9 +373,9 @@ describe('MoreDrawer', () => {
|
||||
expect(screen.getByText('Home')).toBeInTheDocument()
|
||||
expect(screen.getByText('Settings')).toBeInTheDocument()
|
||||
expect(screen.getByText('Logout')).toBeInTheDocument()
|
||||
expect(screen.getByText('Terminal')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Files')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Source Control')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Terminal')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('MCP')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Schedules')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Repos')).not.toBeInTheDocument()
|
||||
|
||||
@@ -38,6 +38,16 @@ const activityMocks = vi.hoisted(() => ({
|
||||
useActivityWindowMinutes: vi.fn(),
|
||||
}))
|
||||
|
||||
const serverMocks = vi.hoisted(() => ({
|
||||
useOpenCodeServers: vi.fn(),
|
||||
useOpenCodeServerStatuses: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useOpenCodeServers', () => ({
|
||||
useOpenCodeServers: serverMocks.useOpenCodeServers,
|
||||
useOpenCodeServerStatuses: serverMocks.useOpenCodeServerStatuses,
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useActiveWork', () => ({
|
||||
useActiveWork: activityMocks.useActiveWork,
|
||||
useActivityWindowMinutes: activityMocks.useActivityWindowMinutes,
|
||||
@@ -132,6 +142,33 @@ function setActivityGroups(groups: {
|
||||
})
|
||||
}
|
||||
|
||||
function createLinkedServer(id: string, name: string, enabled = true) {
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
baseUrl: `https://${id}.example.com`,
|
||||
username: 'opencode',
|
||||
enabled,
|
||||
hasPassword: true,
|
||||
createdAt: 1,
|
||||
updatedAt: 2,
|
||||
}
|
||||
}
|
||||
|
||||
function setLinkedServers(servers: Array<ReturnType<typeof createLinkedServer>>) {
|
||||
serverMocks.useOpenCodeServers.mockReturnValue({ servers, isLoading: false })
|
||||
serverMocks.useOpenCodeServerStatuses.mockReturnValue({
|
||||
statuses: [],
|
||||
statusById: Object.fromEntries(
|
||||
servers.map((server) => [
|
||||
server.id,
|
||||
{ serverId: server.id, connected: true, version: null, error: null },
|
||||
]),
|
||||
),
|
||||
isLoading: false,
|
||||
})
|
||||
}
|
||||
|
||||
function createWrapper() {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: {
|
||||
@@ -173,6 +210,7 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
permissionSessions.current.clear()
|
||||
activityMocks.useActivityWindowMinutes.mockReturnValue(30)
|
||||
setActivityGroups({})
|
||||
setLinkedServers([])
|
||||
})
|
||||
|
||||
it('renders with loading state', async () => {
|
||||
@@ -927,4 +965,60 @@ describe('RepoQuickSwitchSheet', () => {
|
||||
expect(pathname).toBe('/repos/2/sessions/new-session')
|
||||
expect(handleClose).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('renders the Servers group with enabled linked servers', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([createRepo(1, 'repo1', '/path/to/repo1')])
|
||||
setLinkedServers([
|
||||
createLinkedServer('srv_kitchen', 'Kitchen'),
|
||||
createLinkedServer('srv_office', 'Office', false),
|
||||
])
|
||||
|
||||
render(<RepoQuickSwitchSheet isOpen onClose={vi.fn()} />, { wrapper: createWrapper() })
|
||||
|
||||
expect(await screen.findByRole('heading', { name: 'Servers' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('button', { name: /Kitchen/ })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: /Office/ })).not.toBeInTheDocument()
|
||||
expect(screen.getByRole('img', { name: 'Connected' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('hides the Servers group when no linked servers exist', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([createRepo(1, 'repo1', '/path/to/repo1')])
|
||||
|
||||
render(<RepoQuickSwitchSheet isOpen onClose={vi.fn()} />, { wrapper: createWrapper() })
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('repo1')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
expect(screen.queryByRole('heading', { name: 'Servers' })).toBeNull()
|
||||
})
|
||||
|
||||
it('navigates to a linked server and closes the sheet', async () => {
|
||||
vi.mocked(listRepos).mockResolvedValue([createRepo(1, 'repo1', '/path/to/repo1')])
|
||||
setLinkedServers([createLinkedServer('srv_kitchen', 'Kitchen')])
|
||||
const handleClose = vi.fn()
|
||||
|
||||
render(
|
||||
<QueryClientProvider client={new QueryClient()}>
|
||||
<MemoryRouter initialEntries={['/repos/1']}>
|
||||
<Routes>
|
||||
<Route
|
||||
path="*"
|
||||
element={
|
||||
<>
|
||||
<RepoQuickSwitchSheet isOpen onClose={handleClose} />
|
||||
<LocationSpy />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
</MemoryRouter>
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
|
||||
fireEvent.click(await screen.findByRole('button', { name: /Kitchen/ }))
|
||||
|
||||
expect(screen.getByTestId('location')).toHaveTextContent('/servers/srv_kitchen')
|
||||
expect(handleClose).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -11,6 +11,7 @@ import { FolderGit2, Plus } from 'lucide-react'
|
||||
import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
import { getAssistantPath, getRepoPath } from '@/lib/navigation'
|
||||
import { NewSessionButton, RepoSessionNavList, SearchClearButton } from '@/components/navigation/RepoSessionNav'
|
||||
import { LinkedServersNav } from '@/components/navigation/LinkedServersNav'
|
||||
import { getActiveRepoId } from '@/components/navigation/sidebar-session-tree'
|
||||
import { useNavigableRepos } from '@/hooks/useSidebarRepoGroups'
|
||||
|
||||
@@ -96,6 +97,12 @@ export function RepoQuickSwitchSheet({ isOpen, onClose }: RepoQuickSwitchSheetPr
|
||||
</div>
|
||||
</BottomSheetHeader>
|
||||
<BottomSheetContent className="flex flex-col px-0 pt-0 gap-0">
|
||||
{isOpen && (
|
||||
<LinkedServersNav
|
||||
variant="sheet"
|
||||
onNavigate={(path) => navigateAndClose(path, { replace: true })}
|
||||
/>
|
||||
)}
|
||||
{isOpen && !searchQuery.trim() && (
|
||||
<CompactActivityList onNavigate={(path) => navigateAndClose(path)} />
|
||||
)}
|
||||
|
||||
@@ -26,6 +26,7 @@ import { useOpenNavItem } from '@/hooks/useOpenNavItem'
|
||||
import { ActivityList } from '@/components/activity/ActivityList'
|
||||
import { ActivityCountPill } from '@/components/activity/ActivityCountPill'
|
||||
import { withQueryParam } from '@/lib/navigation'
|
||||
import type { TerminalTarget } from '@/lib/terminal-target'
|
||||
import { useActiveWorkCounts, useActivityWindowMinutes } from '@/hooks/useActiveWork'
|
||||
import { formatActivityWindow } from '@/lib/activeWork'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
@@ -84,6 +85,8 @@ interface ToolSidePanelProps {
|
||||
sessionId?: string
|
||||
directory?: string
|
||||
terminalDirectory?: string
|
||||
terminalTarget?: TerminalTarget
|
||||
allowedPanelTools?: readonly PanelTool[]
|
||||
repoDirectory?: string
|
||||
currentBranch?: string
|
||||
selectedFilePath?: string
|
||||
@@ -146,6 +149,8 @@ export function ToolSidePanel({
|
||||
sessionId,
|
||||
directory,
|
||||
terminalDirectory,
|
||||
terminalTarget,
|
||||
allowedPanelTools,
|
||||
repoDirectory,
|
||||
currentBranch = 'main',
|
||||
selectedFilePath,
|
||||
@@ -172,10 +177,16 @@ export function ToolSidePanel({
|
||||
|
||||
const panelTools: Array<{ item: MoreDrawerItem; tool: PanelTool }> = []
|
||||
const actionItems: MoreDrawerItem[] = []
|
||||
const terminalWorkspaceTarget: TerminalTarget | undefined =
|
||||
terminalTarget ?? (repoId === undefined ? undefined : { kind: 'repo', repoId })
|
||||
for (const item of buildToolItems(location.pathname)) {
|
||||
const tool = toolKeyOf(item)
|
||||
if (isPanelTool(tool)) panelTools.push({ item, tool })
|
||||
else actionItems.push(item)
|
||||
if (isPanelTool(tool)) {
|
||||
if (allowedPanelTools && !allowedPanelTools.includes(tool)) continue
|
||||
panelTools.push({ item, tool })
|
||||
} else {
|
||||
actionItems.push(item)
|
||||
}
|
||||
}
|
||||
const activeLabel = panelTools.find(({ tool }) => tool === activeTool)?.item.label
|
||||
|
||||
@@ -197,12 +208,15 @@ export function ToolSidePanel({
|
||||
if (tool === 'mcp') return repoDirectory ? <RepoMcpContent open directory={repoDirectory} /> : null
|
||||
if (tool === 'walkthrough') return sessionId ? <ChangesWalkthroughView /> : null
|
||||
if (tool === 'activity') return <ActivityPanelBody />
|
||||
if (tool === 'terminal') {
|
||||
return terminalWorkspaceTarget
|
||||
? <TerminalWorkspace target={terminalWorkspaceTarget} directory={terminalDirectory ?? directory} isOpen />
|
||||
: null
|
||||
}
|
||||
if (repoId === undefined) return null
|
||||
switch (tool) {
|
||||
case 'sourceControl':
|
||||
return <SourceControlContent repoId={repoId} isOpen currentBranch={currentBranch} compact />
|
||||
case 'terminal':
|
||||
return <TerminalWorkspace repoId={repoId} directory={terminalDirectory ?? directory} isOpen />
|
||||
case 'actions':
|
||||
return <RepoActionsContent repoId={repoId} directory={directory} open />
|
||||
case 'skills':
|
||||
|
||||
@@ -164,6 +164,19 @@ describe('buildToolItems', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('returns the linked server session tools without Manager-only entries', () => {
|
||||
expect(buildToolItems('/servers/srv_kitchen/sessions/ses_1').map((item) => item.key)).toEqual([
|
||||
'activity',
|
||||
'terminal',
|
||||
])
|
||||
expect(buildMoreItems('/servers/srv_kitchen/sessions/ses_1').map((item) => item.key)).toEqual([
|
||||
'home',
|
||||
'terminal',
|
||||
'settings',
|
||||
'logout',
|
||||
])
|
||||
})
|
||||
|
||||
it('returns the home route tools', () => {
|
||||
expect(buildToolItems('/').map((item) => item.key)).toEqual(['activity', 'all-schedules', 'files'])
|
||||
})
|
||||
|
||||
@@ -58,7 +58,6 @@ const NON_TOOL_ITEM_KEYS = new Set(['home', 'settings', 'logout'])
|
||||
const MANAGER_ONLY_ITEM_KEYS: ReadonlySet<string> = new Set([
|
||||
'files',
|
||||
'source-control',
|
||||
'terminal',
|
||||
'preview',
|
||||
'walkthrough',
|
||||
'actions',
|
||||
@@ -136,6 +135,17 @@ function buildRouteNavModel(pathname: string): NavModel {
|
||||
}
|
||||
}
|
||||
|
||||
const serverSessionMatch = /^\/servers\/[^/]+\/sessions\/[^/]+$/.exec(pathname)
|
||||
if (serverSessionMatch) {
|
||||
return {
|
||||
primary: [],
|
||||
items: [
|
||||
{ key: 'terminal', label: 'Terminal', icon: SquareTerminal, dialog: 'terminal' },
|
||||
...baseItems,
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
if (isAssistantPath(pathname)) {
|
||||
const items: MoreDrawerItem[] = [
|
||||
{ key: 'files', label: 'Files', icon: Folder, dialog: 'files' },
|
||||
|
||||
Reference in new issue
Block a user