mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
* fix: enable swipe-back suspension on more drawer and remove unused variable * refactor(frontend): improve dialog component and settings navigation * fix: disable route swipe suspension in MoreDrawer to prevent unintended navigation * fix(frontend): enable swipe-back suspension on more drawer route * refactor(frontend): improve mobile navigation drawer and tab bar * feat: add schedules service and workspace hook with navigation updates * chore: add workspace hook, schedules library, and tests * fix: prevent MoreDrawer sentinel from undoing navigation * feat: per-agent model selection and UI refinements (#217) * feat: per-agent model selection and UI refinements - Add agentModels store with setAgentModel/getAgentModel - PromptInput uses session model priority and stores agent model on change - useContextUsage derives model from assistant message instead of global - Migrate sub-agent/subtask badges from purple to blue with refined styling - Fix MoreDrawer sentinel to skip history-back on navigation * refactor: improve per-agent model selection and task tool call status indicators * feat: add repo management skill and internal repos API * fix: improve assistant session launcher and UI components * fix: update atomic-json test assertions * refactor: split Assistant Mode instructions between AGENTS.md and assistant.md * loop: todo-header-mobile completed after 3 iterations (#218) * loop: stt-perf-1 completed after 5 iterations * fix: load audio worklet per recording context * fix: canonicalize assistant navigation routes * fix: adjust scroll-up threshold for header visibility * fix: update settings and skills handling with assistant redirect * refactor: simplify context usage indicator and extract token sum helper * feat: add currently selected model row to popover and fix responsive truncate
275 lines
8.1 KiB
TypeScript
275 lines
8.1 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { render, screen, waitFor } from '@testing-library/react'
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
import { MemoryRouter, Route, Routes } from 'react-router-dom'
|
|
import { SessionDetail } from '../SessionDetail'
|
|
|
|
const mocks = vi.hoisted(() => ({
|
|
useSession: vi.fn(),
|
|
useMessages: vi.fn(),
|
|
useSSE: vi.fn(),
|
|
useRepoActivity: vi.fn(),
|
|
usePermissions: vi.fn(),
|
|
useQuestions: vi.fn(),
|
|
useSSEHealth: vi.fn(),
|
|
useConfig: vi.fn(),
|
|
useOpenCodeClient: vi.fn(),
|
|
useSettings: vi.fn(),
|
|
useSettingsDialog: vi.fn(),
|
|
useMobile: vi.fn(),
|
|
useVisualViewport: vi.fn(),
|
|
useKeyboardShortcuts: vi.fn(),
|
|
useAutoScroll: vi.fn(),
|
|
useDialogParam: vi.fn(),
|
|
useSidebarAction: vi.fn(),
|
|
RepoSkillsDialog: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useOpenCode', () => ({
|
|
useSession: mocks.useSession,
|
|
useAbortSession: vi.fn(() => ({ mutate: vi.fn() })),
|
|
useUpdateSession: vi.fn(() => ({ mutate: vi.fn() })),
|
|
useCreateSession: vi.fn(() => ({ mutateAsync: vi.fn() })),
|
|
useMessages: mocks.useMessages,
|
|
useConfig: mocks.useConfig,
|
|
}))
|
|
|
|
vi.mock('@/hooks/useModelSelection', () => ({
|
|
useModelSelection: vi.fn(() => ({ model: null, modelString: null })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useOpenCodeClient', () => ({
|
|
useOpenCodeClient: mocks.useOpenCodeClient,
|
|
}))
|
|
|
|
vi.mock('@/hooks/useTTS', () => ({
|
|
useTTS: vi.fn(() => ({ isEnabled: false })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useSettings', () => ({
|
|
useSettings: vi.fn(() => ({
|
|
preferences: { expandToolCalls: false },
|
|
updateSettings: vi.fn(),
|
|
})),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useSettingsDialog', () => ({
|
|
useSettingsDialog: vi.fn(() => ({ open: vi.fn() })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useMobile', () => ({
|
|
useMobile: vi.fn(() => false),
|
|
useSwipeBack: vi.fn(() => ({ ref: vi.fn() })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useVisualViewport', () => ({
|
|
useVisualViewport: vi.fn(() => ({ keyboardHeight: 0 })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useKeyboardShortcuts', () => ({
|
|
useKeyboardShortcuts: vi.fn(() => ({ leaderActive: false })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useAutoScroll', () => ({
|
|
useAutoScroll: vi.fn(() => ({ scrollToBottom: vi.fn() })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useDialogParam', () => ({
|
|
useDialogParam: vi.fn(() => [false, vi.fn()]),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useSidebarAction', () => ({
|
|
useSidebarAction: vi.fn(() => {}),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useAutoPlayLastResponse', () => ({
|
|
getAssistantText: vi.fn(() => ''),
|
|
getLatestPlayableAssistantMessage: vi.fn(() => null),
|
|
useAutoPlayLastResponse: vi.fn(() => {}),
|
|
}))
|
|
|
|
vi.mock('@/stores/uiStateStore', () => ({
|
|
useUIState: vi.fn(() => vi.fn()),
|
|
}))
|
|
|
|
vi.mock('@/stores/sessionStatusStore', () => ({
|
|
useSessionStatus: vi.fn(() => ({ setStatus: vi.fn() })),
|
|
useSessionStatusForSession: vi.fn(() => ({ type: 'idle' })),
|
|
}))
|
|
|
|
vi.mock('@/hooks/useSSE', () => ({
|
|
useSSE: mocks.useSSE,
|
|
}))
|
|
|
|
vi.mock('@/hooks/useRepoActivity', () => ({
|
|
useRepoActivity: mocks.useRepoActivity,
|
|
}))
|
|
|
|
vi.mock('@/contexts/EventContext', async (importOriginal) => {
|
|
const actual = await importOriginal()
|
|
return {
|
|
...(actual as object),
|
|
usePermissions: mocks.usePermissions,
|
|
useQuestions: mocks.useQuestions,
|
|
useSSEHealth: mocks.useSSEHealth,
|
|
}
|
|
})
|
|
|
|
vi.mock('@/api/repos', () => ({
|
|
getRepo: vi.fn(() => Promise.resolve(null)),
|
|
initializeAssistantMode: vi.fn(() => Promise.resolve({ directory: '/abs/assistant', warnings: [] })),
|
|
}))
|
|
|
|
vi.mock('@/components/model/ModelSelectDialog', () => ({
|
|
ModelSelectDialog: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/session/SessionList', () => ({
|
|
SessionList: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/file-browser/FileBrowserSheet', () => ({
|
|
FileBrowserSheet: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/repo/RepoMcpDialog', () => ({
|
|
RepoMcpDialog: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/repo/ResetPermissionsDialog', () => ({
|
|
ResetPermissionsDialog: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/repo/RepoLspDialog', () => ({
|
|
RepoLspDialog: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/repo/RepoSkillsDialog', () => ({
|
|
RepoSkillsDialog: mocks.RepoSkillsDialog,
|
|
}))
|
|
|
|
vi.mock('@/components/source-control', () => ({
|
|
SourceControlPanel: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/session/QuestionPrompt', () => ({
|
|
QuestionPrompt: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/session/MinimizedQuestionIndicator', () => ({
|
|
MinimizedQuestionIndicator: vi.fn(() => null),
|
|
}))
|
|
|
|
vi.mock('@/components/notifications/PendingActionsGroup', () => ({
|
|
PendingActionsGroup: vi.fn(() => null),
|
|
}))
|
|
|
|
describe('SessionDetail assistant loading at repoId=0', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
|
|
mocks.useSession.mockReturnValue({ data: undefined, isLoading: false })
|
|
mocks.useMessages.mockReturnValue({ data: [], isLoading: false })
|
|
mocks.useSSE.mockReturnValue({ isConnected: true, isReconnecting: false })
|
|
mocks.useRepoActivity.mockReturnValue(undefined)
|
|
mocks.usePermissions.mockReturnValue({
|
|
pendingCount: 0,
|
|
hasPermissionsForSession: vi.fn(() => false),
|
|
syncForSession: vi.fn(),
|
|
})
|
|
mocks.useQuestions.mockReturnValue({
|
|
current: null,
|
|
pendingCount: 0,
|
|
hasQuestionsForSession: vi.fn(() => false),
|
|
reply: vi.fn(),
|
|
reject: vi.fn(),
|
|
syncForSession: vi.fn(),
|
|
})
|
|
mocks.useSSEHealth.mockReturnValue({ isHealthy: true })
|
|
mocks.useConfig.mockReturnValue({ data: undefined, isLoading: false })
|
|
mocks.useOpenCodeClient.mockReturnValue({})
|
|
mocks.useSettings.mockReturnValue({
|
|
preferences: { expandToolCalls: false },
|
|
updateSettings: vi.fn(),
|
|
})
|
|
mocks.useSettingsDialog.mockReturnValue({ open: vi.fn() })
|
|
mocks.useMobile.mockReturnValue(false)
|
|
mocks.useVisualViewport.mockReturnValue({ keyboardHeight: 0 })
|
|
mocks.useKeyboardShortcuts.mockReturnValue({ leaderActive: false })
|
|
mocks.useAutoScroll.mockReturnValue({ scrollToBottom: vi.fn() })
|
|
mocks.useDialogParam.mockReturnValue([false, vi.fn()])
|
|
mocks.useSidebarAction.mockReturnValue(undefined)
|
|
})
|
|
|
|
const createQueryClient = () =>
|
|
new QueryClient({
|
|
defaultOptions: {
|
|
queries: { retry: false },
|
|
},
|
|
})
|
|
|
|
const renderAssistantSession = (sessionId: string) => {
|
|
return render(
|
|
<MemoryRouter initialEntries={[`/repos/0/sessions/${sessionId}?assistant=1`]}>
|
|
<QueryClientProvider client={createQueryClient()}>
|
|
<Routes>
|
|
<Route path="/repos/:id/sessions/:sessionId" element={<SessionDetail />} />
|
|
</Routes>
|
|
</QueryClientProvider>
|
|
</MemoryRouter>
|
|
)
|
|
}
|
|
|
|
it('does not show "Loading repository..." for assistant sessions at repoId=0', async () => {
|
|
renderAssistantSession('sess-asst-1')
|
|
|
|
await waitFor(() => {
|
|
expect(screen.queryByText('Loading repository...')).not.toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
it('renders "Assistant" as the workspace display name', async () => {
|
|
renderAssistantSession('sess-asst-1')
|
|
|
|
await waitFor(() => {
|
|
expect(screen.getByText('Assistant')).toBeInTheDocument()
|
|
})
|
|
})
|
|
|
|
it('passes directory from assistantMode to RepoSkillsDialog once loaded', async () => {
|
|
renderAssistantSession('sess-asst-1')
|
|
|
|
await waitFor(() => {
|
|
const lastCall = mocks.RepoSkillsDialog.mock.calls.at(-1)
|
|
expect(lastCall).toBeDefined()
|
|
expect(lastCall![0].directory).toBe('/abs/assistant')
|
|
})
|
|
})
|
|
|
|
it('does not pass empty string for directory when repoDirectory is undefined', async () => {
|
|
renderAssistantSession('sess-asst-1')
|
|
|
|
await waitFor(() => {
|
|
expect(mocks.RepoSkillsDialog).toHaveBeenCalled()
|
|
})
|
|
|
|
mocks.RepoSkillsDialog.mock.calls.forEach(([props]) => {
|
|
expect(props.directory).not.toBe('')
|
|
})
|
|
})
|
|
|
|
it('renders "Assistant" as workspaceDisplayName for non-assistant sessions without repo', async () => {
|
|
mocks.useSession.mockReturnValue({ data: undefined, isLoading: false })
|
|
|
|
return render(
|
|
<MemoryRouter initialEntries={['/repos/1/sessions/sess-1']}>
|
|
<QueryClientProvider client={createQueryClient()}>
|
|
<Routes>
|
|
<Route path="/repos/:id/sessions/:sessionId" element={<SessionDetail />} />
|
|
</Routes>
|
|
</QueryClientProvider>
|
|
</MemoryRouter>
|
|
)
|
|
})
|
|
})
|