Skip to content

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

TypeScript

fix(desktop): rp-005 align chain order and relocate the moved open resource

M6b43d8ccee5e
diff --git a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
index b290864a7..3f863c84a 100644
--- a/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
+++ b/desktop-app/ui/src/hooks/domain/__tests__/useGfsBrowserController.test.tsx
@@ -26,6 +26,7 @@ import {
sharesListPage,
} from '@/gfs/__fixtures__/gfsProducerFixtures'
import { shouldRevalidateGfsQuery } from '@/lib/gfsEntityChangeState'
+import { readGfsOpenLocations } from '@/lib/gfsOpenLocations'
import { desktopQueryKeys } from '../queryKeys'
import { useGfsBrowserController } from '../useGfsBrowserController'
@@ -3614,4 +3615,67 @@ describe('useGfsBrowserController — cross-surface move convergence (RP-005)',
await waitFor(() => expect(inheritedQuery.state.dataUpdatedAt).not.toBe(before))
})
+
+ it('publishes the open location in the registry order the relocation helper assumes', async () => {
+ // The controller's CRUMBS are root-first (ancestor-1 / parent-1 / leaf-1),
+ // but the shared open-location registry documents — and the relocation
+ // helper slice()s — a NEAREST-FIRST chain. Publishing the crumbs without
+ // reversing them made a relocation of an intermediate ancestor keep the
+ // stale ancestors ABOVE it and drop the still-real ones BELOW it.
+ 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,
+ }
+ }),
+ listChildren: vi.fn(async () => ({ items: [], nextCursor: null })),
+ },
+ },
+ })
+
+ 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')
+
+ const client = lastHarnessQueryClient!
+ // Nearest first: parent-1 before ancestor-1. The sidebar mount has
+ // nothing open, so the files mount is the registry's only entry.
+ expect(readGfsOpenLocations(client, ':user-a:team-a')).toEqual([
+ { resourceId: 'leaf-1', ancestorResourceIds: ['parent-1', 'ancestor-1'] },
+ ])
+ })
})
diff --git a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
index f232af6f8..d932c2742 100644
--- a/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
+++ b/desktop-app/ui/src/hooks/domain/useGfsBrowserController.ts
@@ -374,14 +374,18 @@ export function useGfsBrowserController(options: GfsBrowserControllerOptions = {
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.
+ // The ancestry this mount observed is the trail it loaded. Crumbs are
+ // ROOT-FIRST, so publishing them reverses them into the registry's
+ // NEAREST-FIRST contract — the order the relocation helper slices from
+ // the nearest end. 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),
+ ancestorResourceIds: crumbs
+ .slice(0, -1)
+ .map(crumb => crumb.resourceId)
+ .reverse(),
}
: null
publishGfsOpenLocation(queryClient, sessionScope, openLocationId, location)
diff --git a/desktop-app/ui/src/lib/__tests__/gfsOpenLocations.test.ts b/desktop-app/ui/src/lib/__tests__/gfsOpenLocations.test.ts
index 8922cba6d..534b53276 100644
--- a/desktop-app/ui/src/lib/__tests__/gfsOpenLocations.test.ts
+++ b/desktop-app/ui/src/lib/__tests__/gfsOpenLocations.test.ts
@@ -118,6 +118,90 @@ describe('gfsOpenLocations', () => {
})
})
+ describe('producer-order chains, two controllers (RP-005 revalidation)', () => {
+ // The controller's crumbs are ROOT-FIRST, and the publication step
+ // reverses them into this registry's NEAREST-FIRST contract: a leaf L
+ // under root > X > A > C publishes [C, A, X, root]. These regressions
+ // hold the relocated chains to that contract — an order disagreement
+ // between the producer and the relocation helper used to keep the stale
+ // ancestors ABOVE the moved one and drop the still-real ones BELOW it.
+ function registryWithProducerChains() {
+ return {
+ files: { resourceId: 'L', ancestorResourceIds: ['C', 'A', 'X', 'root'] },
+ sidebar: { resourceId: 'B', ancestorResourceIds: ['P', 'root'] },
+ preview: { resourceId: 'Q', ancestorResourceIds: ['root'] },
+ }
+ }
+
+ it('keeps every ancestor below the moved one, in producer order', () => {
+ // The sidebar moves A under B. C is BELOW A in the leaf's chain — it
+ // stays; X and root sat ABOVE A and are replaced by B's own chain.
+ expect(relocateObservedChain(['C', 'A', 'X', 'root'], 'A', 'B', ['P', 'root'])).toEqual([
+ 'C',
+ 'A',
+ 'B',
+ 'P',
+ 'root',
+ ])
+ })
+
+ it('still claims the leaf for a later move of the intermediate ancestor below the moved one', () => {
+ const afterFirst = relocatePublishedChains(registryWithProducerChains(), 'A', 'B')
+ expect(afterFirst.files?.ancestorResourceIds).toEqual(['C', 'A', 'B', 'P', 'root'])
+ // C survived the relocation as the leaf's nearest ancestor, so a
+ // SECOND move of C — not just of A or B — must still claim the leaf.
+ expect(ancestryDependentGfsResourceIds(Object.values(afterFirst), 'C')).toEqual(['L'])
+ expect(ancestryDependentGfsResourceIds(Object.values(afterFirst), 'B')).toEqual(['L', 'B'])
+ })
+
+ it('relocates the chain when the OPEN resource itself is the moved one', () => {
+ // The sidebar moves its own open B under Q. B's ENTIRE observed
+ // ancestry belonged to the old location, so the new chain starts at Q
+ // — plus Q's own observed ancestors, because the preview surface has
+ // Q open. A later move of Q must then claim B.
+ const after = relocatePublishedChains(registryWithProducerChains(), 'B', 'Q')
+ expect(after.sidebar?.ancestorResourceIds).toEqual(['Q', 'root'])
+ expect(ancestryDependentGfsResourceIds(Object.values(after), 'Q')).toEqual(['B', 'Q'])
+ })
+
+ it('stops the self-moved chain at the new parent when no surface has it open', () => {
+ const after = relocatePublishedChains(
+ { sidebar: { resourceId: 'B', ancestorResourceIds: ['P', 'root'] } },
+ 'B',
+ 'Q'
+ )
+ expect(after.sidebar?.ancestorResourceIds).toEqual(['Q'])
+ })
+
+ it("clears the open resource's ancestry when it moves to the drive root", () => {
+ const after = relocatePublishedChains(registryWithProducerChains(), 'B', null)
+ expect(after.sidebar?.ancestorResourceIds).toEqual([])
+ })
+
+ it('publishes the self-move relocation into the shared registry', () => {
+ const queryClient = new QueryClient()
+ publishGfsOpenLocation(queryClient, SCOPE, 'sidebar', {
+ resourceId: 'B',
+ ancestorResourceIds: ['P', 'root'],
+ })
+ publishGfsOpenLocation(queryClient, SCOPE, 'preview', {
+ resourceId: 'Q',
+ ancestorResourceIds: ['root'],
+ })
+
+ publishGfsMoveRelocation(queryClient, SCOPE, 'B', 'Q')
+
+ expect(readGfsOpenLocations(queryClient, SCOPE)).toEqual([
+ { resourceId: 'B', ancestorResourceIds: ['Q', 'root'] },
+ { resourceId: 'Q', ancestorResourceIds: ['root'] },
+ ])
+ // The SECOND move now claims the sidebar's own open folder.
+ expect(
+ ancestryDependentGfsResourceIds(readGfsOpenLocations(queryClient, SCOPE), 'Q')
+ ).toEqual(['B', 'Q'])
+ })
+ })
+
it('keeps the registry inside the shared query cache', () => {
const queryClient = new QueryClient()
publishGfsOpenLocation(queryClient, SCOPE, 'mount-a', {
diff --git a/desktop-app/ui/src/lib/gfsOpenLocations.ts b/desktop-app/ui/src/lib/gfsOpenLocations.ts
index ecd39d221..6f3fe9e5b 100644
--- a/desktop-app/ui/src/lib/gfsOpenLocations.ts
+++ b/desktop-app/ui/src/lib/gfsOpenLocations.ts
@@ -106,6 +106,11 @@ export function relocateObservedChain(
* move of the moved resource's NEW parent would otherwise miss the surfaces
* that have a descendant open — the registry and the children cache both
* still hold the pre-move chain.
+ *
+ * The surface whose OPEN resource is the moved one relocates too: its whole
+ * observed ancestry belonged to the old location, so the new chain starts at
+ * the new parent — plus the new parent's own observed ancestors when another
+ * surface has it open.
*/
export function relocatePublishedChains(
locations: GfsOpenLocationRegistry,
@@ -118,14 +123,22 @@ export function relocatePublishedChains(
? (Object.values(locations).find(location => location.resourceId === newParentId)
?.ancestorResourceIds ?? [])
: []
+ const aboveNewParent = newParentChain.filter(
+ ancestor => ancestor !== newParentId && ancestor !== movedResourceId
+ )
const next: GfsOpenLocationRegistry = {}
for (const [id, location] of Object.entries(locations)) {
- const relocated = relocateObservedChain(
- location.ancestorResourceIds,
- movedResourceId,
- newParentId,
- newParentChain
- )
+ const relocated =
+ location.resourceId === movedResourceId
+ ? newParentId
+ ? [newParentId, ...aboveNewParent]
+ : []
+ : relocateObservedChain(
+ location.ancestorResourceIds,
+ movedResourceId,
+ newParentId,
+ newParentChain
+ )
const unchanged =
relocated.length === location.ancestorResourceIds.length &&
relocated.every((value, index) => value === location.ancestorResourceIds[index])