Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): med-inherited-stale revalidate inherited access after an ancestry-changing move
M0b446aa23757
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsxindex ef32d6327..7d02f7f40 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx@@ -2748,6 +2748,23 @@ function ManageProbe() {<button type="button" onClick={() => swallow(ctrl.refreshShares())}>refresh shares</button>+ <button+ type="button"+ onClick={() =>+ swallow(+ ctrl.convergeCommittedMove(+ {+ resourceId: ctrl.crumbs[0]?.resourceId ?? '',+ destinationId: 'destination-1',+ oldParentId: null,+ },+ { version: 2 }+ )+ )+ }+ >+ move oldest ancestor+ </button><button type="button" onClick={() => swallow(ctrl.revokeShare('share-42'))}>revoke share</button>@@ -3209,6 +3226,79 @@ describe('useGfsBrowserController — grants list / revoke / inherit (#826)', ()expect(screen.getByTestId('inherited-error').textContent).toBe('none')})+ // A move changes the ANCESTRY of the open resource, and the open+ // Share/Manage dialog shows rows derived from that ancestry. The dialog must+ // re-read them: keeping the pre-move observation would present inherited+ // access that no longer exists.+ it('re-reads the open inherited access when a move affects its ancestry', async () => {+ const listGrants = vi.fn(async () => [])+ const listShares = vi.fn(async () => [])+ Object.defineProperty(window, 'clerum', {+ configurable: true,+ value: {+ gfs: {+ listAccessible: vi.fn(async () => ({ items: [], nextCursor: null })),+ resolve: vi.fn(async (uri: string) => {+ const id = uri.split('/').pop()!+ if (id === 'folder1') {+ return {+ resourceId: 'folder-1',+ parentResourceId: null,+ gfsUri: 'gfs://main/folder1',+ name: 'Team docs',+ kind: 'directory',+ version: 1,+ }+ }+ return {+ resourceId: 'file-1',+ parentResourceId: 'folder-1',+ gfsUri: 'gfs://main/file1',+ name: 'report.txt',+ kind: 'file',+ version: 1,+ }+ }),+ listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),+ affordances: vi.fn(async () => ({+ held: ['read', 'manage_acl'],+ canDelegate: true,+ grantableBits: ['read'],+ canCreateShare: false,+ })),+ listGrants,+ listShares,+ },+ },+ })++ render(<ManageProbe />, { wrapper: Harness })++ await act(async () => {+ screen.getByRole('button', { name: 'open root' }).click()+ })+ await waitFor(() => expect(screen.getByTestId('current').textContent).toBe('file-1'))+ await act(async () => {+ screen.getByRole('button', { name: 'open manage' }).click()+ })+ await waitFor(() => expect(listGrants).toHaveBeenCalled())++ const client = lastHarnessQueryClient!+ const scope = ':user-a:team-a'+ const inheritedKey = desktopQueryKeys.gfsInheritedAccess(scope, 'file-1', 'main')+ const inheritedQuery = client.getQueryCache().find({ queryKey: inheritedKey })!+ const before = inheritedQuery.state.dataUpdatedAt+ expect(before).toBeGreaterThan(0)++ // The oldest crumb is an ancestor of the open resource: moving it changes+ // what the open resource inherits.+ await act(async () => {+ screen.getByRole('button', { name: 'move oldest ancestor' }).click()+ })++ await waitFor(() => expect(inheritedQuery.state.dataUpdatedAt).not.toBe(before))+ })+// Every response and rejection crosses the real client/HTTP fixture seam.// The observable contract is session state and protected metadata, not a// briefly presented error string before the authority boundary clears it.diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.tsindex 441f0300c..6adf973a9 100644--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts@@ -1081,6 +1081,23 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {[current?.gfsUri, openUri])+ // The OPEN resource's inherited access is derived from its ANCESTRY. A move+ // of that resource — or of one of its ancestors — changes what it+ // inherits, so an open Share/Manage dialog must re-read those rows instead+ // of showing the pre-move observation. The trail is the ancestry this+ // session actually loaded; nothing outside it is claimed.+ const openAncestryDependentResourceIds = useCallback(+ (movedResourceId: string): string[] => {+ const openResourceId = current?.resourceId+ if (!openResourceId) return []+ const affectsOpenAncestry =+ movedResourceId === openResourceId ||+ crumbs.some(crumb => crumb.resourceId === movedResourceId)+ return affectsOpenAncestry ? [openResourceId] : []+ },+ [crumbs, current?.resourceId]+ )+// Move refreshes through the shared convergence planner (rev-2 §6): the// receipt selectively invalidates the old/new parent children listings and// accessible roots, and marks the moved resource plus its KNOWN cached@@ -1120,17 +1137,25 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {))if (sessionScope) {- applyMoveConvergence(queryClient, sessionScope, DRIVE, {- resourceId: input.resourceId,- oldParentId: input.oldParentId ?? null,- newParentId: input.destinationId,- })+ applyMoveConvergence(+ queryClient,+ sessionScope,+ DRIVE,+ {+ resourceId: input.resourceId,+ oldParentId: input.oldParentId ?? null,+ newParentId: input.destinationId,+ },+ {+ ancestryDependentResourceIds: openAncestryDependentResourceIds(input.resourceId),+ }+ )} else {await refreshGfs()}if (movedCrumb) await openUri(movedCrumb.gfsUri)},- [crumbs, openUri, queryClient, refreshGfs, sessionScope]+ [crumbs, openAncestryDependentResourceIds, openUri, queryClient, refreshGfs, sessionScope])const moveResourceMutation = useMutation({diff --git a/desktop-app/ui/src/lib/__tests__/gfsEntityChangeState.test.ts b/desktop-app/ui/src/lib/__tests__/gfsEntityChangeState.test.tsindex 539ed820e..b06c4236b 100644--- a/desktop-app/ui/src/lib/__tests__/gfsEntityChangeState.test.ts+++ b/desktop-app/ui/src/lib/__tests__/gfsEntityChangeState.test.ts@@ -1,5 +1,10 @@-import { describe, expect, it } from 'vitest'+import { describe, expect, it, vi } from 'vitest'+// ── selective move convergence (rev-2 drag-and-drop §6) ─────────────────────++import { QueryClient, QueryObserver } from '@tanstack/react-query'+import { desktopQueryKeys } from '@hooks/domain/queryKeys'import { markPluginGfsPreviewUnavailable } from '../gfsEntityChangeState'+import { applyMoveConvergence, collectKnownChildParents } from '../gfsEntityChangeState'describe('plugin preview unavailable reconciliation', () => {it('increments the reload identity once and preserves it on repeated invalidation', () => {@@ -31,12 +36,6 @@ describe('plugin preview unavailable reconciliation', () => {})})-// ── selective move convergence (rev-2 drag-and-drop §6) ─────────────────────--import { QueryClient } from '@tanstack/react-query'-import { applyMoveConvergence, collectKnownChildParents } from '../gfsEntityChangeState'-import { desktopQueryKeys } from '@hooks/domain/queryKeys'-const SCOPE = 'test:user-1:team-1'const DRIVE = 'main'@@ -83,10 +82,7 @@ describe('applyMoveConvergence', () => {it('invalidates old/new parent children and accessible, and marks known descendants stale without refetch', async () => {const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })seedChildren(queryClient, 'A', [{ resourceId: 'M' }])- seedChildren(queryClient, 'M', [- { resourceId: 'c1' },- { resourceId: 'c2', name: 'nested' },- ])+ seedChildren(queryClient, 'M', [{ resourceId: 'c1' }, { resourceId: 'c2', name: 'nested' }])seedChildren(queryClient, 'c1', [{ resourceId: 'c3' }])seedChildren(queryClient, 'B', [{ resourceId: 'unrelated' }])queryClient.setQueryData(desktopQueryKeys.gfsAccessible(SCOPE, DRIVE), {@@ -123,4 +119,64 @@ describe('applyMoveConvergence', () => {expect(stale(desktopQueryKeys.gfsChildren(SCOPE, 'M', DRIVE))).toBe(false)expect(stale(desktopQueryKeys.gfsAffordances(SCOPE, 'B', DRIVE))).toBe(false)})++ it('re-reads the inherited access of the moved resource and of an ancestry-dependent one', async () => {+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })+ // The OPEN Share/Manage dialog observes this resource's inherited rows.+ // An active observer is what makes the query "active" for the+ // invalidation below.+ const openKey = desktopQueryKeys.gfsInheritedAccess(SCOPE, 'open', DRIVE)+ let openReads = 0+ const openObserver = new QueryObserver(queryClient, {+ queryKey: openKey,+ queryFn: async () => {+ openReads += 1+ return { items: [], coverage: 'complete' }+ },+ })+ const unsubscribe = openObserver.subscribe(() => {})+ const openQuery = queryClient.getQueryCache().find({ queryKey: openKey })!+ await vi.waitFor(() => expect(openQuery.state.fetchStatus).toBe('idle'))+ expect(openReads).toBe(1)++ applyMoveConvergence(+ queryClient,+ SCOPE,+ DRIVE,+ { resourceId: 'ancestor', oldParentId: 'A', newParentId: 'B' },+ { ancestryDependentResourceIds: ['open'] }+ )++ // The dialog's rows were derived from an ancestry that no longer exists:+ // they are re-read, not merely marked stale.+ await vi.waitFor(() => expect(openReads).toBe(2))+ unsubscribe()+ })++ it('leaves an unrelated open inherited-access query alone', async () => {+ const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })+ const openKey = desktopQueryKeys.gfsInheritedAccess(SCOPE, 'open', DRIVE)+ let openReads = 0+ const openObserver = new QueryObserver(queryClient, {+ queryKey: openKey,+ queryFn: async () => {+ openReads += 1+ return { items: [], coverage: 'complete' }+ },+ })+ const unsubscribe = openObserver.subscribe(() => {})+ const openQuery = queryClient.getQueryCache().find({ queryKey: openKey })!+ await vi.waitFor(() => expect(openQuery.state.fetchStatus).toBe('idle'))+ expect(openReads).toBe(1)++ applyMoveConvergence(queryClient, SCOPE, DRIVE, {+ resourceId: 'unrelated',+ oldParentId: 'A',+ newParentId: 'B',+ })++ await Promise.resolve()+ expect(openReads).toBe(1)+ unsubscribe()+ })})diff --git a/desktop-app/ui/src/lib/gfsEntityChangeState.ts b/desktop-app/ui/src/lib/gfsEntityChangeState.tsindex dee789c98..ead25034a 100644--- a/desktop-app/ui/src/lib/gfsEntityChangeState.ts+++ b/desktop-app/ui/src/lib/gfsEntityChangeState.ts@@ -57,6 +57,17 @@ export interface GfsMoveReceiptInput {newParentId: string | null}+/**+ * Resources whose INHERITED access depends on the moved resource's ancestry.+ * The open Share/Manage dialog is the live instance: when the moved item is+ * that resource or one of its ancestors, the rows it shows were derived from+ * a chain that no longer exists, and the dialog must re-read them instead of+ * keeping the pre-move observation.+ */+export interface GfsMoveConvergenceOptions {+ ancestryDependentResourceIds?: readonly string[]+}+/*** Collect the child→parent links currently present in cached children* listings (an observation of what this session has loaded — never a claim@@ -97,12 +108,19 @@ export function collectKnownChildParents(* (affordances, grants, shares, inherited access) without eager refetches.* Local receipts and remote hints converge through the same cache; there is* deliberately no echo matching (user hint frames carry no operation ids).+ *+ * Inherited access is the ONE family that is re-read rather than marked+ * stale: it is derived from the resource's ANCESTRY, so a move of the+ * resource or of one of its ancestors invalidates the rows an OPEN+ * Share/Manage dialog is showing. `refetchType: 'active'` keeps that+ * bounded — only a mounted dialog refetches; the rest stay stale-on-entry.*/export function applyMoveConvergence(queryClient: QueryClient,scope: string,drive: string,- receipt: GfsMoveReceiptInput+ receipt: GfsMoveReceiptInput,+ options: GfsMoveConvergenceOptions = {}): void {const known = { childParentByResourceId: collectKnownChildParents(queryClient, scope, drive) }const plan = planMoveConvergence(receipt, known)@@ -135,10 +153,16 @@ export function applyMoveConvergence(queryKey: desktopQueryKeys.gfsShares(scope, resourceId, drive),refetchType: 'none',})+ }+ const inheritedAccessResourceIds = new Set([+ ...plan.staleResourceIds,+ ...(options.ancestryDependentResourceIds ?? []),+ ])+ for (const resourceId of inheritedAccessResourceIds) {void queryClient.invalidateQueries({exact: true,queryKey: desktopQueryKeys.gfsInheritedAccess(scope, resourceId, drive),- refetchType: 'none',+ refetchType: 'active',})}}