diff --git a/frontend/src/contexts/EventContext.test.tsx b/frontend/src/contexts/EventContext.test.tsx index b0f77597..31218351 100644 --- a/frontend/src/contexts/EventContext.test.tsx +++ b/frontend/src/contexts/EventContext.test.tsx @@ -814,6 +814,7 @@ describe('EventProvider permissions and forms', () => { it.each<[string, string[]]>([ ['agent.updated', ['opencode', 'agents']], ['command.updated', ['opencode', 'commands']], + ['skill.updated', ['opencode', 'skills']], ])('invalidates the %s cache', async (type, queryKey) => { const queryClient = createTestQueryClient() const invalidateQueries = vi.spyOn(queryClient, 'invalidateQueries') @@ -835,6 +836,53 @@ describe('EventProvider permissions and forms', () => { }) }) + it('invalidates the location catalog caches on an upstream resync', async () => { + const queryClient = createTestQueryClient() + const invalidateQueries = vi.spyOn(queryClient, 'invalidateQueries') + + render(, { wrapper: createWrapper(queryClient) }) + + await waitFor(() => expect(mocks.subscribeGlobalMonitor).toHaveBeenCalled()) + invalidateQueries.mockClear() + + const lastSubscribeCall = mocks.subscribeGlobalMonitor.mock.calls[mocks.subscribeGlobalMonitor.mock.calls.length - 1] + const onResync = lastSubscribeCall[0].onResync as (() => void) | undefined + + act(() => { + onResync?.() + }) + + await waitFor(() => { + expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'commands'] }) + expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'agents'] }) + expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'skills'] }) + }) + }) + + it('invalidates the location catalog caches when the browser stream reconnects', async () => { + const queryClient = createTestQueryClient() + const invalidateQueries = vi.spyOn(queryClient, 'invalidateQueries') + + render(, { wrapper: createWrapper(queryClient) }) + + await waitFor(() => expect(mocks.subscribeGlobalMonitor).toHaveBeenCalled()) + invalidateQueries.mockClear() + + const lastSubscribeCall = mocks.subscribeGlobalMonitor.mock.calls[mocks.subscribeGlobalMonitor.mock.calls.length - 1] + const handleStatusChange = lastSubscribeCall[0].onStatusChange as (connected: boolean) => void + + act(() => { + handleStatusChange(false) + handleStatusChange(true) + }) + + await waitFor(() => { + expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'commands'] }) + expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'agents'] }) + expect(invalidateQueries).toHaveBeenCalledWith({ queryKey: ['opencode', 'skills'] }) + }) + }) + it('invalidates both config caches on config.updated', async () => { const queryClient = createTestQueryClient() const invalidateQueries = vi.spyOn(queryClient, 'invalidateQueries') diff --git a/frontend/src/contexts/EventContext.tsx b/frontend/src/contexts/EventContext.tsx index bcef20aa..cd8fd19c 100644 --- a/frontend/src/contexts/EventContext.tsx +++ b/frontend/src/contexts/EventContext.tsx @@ -29,6 +29,12 @@ import { const STATUS_POLL_INTERVAL_MS = 5000 +const LOCATION_CATALOG_QUERY_KEYS = [ + ['opencode', 'commands'], + ['opencode', 'agents'], + ['opencode', 'skills'], +] as const + type PermissionsBySession = Record type FormsBySession = Record type SSEHealthState = Pick @@ -568,6 +574,9 @@ export function EventProvider({ children }: { children: React.ReactNode }) { case 'command.updated': invalidateQueryKeysDebounced(queryClient, [['opencode', 'commands']]) break + case 'skill.updated': + invalidateQueryKeysDebounced(queryClient, [['opencode', 'skills']]) + break case 'config.updated': invalidateQueryKeysDebounced(queryClient, [['opencode', 'config'], ['opencode-config']]) break @@ -599,6 +608,7 @@ export function EventProvider({ children }: { children: React.ReactNode }) { fetchInitialPendingData() fetchInitialSessionStatuses() invalidateChildSessionCaches(queryClient) + invalidateQueryKeysDebounced(queryClient, LOCATION_CATALOG_QUERY_KEYS) startStatusPoll() } else { statusSyncVersionRef.current += 1 @@ -610,6 +620,7 @@ export function EventProvider({ children }: { children: React.ReactNode }) { void reconcilePendingActionsForDirectories(collectTrackedDirectories()) void fetchInitialSessionStatuses() invalidateChildSessionCaches(queryClient) + invalidateQueryKeysDebounced(queryClient, LOCATION_CATALOG_QUERY_KEYS) } const initialDirectories = [...new Set((reposRef.current ?? []).map(r => r.fullPath))]