mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
feat(servers): bring linked-server sessions to parity with local
Add a read-only Source Control panel for linked servers backed by the OpenCode VCS API, broadcast remote events to every client, include recent linked-server sessions in Activity with per-server sidebar indicators, and enable the session picker, tool shortcuts, mobile activity, remote Skills panel and remote permission prompt titles.
This commit is contained in:
1 parent
9ec2ed5903
commit
7874afdab9
38 files changed
+1506
-279
No files matched your search
@@ -0,0 +1,114 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { RemoteSourceControlContent } from './RemoteSourceControlContent'
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
getVcsInfo: vi.fn(),
|
||||
listVcsStatus: vi.fn(),
|
||||
getVcsDiff: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/opencode', () => ({
|
||||
getVcsInfo: mocks.getVcsInfo,
|
||||
listVcsStatus: mocks.listVcsStatus,
|
||||
getVcsDiff: mocks.getVcsDiff,
|
||||
}))
|
||||
|
||||
const WORKING_FILES = [
|
||||
{ file: 'src/app.ts', additions: 3, deletions: 1, status: 'modified' as const },
|
||||
{ file: 'src/new.ts', additions: 5, deletions: 0, status: 'added' as const },
|
||||
]
|
||||
|
||||
const WORKING_DIFF = [
|
||||
{
|
||||
file: 'src/app.ts',
|
||||
patch: '@@ -1,2 +1,2 @@\n-old line\n+new line',
|
||||
additions: 1,
|
||||
deletions: 1,
|
||||
status: 'modified' as const,
|
||||
},
|
||||
]
|
||||
|
||||
const BRANCH_DIFF = [
|
||||
{
|
||||
file: 'src/branch-only.ts',
|
||||
patch: '@@ -1,1 +1,2 @@\n branch file\n+extra branch line',
|
||||
additions: 1,
|
||||
deletions: 0,
|
||||
status: 'added' as const,
|
||||
},
|
||||
]
|
||||
|
||||
function renderContent() {
|
||||
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
||||
return render(
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<RemoteSourceControlContent serverId="srv_kitchen" directory="/home/me/app" />
|
||||
</QueryClientProvider>,
|
||||
)
|
||||
}
|
||||
|
||||
describe('RemoteSourceControlContent', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.getVcsInfo.mockResolvedValue({
|
||||
provider: 'github',
|
||||
branch: { current: 'feature/remote', default: 'main' },
|
||||
})
|
||||
mocks.listVcsStatus.mockResolvedValue(WORKING_FILES)
|
||||
mocks.getVcsDiff.mockImplementation((_directory: string, mode: string) =>
|
||||
Promise.resolve(mode === 'branch' ? BRANCH_DIFF : WORKING_DIFF),
|
||||
)
|
||||
})
|
||||
|
||||
it('lists the working-copy changes with the current branch', async () => {
|
||||
renderContent()
|
||||
|
||||
expect(await screen.findByText('app.ts')).toBeInTheDocument()
|
||||
expect(screen.getByText('new.ts')).toBeInTheDocument()
|
||||
expect(screen.getByText('feature/remote')).toBeInTheDocument()
|
||||
expect(mocks.listVcsStatus).toHaveBeenCalledWith('/home/me/app', 'srv_kitchen')
|
||||
})
|
||||
|
||||
it('switches to branch changes and lists the diff files', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderContent()
|
||||
|
||||
await user.click(await screen.findByRole('button', { name: 'Branch changes' }))
|
||||
|
||||
expect(await screen.findByText('branch-only.ts')).toBeInTheDocument()
|
||||
expect(screen.queryByText('new.ts')).not.toBeInTheDocument()
|
||||
expect(mocks.getVcsDiff).toHaveBeenCalledWith('/home/me/app', 'branch', 'srv_kitchen')
|
||||
})
|
||||
|
||||
it('shows the patch after selecting a changed file', async () => {
|
||||
const user = userEvent.setup()
|
||||
renderContent()
|
||||
|
||||
await user.click(await screen.findByText('app.ts'))
|
||||
|
||||
expect(await screen.findByText('new line')).toBeInTheDocument()
|
||||
expect(mocks.getVcsDiff).toHaveBeenCalledWith('/home/me/app', 'working', 'srv_kitchen')
|
||||
|
||||
await user.click(screen.getByRole('button', { name: 'Back to changed files' }))
|
||||
|
||||
expect(await screen.findByText('new.ts')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('shows an empty state when the working copy has no changes', async () => {
|
||||
mocks.listVcsStatus.mockResolvedValue([])
|
||||
renderContent()
|
||||
|
||||
expect(await screen.findByText('No working changes')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('reports a failed status load', async () => {
|
||||
mocks.listVcsStatus.mockRejectedValue(new Error('vcs unavailable'))
|
||||
renderContent()
|
||||
|
||||
expect(await screen.findByText('Failed to load changes')).toBeInTheDocument()
|
||||
expect(screen.getByText('vcs unavailable')).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user