Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): r6-h10 purge denied child listings
Josuéc4bdafffb0ed
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.tsxindex f114c90d4..88ef11e53 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@@ -527,6 +527,43 @@ describe('FileExplorerTree — expanded folder revalidates its listing (R1-H5)',focusManager.setFocused(undefined)}})++ it('purges cached children when an expanded folder is authoritatively denied', async () => {+ let call = 0+ const listChildren = vi.fn(async () => {+ call += 1+ if (call === 1) return listChildrenPage([childView('private-1', 'private.md', 'file')])+ throw new Error('403 Forbidden: httpStatus=403')+ })+ 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: 'private.md' })).toBeTruthy()++ act(() => {+ focusManager.setFocused(false)+ focusManager.setFocused(true)+ })++ try {+ await waitFor(() => expect(listChildren).toHaveBeenCalledTimes(2))+ await waitFor(() => expect(screen.queryByRole('button', { name: 'private.md' })).toBeNull())+ } finally {+ focusManager.setFocused(undefined)+ }+ })})describe('FileExplorerTree — unreadable rows refuse activation (R1-H1)', () => {diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsxindex dde3bb554..85aef9e11 100644--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx@@ -1,5 +1,5 @@import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'-import { useInfiniteQuery } from '@tanstack/react-query'+import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query'import { Badge, Button, IconButton, StatusBanner } from '@components/Common'import { GfsFileIcon } from '@components/GfsFileIcon'import { GFS_DRIVE_MAIN } from '@constants/gfsBrowser'@@ -11,6 +11,7 @@ import {import { saveGfsFileToDisk } from '@lib/gfsDownload'import { resolveGfsPreview } from '@lib/gfsPreview'import { sanitizeAppTabTitle } from '@lib/sanitizeAppTabTitle'+import { isGfsChildrenDenied, purgeDeniedGfsChildren } from '@/gfs/deniedChildren'import { IconChevronRight, IconContexts } from '../icons'import type { FileExplorerNodeProps, FileExplorerTreeProps } from './types'@@ -64,6 +65,7 @@ function FileExplorerNode({onActivateFile,onAuthorityFailure,}: FileExplorerNodeProps) {+ const queryClient = useQueryClient()const isDirectory = node.kind === 'directory'const isExpanded = isDirectory && expandedIds.has(node.resourceId)const isSelected = selectedId === node.resourceId@@ -75,8 +77,9 @@ function FileExplorerNode({// (older servers) is treated as unknown, not unreadable.const isUnreadable = node.readable === false+ const childQueryKey = desktopQueryKeys.gfsChildren(scope, node.resourceId, GFS_DRIVE_MAIN)const childQuery = useInfiniteQuery({- queryKey: desktopQueryKeys.gfsChildren(scope, node.resourceId, GFS_DRIVE_MAIN),+ queryKey: childQueryKey,queryFn: ({ pageParam }) =>window.clerum.gfs.listChildren(node.resourceId, GFS_DRIVE_MAIN, pageParam),// Gate on live access as the controller's own children query does: a revoked@@ -95,14 +98,18 @@ function FileExplorerNode({getNextPageParam: lastPage => lastPage.nextCursor ?? undefined,})const childError = errorMessage(childQuery.error)+ const childDenied = isGfsChildrenDenied(childQuery.error)const childItems = useMemo(- () => sortTreeItems((childQuery.data?.pages ?? []).flatMap(page => page.items)),- [childQuery.data]+ () =>+ childDenied ? [] : sortTreeItems((childQuery.data?.pages ?? []).flatMap(page => page.items)),+ [childDenied, childQuery.data])useEffect(() => {+ if (!childQuery.error) return+ purgeDeniedGfsChildren(queryClient, childQueryKey, childQuery.error)if (childError) onAuthorityFailure(childError)- }, [childError, onAuthorityFailure])+ }, [childError, childQuery.error, childQueryKey, onAuthorityFailure, queryClient])// Deferred folder toggle: cancelled by a double-click within the window.const clickTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null)diff --git a/desktop-app/ui/src/gfs/__tests__/moveDialog.test.tsx b/desktop-app/ui/src/gfs/__tests__/moveDialog.test.tsxindex 26125f54e..131dcf52a 100644--- a/desktop-app/ui/src/gfs/__tests__/moveDialog.test.tsx+++ b/desktop-app/ui/src/gfs/__tests__/moveDialog.test.tsx@@ -1,7 +1,8 @@// @vitest-environment jsdomimport { afterEach, describe, expect, it, vi } from 'vitest'import { QueryClient, QueryClientProvider } from '@tanstack/react-query'-import { cleanup, fireEvent, render, screen, within } from '@testing-library/react'+import { act, cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'+import { desktopQueryKeys } from '@hooks/domain/queryKeys'import type { GfsBrowserChild, GfsCrumb } from '@hooks/domain/useGfsBrowserController'import { GfsMoveDialog } from '../moveDialog'@@ -62,7 +63,7 @@ function renderDialog(},},})- return render(+ const rendered = render(<QueryClientProvider client={queryClient}><GfsMoveDialogtarget={target}@@ -73,9 +74,40 @@ function renderDialog(/></QueryClientProvider>)+ return { ...rendered, queryClient }}describe('GfsMoveDialog pagination', () => {+ it('purges cached destination rows after an expanded folder is denied', async () => {+ let childReads = 0+ const listAccessible = vi.fn(async () => ({+ items: [folder('folder-1', 'Product')],+ nextCursor: null,+ }))+ const listChildren = vi.fn(async () => {+ childReads += 1+ if (childReads === 1) return { items: [folder('folder-2', 'Assets')], nextCursor: null }+ throw new Error('403 Forbidden: httpStatus=403')+ })+ const { queryClient } = renderDialog({ listAccessible, listChildren })++ const dialog = await screen.findByRole('dialog', { name: 'Move file notes.txt' })+ const tree = within(dialog).getByRole('tree', { name: 'EvenDrive destination folders' })+ expect(await within(tree).findByRole('button', { name: 'Product' })).toBeTruthy()+ await fireEvent.click(within(tree).getByRole('button', { name: 'Expand Product' }))+ expect(await within(tree).findByRole('button', { name: 'Assets' })).toBeTruthy()++ await act(async () => {+ await queryClient.invalidateQueries({+ queryKey: desktopQueryKeys.gfsChildren('anonymous', 'folder-1', 'main'),+ })+ })++ expect(listChildren).toHaveBeenCalledTimes(2)+ await waitFor(() => expect(within(tree).queryByRole('button', { name: 'Assets' })).toBeNull())+ expect(within(tree).getByRole('button', { name: 'Product' })).toBeTruthy()+ })+it('loads page two of the root destinations and commits a move to a page-two folder', async () => {const onMove = vi.fn(async () => undefined)let call = 0diff --git a/desktop-app/ui/src/gfs/deniedChildren.ts b/desktop-app/ui/src/gfs/deniedChildren.tsnew file mode 100644index 000000000..33ff3e80c--- /dev/null+++ b/desktop-app/ui/src/gfs/deniedChildren.ts@@ -0,0 +1,38 @@+import type { QueryClient, QueryKey } from '@tanstack/react-query'+import { parseHttpStatus } from '@lib/gfsGrantErrors'++function errorMessage(error: unknown): string {+ return error instanceof Error ? error.message : String(error ?? '')+}++/** Drop previously authorized child metadata only after an authoritative denial. */+export function purgeDeniedGfsChildren(+ queryClient: QueryClient,+ queryKey: QueryKey,+ error: unknown+): boolean {+ if (!isGfsChildrenDenied(error)) return false++ // A failed TanStack refetch retains its last successful data by design. For+ // a definitive denial, replace only cached child rows; later invalidation can+ // still refetch the same key if access is granted again.+ queryClient.setQueryData<unknown>(queryKey, current => {+ if (!current || typeof current !== 'object' || !('pages' in current)) return current+ const pages = (current as { pages?: unknown }).pages+ if (!Array.isArray(pages)) return current+ return {+ ...current,+ pages: pages.map(page =>+ page && typeof page === 'object' && 'items' in page && Array.isArray(page.items)+ ? { ...page, items: [], nextCursor: null }+ : page+ ),+ }+ })+ return true+}++export function isGfsChildrenDenied(error: unknown): boolean {+ const status = parseHttpStatus(errorMessage(error))+ return status === 403 || status === 404+}diff --git a/desktop-app/ui/src/gfs/moveDialog.tsx b/desktop-app/ui/src/gfs/moveDialog.tsxindex 4effebf9a..550556049 100644--- a/desktop-app/ui/src/gfs/moveDialog.tsx+++ b/desktop-app/ui/src/gfs/moveDialog.tsx@@ -1,11 +1,12 @@import { useEffect, useMemo, useState } from 'react'-import { useInfiniteQuery } from '@tanstack/react-query'+import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query'import { Button, IconButton, StatusBanner } from '@components/Common'import { IconCheck, IconChevronRight, IconClose, IconContexts } from '@components/SidebarNav/icons'import { GFS_DRIVE_MAIN } from '@constants/gfsBrowser'import { desktopQueryKeys } from '@hooks/domain/queryKeys'import type { GfsBrowserChild } from '@hooks/domain/useGfsBrowserController'import { describeGfsReadError } from '@lib/gfsGrantErrors'+import { isGfsChildrenDenied, purgeDeniedGfsChildren } from './deniedChildren'import type { GfsMoveDialogProps } from './moveDialog.types'type SelectedDestination = Pick<GfsBrowserChild, 'resourceId' | 'name'>@@ -54,9 +55,11 @@ function GfsMoveTreeFolder({onSelect,onAuthorityFailure,}: GfsMoveTreeFolderProps) {+ const queryClient = useQueryClient()const isExpanded = expandedFolderIds.has(folder.resourceId)+ const childQueryKey = desktopQueryKeys.gfsChildren(scope, folder.resourceId, GFS_DRIVE_MAIN)const childQuery = useInfiniteQuery({- queryKey: desktopQueryKeys.gfsChildren(scope, folder.resourceId, GFS_DRIVE_MAIN),+ queryKey: childQueryKey,queryFn: ({ pageParam }) =>window.clerum.gfs.listChildren(folder.resourceId, GFS_DRIVE_MAIN, pageParam),enabled: isExpanded,@@ -64,18 +67,22 @@ function GfsMoveTreeFolder({getNextPageParam: lastPage => lastPage.nextCursor ?? undefined,})const childError = errorMessage(childQuery.error)+ const childDenied = isGfsChildrenDenied(childQuery.error)const childFolders = useMemo(() =>- folderItems(- (childQuery.data?.pages ?? []).flatMap(page => page.items),- new Set([targetResourceId, ...ancestors])- ),- [ancestors, childQuery.data, targetResourceId]+ childDenied+ ? []+ : folderItems(+ (childQuery.data?.pages ?? []).flatMap(page => page.items),+ new Set([targetResourceId, ...ancestors])+ ),+ [ancestors, childDenied, childQuery.data, targetResourceId])useEffect(() => {+ if (childQuery.error) purgeDeniedGfsChildren(queryClient, childQueryKey, childQuery.error)if (childError) onAuthorityFailure?.(childError)- }, [childError, onAuthorityFailure])+ }, [childError, childQuery.error, childQueryKey, onAuthorityFailure, queryClient])const loadingChildren = Boolean(isExpanded && childQuery.isFetching && !childQuery.data)const hasMoreChildren = Boolean(childQuery.hasNextPage)