Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(desktop): revalidate sidebar file-explorer child listings (R1-H5)

Diego Zacariase97c69b1e600
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx
index 395c27e9d..33e7dc93b 100644
--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx
+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/__tests__/FileExplorerTree.test.tsx
@@ -1,8 +1,9 @@
// @vitest-environment jsdom
import { useRef, useState } from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
-import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { QueryClient, QueryClientProvider, focusManager } from '@tanstack/react-query'
import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
+import { desktopQueryDefaults } from '@lib/queryClient'
import { activeWorkspaceTab, openFilesTab } from '@lib/workspaceTabs'
import type { WorkspaceTabsState } from '@lib/workspaceTabs.types'
import {
@@ -470,6 +471,63 @@ describe('FileExplorerTree — folder activation focuses an existing files tab',
})
})
+describe('FileExplorerTree — expanded folder revalidates its listing (R1-H5)', () => {
+ // The sidebar is a persistent surface. Folder contents change out-of-band
+ // (agents, other sessions, operator writes never pass through this client), so
+ // an expanded folder must revalidate on window focus — not serve its first
+ // page forever under the app's Infinity staleTime.
+ //
+ // This test runs under the REAL desktop cache policy (`desktopQueryDefaults`:
+ // Infinity staleTime, refetch flags off by default). The loose harness client
+ // the other tests use inherits TanStack's default refetchOnWindowFocus:true,
+ // which would refetch anyway and hide the bug — so it must NOT be used here.
+ it('re-fetches an expanded folder on window focus and renders the new children', async () => {
+ // The producer returns a DIFFERENT children page on the second fetch: the
+ // out-of-band change the sidebar must surface without a hard reload.
+ let call = 0
+ const listChildren = vi.fn(async () => {
+ call += 1
+ return call === 1
+ ? listChildrenPage([childView('old-1', 'old.md', 'file')])
+ : listChildrenPage([childView('new-1', 'new.md', 'file')])
+ })
+ installClerum({
+ listAccessible: vi.fn(async () =>
+ listAccessiblePage([accessibleResource('reports', 'Reports', 'directory')])
+ ),
+ listChildren,
+ })
+
+ const queryClient = new QueryClient({ defaultOptions: desktopQueryDefaults })
+ render(
+ <QueryClientProvider client={queryClient}>
+ <FileExplorerTree onOpenFolder={vi.fn()} onOpenPreview={vi.fn()} pushToast={vi.fn()} />
+ </QueryClientProvider>
+ )
+
+ fireEvent.click(await screen.findByRole('button', { name: 'Expand Reports' }))
+ expect(await screen.findByRole('button', { name: 'old.md' })).toBeTruthy()
+
+ // Return focus to the window (force a false→true transition so the focus
+ // listener fires). Under Infinity staleTime, only refetchOnWindowFocus:
+ // 'always' triggers a refetch of the still-fresh listing.
+ act(() => {
+ focusManager.setFocused(false)
+ focusManager.setFocused(true)
+ })
+
+ try {
+ // Observable output (T4): the tree renders the NEW child and drops the stale
+ // one — not a refetch spy count.
+ expect(await screen.findByRole('button', { name: 'new.md' })).toBeTruthy()
+ await waitFor(() => expect(screen.queryByRole('button', { name: 'old.md' })).toBeNull())
+ } finally {
+ // Restore event-driven focus detection so this global state does not leak.
+ focusManager.setFocused(undefined)
+ }
+ })
+})
+
describe('FileExplorerTree — unreadable rows refuse activation (R1-H1)', () => {
// A `readable: false` child (a folder grant without inheritance; a file whose
// parent does not inherit) is listed but cannot be opened. The tree must
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
index 34f848c97..9c7b1368a 100644
--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
@@ -83,6 +83,14 @@ function FileExplorerNode({
// session fetches nothing (the subtree also unmounts as accessibleResources
// empties, but this keeps the guard robust to future refactors).
enabled: isExpanded && accessActive,
+ // Folder contents change out-of-band: agents with host grants, other
+ // sessions, and operator writes never pass through this client. The sidebar
+ // is a persistent surface, so under the app's Infinity staleTime an expanded
+ // folder would otherwise serve its first page forever — removed files linger
+ // and new files never appear until a hard reload. Revalidate on revisit and
+ // window focus, matching the controller's own children query.
+ refetchOnMount: 'always',
+ refetchOnWindowFocus: 'always',
initialPageParam: undefined as string | undefined,
getNextPageParam: lastPage => lastPage.nextCursor ?? undefined,
})