Skip to content

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

TypeScript

fix(desktop): r7-m5 preserve denied child query state

Josuéd0c609e3018f
diff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
index 85aef9e11..56afcf16a 100644
--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx
@@ -97,8 +97,10 @@ function FileExplorerNode({
initialPageParam: undefined as string | undefined,
getNextPageParam: lastPage => lastPage.nextCursor ?? undefined,
})
- const childError = errorMessage(childQuery.error)
- const childDenied = isGfsChildrenDenied(childQuery.error)
+ const childDenied = isGfsChildrenDenied(childQuery.error, childQuery.data)
+ const childError = childDenied
+ ? 'This folder is no longer available.'
+ : errorMessage(childQuery.error)
const childItems = useMemo(
() =>
childDenied ? [] : sortTreeItems((childQuery.data?.pages ?? []).flatMap(page => page.items)),
diff --git a/desktop-app/ui/src/gfs/__tests__/deniedChildren.test.ts b/desktop-app/ui/src/gfs/__tests__/deniedChildren.test.ts
new file mode 100644
index 000000000..c7881ac2d
--- /dev/null
+++ b/desktop-app/ui/src/gfs/__tests__/deniedChildren.test.ts
@@ -0,0 +1,31 @@
+import { describe, expect, it } from 'vitest'
+import { QueryClient } from '@tanstack/react-query'
+import { isGfsChildrenDenied, purgeDeniedGfsChildren } from '../deniedChildren'
+
+describe('denied GFS children cache', () => {
+ it('purges cached rows without representing a revoked folder as a successful empty folder', () => {
+ const queryClient = new QueryClient()
+ const queryKey = ['desktop-app', 'gfs', 'session', 'children', 'main', 'folder']
+ queryClient.setQueryData(queryKey, {
+ pages: [{ items: [{ resourceId: 'secret-child' }], nextCursor: 'next' }],
+ pageParams: [undefined],
+ })
+
+ expect(
+ purgeDeniedGfsChildren(queryClient, queryKey, new Error('resource denied httpStatus=403'))
+ ).toBe(true)
+
+ const cached = queryClient.getQueryData(queryKey)
+ expect(cached).toMatchObject({
+ accessDenied: true,
+ pages: [{ items: [], nextCursor: null }],
+ })
+ expect(isGfsChildrenDenied(undefined, cached)).toBe(true)
+
+ queryClient.setQueryData(queryKey, {
+ pages: [{ items: [{ resourceId: 'newly-visible-child' }], nextCursor: null }],
+ pageParams: [undefined],
+ })
+ expect(isGfsChildrenDenied(undefined, queryClient.getQueryData(queryKey))).toBe(false)
+ })
+})
diff --git a/desktop-app/ui/src/gfs/deniedChildren.ts b/desktop-app/ui/src/gfs/deniedChildren.ts
index 7dc47b957..45b0423a1 100644
--- a/desktop-app/ui/src/gfs/deniedChildren.ts
+++ b/desktop-app/ui/src/gfs/deniedChildren.ts
@@ -22,6 +22,10 @@ export function purgeDeniedGfsChildren(
if (!Array.isArray(pages)) return current
return {
...current,
+ // setQueryData records a successful cache write and can clear TanStack's
+ // error field. Keep denial separate from successful empty-list data so
+ // consumers cannot render a revoked folder as a valid empty folder.
+ accessDenied: true,
pages: pages.map(page =>
page && typeof page === 'object' && 'items' in page && Array.isArray(page.items)
? { ...page, items: [], nextCursor: null }
@@ -32,7 +36,13 @@ export function purgeDeniedGfsChildren(
return true
}
-export function isGfsChildrenDenied(error: unknown): boolean {
+export function isGfsChildrenDenied(error: unknown, data?: unknown): boolean {
const status = parseHttpStatus(errorMessage(error))
- return status === 403 || status === 404
+ if (status === 403 || status === 404) return true
+ return Boolean(
+ data &&
+ typeof data === 'object' &&
+ 'accessDenied' in data &&
+ (data as { accessDenied?: unknown }).accessDenied === true
+ )
}
diff --git a/desktop-app/ui/src/gfs/moveDialog.tsx b/desktop-app/ui/src/gfs/moveDialog.tsx
index 550556049..57fe714c0 100644
--- a/desktop-app/ui/src/gfs/moveDialog.tsx
+++ b/desktop-app/ui/src/gfs/moveDialog.tsx
@@ -66,8 +66,10 @@ function GfsMoveTreeFolder({
initialPageParam: undefined as string | undefined,
getNextPageParam: lastPage => lastPage.nextCursor ?? undefined,
})
- const childError = errorMessage(childQuery.error)
- const childDenied = isGfsChildrenDenied(childQuery.error)
+ const childDenied = isGfsChildrenDenied(childQuery.error, childQuery.data)
+ const childError = childDenied
+ ? 'This folder is no longer available.'
+ : errorMessage(childQuery.error)
const childFolders = useMemo(
() =>
childDenied