mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(session): paginated session list with infinite scroll and assistant mode improvements (#243)
* feat(session): paginated session list with infinite scroll and search Replace per-directory useQueries session listing with a combined cursor-based useInfiniteQuery (25 per page, loads more on scroll) and move search into the API query instead of client-side filtering. Add OpenCodeClient.listSessionsPage backed by the v2 /api/session endpoint plus a toLegacySession adapter. Add invalidateSessionListCaches to centralize session-list cache invalidation for infinite queries, and update EventContext and useSSE to handle the new infinite-query cache shape. * fix(session): centralize and debounce session-list cache invalidation Migrate ResetPermissionsDialog off the stale per-directory cache key (which no longer matches the infinite-query key shape and hardcoded the opencode URL) to the shared invalidateSessionListCaches helper, and drop the now-unused repoDirectory prop and its call sites. Debounce session-list invalidation on SSE session.updated events in EventContext and useSSE so a burst of updates coalesces into a single refetch instead of one per event. Fix the directory fallback in EventContext getClient so it never returns the joined directory key. * fix(permissions): scope instance dispose to the repo directory Drop the session-list cache invalidation from ResetPermissionsDialog: disposing the OpenCode instance does not change the persisted session list, so the refetch was unnecessary, and the prior cache key no longer matched the paginated shape. Guard the reset-permissions route against an empty repo directory so it never forwards /instance/dispose without a directory, which would dispose the entire server instead of only the repo's instance.
This commit is contained in:
1 parent
78d934772e
commit
eedbbfb94e
17 files changed
+931
-116
No files matched your search
@@ -470,7 +470,11 @@ app.get('/', async (c) => {
|
||||
if (!repo) {
|
||||
return c.json({ error: 'Repo not found' }, 404)
|
||||
}
|
||||
|
||||
|
||||
if (!repo.fullPath) {
|
||||
return c.json({ error: 'Repo has no directory to reset' }, 400)
|
||||
}
|
||||
|
||||
const response = await openCodeClient.forward({
|
||||
method: 'POST',
|
||||
path: '/instance/dispose',
|
||||
|
||||
@@ -248,4 +248,63 @@ describe('Repo Routes', () => {
|
||||
expect(res.status).toBe(500)
|
||||
})
|
||||
})
|
||||
|
||||
describe('POST /:id/reset-permissions', () => {
|
||||
it('should return 404 when repo not found', async () => {
|
||||
vi.mocked(db.getRepoById).mockReturnValue(null)
|
||||
|
||||
const app = createRepoRoutes(mockDb, mockGitAuthService, mockScheduleService, createStubOpenCodeClient())
|
||||
const res = await app.request('/1/reset-permissions', { method: 'POST' })
|
||||
|
||||
expect(res.status).toBe(404)
|
||||
})
|
||||
|
||||
it('should return 400 without disposing when repo has no directory', async () => {
|
||||
const mockRepo = {
|
||||
id: 1,
|
||||
repoUrl: undefined,
|
||||
localPath: 'assistant',
|
||||
fullPath: '',
|
||||
sourcePath: undefined,
|
||||
branch: undefined,
|
||||
defaultBranch: 'main',
|
||||
cloneStatus: 'ready' as const,
|
||||
clonedAt: Date.now(),
|
||||
}
|
||||
vi.mocked(db.getRepoById).mockReturnValue(mockRepo)
|
||||
|
||||
const forward = vi.fn(async () => new Response(JSON.stringify(true), { status: 200 }))
|
||||
const app = createRepoRoutes(mockDb, mockGitAuthService, mockScheduleService, createStubOpenCodeClient({ forward }))
|
||||
const res = await app.request('/1/reset-permissions', { method: 'POST' })
|
||||
|
||||
expect(res.status).toBe(400)
|
||||
expect(forward).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should dispose only the repo directory and return success', async () => {
|
||||
const mockRepo = {
|
||||
id: 1,
|
||||
repoUrl: 'https://github.com/test/repo',
|
||||
localPath: 'repos/test-repo',
|
||||
fullPath: '/tmp/test-repo',
|
||||
sourcePath: '/tmp/test-repo/.git',
|
||||
branch: 'main',
|
||||
defaultBranch: 'main',
|
||||
cloneStatus: 'ready' as const,
|
||||
clonedAt: Date.now(),
|
||||
}
|
||||
vi.mocked(db.getRepoById).mockReturnValue(mockRepo)
|
||||
|
||||
const forward = vi.fn(async () => new Response(JSON.stringify(true), { status: 200 }))
|
||||
const app = createRepoRoutes(mockDb, mockGitAuthService, mockScheduleService, createStubOpenCodeClient({ forward }))
|
||||
const res = await app.request('/1/reset-permissions', { method: 'POST' })
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(forward).toHaveBeenCalledWith({
|
||||
method: 'POST',
|
||||
path: '/instance/dispose',
|
||||
directory: '/tmp/test-repo',
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user