@@ -161,6 +161,62 @@ async function rows(projectId: string) {
161161}
162162
163163describe ( 'Project file content against PostgreSQL and the local object store' , ( ) => {
164+ check (
165+ 'folder tree copy hydrates destination paths once while preserving nested paths' ,
166+ async ( ) => {
167+ const { copyFileItems } = await import ( '@/lib/workspace-files/application/copy-file-items' )
168+ const f = await fixture ( )
169+ const root = await createProjectFileFolder . execute ( {
170+ principal : f . principal ,
171+ input : { projectId : f . projectId , name : 'Root' } ,
172+ } )
173+ await db . insert ( folder ) . values (
174+ Array . from ( { length : 20 } , ( _ , index ) => ( {
175+ id : generateId ( ) ,
176+ projectId : f . projectId ,
177+ parentId : root . folder . id ,
178+ resourceType : 'file' as const ,
179+ name : `Child-${ index } ` ,
180+ userId : f . ownerId ,
181+ } ) )
182+ )
183+ const originalDebug = db . $client . options . debug
184+ const queries : string [ ] = [ ]
185+ db . $client . options . debug = ( _connection , query ) => {
186+ queries . push ( query )
187+ }
188+ try {
189+ const result = await copyFileItems . execute ( {
190+ principal : f . principal ,
191+ input : {
192+ source : {
193+ owner : { entityType : 'project' , entityId : f . projectId } ,
194+ fileIds : [ ] ,
195+ folderIds : [ root . folder . id ] ,
196+ } ,
197+ destination : {
198+ owner : { entityType : 'workspace' , entityId : f . workspaceId } ,
199+ folderId : null ,
200+ } ,
201+ } ,
202+ } )
203+ expect ( result . folders ) . toHaveLength ( 21 )
204+ const copiedRoot = result . folders . find ( ( item ) => item . parentId === null )
205+ if ( ! copiedRoot ) throw new Error ( 'Copied root missing' )
206+ expect ( result . folders . filter ( ( item ) => item . parentId === copiedRoot . id ) ) . toHaveLength ( 20 )
207+ for ( const item of result . folders . filter ( ( item ) => item . id !== copiedRoot . id ) )
208+ expect ( item . path ) . toBe ( `${ copiedRoot . path } /${ item . name } ` )
209+ expect (
210+ queries . filter ( ( query ) =>
211+ query . startsWith ( 'select "id", "name", "parent_id" from "folder"' )
212+ )
213+ ) . toHaveLength ( 0 )
214+ } finally {
215+ db . $client . options . debug = originalDebug
216+ }
217+ }
218+ )
219+
164220 check (
165221 'copy selection ignores unrelated folders when the owner exceeds the selection limit' ,
166222 async ( ) => {
0 commit comments