mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
fix(sessions): scope the session picker to the OpenCode project across worktrees
This commit is contained in:
1 parent
04cb3f8291
commit
e40eca2838
7 files changed
+288
-59
No files matched your search
@@ -4,7 +4,7 @@ import { useSessionSearch } from './useSessionSearch'
|
||||
|
||||
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 } } | undefined },
|
||||
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 } },
|
||||
}))
|
||||
|
||||
@@ -12,7 +12,7 @@ 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 }) => {
|
||||
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
|
||||
@@ -96,6 +96,22 @@ describe('useSessionSearch', () => {
|
||||
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('passes isError through from useSessionsAcrossDirectories', () => {
|
||||
flagsRef.current = { hasNextPage: false, isFetchingNextPage: false, isFetchNextPageError: false, isPlaceholderData: false, isError: true }
|
||||
|
||||
|
||||
Reference in new issue
Block a user