mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
Merge remote-tracking branch 'origin/feat/linked-opencode-servers' into feat/remote-server-automation
# Conflicts: # backend/src/services/remote-server-events.ts # frontend/src/components/navigation/MoreDrawer.test.tsx # frontend/src/components/navigation/moreDrawerItems.test.ts # frontend/src/lib/opencode-event-stream/openCodeEventStream.ts # frontend/src/pages/SessionDetail.tsx # frontend/src/pages/__tests__/SessionDetail.remote.test.tsx
This commit is contained in:
commit
780d31087b
92 files changed
+3828
-817
No files matched your search
@@ -2,6 +2,7 @@ import { useState } from 'react'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { useDesktop } from '@/hooks/useDesktop'
|
||||
import { useSidebarCollapsed } from '@/hooks/useSidebarCollapsed'
|
||||
import { useSidebarWidth } from '@/hooks/useSidebarWidth'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useUrlParams } from '@/hooks/useUrlParams'
|
||||
import { useOpenNavItem } from '@/hooks/useOpenNavItem'
|
||||
@@ -24,6 +25,7 @@ export function DesktopSidebar() {
|
||||
const { updateParams } = useUrlParams()
|
||||
const openNavItem = useOpenNavItem()
|
||||
const [collapsed, toggle] = useSidebarCollapsed()
|
||||
const [sidebarWidth, setSidebarWidth] = useSidebarWidth()
|
||||
const [repoSwitcherOpen, setRepoSwitcherOpen] = useState(false)
|
||||
const { isAuthenticated, isLoading, logout } = useAuth()
|
||||
|
||||
@@ -63,7 +65,13 @@ export function DesktopSidebar() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Sidebar collapsed={collapsed} onToggle={toggle} className='mt-2'>
|
||||
<Sidebar
|
||||
collapsed={collapsed}
|
||||
onToggle={toggle}
|
||||
width={sidebarWidth}
|
||||
onWidthChange={setSidebarWidth}
|
||||
className='mt-2'
|
||||
>
|
||||
{primary.length > 0 && (
|
||||
<SidebarSection collapsed={collapsed}>
|
||||
{primary.map((item: NavPrimaryCta) => (
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useAuth } from '@/hooks/useAuth'
|
||||
import { useServerHealth } from '@/hooks/useServerHealth'
|
||||
import { getRepo } from '@/api/repos'
|
||||
import type { ActiveWorkItem } from '@/lib/activeWork'
|
||||
import type { UnreadScheduleRun } from '@/api/schedules'
|
||||
|
||||
vi.mock('@/hooks/useAuth')
|
||||
vi.mock('@/hooks/useServerHealth')
|
||||
@@ -32,6 +33,16 @@ vi.mock('@/hooks/useActiveWork', () => ({
|
||||
useRepoActivityState: () => null,
|
||||
}))
|
||||
|
||||
const scheduleMocks = vi.hoisted(() => ({
|
||||
useUnreadScheduleRuns: vi.fn(),
|
||||
useMarkAllScheduleRunsViewed: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSchedules', () => ({
|
||||
useUnreadScheduleRuns: scheduleMocks.useUnreadScheduleRuns,
|
||||
useMarkAllScheduleRunsViewed: scheduleMocks.useMarkAllScheduleRunsViewed,
|
||||
}))
|
||||
|
||||
function createActiveWorkItem(): ActiveWorkItem {
|
||||
const now = Date.now()
|
||||
return {
|
||||
@@ -61,6 +72,33 @@ function createActiveWorkItem(): ActiveWorkItem {
|
||||
}
|
||||
}
|
||||
|
||||
function createUnreadScheduleRun(): UnreadScheduleRun {
|
||||
const now = Date.now()
|
||||
return {
|
||||
id: 1,
|
||||
jobId: 1,
|
||||
repoId: 1,
|
||||
triggerSource: 'schedule',
|
||||
status: 'completed',
|
||||
startedAt: now - 60000,
|
||||
finishedAt: now - 30000,
|
||||
viewedAt: null,
|
||||
createdAt: now - 60000,
|
||||
sessionId: null,
|
||||
sessionTitle: null,
|
||||
logText: null,
|
||||
responseText: null,
|
||||
errorText: null,
|
||||
runBranch: null,
|
||||
commitHash: null,
|
||||
worktreePath: null,
|
||||
jobName: 'Nightly report',
|
||||
repoName: 'repo1',
|
||||
repoPath: '/path/to/repo1',
|
||||
preview: 'Report ready',
|
||||
}
|
||||
}
|
||||
|
||||
function setActivityGroups(groups: {
|
||||
needsInput?: ActiveWorkItem[]
|
||||
running?: ActiveWorkItem[]
|
||||
@@ -158,6 +196,8 @@ describe('MoreDrawer', () => {
|
||||
})
|
||||
activityMocks.useActivityWindowMinutes.mockReturnValue(30)
|
||||
setActivityGroups({})
|
||||
scheduleMocks.useUnreadScheduleRuns.mockReturnValue({ data: { runs: [], total: 0, failed: 0 } })
|
||||
scheduleMocks.useMarkAllScheduleRunsViewed.mockReturnValue({ mutate: vi.fn(), isPending: false })
|
||||
})
|
||||
|
||||
it('renders Settings and Logout menu items', () => {
|
||||
@@ -361,7 +401,7 @@ describe('MoreDrawer', () => {
|
||||
expect(handleClose).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('offers the terminal plus account items on a linked-server route', () => {
|
||||
it('offers only the remote-capable project items on a linked-server route', () => {
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
setActivityGroups({ recent: [createActiveWorkItem()] })
|
||||
@@ -371,15 +411,35 @@ describe('MoreDrawer', () => {
|
||||
})
|
||||
|
||||
expect(screen.getByText('Home')).toBeInTheDocument()
|
||||
expect(screen.getByText('MCP')).toBeInTheDocument()
|
||||
expect(screen.getByText('Skills')).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('MCP')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Preview')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Schedules')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Reset Permissions')).not.toBeInTheDocument()
|
||||
expect(screen.queryByText('Repos')).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('button', { name: 'Assistant' })).not.toBeInTheDocument()
|
||||
expect(screen.queryByRole('heading', { name: 'Activity' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows unread reports and marks them all read', () => {
|
||||
const markAllReportsViewed = vi.fn()
|
||||
mockAuth()
|
||||
mockServerHealth()
|
||||
scheduleMocks.useUnreadScheduleRuns.mockReturnValue({
|
||||
data: { runs: [createUnreadScheduleRun()], total: 1, failed: 0 },
|
||||
})
|
||||
scheduleMocks.useMarkAllScheduleRunsViewed.mockReturnValue({ mutate: markAllReportsViewed, isPending: false })
|
||||
renderMoreDrawer({ initialEntry: '/repos/1/sessions/session-1', routePath: '/repos/:id/sessions/:sessionId' })
|
||||
|
||||
expect(screen.getByText('Nightly report')).toBeInTheDocument()
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Mark all read' }))
|
||||
|
||||
expect(markAllReportsViewed).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
@@ -9,6 +9,8 @@ import { getRepo } from '@/api/repos'
|
||||
import { useRefreshOnOpen } from '@/hooks/useRefreshOnOpen'
|
||||
import { SideDrawer, SideDrawerContent } from '@/components/ui/side-drawer'
|
||||
import { CompactActivityList } from '@/components/activity/CompactActivityList'
|
||||
import { ScheduleReportsList } from '@/components/notifications/ScheduleReportsBell'
|
||||
import { useMarkAllScheduleRunsViewed, useUnreadScheduleRuns } from '@/hooks/useSchedules'
|
||||
import { buildMoreItems, buildNavModel, isManagerOnlyNavItem, isSessionDetailPath, type MoreDrawerItem } from './moreDrawerItems'
|
||||
import { useSwipeBack } from '@/hooks/useMobile'
|
||||
import { cn, getRepoDisplayName } from '@/lib/utils'
|
||||
@@ -79,6 +81,9 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
const isAssistantSession = isSessionDetail && searchParams.get('assistant') === '1'
|
||||
const isRemoteRoute = !isLocalOpenCodeServer(useRouteOpenCodeServerId())
|
||||
const { open: openMobileSheet } = useMobileTabBar()
|
||||
const { data: unreadReports } = useUnreadScheduleRuns()
|
||||
const markAllReportsViewed = useMarkAllScheduleRunsViewed()
|
||||
const total = unreadReports?.total ?? 0
|
||||
|
||||
useEffect(() => {
|
||||
if (isOpen && swipeRef.current) {
|
||||
@@ -188,6 +193,18 @@ export function MoreDrawer({ isOpen, onClose }: MoreDrawerProps) {
|
||||
)}
|
||||
</div>
|
||||
<SideDrawerContent className="flex flex-col gap-4 pb-3">
|
||||
{total > 0 && (
|
||||
<div className="overflow-hidden rounded-lg border border-border">
|
||||
<ScheduleReportsList
|
||||
runs={unreadReports?.runs ?? []}
|
||||
total={total}
|
||||
rowClassName="py-3"
|
||||
onMarkAllRead={() => markAllReportsViewed.mutate()}
|
||||
markAllPending={markAllReportsViewed.isPending}
|
||||
maxHeightClass=""
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{isOpen && !isRemoteRoute && (
|
||||
<CompactActivityList onNavigate={(path) => navigate(path)} />
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { fireEvent, render, screen } from '@testing-library/react'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { SessionMoreButton } from './SessionMoreButton'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
open: vi.fn(),
|
||||
useUnreadScheduleRuns: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useMobileTabBar', () => ({
|
||||
useMobileTabBar: () => ({ open: mocks.open, openSheet: null, close: vi.fn() }),
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useSchedules', () => ({
|
||||
useUnreadScheduleRuns: mocks.useUnreadScheduleRuns,
|
||||
}))
|
||||
|
||||
describe('SessionMoreButton', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('shows the unread report count and opens the drawer', () => {
|
||||
mocks.useUnreadScheduleRuns.mockReturnValue({ data: { runs: [], total: 4, failed: 0 } })
|
||||
render(<SessionMoreButton />)
|
||||
|
||||
const button = screen.getByRole('button', { name: 'More, 4 unread reports' })
|
||||
expect(screen.getByText('4')).toBeInTheDocument()
|
||||
|
||||
fireEvent.click(button)
|
||||
|
||||
expect(mocks.open).toHaveBeenCalledWith('more')
|
||||
})
|
||||
|
||||
it('shows no count when there are no unread reports', () => {
|
||||
mocks.useUnreadScheduleRuns.mockReturnValue({ data: { runs: [], total: 0, failed: 0 } })
|
||||
render(<SessionMoreButton />)
|
||||
|
||||
expect(screen.getByRole('button', { name: 'More' })).toBeInTheDocument()
|
||||
expect(screen.queryByText('0')).not.toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -1,19 +1,25 @@
|
||||
import { MoreVertical } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { ScheduleReportsBadge } from '@/components/notifications/ScheduleReportsBadge'
|
||||
import { useUnreadScheduleRuns } from '@/hooks/useSchedules'
|
||||
import { useMobileTabBar } from '@/hooks/useMobileTabBar'
|
||||
|
||||
export function SessionMoreButton() {
|
||||
const { open } = useMobileTabBar()
|
||||
const { data } = useUnreadScheduleRuns()
|
||||
const total = data?.total ?? 0
|
||||
const failed = data?.failed ?? 0
|
||||
|
||||
return (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => open('more')}
|
||||
className="md:hidden h-10 w-10 p-0 text-foreground border-border hover:bg-accent"
|
||||
aria-label="More"
|
||||
className="relative md:hidden h-10 w-10 p-0 text-foreground border-border hover:bg-accent"
|
||||
aria-label={total > 0 ? `More, ${total} unread reports` : 'More'}
|
||||
>
|
||||
<MoreVertical className="w-5 h-5" />
|
||||
<ScheduleReportsBadge total={total} failed={failed} />
|
||||
</Button>
|
||||
)
|
||||
}
|
||||
@@ -149,6 +149,23 @@ function HomeHarness() {
|
||||
)
|
||||
}
|
||||
|
||||
function RemoteHarness() {
|
||||
const panel = useToolPanel(true)
|
||||
return (
|
||||
<>
|
||||
<ToolSidePanel
|
||||
panel={panel}
|
||||
repoId={0}
|
||||
sessionId="ses_remote"
|
||||
directory="/home/me/app"
|
||||
repoDirectory="/home/me/app"
|
||||
filesBasePath={undefined}
|
||||
/>
|
||||
<LocationProbe />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
activityMocks.useActiveWorkCounts.mockReturnValue({ needsInput: 0, running: 0 })
|
||||
@@ -330,6 +347,25 @@ describe('ToolSidePanel', () => {
|
||||
expect(buttons[0]).toHaveAccessibleName('Activity')
|
||||
})
|
||||
|
||||
it('shows only the remote-capable tools on a linked-server route', async () => {
|
||||
const user = userEvent.setup()
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/servers/srv_kitchen/sessions/ses_remote']}>
|
||||
<RemoteHarness />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
|
||||
const rail = screen.getByRole('navigation', { name: 'Tools' })
|
||||
expect(
|
||||
within(rail)
|
||||
.getAllByRole('button')
|
||||
.map((button) => button.getAttribute('aria-label') ?? button.textContent?.trim()),
|
||||
).toEqual(['Activity', 'MCP', 'Skills', 'Terminal'])
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'MCP' }))
|
||||
expect(await screen.findByText('mcp-tool')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('opens the Activity panel with rows and the window label when clicked', async () => {
|
||||
const user = userEvent.setup()
|
||||
setActivityGroups([createActivityItem('other', 'Other Session', 2, 'Beta')])
|
||||
|
||||
@@ -32,11 +32,14 @@ import { formatActivityWindow } from '@/lib/activeWork'
|
||||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip'
|
||||
import { restoreOverlayFocus } from '@/lib/overlayFocus'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { isLocalOpenCodeServer, useRouteOpenCodeServerId } from '@/contexts/OpenCodeServerContext'
|
||||
|
||||
const PANEL_WIDTH_CLASSES: Partial<Record<PanelTool, string>> = {
|
||||
activity: 'w-80',
|
||||
}
|
||||
|
||||
const REMOTE_TOOL_KEYS: ReadonlySet<string> = new Set(['activity', 'mcp', 'skills', 'terminal'])
|
||||
|
||||
function ActivityWindowLabel() {
|
||||
const minutes = useActivityWindowMinutes()
|
||||
return (
|
||||
@@ -86,7 +89,6 @@ interface ToolSidePanelProps {
|
||||
directory?: string
|
||||
terminalDirectory?: string
|
||||
terminalTarget?: TerminalTarget
|
||||
allowedPanelTools?: readonly PanelTool[]
|
||||
repoDirectory?: string
|
||||
currentBranch?: string
|
||||
selectedFilePath?: string
|
||||
@@ -150,7 +152,6 @@ export function ToolSidePanel({
|
||||
directory,
|
||||
terminalDirectory,
|
||||
terminalTarget,
|
||||
allowedPanelTools,
|
||||
repoDirectory,
|
||||
currentBranch = 'main',
|
||||
selectedFilePath,
|
||||
@@ -162,6 +163,7 @@ export function ToolSidePanel({
|
||||
const { activeTool, toggleTool, closePanel } = panel
|
||||
const location = useLocation()
|
||||
const openNavItem = useOpenNavItem()
|
||||
const isRemoteRoute = !isLocalOpenCodeServer(useRouteOpenCodeServerId())
|
||||
const railRef = useRef<HTMLElement>(null)
|
||||
const previousActiveToolRef = useRef(activeTool)
|
||||
|
||||
@@ -180,13 +182,10 @@ export function ToolSidePanel({
|
||||
const terminalWorkspaceTarget: TerminalTarget | undefined =
|
||||
terminalTarget ?? (repoId === undefined ? undefined : { kind: 'repo', repoId })
|
||||
for (const item of buildToolItems(location.pathname)) {
|
||||
if (isRemoteRoute && !REMOTE_TOOL_KEYS.has(item.key)) continue
|
||||
const tool = toolKeyOf(item)
|
||||
if (isPanelTool(tool)) {
|
||||
if (allowedPanelTools && !allowedPanelTools.includes(tool)) continue
|
||||
panelTools.push({ item, tool })
|
||||
} else {
|
||||
actionItems.push(item)
|
||||
}
|
||||
if (isPanelTool(tool)) panelTools.push({ item, tool })
|
||||
else actionItems.push(item)
|
||||
}
|
||||
const activeLabel = panelTools.find(({ tool }) => tool === activeTool)?.item.label
|
||||
|
||||
|
||||
@@ -62,6 +62,11 @@ describe('buildMoreItems', () => {
|
||||
expect(items[12].key).toBe('logout')
|
||||
})
|
||||
|
||||
it('returns only the server tools a linked server can serve for /servers/:id/sessions/:sid', () => {
|
||||
const items = buildMoreItems('/servers/srv_kitchen/sessions/abc')
|
||||
expect(items.map((item) => item.key)).toEqual(['home', 'mcp', 'skills', 'terminal', 'settings', 'logout'])
|
||||
})
|
||||
|
||||
it('omits the Actions item for an Assistant session', () => {
|
||||
const items = buildMoreItems('/repos/0/sessions/abc')
|
||||
expect(items).toHaveLength(12)
|
||||
@@ -164,17 +169,13 @@ 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([
|
||||
it('returns the linked-server session tools for the tool rail', () => {
|
||||
expect(buildToolItems('/servers/srv_kitchen/sessions/abc').map((item) => item.key)).toEqual([
|
||||
'activity',
|
||||
'mcp',
|
||||
'skills',
|
||||
'terminal',
|
||||
])
|
||||
expect(buildMoreItems('/servers/srv_kitchen/sessions/ses_1').map((item) => item.key)).toEqual([
|
||||
'home',
|
||||
'terminal',
|
||||
'settings',
|
||||
'logout',
|
||||
])
|
||||
})
|
||||
|
||||
it('returns the home route tools', () => {
|
||||
|
||||
@@ -48,6 +48,7 @@ function getBaseItems(): MoreDrawerItem[] {
|
||||
}
|
||||
|
||||
const SESSION_DETAIL_PATH = /^\/repos\/(\d+)\/sessions\/[^/]+$/
|
||||
const SERVER_SESSION_DETAIL_PATH = /^\/servers\/[^/]+\/sessions\/[^/]+$/
|
||||
|
||||
export function isSessionDetailPath(pathname: string): boolean {
|
||||
return SESSION_DETAIL_PATH.test(pathname)
|
||||
@@ -61,8 +62,6 @@ const MANAGER_ONLY_ITEM_KEYS: ReadonlySet<string> = new Set([
|
||||
'preview',
|
||||
'walkthrough',
|
||||
'actions',
|
||||
'mcp',
|
||||
'skills',
|
||||
'reset-permissions',
|
||||
'schedules',
|
||||
'all-schedules',
|
||||
@@ -87,6 +86,18 @@ export function toolKeyOf(item: MoreDrawerItem): string | null {
|
||||
function buildRouteNavModel(pathname: string): NavModel {
|
||||
const baseItems = getBaseItems()
|
||||
|
||||
if (SERVER_SESSION_DETAIL_PATH.test(pathname)) {
|
||||
return {
|
||||
primary: [getAssistantNavItem()],
|
||||
items: [
|
||||
{ key: 'mcp', label: 'MCP', icon: Plug, dialog: 'mcp' },
|
||||
{ key: 'skills', label: 'Skills', icon: Sparkles, dialog: 'skills' },
|
||||
{ key: 'terminal', label: 'Terminal', icon: SquareTerminal, dialog: 'terminal' },
|
||||
...baseItems,
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
const repoDetailMatch = /^\/repos\/(\d+)$/.exec(pathname)
|
||||
if (repoDetailMatch) {
|
||||
const id = repoDetailMatch[1]
|
||||
@@ -135,17 +146,6 @@ 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