Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): rp-003-residual carry Move-dialog destination names into the commit
Mb4b637173744
diff --git a/control-ui/components/GfsBrowser.tsx b/control-ui/components/GfsBrowser.tsxindex 7b7fcc36c..3fc496e4c 100644--- a/control-ui/components/GfsBrowser.tsx+++ b/control-ui/components/GfsBrowser.tsx@@ -1346,7 +1346,18 @@ export function GfsBrowser(): React.JSX.Element {async function moveResource(source: GfsChild,destination: Pick<GfsChild, 'resourceId' | 'name' | 'kind'>,- options: { bubbleError?: boolean; allowNumberedRename?: boolean } = {}+ options: {+ bubbleError?: boolean+ allowNumberedRename?: boolean+ /**+ * Names the caller already knows the destination holds (the Move+ * dialog loads them while it shows the destination tree). They are+ * merged into the ladder seed, so a destination the browser's children+ * cache never saw does not cost three blind attempts on names that+ * are already taken (RP-003).+ */+ occupiedNames?: readonly string[]+ } = {}): Promise<void> {const { bubbleError = false, allowNumberedRename = true } = optionsif (@@ -1361,11 +1372,13 @@ export function GfsBrowser(): React.JSX.Element {setMovingResourceId(source.resourceId)try {// Seed the ladder with the destination's known children (the same cache- // the confirmation suggestion came from) so the first 409 skips every- // already-taken numbered name instead of guessing it blind.- const occupiedNames = new Set<string>(- (childCacheRef.current.get(destination.resourceId)?.items ?? []).map(item => item.name)- )+ // the confirmation suggestion came from, plus whatever the caller+ // observed) so the first 409 skips every already-taken numbered name+ // instead of guessing it blind.+ const occupiedNames = new Set<string>([+ ...(childCacheRef.current.get(destination.resourceId)?.items ?? []).map(item => item.name),+ ...(options.occupiedNames ?? []),+ ])let moveName = source.namelet moved = falselet moveResult: unknown@@ -2696,11 +2709,11 @@ export function GfsBrowser(): React.JSX.Element {busy={movingResourceId === moveTarget.resourceId}initialCrumbs={moveDialogCrumbs}onClose={() => setMoveTarget(null)}- onMove={async (destinationId, destinationName) => {+ onMove={async destination => {await moveResource(moveTarget,- { resourceId: destinationId, name: destinationName, kind: 'directory' },- { bubbleError: true }+ { resourceId: destination.resourceId, name: destination.name, kind: 'directory' },+ { bubbleError: true, occupiedNames: destination.occupiedNames })setMoveTarget(null)}}diff --git a/control-ui/components/GfsMoveDialog/index.tsx b/control-ui/components/GfsMoveDialog/index.tsxindex dd0483c7c..895df3c09 100644--- a/control-ui/components/GfsMoveDialog/index.tsx+++ b/control-ui/components/GfsMoveDialog/index.tsx@@ -1,6 +1,6 @@'use client'-import { useEffect, useMemo, useState } from 'react'+import { useEffect, useMemo, useRef, useState } from 'react'import { IconFolder } from '@components/Sidebar/icons'import { IconCheck, IconChevronRight, IconX } from '@components/icons'import { Button } from '@components/ui'@@ -34,11 +34,16 @@ function TreeFolder({level,selected,targetId,+ onChildrenLoaded,onSelect,onToggle,}: MoveTreeFolderProps) {const expanded = expandedIds.has(folder.resourceId)const [children, setChildren] = useState<MoveFolder[]>([])+ // The accumulated children across pages. A ref (not state) so the load+ // never merges a stale page set, and so the names reported upward are the+ // complete list this folder has shown.+ const loadedChildrenRef = useRef<MoveFolder[]>([])const [nextCursor, setNextCursor] = useState<string | null>(null)const [loaded, setLoaded] = useState(false)const [attempted, setAttempted] = useState(false)@@ -64,9 +69,19 @@ function TreeFolder({`/api/v1/gfs/resources/${encodeURIComponent(folder.resourceId)}/children`,query)) as MoveTreePage- setChildren(previous => (cursor ? [...previous, ...page.items] : page.items))+ const merged = cursor ? [...loadedChildrenRef.current, ...page.items] : page.items+ loadedChildrenRef.current = merged+ setChildren(merged)setNextCursor(page.nextCursor)setLoaded(true)+ // These are the names the folder already holds. The move ladder needs+ // them: a destination discovered only through this dialog is unknown to+ // the browser's children cache, and a blind ladder burns its attempts+ // on names that are already taken (RP-003).+ onChildrenLoaded(+ folder.resourceId,+ merged.map(item => item.name)+ )} catch (loadError) {setError(messageOf(loadError))} finally {@@ -136,6 +151,7 @@ function TreeFolder({folder={child}key={child.resourceId}level={level + 1}+ onChildrenLoaded={onChildrenLoaded}onSelect={onSelect}onToggle={onToggle}selected={selected}@@ -195,6 +211,14 @@ export function GfsMoveDialog({const [loading, setLoading] = useState(false)const [loaded, setLoaded] = useState(false)const [error, setError] = useState('')+ // The names this dialog has observed inside each folder. The drive root's+ // own listing arrives with the tree; every other folder reports its+ // children as they load (RP-003).+ const knownChildNamesRef = useRef<Map<string, string[]>>(new Map())++ function reportChildrenLoaded(folderId: string, names: string[]): void {+ knownChildNamesRef.current.set(folderId, names)+ }async function loadRoots(cursor?: string): Promise<void> {setLoading(true)@@ -247,11 +271,46 @@ export function GfsMoveDialog({setExpandedIds(previous => new Set(previous).add(folder.resourceId))}+ /**+ * The names the destination already holds, as far as this dialog knows+ * them. The drive root's listing IS the root's children; every other+ * destination reports its children while the tree loads them. A destination+ * that was never expanded is read once here, so the ladder is never seeded+ * blind — the browser's own children cache is cold for a folder only this+ * dialog discovered (RP-003).+ */+ async function destinationOccupiedNames(destination: SelectedMoveDestination): Promise<string[]> {+ if (destination.resourceId === rootResourceId) {+ return rootFolders.map(folder => folder.name)+ }+ const known = knownChildNamesRef.current.get(destination.resourceId)+ if (known) return known+ try {+ const page = (await apiGet(+ `/api/v1/gfs/resources/${encodeURIComponent(destination.resourceId)}/children`,+ { drive: DRIVE }+ )) as MoveTreePage+ const names = (page?.items ?? []).map(item => item.name)+ knownChildNamesRef.current.set(destination.resourceId, names)+ return names+ } catch {+ // The seed is an optimization, never the authority: the server's 409 is+ // what decides a collision. A failed read leaves the ladder blind but+ // the move itself intact.+ return []+ }+ }+async function commit(): Promise<void> {if (!selected || busy) returnsetError('')try {- await onMove(selected.resourceId, selected.name)+ const occupiedNames = await destinationOccupiedNames(selected)+ await onMove({+ resourceId: selected.resourceId,+ name: selected.name,+ occupiedNames,+ })} catch (moveError) {setError(messageOf(moveError))}@@ -355,6 +414,7 @@ export function GfsMoveDialog({folder={folder}key={folder.resourceId}level={rootResourceId ? 2 : 1}+ onChildrenLoaded={reportChildrenLoaded}onSelect={selectFolder}onToggle={toggleFolder}selected={selected}diff --git a/control-ui/components/GfsMoveDialog/types.ts b/control-ui/components/GfsMoveDialog/types.tsindex 3828da484..b2d872257 100644--- a/control-ui/components/GfsMoveDialog/types.ts+++ b/control-ui/components/GfsMoveDialog/types.ts@@ -19,12 +19,30 @@ export type MoveTreePage = {export type SelectedMoveDestination = Pick<MoveFolder, 'resourceId' | 'name'>+/**+ * The destination the operator approved, together with the names the dialog+ * already knows INSIDE it.+ *+ * The browser's own children cache is cold for a destination that only this+ * dialog discovered (a nested folder the current listing never showed), so+ * without this seed the numbered-name ladder starts blind: it burns its+ * three attempts on names the destination already holds and reports "The+ * destination changed" instead of landing on the first free numbered name+ * (RP-003).+ */+export type MoveDestinationRequest = {+ resourceId: string+ name: string+ /** Names the destination already holds, as observed by this dialog. */+ occupiedNames: string[]+}+export type GfsMoveDialogProps = {target: MoveFolderinitialCrumbs: MoveCrumb[]busy?: booleanonClose: () => void- onMove: (destinationId: string, destinationName: string) => Promise<void>+ onMove: (destination: MoveDestinationRequest) => Promise<void>}export type MoveTreeFolderProps = {@@ -34,6 +52,9 @@ export type MoveTreeFolderProps = {level: numberselected: SelectedMoveDestination | nulltargetId: string+ /** Reports the names loaded inside a folder so the dialog can seed the+ * numbered-name ladder with them (RP-003). */+ onChildrenLoaded: (folderId: string, names: string[]) => voidonSelect: (folder: MoveFolder) => voidonToggle: (folderId: string) => void}diff --git a/control-ui/components/__tests__/GfsBrowser.test.tsx b/control-ui/components/__tests__/GfsBrowser.test.tsxindex c83fb842f..825d29a75 100644--- a/control-ui/components/__tests__/GfsBrowser.test.tsx+++ b/control-ui/components/__tests__/GfsBrowser.test.tsx@@ -1914,6 +1914,88 @@ describe('GfsBrowser', () => {await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())})+ it('seeds the Move-dialog ladder with the names the destination already holds', async () => {+ // RP-003 residual: the destination is a NESTED folder, so the browser's+ // children cache never saw it — the Move dialog is the only surface that+ // knows the names it holds. Without that seed the ladder starts blind,+ // burns all three attempts on name, name (1) and name (2) and reports+ // "The destination changed" while name (3) is free.+ const projects = child('Projects', 'directory', 1)+ const source = child('name', 'file', 2)+ const archive = child('Archive', 'directory', 3)+ mockApiGet.mockImplementation(async (path: string) => {+ if (path === '/api/v1/gfs/tree') {+ return {+ rootResourceId: '11111111-1111-1111-1111-111111111111',+ items: [projects, source],+ nextCursor: null,+ }+ }+ if (path === '/api/v1/gfs/resources/id-1/children') {+ return { items: [archive], nextCursor: null }+ }+ if (path === '/api/v1/gfs/resources/id-3/children') {+ return {+ items: [+ child('name', 'file', 4),+ child('name (1)', 'file', 5),+ child('name (2)', 'file', 6),+ ],+ nextCursor: null,+ }+ }+ return { items: [], nextCursor: null }+ })+ const actualApi = await vi.importActual<typeof import('@lib/api')>('@lib/api')+ const conflict = () => {+ const text = JSON.stringify({+ error: { code: 'already_exists', message: 'a resource with this name already exists' },+ })+ return actualApi.formatApiError(+ new Response(text, { status: 409, statusText: 'Conflict' }),+ text+ )+ }+ // The destination holds name, name (1) and name (2); name (3) is free.+ mockApiSend.mockImplementation(async (_method: string, _path: string, body: unknown) => {+ const requested = (body as { newName?: string } | undefined)?.newName ?? 'name'+ if (requested !== 'name (3)') throw conflict()+ return { ok: true, data: { resourceId: 'id-2', version: 1 } }+ })+ renderBrowser()++ await waitFor(() => expect(screen.queryByRole('status', { name: 'Loading files' })).toBeNull())+ // The destination is NOT part of the visible listing: the browser's+ // children cache is cold for it.+ const list = screen.getByRole('list', { name: 'Current folder resources' })+ expect(within(list).queryByText('Archive')).toBeNull()++ await openResourceMenu('name')+ fireEvent.click(screen.getByRole('menuitem', { name: 'Move to…' }))+ const dialog = await screen.findByRole('dialog', { name: 'Move file name' })+ // Walk the dialog tree down to the nested destination.+ fireEvent.click(await within(dialog).findByRole('button', { name: 'Projects' }))+ fireEvent.click(await within(dialog).findByRole('button', { name: 'Archive' }))+ fireEvent.click(within(dialog).getByRole('button', { name: 'Move here (Archive)' }))++ await waitFor(() => expect(mockApiSend).toHaveBeenCalledTimes(2))+ expect(mockApiSend).toHaveBeenNthCalledWith(+ 1,+ 'PATCH',+ '/api/v1/gfs/resources/id-2',+ { drive: 'main', newParentId: 'id-3', ifMatch: 0 },+ { drive: 'main' }+ )+ expect(mockApiSend).toHaveBeenNthCalledWith(+ 2,+ 'PATCH',+ '/api/v1/gfs/resources/id-2',+ { drive: 'main', newParentId: 'id-3', ifMatch: 0, newName: 'name (3)' },+ { drive: 'main' }+ )+ expect(await screen.findByText('Moved "name" to "Archive" as "name (3)".')).toBeTruthy()+ })+it('retries a conflicting move with numbered names until the destination accepts it', async () => {const actualApi = await vi.importActual<typeof import('@lib/api')>('@lib/api')const folder = child('archive', 'directory', 1)diff --git a/control-ui/components/__tests__/GfsMoveDialog.test.tsx b/control-ui/components/__tests__/GfsMoveDialog.test.tsxindex 78459f3ef..ea3ad7648 100644--- a/control-ui/components/__tests__/GfsMoveDialog.test.tsx+++ b/control-ui/components/__tests__/GfsMoveDialog.test.tsx@@ -61,7 +61,11 @@ describe('GfsMoveDialog', () => {})fireEvent.click(within(dialog).getByRole('button', { name: 'Move here (Archive)' }))- await waitFor(() => expect(onMove).toHaveBeenCalledWith('archive-1', 'Archive'))+ await waitFor(() =>+ expect(onMove).toHaveBeenCalledWith(+ expect.objectContaining({ resourceId: 'archive-1', name: 'Archive' })+ )+ )})it('moves a file to the main root', async () => {@@ -85,7 +89,11 @@ describe('GfsMoveDialog', () => {fireEvent.click(await within(dialog).findByRole('button', { name: 'main' }))fireEvent.click(within(dialog).getByRole('button', { name: 'Move here (main)' }))- await waitFor(() => expect(onMove).toHaveBeenCalledWith('root-1', 'main'))+ await waitFor(() =>+ expect(onMove).toHaveBeenCalledWith(+ expect.objectContaining({ resourceId: 'root-1', name: 'main' })+ )+ )})it('refuses a no-op move into the folder that already contains the target', async () => {@@ -127,7 +135,63 @@ describe('GfsMoveDialog', () => {fireEvent.click(within(dialog).getByRole('button', { name: 'Archive' }))fireEvent.click(within(dialog).getByRole('button', { name: 'Move here (Archive)' }))- await waitFor(() => expect(onMove).toHaveBeenCalledWith('archive-1', 'Archive'))+ await waitFor(() =>+ expect(onMove).toHaveBeenCalledWith(+ expect.objectContaining({ resourceId: 'archive-1', name: 'Archive' })+ )+ )expect(onMove).toHaveBeenCalledTimes(1)})++ // RP-003 residual: the names the destination already holds are the ones the+ // browser's move ladder must skip. The dialog loads them while it shows the+ // destination tree, so they travel with the commit — a destination the+ // browser's own children cache never saw would otherwise cost three blind+ // attempts on names that are already taken.+ it('commits with the names the destination already holds', async () => {+ mockApiGet.mockImplementation(async path => {+ if (path === '/api/v1/gfs/tree') {+ return {+ rootResourceId: 'root-1',+ items: [{ resourceId: 'archive-1', name: 'Archive', kind: 'directory' }],+ nextCursor: null,+ }+ }+ if (path === '/api/v1/gfs/resources/archive-1/children') {+ return {+ items: [+ { resourceId: 'file-1', name: 'name', kind: 'file' },+ { resourceId: 'file-2', name: 'name (1)', kind: 'file' },+ { resourceId: 'file-3', name: 'name (2)', kind: 'file' },+ ],+ nextCursor: null,+ }+ }+ return { items: [], nextCursor: null }+ })+ const onMove = vi.fn(async () => undefined)++ render(+ <GfsMoveDialog+ initialCrumbs={[{ id: 'product-1', name: 'Product' }]}+ onClose={vi.fn()}+ onMove={onMove}+ target={{ resourceId: 'file-9', name: 'name', kind: 'file' }}+ />+ )++ const dialog = screen.getByRole('dialog', { name: 'Move file name' })+ // Selecting the destination expands it, so its children load.+ fireEvent.click(await within(dialog).findByRole('button', { name: 'Archive' }))+ await within(dialog).findByText('No subfolders.')+ fireEvent.click(within(dialog).getByRole('button', { name: 'Move here (Archive)' }))++ await waitFor(() =>+ expect(onMove).toHaveBeenCalledWith({+ resourceId: 'archive-1',+ name: 'Archive',+ occupiedNames: ['name', 'name (1)', 'name (2)'],+ })+ )+ })})diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex bfdb09b07..0a9d88d39 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.743",+ "version": "0.1.744","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.743",+ "version": "0.1.744","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 e7ee9b82e..3437fedb6 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.743",+ "version": "0.1.744","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",