Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): r1-m4 stale drop cleanup cannot clear a newer gesture
Mb75705832567
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 691261ebe..7e3325c5a 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@@ -17,9 +17,14 @@ import {} from '@/gfs/__fixtures__/gfsProducerFixtures'// ── drag-and-drop (rev-2 D1) ─────────────────────────────────────────────────-import { GfsDragSessionProvider } from '@/gfs/dragSession'+import { GfsDragSessionProvider, useGfsDragSession } from '@/gfs/dragSession'import { FileExplorerTree } from '..'+function SessionProbe({ onApi }: { onApi: (api: ReturnType<typeof useGfsDragSession>) => void }) {+ onApi(useGfsDragSession())+ return null+}+// useGfsBrowserController only reads { isAuthenticated, me, runtimeConfigState }// from AuthContext. Mock just those so the tree's controller instance stands up// without the full provider tree.@@ -909,6 +914,176 @@ describe('FileExplorerTree — drag-and-drop moves', () => {expect(screen.queryByRole('dialog', { name: 'Move folder A to C' })).toBeNull()})+ it('a stale drop’s cleanup does not clear a newer gesture in the tree', async () => {+ // R1-M4: gesture A’s drop adjudication is pending when gesture B starts on+ // the same surface. A’s late resolution must return without ending B: B’s+ // drop must still open the confirmation for B.+ const moveResource = vi.fn(async () => ({ resourceId: 'folderb', version: 9 }))+ type Affordances = { held: string[] }+ let releaseA!: (value: Affordances) => void+ const gatedA = new Promise<Affordances>(resolve => {+ releaseA = resolve+ })+ let aProbePending = true+ const affordances = vi.fn((): Promise<Affordances> => {+ if (aProbePending) {+ aProbePending = false+ return gatedA+ }+ return Promise.resolve({ held: ['read', 'write', 'delete'] })+ })+ const resolve = vi.fn(async (uri: string) => {+ const id = uri.split('/').pop()+ const parent = id === 'grand' ? null : 'grand'+ const name =+ id === 'foldera' ? 'A' : id === 'folderb' ? 'B' : id === 'folderc' ? 'C' : 'Grand'+ return {+ drive: 'main',+ resourceId: id === 'grand' ? 'grand' : id,+ parentResourceId: parent,+ name,+ kind: 'directory',+ version: id === 'foldera' ? 4 : 1,+ }+ })+ installDndClerum({+ listAccessible: vi.fn(async () =>+ listAccessiblePage([+ accessibleResource('foldera', 'A', 'directory', { version: 4 }),+ accessibleResource('folderb', 'B', 'directory'),+ accessibleResource('folderc', 'C', 'directory'),+ ])+ ),+ affordances,+ resolve,+ moveResource,+ })+ renderTreeWithSession()++ const rowA = await screen.findByRole('button', { name: 'A' })+ const rowB = await screen.findByRole('button', { name: 'B' })+ const rowC = await screen.findByRole('button', { name: 'C' })+ const dataTransfer = dragTypes()+ const cRow = rowC.closest('[role="treeitem"]')!.querySelector('.da-file-explorer__row')!++ // Gesture A: its drop adjudication parks on the gated affordances probe.+ fireEvent.dragStart(rowA, { dataTransfer })+ fireEvent.drop(cRow, { dataTransfer })++ // Gesture B starts before A’s adjudication resolves (supersedes A).+ fireEvent.dragStart(rowB, { dataTransfer })++ // A resolves late: wrong epoch — no dialog for A, no commit, no cleanup+ // of B.+ await act(async () => {+ releaseA({ held: ['read', 'write'] })+ })+ expect(screen.queryByRole('dialog', { name: 'Move folder A to C' })).toBeNull()+ expect(moveResource).not.toHaveBeenCalled()++ // B’s drop is still operable and confirms B’s move.+ fireEvent.drop(cRow, { dataTransfer })+ await screen.findByRole('dialog', { name: 'Move folder B to C' })+ })++ it('a stale drop’s cleanup releases only its own shared-store gesture', async () => {+ // R1-M4 cross-surface: A’s drop is pending in the tree when another+ // surface begins gesture B (here driven through the session api). A’s+ // surface epoch is unchanged, so A’s own dialog legitimately opens — but+ // its cleanup must not endDrag the shared store now owned by B.+ const moveResource = vi.fn(async () => ({ resourceId: 'foldera', version: 9 }))+ type Affordances = { held: string[] }+ let releaseA!: (value: Affordances) => void+ const gatedA = new Promise<Affordances>(resolve => {+ releaseA = resolve+ })+ let aProbePending = true+ const affordances = vi.fn((): Promise<Affordances> => {+ if (aProbePending) {+ aProbePending = false+ return gatedA+ }+ return Promise.resolve({ held: ['read', 'write', 'delete'] })+ })+ const resolve = vi.fn(async (uri: string) => {+ const id = uri.split('/').pop()+ const parent = id === 'grand' ? null : 'grand'+ const name = id === 'foldera' ? 'A' : id === 'folderc' ? 'C' : 'Grand'+ return {+ drive: 'main',+ resourceId: id === 'grand' ? 'grand' : id,+ parentResourceId: parent,+ name,+ kind: 'directory',+ version: 1,+ }+ })+ installDndClerum({+ listAccessible: vi.fn(async () =>+ listAccessiblePage([+ accessibleResource('foldera', 'A', 'directory', { version: 1 }),+ accessibleResource('folderc', 'C', 'directory'),+ ])+ ),+ affordances,+ resolve,+ moveResource,+ })+ let sessionApi: ReturnType<typeof useGfsDragSession> | null = null+ const onOpenFolder = vi.fn()+ const onOpenPreview = vi.fn()+ const pushToast = vi.fn()+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })+ render(+ <QueryClientProvider client={queryClient}>+ <GfsDragSessionProvider>+ <FileExplorerTree+ onOpenFolder={onOpenFolder}+ onOpenPreview={onOpenPreview}+ pushToast={pushToast}+ />+ <SessionProbe onApi={api => (sessionApi = api)} />+ </GfsDragSessionProvider>+ </QueryClientProvider>+ )++ const rowA = await screen.findByRole('button', { name: 'A' })+ const rowC = await screen.findByRole('button', { name: 'C' })+ const dataTransfer = dragTypes()+ const cRow = rowC.closest('[role="treeitem"]')!.querySelector('.da-file-explorer__row')!++ // Gesture A (this surface): drop adjudication parks on the gated probe.+ fireEvent.dragStart(rowA, { dataTransfer })+ fireEvent.drop(cRow, { dataTransfer })++ // The OTHER surface begins gesture B: the shared store superscedes, but+ // this surface’s epoch is untouched.+ expect(+ sessionApi!.beginDrag({+ resourceId: 'file-external',+ gfsUri: 'gfs://main/file-external',+ drive: 'main',+ kind: 'file',+ name: 'ext.txt',+ parentKnown: true,+ parentResourceId: 'grand',+ knownAncestorIds: ['grand'],+ origin: 'files',+ scope: 'test:user-1:team-1',+ })+ ).toBe(true)++ // A resolves late: its surface epoch is unchanged, so A’s own+ // confirmation legitimately opens.+ await act(async () => {+ releaseA({ held: ['read', 'write'] })+ })+ await screen.findByRole('dialog', { name: 'Move folder A to C' })++ // A’s cleanup must not have ended the shared store’s newer gesture.+ expect(sessionApi!.activeSource()?.resourceId).toBe('file-external')+ })+it('moves a dragged folder into an unrelated folder through the one confirmation', async () => {// Two directly-shared folders under one unshared common parent 'grand':// the drop must walk B's (bounded) ancestry, find the common anchor viadiff --git a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsxindex 6ce61c40b..c6c75e28c 100644--- a/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx+++ b/desktop-app/ui/src/components/SidebarNav/FileExplorerTree/index.tsx@@ -481,6 +481,27 @@ export function FileExplorerTree({setDropStatesByResourceId({})}, [adjudication, dragSession])+ /** Drop-path cleanup owned by the gesture that started the drop: a newer+ * gesture on THIS surface (epoch advanced) owns every local ref and timer,+ * and a newer gesture on ANY surface (shared generation advanced) owns the+ * session store. The unconditional native-dragend clear above stays. */+ const finishNodeDropCleanup = useCallback(+ (epoch: number, sessionGeneration: number | null) => {+ if (epoch !== dragSessionEpochRef.current) return+ draggingSourceRef.current = null+ setDropStatesByResourceId({})+ if (+ dragSession &&+ sessionGeneration !== null &&+ dragSession.currentGeneration() === sessionGeneration+ ) {+ dragSession.endDrag()+ }+ adjudication.endDragSession()+ },+ [adjudication, dragSession, dragSessionEpochRef]+ )+const treeDragSourceFrom = useCallback((node: GfsBrowserChild,@@ -687,6 +708,7 @@ export function FileExplorerTree({const source = resolveActiveSource()if (!source || node.kind !== 'directory' || movingResourceIdRef.current) returnconst epoch = dragSessionEpochRef.current+ const sessionGeneration = dragSession?.currentGeneration() ?? nulltry {const decision = await adjudication.adjudicateDrop(source, {resourceId: node.resourceId,@@ -714,10 +736,17 @@ export function FileExplorerTree({decision.allowNumberedRename)} finally {- clearDragState()+ finishNodeDropCleanup(epoch, sessionGeneration)}},- [adjudication, clearDragState, commitMove, dragSessionEpochRef, pushToast, resolveActiveSource]+ [+ adjudication,+ finishNodeDropCleanup,+ commitMove,+ dragSessionEpochRef,+ pushToast,+ resolveActiveSource,+ ])const handleRequestMove = useCallback(diff --git a/desktop-app/ui/src/gfs/dragSession.tsx b/desktop-app/ui/src/gfs/dragSession.tsxindex 8d400650d..0aa7c6b37 100644--- a/desktop-app/ui/src/gfs/dragSession.tsx+++ b/desktop-app/ui/src/gfs/dragSession.tsx@@ -117,6 +117,7 @@ export function GfsDragSessionProvider({ children }: { children: React.ReactNodeactiveSource: () => store.activeSource(),matchesScope: candidate => store.matchesScope(candidate),invalidate: reason => store.invalidate(reason),+ currentGeneration: () => store.currentGeneration(),}),[accessState, scope, store])diff --git a/desktop-app/ui/src/gfs/dragSession.types.ts b/desktop-app/ui/src/gfs/dragSession.types.tsindex 8093f6823..0563b52e3 100644--- a/desktop-app/ui/src/gfs/dragSession.types.ts+++ b/desktop-app/ui/src/gfs/dragSession.types.ts@@ -88,4 +88,7 @@ export interface GfsDragSessionApi {/** True while the stored source belongs to the caller's live scope. */matchesScope(scope: string | null): booleaninvalidate(reason: 'authority' | 'scope-change'): void+ /** Monotonic gesture counter; lets a surface release the shared store only+ * when the store still belongs to the gesture that captured it. */+ currentGeneration(): number}diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsxindex 97345b83b..a133c35a8 100644--- a/desktop-app/ui/src/pages/FilesPage.tsx+++ b/desktop-app/ui/src/pages/FilesPage.tsx@@ -984,6 +984,28 @@ export function FilesPage({setDropStatesById({})}+ /** Drop-path cleanup owned by the gesture that started the drop: a newer+ * gesture on THIS surface (epoch advanced) owns every local ref and timer,+ * and a newer gesture on ANY surface (shared generation advanced) owns the+ * session store. The unconditional native-dragend clear above stays. */+ const finishDropCleanup = (gestureGeneration: number, sessionGeneration: number | null) => {+ if (gestureGeneration !== dragSessionRef.current) return+ draggingResourceRef.current = null+ draggingSourceRef.current = null+ hoveredFolderRef.current = null+ setDraggingResourceId(null)+ setDragOverFolderId(null)+ setDropStatesById({})+ if (+ dragSession &&+ sessionGeneration !== null &&+ dragSession.currentGeneration() === sessionGeneration+ ) {+ dragSession.endDrag()+ }+ adjudication.endDragSession()+ }+/** Ancestor chain of rows in the current listing, nearest-first: the open* folder and its breadcrumb ancestors (an observation, never a guess). */const rowTargetAncestorIds = (): (string | null)[] =>@@ -1239,6 +1261,7 @@ export function FilesPage({if (!source || destination.kind !== 'directory' || movingResourceRef.current) returnconst dragGeneration = dragSessionRef.current+ const sessionGeneration = dragSession?.currentGeneration() ?? nulltry {const decision = await adjudication.adjudicateDrop(source, {resourceId: destination.resourceId,@@ -1271,7 +1294,7 @@ export function FilesPage({decision.allowNumberedRename)} finally {- clearResourceDrag()+ finishDropCleanup(dragGeneration, sessionGeneration)}}diff --git a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsxindex c457ad2a8..a0c678566 100644--- a/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx+++ b/desktop-app/ui/src/pages/__tests__/FilesPage.test.tsx@@ -3896,6 +3896,152 @@ describe('FilesPage', () => {)})+ it('a stale drop’s cleanup does not clear a newer gesture', async () => {+ // R1-M4: gesture A’s drop adjudication is still pending when gesture B+ // starts on the same surface. A’s late resolution must return without+ // cleaning up B: B’s hover state stays, and B’s drop still commits B.+ const pushToast = vi.fn()+ const moveResource = vi.fn(async (_resourceId: string, _destinationId: string) => ({}))+ type Affordances = {+ held: string[]+ canDelegate: boolean+ grantableBits: string[]+ canCreateShare: boolean+ }+ let releaseA!: (value: Affordances) => void+ const gatedA = new Promise<Affordances>(resolve => {+ releaseA = resolve+ })+ let aProbePending = true+ const affordances = vi.fn((): Promise<Affordances> => {+ if (aProbePending) {+ aProbePending = false+ return gatedA+ }+ return Promise.resolve({+ held: ['read', 'write', 'delete'],+ canDelegate: false,+ grantableBits: [],+ canCreateShare: false,+ })+ })+ Object.defineProperty(window, 'clerum', {+ configurable: true,+ value: {+ gfs: {+ affordances,+ resolve: vi.fn(async (uri: string) => {+ const id = uri.split('/').pop() ?? ''+ return {+ resourceId: id,+ gfsUri: uri,+ kind: 'file',+ name: id === 'file-2' ? 'b.txt' : 'a.txt',+ version: 3,+ parentResourceId: 'folder-1',+ }+ }),+ },+ },+ })+ hookMock.useGfsBrowserController.mockReturnValue({+ ...baseController(),+ current: {+ resourceId: 'folder-1',+ gfsUri: 'gfs://main/folder-1',+ name: 'Product',+ kind: 'directory',+ version: 1,+ },+ items: [+ {+ resourceId: 'file-1',+ rid: 'file-1',+ gfsUri: 'gfs://main/file-1',+ drive: 'main',+ parentResourceId: 'folder-1',+ name: 'a.txt',+ kind: 'file',+ path: '/Product/a.txt',+ version: 3,+ bytes: 12,+ },+ {+ resourceId: 'file-2',+ rid: 'file-2',+ gfsUri: 'gfs://main/file-2',+ drive: 'main',+ parentResourceId: 'folder-1',+ name: 'b.txt',+ kind: 'file',+ path: '/Product/b.txt',+ version: 3,+ bytes: 12,+ },+ {+ resourceId: 'dest-1',+ rid: 'dest-1',+ gfsUri: 'gfs://main/dest-1',+ drive: 'main',+ parentResourceId: 'folder-1',+ name: 'Dest',+ kind: 'directory',+ path: '/Product/Dest',+ version: 2,+ bytes: 0,+ },+ ],+ moveResource,+ })+ renderFilesPage(pushToast)++ const rowA = screen.getByRole('button', { name: 'Open a.txt' })+ const rowB = screen.getByRole('button', { name: 'Open b.txt' })+ const destinationRow = screen.getByRole('button', { name: 'Open Dest' })+ const dataTransfer = {+ types: ['application/x-evenfire-gfs-resource'],+ files: [],+ effectAllowed: 'none',+ dropEffect: 'none',+ setData: vi.fn(),+ }++ // Gesture A: drop adjudication parks on the gated affordances probe.+ fireEvent.dragStart(rowA, { dataTransfer })+ fireEvent.dragOver(destinationRow, { dataTransfer })+ fireEvent.drop(destinationRow, { dataTransfer })++ // Gesture B starts before A’s adjudication resolves; its hover is live.+ fireEvent.dragStart(rowB, { dataTransfer })+ fireEvent.dragOver(destinationRow, { dataTransfer })+ await waitFor(() => expect(destinationRow.getAttribute('data-drop-state')).toBe('checking'))++ // A resolves late: it must return (wrong generation) and clean up nothing.+ await act(async () => {+ releaseA({+ held: ['read', 'write', 'delete'],+ canDelegate: false,+ grantableBits: [],+ canCreateShare: false,+ })+ })+ expect(moveResource).not.toHaveBeenCalledWith(+ 'file-1',+ 'dest-1',+ expect.anything(),+ expect.anything()+ )+ // B’s hover state survived A’s stale cleanup.+ expect(destinationRow.getAttribute('data-drop-state')).toBe('checking')++ // B’s drop is still operable and commits B.+ fireEvent.drop(destinationRow, { dataTransfer })+ await waitFor(() => expect(moveResource).toHaveBeenCalled())+ expect(moveResource.mock.calls[0]![0]).toBe('file-2')+ expect(moveResource.mock.calls[0]![1]).toBe('dest-1')+ await waitFor(() => expect(pushToast).toHaveBeenCalledWith('Moved b.txt to Dest', 'success'))+ })+it('presents a rate-limited drop check in the shared read-plane words', async () => {// The affordances check is one of the nine methods `surfaceGfsGrantError`// wraps, so its rejection reaches the renderer as the IPC wrapper plus the