fix(desktop): refresh sessions on profile switch
Re-run the foreground session-list refresh whenever the active gateway profile changes, preventing rows from the previously selected profile from persisting in the sidebar.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { act, cleanup, renderHook } from '@testing-library/react'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
import { $changeEventsAvailable, $cronChangeTick, $sessionsChangeTick } from '@/store/live-sync'
|
||||
import { $activeSessionId } from '@/store/session'
|
||||
|
||||
import { useBackgroundSync } from './use-background-sync'
|
||||
|
||||
const noop = () => undefined
|
||||
const requestGateway = async () => ({ sessions: [] })
|
||||
|
||||
function render(activeGatewayProfile: string, refreshSessions: () => Promise<void>) {
|
||||
return renderHook(
|
||||
({ profile }: { profile: string }) => {
|
||||
useBackgroundSync({
|
||||
activeGatewayProfile: profile,
|
||||
activeIsMessaging: false,
|
||||
activeSessionId: null,
|
||||
freshDraftReady: false,
|
||||
gatewayState: 'open',
|
||||
refreshActiveMessagingTranscript: noop,
|
||||
refreshCronJobs: noop,
|
||||
refreshCurrentModel: noop,
|
||||
refreshHermesConfig: noop,
|
||||
refreshMessagingSessions: noop,
|
||||
refreshSessions,
|
||||
requestGateway
|
||||
})
|
||||
},
|
||||
{ initialProps: { profile: activeGatewayProfile } }
|
||||
)
|
||||
}
|
||||
|
||||
describe('useBackgroundSync profile-scoped session refresh', () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
$activeSessionId.set(null)
|
||||
$changeEventsAvailable.set(false)
|
||||
$cronChangeTick.set(0)
|
||||
$sessionsChangeTick.set(0)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
it('refreshes the session list after the active gateway profile changes', async () => {
|
||||
const refreshSessions = vi.fn(async () => undefined)
|
||||
const hook = render('default', refreshSessions)
|
||||
|
||||
await act(async () => undefined)
|
||||
expect(refreshSessions).toHaveBeenCalledTimes(1)
|
||||
refreshSessions.mockClear()
|
||||
|
||||
hook.rerender({ profile: 'nova' })
|
||||
|
||||
await act(async () => undefined)
|
||||
expect(refreshSessions).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
@@ -411,7 +411,7 @@ export function useBackgroundSync({
|
||||
})
|
||||
.catch(() => undefined)
|
||||
}
|
||||
}, [gatewayState, refreshCurrentModel, refreshSessions, requestGateway])
|
||||
}, [activeGatewayProfile, gatewayState, refreshCurrentModel, refreshSessions, requestGateway])
|
||||
|
||||
// A reconnect loses renderer-only working/attention atoms while the backend
|
||||
// keeps the actual turns alive. Re-seed from the gateway's in-memory session
|
||||
|
||||
Reference in New Issue
Block a user