Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop-app): r3-m1 reconcile remote folder changes
Josuédc851f1b5d18
diff --git a/desktop-app/ui/src/App.tsx b/desktop-app/ui/src/App.tsxindex 963fbd8bd..fa123a784 100644--- a/desktop-app/ui/src/App.tsx+++ b/desktop-app/ui/src/App.tsx@@ -288,6 +288,7 @@ export function App() {// DOM focus/blur so focus-aware query revalidation actually runs.useWindowFocusBridge()const [themeMode, setThemeMode] = React.useState<ThemeMode>(getInitialThemeMode)+ const [remoteGfsChangeEpoch, setRemoteGfsChangeEpoch] = React.useState(0)const [sidebarCollapsed, setSidebarCollapsed] = React.useState<boolean>(getInitialSidebarCollapsed)@@ -1060,6 +1061,7 @@ export function App() {let active = truelet stopSubscription: (() => Promise<void>) | null = nullconst unsubscribeGfs = entityChangeRegistry.subscribe(['gfs', 'authorization'], event => {+ setRemoteGfsChangeEpoch(epoch => epoch + 1)if (event.scopes.includes('authorization')) {void queryClient.resetQueries({ queryKey: desktopQueryKeys.gfsRoot })} else {@@ -2792,6 +2794,7 @@ export function App() {key={activeFilesTabId ?? 'files'}pushToast={vm.pushToast}pendingGfsUri={filesSeedPath}+ remoteGfsChangeEpoch={remoteGfsChangeEpoch}onLocationChange={handleFilesLocationChange}onOpenPreview={vm.openPreviewSection}/>diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.tsindex 39f782143..3551d60d4 100644--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts@@ -302,6 +302,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {const [crumbs, setCrumbs] = useState<GfsCrumb[]>([])const [openError, setOpenError] = useState<string | null>(null)const [resolving, setResolving] = useState(false)+ const openUriGenerationRef = useRef(0)const previousSessionScopeRef = useRef<string | null>(null)// Per controller-mount timestamp: discovery (`refetchOnMount: 'always'`) must// land a response newer than this before cached GFS state may render again.@@ -890,11 +891,13 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {: nullconst openUri = useCallback(- async (uri: string) => {+ async (uri: string, options?: { clearIfUnavailable?: boolean }) => {+ const generation = ++openUriGenerationRef.currentsetOpenError(null)setResolving(true)try {const resource = await window.clerum.gfs.resolve(uri.trim())+ if (openUriGenerationRef.current !== generation) return falseconst crumb: GfsCrumb = {resourceId: resource.resourceId,gfsUri: resource.gfsUri,@@ -915,6 +918,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {try {const parentRid = parentResourceId.replace(/-/g, '').toLowerCase()const parent = await window.clerum.gfs.resolve(`gfs://${resource.drive}/${parentRid}`)+ if (openUriGenerationRef.current !== generation) return falseif (parent.kind !== 'directory') breakif (parent.name) {ancestors.push({@@ -937,6 +941,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {setCrumbs([...ancestors.reverse(), crumb])return crumb} catch (error) {+ if (openUriGenerationRef.current !== generation) return falseconst message = toMessage(error)// Opening a URI is an operation on one resource. A generic 403 may be// a per-resource policy decision; only a session-authority failure@@ -944,15 +949,30 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {//// The authority check reads the RAW message — it matches status codes// and lifecycle tokens — while the banner shows the presented verdict.- if (!handleAuthorityFailure(message, 'operation')) setOpenError(toPresentedMessage(error))+ if (!handleAuthorityFailure(message, 'operation')) {+ const status = parseHttpStatus(message)+ if (options?.clearIfUnavailable && (status === 403 || status === 404)) {+ setCrumbs([])+ setOpenError(null)+ void queryClient.removeQueries({ queryKey: desktopQueryKeys.gfsRoot })+ } else {+ setOpenError(toPresentedMessage(error))+ }+ }return false} finally {- setResolving(false)+ if (openUriGenerationRef.current === generation) setResolving(false)}},- [handleAuthorityFailure]+ [handleAuthorityFailure, queryClient])+ const refreshCurrentLocation = useCallback(async () => {+ const uri = current?.gfsUri+ if (!uri) return false+ return openUri(uri, { clearIfUnavailable: true })+ }, [current?.gfsUri, openUri])+// Move refreshes the old parent's children, the destination's children,// and the accessible roots in one shot via refreshGfs. The moved resource's// id does not change, but its version does, and when the OPEN folder (or@@ -1156,6 +1176,7 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {void accessibleQuery.fetchNextPage()},openUri,+ refreshCurrentLocation,openResource,openChild,goToCrumb,diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsxindex e876bae15..4344a51e7 100644--- a/desktop-app/ui/src/pages/FilesPage.tsx+++ b/desktop-app/ui/src/pages/FilesPage.tsx@@ -240,6 +240,7 @@ export function FilesPage({pushToast,pendingGfsUri,onPendingGfsUriHandled,+ remoteGfsChangeEpoch,onLocationChange,onOpenPreview,}: FilesPageProps) {@@ -310,6 +311,14 @@ export function FilesPage({refreshAffordances,} = ctrl+ const lastRemoteGfsChangeEpochRef = useRef(remoteGfsChangeEpoch)+ useEffect(() => {+ if (remoteGfsChangeEpoch === undefined) return+ if (lastRemoteGfsChangeEpochRef.current === remoteGfsChangeEpoch) return+ lastRemoteGfsChangeEpochRef.current = remoteGfsChangeEpoch+ void ctrl.refreshCurrentLocation()+ }, [ctrl.refreshCurrentLocation, remoteGfsChangeEpoch])+// Warm the cache for directory rows in the current view so clicking into a// folder is instant. TanStack Query's staleTime:Infinity (set in// lib/queryClient.ts) keeps the cached data hot until the user navigates.diff --git a/desktop-app/ui/src/pages/FilesPage.types.ts b/desktop-app/ui/src/pages/FilesPage.types.tsindex 810997f80..243e307d9 100644--- a/desktop-app/ui/src/pages/FilesPage.types.ts+++ b/desktop-app/ui/src/pages/FilesPage.types.ts@@ -26,6 +26,8 @@ export interface FilesPageProps {* `gfsUri` carries no name, hence the second argument.*/onLocationChange?: (gfsUri: string | null, name: string | null) => void+ /** Monotonic signal from the app-level entity stream for live path reconciliation. */+ remoteGfsChangeEpoch?: number/*** Open (or focus) a preview tab for a previewable file (spec 18 §3.B.4). The* files browser no longer renders a preview modal: `openFilePreview` resolvesdiff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.seedLocation.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.seedLocation.test.tsxindex c4bce45c8..d422c0197 100644--- a/desktop-app/ui/src/pages/__tests__/FilesPage.seedLocation.test.tsx+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.seedLocation.test.tsx@@ -1,11 +1,13 @@// @vitest-environment jsdom-import { useRef, useState } from 'react'+import { useEffect, useRef, useState } from 'react'import { afterEach, describe, expect, it, vi } from 'vitest'import { AuthContext, type AuthContextValue } from '@contexts/AuthContext'-import { QueryClient, QueryClientProvider } from '@tanstack/react-query'+import { QueryClient, QueryClientProvider, useQueryClient } from '@tanstack/react-query'import { act, cleanup, render, screen, waitFor } from '@testing-library/react'+import { desktopQueryKeys } from '@hooks/domain/queryKeys'import { createEmptyWorkspaceTabsState, openFilesTab, setFilesTabPath } from '@lib/workspaceTabs'import type { WorkspaceTabsState } from '@lib/workspaceTabs.types'+import { resolveDeniedMessage } from '@/gfs/__fixtures__/gfsProducerFixtures'import { FilesPage } from '../FilesPage'// This suite mounts the REAL FilesPage on the REAL useGfsBrowserController (T1:@@ -81,7 +83,8 @@ function authValue(): AuthContextValue {const SEED_URI = 'gfs://main/aaa'/** App's files render seam, reduced to the tab-persistence contract under test. */-function FilesTabHarness() {+function FilesTabHarness({ remoteGfsChangeEpoch = 0 }: { remoteGfsChangeEpoch?: number }) {+ const queryClient = useQueryClient()const [state, setState] = useState<WorkspaceTabsState>(() => {let next = createEmptyWorkspaceTabsState()// A non-root files tab, already persisted at a live gfsUri (as if reopened@@ -98,6 +101,14 @@ function FilesTabHarness() {// Seed captured once per active tab id (App uses a ref; here the id is stable).const seedPath = activeFilesTab?.files?.path ?? null+ useEffect(() => {+ if (remoteGfsChangeEpoch === 0) return+ void queryClient.invalidateQueries({+ queryKey: desktopQueryKeys.gfsRoot,+ refetchType: 'active',+ })+ }, [queryClient, remoteGfsChangeEpoch])+const handleLocationChange = (gfsUri: string | null, name: string | null) => {const id = activeIdRef.currentif (!id) return@@ -116,6 +127,7 @@ function FilesTabHarness() {key={activeFilesTab.id}pendingGfsUri={seedPath}onLocationChange={handleLocationChange}+ {...({ remoteGfsChangeEpoch } as Record<string, number>)}/>)}</>@@ -124,13 +136,16 @@ function FilesTabHarness() {function renderHarness() {const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })- return render(- <AuthContext.Provider value={authValue()}>- <QueryClientProvider client={client}>- <FilesTabHarness />- </QueryClientProvider>- </AuthContext.Provider>- )+ return {+ client,+ ...render(+ <AuthContext.Provider value={authValue()}>+ <QueryClientProvider client={client}>+ <FilesTabHarness />+ </QueryClientProvider>+ </AuthContext.Provider>+ ),+ }}describe('FilesPage seed → onLocationChange round-trip (mini-spec 06 §3)', () => {@@ -193,4 +208,174 @@ describe('FilesPage seed → onLocationChange round-trip (mini-spec 06 §3)', ()await waitFor(() => expect(tab()).toBe(`${SEED_URI}|Q4 Reports`))})++ it('refreshes an open folder path and its child list after a remote move and create', async () => {+ let moved = false+ Object.defineProperty(window, 'clerum', {+ configurable: true,+ value: {+ gfs: {+ listAccessible: vi.fn(async () => ({ items: [], nextCursor: null })),+ resolve: vi.fn(async (uri: string) => {+ if (uri === SEED_URI) {+ return {+ resourceId: 'folder-current',+ gfsUri: SEED_URI,+ drive: 'main',+ name: 'Reports',+ kind: 'directory',+ parentResourceId: moved ? 'parent-new' : 'parent-old',+ version: moved ? 2 : 1,+ }+ }+ if (uri === 'gfs://main/parentold') {+ return {+ resourceId: 'parent-old',+ gfsUri: uri,+ name: 'Old location',+ kind: 'directory',+ parentResourceId: null,+ version: 1,+ }+ }+ if (uri === 'gfs://main/parentnew') {+ return {+ resourceId: 'parent-new',+ gfsUri: uri,+ name: 'New location',+ kind: 'directory',+ parentResourceId: null,+ version: 1,+ }+ }+ throw new Error(`Unexpected GFS resolve URI: ${uri}`)+ }),+ listChildren: vi.fn(async (resourceId: string) => ({+ items:+ moved && resourceId === 'folder-current'+ ? [+ {+ resourceId: 'new-file',+ rid: 'new-file',+ gfsUri: 'gfs://main/new-file',+ drive: 'main',+ parentResourceId: 'folder-current',+ name: 'new-note.md',+ kind: 'file',+ path: '/new-location/Reports/new-note.md',+ version: 1,+ bytes: 12,+ },+ ]+ : [],+ nextCursor: null,+ })),+ affordances: vi.fn(async () => ({+ held: [],+ canDelegate: false,+ grantableBits: [],+ canCreateShare: false,+ })),+ },+ },+ })++ const { client, rerender } = renderHarness()+ const location = () => screen.getByRole('navigation', { name: 'File location' }).textContent+ await waitFor(() => expect(location()).toContain('Old location'))+ expect(location()).toContain('Reports')+ expect(await screen.findByText('This folder is empty')).toBeTruthy()++ moved = true+ await act(async () => {+ rerender(+ <AuthContext.Provider value={authValue()}>+ <QueryClientProvider client={client}>+ <FilesTabHarness remoteGfsChangeEpoch={1} />+ </QueryClientProvider>+ </AuthContext.Provider>+ )+ })++ expect(await screen.findByText('new-note.md')).toBeTruthy()+ await waitFor(() => expect(location()).toContain('New location'))+ expect(location()).toContain('Reports')+ expect(location()).not.toContain('Old location')+ })++ it('clears an open folder and cached rows when remote authorization is revoked', async () => {+ const denial = await resolveDeniedMessage(SEED_URI)+ let revoked = false+ Object.defineProperty(window, 'clerum', {+ configurable: true,+ value: {+ gfs: {+ listAccessible: vi.fn(async () => ({ items: [], nextCursor: null })),+ resolve: vi.fn(async (uri: string) => {+ if (revoked) throw new Error(denial)+ if (uri !== SEED_URI) throw new Error(`Unexpected GFS resolve URI: ${uri}`)+ return {+ resourceId: 'folder-current',+ gfsUri: SEED_URI,+ drive: 'main',+ name: 'Private folder',+ kind: 'directory',+ parentResourceId: null,+ version: 1,+ }+ }),+ listChildren: vi.fn(async () => {+ if (revoked) throw new Error(denial)+ return {+ items: [+ {+ resourceId: 'private-file',+ rid: 'private-file',+ gfsUri: 'gfs://main/private-file',+ drive: 'main',+ parentResourceId: 'folder-current',+ name: 'private-notes.md',+ kind: 'file',+ path: '/Private folder/private-notes.md',+ version: 1,+ bytes: 30,+ },+ ],+ nextCursor: null,+ }+ }),+ affordances: vi.fn(async () => ({+ held: [],+ canDelegate: false,+ grantableBits: [],+ canCreateShare: false,+ })),+ },+ },+ })++ const { client, rerender } = renderHarness()+ await screen.findByText('private-notes.md')+ expect(screen.getByRole('navigation', { name: 'File location' }).textContent).toContain(+ 'Private folder'+ )++ revoked = true+ await act(async () => {+ rerender(+ <AuthContext.Provider value={authValue()}>+ <QueryClientProvider client={client}>+ <FilesTabHarness remoteGfsChangeEpoch={1} />+ </QueryClientProvider>+ </AuthContext.Provider>+ )+ })++ await waitFor(() => {+ expect(screen.getByRole('navigation', { name: 'File location' }).textContent).toBe(+ 'Shared with me'+ )+ expect(screen.queryByText('private-notes.md')).toBeNull()+ })+ })})