Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(desktop): rp-005-residual share the open location across GFS controllers
M4f1f0c57df1a
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsxindex 10a633198..b290864a7 100644--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx@@ -3483,3 +3483,135 @@ describe('useGfsBrowserController — grants list / revoke / inherit (#826)', ()}}})++// A move committed by ONE surface must reach the Share/Manage dialog ANOTHER+// surface has open. The Files page opened a deep descendant by URI — its+// ancestry lives in ITS controller, and the children caches that could+// connect it to the moved ancestor were never loaded — while the sidebar, a+// SEPARATE controller with its own crumbs, moves that ancestor.+function TwoSurfaceProbe() {+ const [manageOpen, setManageOpen] = useState(false)+ const files = useGfsBrowserController({ grantsListEnabled: manageOpen })+ const sidebar = useGfsBrowserController()+ return (+ <>+ <div data-testid="files-current">{files.current?.resourceId ?? 'none'}</div>+ <div data-testid="files-crumbs">+ {files.crumbs.map(crumb => crumb.resourceId).join(' / ')}+ </div>+ <button type="button" onClick={() => swallow(files.openUri('gfs://main/leaf1'))}>+ open leaf+ </button>+ <button type="button" onClick={() => setManageOpen(true)}>+ open manage+ </button>+ <button+ type="button"+ onClick={() =>+ swallow(+ sidebar.convergeCommittedMove(+ {+ resourceId: 'ancestor-1',+ destinationId: 'destination-1',+ oldParentId: null,+ },+ { version: 2 }+ )+ )+ }+ >+ move ancestor+ </button>+ </>+ )+}++describe('useGfsBrowserController — cross-surface move convergence (RP-005)', () => {+ afterEach(() => {+ cleanup()+ lastHarnessQueryClient = null+ vi.restoreAllMocks()+ })++ it("re-reads another surface's 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 === 'leaf1') {+ return {+ resourceId: 'leaf-1',+ parentResourceId: 'parent-1',+ gfsUri: 'gfs://main/leaf1',+ name: 'leaf.txt',+ kind: 'file',+ version: 1,+ }+ }+ if (id === 'parent1') {+ return {+ resourceId: 'parent-1',+ parentResourceId: 'ancestor-1',+ gfsUri: 'gfs://main/parent1',+ name: 'Parent',+ kind: 'directory',+ version: 1,+ }+ }+ return {+ resourceId: 'ancestor-1',+ parentResourceId: null,+ gfsUri: 'gfs://main/ancestor1',+ name: 'Ancestor',+ kind: 'directory',+ version: 1,+ }+ }),+ // No children listing is ever loaded, so the shared cache holds no+ // child→parent link that could connect the open leaf to its+ // ancestor: the ancestry exists only in the Files controller.+ listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),+ affordances: vi.fn(async () => ({+ held: ['read', 'manage_acl'],+ canDelegate: true,+ grantableBits: ['read'],+ canCreateShare: false,+ })),+ listGrants,+ listShares,+ },+ },+ })++ render(<TwoSurfaceProbe />, { wrapper: Harness })++ await act(async () => {+ screen.getByRole('button', { name: 'open leaf' }).click()+ })+ await waitFor(() => expect(screen.getByTestId('files-current').textContent).toBe('leaf-1'))+ expect(screen.getByTestId('files-crumbs').textContent).toBe('ancestor-1 / parent-1 / leaf-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, 'leaf-1', 'main')+ const inheritedQuery = client.getQueryCache().find({ queryKey: inheritedKey })!+ const before = inheritedQuery.state.dataUpdatedAt+ expect(before).toBeGreaterThan(0)++ // The OTHER surface moves the open leaf's ancestor.+ await act(async () => {+ screen.getByRole('button', { name: 'move ancestor' }).click()+ })++ await waitFor(() => expect(inheritedQuery.state.dataUpdatedAt).not.toBe(before))+ })+})diff --git a/desktop-app/ui/src/hooks/domain/queryKeys.ts b/desktop-app/ui/src/hooks/domain/queryKeys.tsindex d3a61acd8..c0b84617a 100644--- a/desktop-app/ui/src/hooks/domain/queryKeys.ts+++ b/desktop-app/ui/src/hooks/domain/queryKeys.ts@@ -35,6 +35,16 @@ export const desktopQueryKeys = {['desktop-app', 'gfs', sessionScope, 'shares', drive, resourceId] as const,gfsInheritedAccess: (sessionScope: string, resourceId: string, drive: string) =>['desktop-app', 'gfs', sessionScope, 'inherited-access', drive, resourceId] as const,+ // Open GFS locations, SHARED across every controller mount (the sidebar+ // tree, FilesPage, FilePreviewPage) via the query cache: each mount+ // publishes the resource it has open together with the ancestry it+ // observed, so a move committed by ONE surface can tell that it changes+ // what ANOTHER surface's open Share/Manage dialog inherits. Kept OUTSIDE+ // the `gfsRoot` prefix on purpose: the fail-closed purge removes+ // everything under `gfsRoot`, and the registry must survive that purge+ // (the mounts republish it as their access state settles).+ gfsOpenLocations: (sessionScope: string) =>+ ['desktop-app', 'gfs-open-locations', sessionScope] as const,// Proactive connectors panel (spec 11 U2). Invalidated on connect/disconnect// completion (U3/U4) so the tri-state re-reads the authoritative grant store.connectors: ['desktop-app', 'connectors'] as const,diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.tsindex 1e42e3ad2..f232af6f8 100644--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts@@ -17,6 +17,13 @@ import {parseHttpStatus,parseRetryAfterSeconds,} from '@lib/gfsGrantErrors'+import {+ type GfsOpenLocationRegistry,+ ancestryDependentGfsResourceIds,+ nextGfsOpenLocationId,+ publishGfsOpenLocation,+ readGfsOpenLocations,+} from '@lib/gfsOpenLocations'import type {GfsGrantListItem,GfsInheritedAccessResult,@@ -340,6 +347,49 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {[queryClient, sessionScope])+ // The open location is CLIENT state, not server state: it records which+ // resource this mount has open and the ancestry this mount observed. It is+ // published through the query cache so EVERY mount sees it — a move+ // committed by the sidebar must be able to tell that it changes what the+ // Files page's open Share/Manage dialog inherits (RP-005).+ //+ // The subscription exists only to keep the cache entry alive: an+ // unobserved entry is garbage-collected while the app is idle, and the+ // registry would silently empty itself. `notifyOnChangeProps: []` keeps+ // another mount's publish from re-rendering this one — the registry is+ // read imperatively, never rendered.+ useQuery({+ queryKey: desktopQueryKeys.gfsOpenLocations(sessionScope ?? 'anonymous'),+ queryFn: async () => ({}) as GfsOpenLocationRegistry,+ enabled: false,+ initialData: {} as GfsOpenLocationRegistry,+ gcTime: Infinity,+ staleTime: Infinity,+ notifyOnChangeProps: [],+ })+ // One identity per controller mount: the registry holds an entry per+ // mount, and a mount that navigates replaces only its own entry.+ const openLocationIdRef = useRef<string | null>(null)+ if (openLocationIdRef.current === null) openLocationIdRef.current = nextGfsOpenLocationId()+ const openLocationId = openLocationIdRef.current+ useEffect(() => {+ if (!sessionScope) return+ // The ancestry this mount observed is the trail it loaded: the open+ // resource's ancestors, nearest first. A revoked session has no open+ // location to claim.+ const location =+ accessState === 'active' && current+ ? {+ resourceId: current.resourceId,+ ancestorResourceIds: crumbs.slice(0, -1).map(crumb => crumb.resourceId),+ }+ : null+ publishGfsOpenLocation(queryClient, sessionScope, openLocationId, location)+ return () => {+ publishGfsOpenLocation(queryClient, sessionScope, openLocationId, null)+ }+ }, [accessState, crumbs, current?.resourceId, openLocationId, queryClient, sessionScope])+useEffect(() => {const previous = previousSessionScopeRef.currentif (previous === sessionScope) return@@ -1098,18 +1148,23 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {// 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.+ // of showing the pre-move observation.+ //+ // The ancestry is read from the SHARED open-location registry, not from+ // this mount's own crumbs: the dialog that shows those rows can live in+ // ANOTHER controller (the Files page) while the move is committed by this+ // one (the sidebar). Controller-local crumbs only ever proved the chain+ // this mount observed, and a resource opened by URI has ancestors that no+ // children cache ever listed (RP-005).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] : []+ if (!sessionScope) return []+ return ancestryDependentGfsResourceIds(+ readGfsOpenLocations(queryClient, sessionScope),+ movedResourceId+ )},- [crumbs, current?.resourceId]+ [queryClient, sessionScope])// Move refreshes through the shared convergence planner (rev-2 §6): thediff --git a/desktop-app/ui/src/lib/__tests__/gfsOpenLocations.test.ts b/desktop-app/ui/src/lib/__tests__/gfsOpenLocations.test.tsnew file mode 100644index 000000000..136551595--- /dev/null+++ b/desktop-app/ui/src/lib/__tests__/gfsOpenLocations.test.ts@@ -0,0 +1,68 @@+import { describe, expect, it } from 'vitest'+import { QueryClient } from '@tanstack/react-query'+import { desktopQueryKeys } from '@hooks/domain/queryKeys'+import {+ ancestryDependentGfsResourceIds,+ nextGfsOpenLocationId,+ publishGfsOpenLocation,+ readGfsOpenLocations,+} from '../gfsOpenLocations'++const SCOPE = 'test:user-1:team-1'+const OTHER_SCOPE = 'test:user-1:team-2'++describe('gfsOpenLocations', () => {+ it('gives every controller mount its own registry identity', () => {+ expect(nextGfsOpenLocationId()).not.toBe(nextGfsOpenLocationId())+ })++ it("publishes and retracts one mount's open location per session scope", () => {+ const queryClient = new QueryClient()+ publishGfsOpenLocation(queryClient, SCOPE, 'mount-a', {+ resourceId: 'leaf-1',+ ancestorResourceIds: ['ancestor-1'],+ })+ publishGfsOpenLocation(queryClient, SCOPE, 'mount-b', {+ resourceId: 'other-1',+ ancestorResourceIds: [],+ })++ expect(readGfsOpenLocations(queryClient, SCOPE)).toEqual([+ { resourceId: 'leaf-1', ancestorResourceIds: ['ancestor-1'] },+ { resourceId: 'other-1', ancestorResourceIds: [] },+ ])++ // A mount that closes its location retracts only its own entry.+ publishGfsOpenLocation(queryClient, SCOPE, 'mount-a', null)+ expect(readGfsOpenLocations(queryClient, SCOPE)).toEqual([+ { resourceId: 'other-1', ancestorResourceIds: [] },+ ])++ // Another session scope never sees another scope's locations.+ expect(readGfsOpenLocations(queryClient, OTHER_SCOPE)).toEqual([])+ })++ it('claims only the resources whose observed ancestry contains the moved resource', () => {+ const locations = [+ { resourceId: 'leaf-1', ancestorResourceIds: ['ancestor-1', 'parent-1'] },+ { resourceId: 'sibling-1', ancestorResourceIds: ['parent-1'] },+ { resourceId: 'moved-1', ancestorResourceIds: [] },+ ]++ expect(ancestryDependentGfsResourceIds(locations, 'ancestor-1')).toEqual(['leaf-1'])+ expect(ancestryDependentGfsResourceIds(locations, 'parent-1')).toEqual(['leaf-1', 'sibling-1'])+ expect(ancestryDependentGfsResourceIds(locations, 'moved-1')).toEqual(['moved-1'])+ expect(ancestryDependentGfsResourceIds(locations, 'unrelated-1')).toEqual([])+ })++ it('keeps the registry inside the shared query cache', () => {+ const queryClient = new QueryClient()+ publishGfsOpenLocation(queryClient, SCOPE, 'mount-a', {+ resourceId: 'leaf-1',+ ancestorResourceIds: [],+ })+ expect(queryClient.getQueryData(desktopQueryKeys.gfsOpenLocations(SCOPE))).toMatchObject({+ 'mount-a': { resourceId: 'leaf-1' },+ })+ })+})diff --git a/desktop-app/ui/src/lib/gfsOpenLocations.ts b/desktop-app/ui/src/lib/gfsOpenLocations.tsnew file mode 100644index 000000000..7601f4388--- /dev/null+++ b/desktop-app/ui/src/lib/gfsOpenLocations.ts@@ -0,0 +1,93 @@+import type { QueryClient } from '@tanstack/react-query'+import { desktopQueryKeys } from '@hooks/domain/queryKeys'++/**+ * The resource one controller mount has open, together with the ancestry+ * that mount observed on the way there.+ *+ * Every GFS surface mounts its OWN controller (the sidebar tree, the Files+ * page, the preview page, the composer's file modal), so the ancestry of an+ * open resource exists ONLY in the controller that opened it. A resource+ * opened by URI has ancestors that no children listing ever named, so the+ * shared children cache cannot connect it to the folder that was moved:+ * the observed chain is the only record of it.+ *+ * Publishing the open location makes that chain shared: a move committed by+ * ONE surface can then see that it changes what ANOTHER surface's open+ * Share/Manage dialog inherits.+ */+export type GfsOpenLocation = {+ /** The resource this mount has open. */+ resourceId: string+ /** The ancestors this mount observed, nearest first. */+ ancestorResourceIds: string[]+}++/** One entry per controller mount, keyed by that mount's identity. */+export type GfsOpenLocationRegistry = Record<string, GfsOpenLocation>++let openLocationCounter = 0++/** A stable identity for one controller mount's entry in the registry. */+export function nextGfsOpenLocationId(): string {+ openLocationCounter += 1+ return `gfs-open-location-${openLocationCounter}`+}++/**+ * Publish (or retract) one controller mount's open location.+ *+ * A `null` location retracts the entry: the mount has nothing open, its+ * session was revoked, or it unmounted.+ */+export function publishGfsOpenLocation(+ queryClient: QueryClient,+ sessionScope: string,+ locationId: string,+ location: GfsOpenLocation | null+): void {+ queryClient.setQueryData<GfsOpenLocationRegistry>(+ desktopQueryKeys.gfsOpenLocations(sessionScope),+ previous => {+ const next: GfsOpenLocationRegistry = { ...(previous ?? {}) }+ if (location) next[locationId] = location+ else delete next[locationId]+ return next+ }+ )+}++/** Every open location published in this session scope. */+export function readGfsOpenLocations(+ queryClient: QueryClient,+ sessionScope: string+): GfsOpenLocation[] {+ const registry = queryClient.getQueryData<GfsOpenLocationRegistry>(+ desktopQueryKeys.gfsOpenLocations(sessionScope)+ )+ return registry ? Object.values(registry) : []+}++/**+ * The open resources whose inherited access depends on the moved resource's+ * ancestry: the resource itself, or any resource below it.+ *+ * Only a chain that was OBSERVED counts. A resource whose ancestry no+ * surface observed is not claimed to depend on the move — an unproven link+ * is not evidence, and claiming it would re-read rows that cannot change.+ */+export function ancestryDependentGfsResourceIds(+ locations: readonly GfsOpenLocation[],+ movedResourceId: string+): string[] {+ const dependent = new Set<string>()+ for (const location of locations) {+ if (+ location.resourceId === movedResourceId ||+ location.ancestorResourceIds.includes(movedResourceId)+ ) {+ dependent.add(location.resourceId)+ }+ }+ return [...dependent]+}