mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
Critical and high: - repos: unlinking a local repo removes only the Manager reference and alias, never the repository files; confirm button reads "Unlink" - auth: rate-limit by the socket address; trust proxy headers only when AUTH_TRUSTED_PROXY_HEADERS is set (documented and forwarded in compose) - composer: per-session in-memory drafts (text, bash mode, attachments); Escape no longer clears the prompt - url params: compose same-tick updates so schedule dialogs stay closed after create/delete; delete dialog names the job Medium: - tool rows show failures (non-zero shell exit, failed exploration members) - voice conversation shows the specific error and a starting state - settings: Escape in dropdowns and the shortcut recorder no longer closes the dialog; mobile deep links open the requested section; one content tree per platform - closing pushed sheets, settings, tool panels and schedule dialogs goes back in history - login returns to the requested page; signed-out pages make no authenticated requests - action terminals keep their output (Manager-side output capture and replay) - unpushed-commit detection, commit message kept on failure - binary files with unknown extensions are detected and not editable - tool panel resizes when docked and floats as a dismissible sheet when the page is too narrow - Docker image runs tini as PID 1 Low: not-found states, add-repo and branch validation errors (4xx), search-aware empty states, mobile repo sort/filter/select cues, sidebar resize affordance and collapse shortcut, mobile unread badge, preview port filtering, terminal close handling, walkthrough empty state and helper session filtering, placeholder contrast, permission labels and focus, TTS task-list sanitizing, git identity email validation, quieter git logging, hermetic worktree tests, and accessible names for icon-only controls.
187 lines
7.3 KiB
TypeScript
187 lines
7.3 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { act, renderHook } from '@testing-library/react'
|
|
import { useSessionSearch } from './useSessionSearch'
|
|
|
|
const helperSessionIdsRef = vi.hoisted(() => ({ current: new Set<string>() }))
|
|
|
|
vi.mock('@/hooks/useChangeWalkthrough', () => ({
|
|
useWalkthroughHelperSessionIds: () => helperSessionIdsRef.current,
|
|
}))
|
|
|
|
const { sessionsData, lastArgsRef, flagsRef } = vi.hoisted(() => ({
|
|
sessionsData: [] as Array<{ id: string; title: string; location: { directory: string }; parentID?: string; time: { updated: number } }>,
|
|
lastArgsRef: { current: undefined as { directories: string[]; options?: { search?: string; limit?: number; keepPreviousResults?: boolean; allDirectories?: boolean; project?: { id: string; subpath: string } } } | undefined },
|
|
flagsRef: { current: { hasNextPage: false, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false, isError: false } },
|
|
}))
|
|
|
|
vi.mock('@/hooks/useOpenCode', async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import('@/hooks/useOpenCode')>()
|
|
return {
|
|
...actual,
|
|
useSessionsAcrossDirectories: (directories: string[], options?: { search?: string; limit?: number; keepPreviousResults?: boolean; allDirectories?: boolean; project?: { id: string; subpath: string } }) => {
|
|
lastArgsRef.current = { directories, options }
|
|
const search = options?.search?.toLowerCase() ?? ''
|
|
const data = search
|
|
? sessionsData.filter((session) => session.title.toLowerCase().includes(search))
|
|
: sessionsData
|
|
return {
|
|
data,
|
|
isLoading: false,
|
|
isError: flagsRef.current.isError,
|
|
isPlaceholderData: flagsRef.current.isPlaceholderData,
|
|
fetchNextPage: vi.fn(),
|
|
hasNextPage: flagsRef.current.hasNextPage,
|
|
isFetchingNextPage: flagsRef.current.isFetchingNextPage,
|
|
isFetchNextPageError: flagsRef.current.isFetchNextPageError,
|
|
}
|
|
},
|
|
}
|
|
})
|
|
|
|
describe('useSessionSearch', () => {
|
|
beforeEach(() => {
|
|
sessionsData.splice(0, sessionsData.length,
|
|
{ id: 'ses_alpha', title: 'alpha task', location: { directory: '/w/a' }, time: { updated: 2 } },
|
|
{ id: 'ses_beta', title: 'beta task', location: { directory: '/w/a' }, time: { updated: 1 } },
|
|
)
|
|
lastArgsRef.current = undefined
|
|
helperSessionIdsRef.current = new Set()
|
|
flagsRef.current = { hasNextPage: false, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false, isError: false }
|
|
})
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
it('filters sessions locally by title immediately', () => {
|
|
const { result } = renderHook(() => useSessionSearch(['/w/a']))
|
|
|
|
act(() => {
|
|
result.current.setQuery('alpha')
|
|
})
|
|
|
|
expect(result.current.filteredSessions.map((session) => session.title)).toEqual(['alpha task'])
|
|
expect(lastArgsRef.current?.options?.search).toBe('')
|
|
})
|
|
|
|
it('passes the debounced search to useSessionsAcrossDirectories with keepPreviousResults', () => {
|
|
vi.useFakeTimers()
|
|
const { result } = renderHook(() => useSessionSearch(['/w/a']))
|
|
|
|
act(() => {
|
|
result.current.setQuery('deploy')
|
|
})
|
|
act(() => {
|
|
vi.advanceTimersByTime(150)
|
|
})
|
|
|
|
expect(lastArgsRef.current?.options?.search).toBe('deploy')
|
|
expect(lastArgsRef.current?.options?.limit).toBe(25)
|
|
expect(lastArgsRef.current?.options?.keepPreviousResults).toBe(true)
|
|
})
|
|
|
|
it('reports a pending search before the debounce settles', () => {
|
|
vi.useFakeTimers()
|
|
const { result } = renderHook(() => useSessionSearch(['/w/a']))
|
|
|
|
act(() => {
|
|
result.current.setQuery('deploy')
|
|
})
|
|
|
|
expect(result.current.isSearchPending).toBe(true)
|
|
|
|
act(() => {
|
|
vi.advanceTimersByTime(150)
|
|
})
|
|
|
|
expect(result.current.isSearchPending).toBe(false)
|
|
})
|
|
|
|
it('passes allDirectories through to useSessionsAcrossDirectories', () => {
|
|
renderHook(() => useSessionSearch(['/w/a'], { allDirectories: true }))
|
|
|
|
expect(lastArgsRef.current?.options?.allDirectories).toBe(true)
|
|
})
|
|
|
|
it('forwards a project scope and skips directory filtering', () => {
|
|
sessionsData.splice(
|
|
0,
|
|
sessionsData.length,
|
|
{ id: 'ses_root', title: 'root', location: { directory: '/w/a' }, time: { updated: 2 } },
|
|
{ id: 'ses_wt', title: 'worktree', location: { directory: '/w/other' }, time: { updated: 1 } },
|
|
)
|
|
|
|
const { result } = renderHook(() =>
|
|
useSessionSearch(['/w/a'], { project: { id: 'proj_x', subpath: '' } }),
|
|
)
|
|
|
|
expect(lastArgsRef.current?.options?.project).toEqual({ id: 'proj_x', subpath: '' })
|
|
expect(result.current.filteredSessions.map((session) => session.id)).toEqual(['ses_root', 'ses_wt'])
|
|
})
|
|
|
|
it('hides walkthrough helper sessions from the session list', () => {
|
|
sessionsData.splice(
|
|
0,
|
|
sessionsData.length,
|
|
{ id: 'ses_user', title: 'user task', location: { directory: '/w/a' }, time: { updated: 2 } },
|
|
{ id: 'ses_walk', title: 'Walkthrough · user task', location: { directory: '/w/a' }, time: { updated: 1 } },
|
|
)
|
|
helperSessionIdsRef.current = new Set(['ses_walk'])
|
|
|
|
const { result } = renderHook(() => useSessionSearch(['/w/a']))
|
|
|
|
expect(result.current.filteredSessions.map((session) => session.id)).toEqual(['ses_user'])
|
|
})
|
|
|
|
it('passes isError through from useSessionsAcrossDirectories', () => {
|
|
flagsRef.current = { hasNextPage: false, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false, isError: true }
|
|
|
|
const { result } = renderHook(() => useSessionSearch(['/w/a']))
|
|
|
|
expect(result.current.isError).toBe(true)
|
|
})
|
|
|
|
it('blocks pagination while a search is pending', () => {
|
|
vi.useFakeTimers()
|
|
flagsRef.current = { hasNextPage: true, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false, isError: false }
|
|
const { result } = renderHook(() => useSessionSearch(['/w/a']))
|
|
|
|
expect(result.current.canFetchNextPage).toBe(true)
|
|
|
|
act(() => {
|
|
result.current.setQuery('deploy')
|
|
})
|
|
|
|
expect(result.current.isSearchPending).toBe(true)
|
|
expect(result.current.canFetchNextPage).toBe(false)
|
|
|
|
act(() => {
|
|
vi.advanceTimersByTime(150)
|
|
})
|
|
|
|
expect(result.current.isSearchPending).toBe(false)
|
|
expect(result.current.canFetchNextPage).toBe(true)
|
|
})
|
|
|
|
it('exposes canFetchNextPage only when paging is safe', () => {
|
|
const { result, rerender } = renderHook(() => useSessionSearch(['/w/a']))
|
|
expect(result.current.canFetchNextPage).toBe(false)
|
|
|
|
flagsRef.current = { hasNextPage: true, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false, isError: false }
|
|
rerender()
|
|
expect(result.current.canFetchNextPage).toBe(true)
|
|
|
|
flagsRef.current = { hasNextPage: true, isFetchingNextPage: true, isFetchNextPageError: false, isPlaceholderData: false, isError: false }
|
|
rerender()
|
|
expect(result.current.canFetchNextPage).toBe(false)
|
|
|
|
flagsRef.current = { hasNextPage: true, isFetchingNextPage: false, isFetchNextPageError: true, isPlaceholderData: false, isError: false }
|
|
rerender()
|
|
expect(result.current.canFetchNextPage).toBe(false)
|
|
|
|
flagsRef.current = { hasNextPage: true, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: true, isError: false }
|
|
rerender()
|
|
expect(result.current.canFetchNextPage).toBe(false)
|
|
})
|
|
})
|