Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): refresh breadcrumbs after remote GFS moves
Josué12e332cd5132
diff --git a/control-ui/components/GfsBrowser.tsx b/control-ui/components/GfsBrowser.tsxindex 03de764a2..740b4f32a 100644--- a/control-ui/components/GfsBrowser.tsx+++ b/control-ui/components/GfsBrowser.tsx@@ -116,6 +116,14 @@ interface Crumb {name: string}+interface GfsResolvedLocation {+ resourceId: string+ rid: string+ name: string+ kind: string+ path: string | null+}+const DRIVE = 'main'const PENDING_GFS_UPLOAD_KEY = 'evenfire:gfs-upload-v2:pending'const GFS_RESOURCE_DRAG_TYPE = 'application/x-evenfire-gfs-resource'@@ -335,6 +343,8 @@ export function GfsBrowser(): React.JSX.Element {const current = crumbs[crumbs.length - 1]const currentCrumbRef = useRef(current)currentCrumbRef.current = current+ const crumbsRef = useRef(crumbs)+ crumbsRef.current = crumbsconst currentLabel = current?.name === '/' ? DRIVE : current?.name || DRIVEconst load = useCallback(@@ -457,6 +467,7 @@ export function GfsBrowser(): React.JSX.Element {// keeps the cached rows (no spinner) while the server state re-syncs.const revalidateNextLoadRef = useRef(false)const streamCursorRef = useRef<string | null>(null)+ const hierarchyRefreshGenerationRef = useRef(0)// Warm the cache for every folder row visible in the current view.// Re-runs whenever the listing changes (folder navigation, refresh,@@ -516,6 +527,11 @@ export function GfsBrowser(): React.JSX.Element {setSelected(null)setRenameTarget(null)setDeleteOpen(false)+ setMoveTarget(null)+ setItems([])+ setNextCursor(null)+ setError('')+ setLoading(true)const previews = openPreviewsRef.currentif (previews.length > 0) {const generation = ++previewRefreshGenerationRef.current@@ -575,7 +591,52 @@ export function GfsBrowser(): React.JSX.Element {})}const visibleCrumb = currentCrumbRef.current- if (visibleCrumb) void load(visibleCrumb)+ if (!visibleCrumb) return+ if (visibleCrumb.id === null) {+ void load(visibleCrumb)+ return+ }++ const visibleResourceId = visibleCrumb.id+ const generation = ++hierarchyRefreshGenerationRef.current+ void (async () => {+ const rootCrumb = { ...(crumbsRef.current[0] ?? { id: null, rid: null, name: '/' }) }+ let refreshed: Crumb[] = [rootCrumb]+ try {+ const resolved = (await apiGet('/api/v1/gfs/resolve', {+ uri: `gfs://${DRIVE}/${visibleCrumb.rid ?? ridOfResourceId(visibleResourceId)}`,+ })) as GfsResolvedLocation+ if (resolved.kind !== 'directory' || !resolved.path?.startsWith('/')) {+ throw new Error('Current GFS folder is no longer available')+ }+ let path = ''+ for (const segment of resolved.path.split('/').filter(Boolean)) {+ path += `/${segment}`+ const ancestor = (await apiGet('/api/v1/gfs/by-path', {+ drive: DRIVE,+ path,+ })) as GfsResolvedLocation+ if (ancestor.kind !== 'directory') {+ throw new Error('GFS folder hierarchy changed during refresh')+ }+ refreshed.push({ id: ancestor.resourceId, rid: ancestor.rid, name: ancestor.name })+ }+ if (refreshed[refreshed.length - 1]?.id !== resolved.resourceId) {+ throw new Error('GFS folder hierarchy changed during refresh')+ }+ } catch {+ // Do not keep presenting the stale hierarchy if the current folder+ // was deleted, moved during resolution, or is no longer authorized.+ refreshed = [rootCrumb]+ }+ if (+ generation !== hierarchyRefreshGenerationRef.current ||+ currentCrumbRef.current?.id !== visibleResourceId+ ) {+ return+ }+ setCrumbs(refreshed)+ })()}async function consume(): Promise<void> {diff --git a/control-ui/components/__tests__/GfsBrowser.test.tsx b/control-ui/components/__tests__/GfsBrowser.test.tsxindex 118777eb7..814e87ba7 100644--- a/control-ui/components/__tests__/GfsBrowser.test.tsx+++ b/control-ui/components/__tests__/GfsBrowser.test.tsx@@ -495,6 +495,97 @@ describe('GfsBrowser', () => {expect(JSON.stringify(mockApiSend.mock.calls)).toContain('remote-folder')})+ it('rebuilds the open directory breadcrumbs after a remote move', async () => {+ const rootId = 'root-id'+ const streamControllers: ReadableStreamDefaultController<Uint8Array>[] = []+ mockApiGet.mockImplementation(async (path: string, query?: Record<string, string>) => {+ if (path === '/api/v1/gfs/tree') {+ return {+ rootResourceId: rootId,+ items: [child('old-parent', 'directory', 1)],+ nextCursor: null,+ }+ }+ if (path === '/api/v1/gfs/resolve') {+ return {+ resourceId: 'id-2',+ rid: 'r2',+ name: 'renamed-folder',+ kind: 'directory',+ path: '/new-parent/renamed-folder',+ }+ }+ if (path === '/api/v1/gfs/by-path' && query?.path === '/new-parent') {+ return {+ resourceId: 'id-3',+ rid: 'r3',+ name: 'new-parent',+ kind: 'directory',+ path: '/new-parent',+ }+ }+ if (path === '/api/v1/gfs/by-path' && query?.path === '/new-parent/renamed-folder') {+ return {+ resourceId: 'id-2',+ rid: 'r2',+ name: 'renamed-folder',+ kind: 'directory',+ path: '/new-parent/renamed-folder',+ }+ }+ if (path.endsWith('/children')) {+ if (path.endsWith('/root-id/children')) {+ return { items: [child('old-parent', 'directory', 1)], nextCursor: null }+ }+ if (path.endsWith('/id-1/children')) {+ return { items: [child('old-folder', 'directory', 2)], nextCursor: null }+ }+ return { items: [], nextCursor: null }+ }+ return { items: [], nextCursor: null }+ })+ vi.stubGlobal(+ 'fetch',+ vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {+ const body = new ReadableStream<Uint8Array>({+ start(controller) {+ streamControllers.push(controller)+ init?.signal?.addEventListener('abort', () => controller.close(), { once: true })+ },+ })+ return new Response(body, {+ status: 200,+ headers: { 'content-type': 'application/x-ndjson' },+ })+ })+ )++ renderBrowser()+ await waitFor(() => expect(streamControllers).toHaveLength(1))+ fireEvent.click(await screen.findByRole('button', { name: 'old-parent' }))+ fireEvent.click(await screen.findByRole('button', { name: 'old-folder' }))+ await screen.findByText('No resources are visible in this folder.')++ const frame = JSON.stringify({+ schemaVersion: 1,+ type: 'scope.invalidated',+ cursor: 'd119f895-1ef8-4e73-8f08-f9754919682a',+ scopes: ['gfs'],+ })+ await act(async () => {+ streamControllers[0].enqueue(new TextEncoder().encode(`${frame}\n`))+ })++ const breadcrumb = screen.getByRole('navigation', { name: 'Breadcrumb' })+ await within(breadcrumb).findByRole('button', { name: 'new-parent' })+ expect(within(breadcrumb).getByRole('button', { name: 'renamed-folder' })).toBeTruthy()+ expect(within(breadcrumb).queryByRole('button', { name: 'old-parent' })).toBeNull()+ expect(mockApiGet).toHaveBeenCalledWith('/api/v1/gfs/by-path', {+ drive: 'main',+ path: '/new-parent/renamed-folder',+ })+ })+it.each(['secret.png', 'secret.md', 'secret.mp4'])('purges an open %s preview when the authoritative refetch denies access',async fileName => {diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 2f7f229cf..d7ae0683f 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.609",+ "version": "0.1.610","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.609",+ "version": "0.1.610","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/frontend-components": "file:../packages/frontend-components",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 38857b5dc..71611322d 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.609",+ "version": "0.1.610","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",