@@ -15,16 +15,37 @@ import {
1515 readHistoryFile ,
1616 writeToHistoryFile ,
1717 createMetadataFile ,
18- copyArtifacts ,
1918 cleanupTempJobFiles ,
2019 refreshJob ,
2120 JobMetadata ,
2221} from '../../codewhisperer/service/transformByQ/transformationHistoryHandler'
22+ import { copyArtifacts } from '../../codewhisperer/service/transformByQ/transformFileHandler'
2323import * as transformApiHandler from '../../codewhisperer/service/transformByQ/transformApiHandler'
2424import { ExportResultArchiveStructure } from '../../shared/utilities/download'
2525import { JDKVersion , TransformationType } from '../../codewhisperer'
2626
2727describe ( 'Transformation History Handler' , function ( ) {
28+ function setupFileSystemMocks ( ) {
29+ const createdFiles = new Map < string , string > ( )
30+ const createdDirs = new Set < string > ( )
31+
32+ // Mock file operations to track what gets created
33+ sinon . stub ( fs , 'mkdir' ) . callsFake ( async ( dirPath : any ) => {
34+ createdDirs . add ( dirPath . toString ( ) )
35+ } )
36+ sinon . stub ( fs , 'copy' ) . callsFake ( async ( src : any , dest : any ) => {
37+ createdFiles . set ( dest . toString ( ) , `copied from ${ src . toString ( ) } ` )
38+ } )
39+ sinon . stub ( fs , 'writeFile' ) . callsFake ( async ( filePath : any , content : any ) => {
40+ createdFiles . set ( filePath . toString ( ) , content . toString ( ) )
41+ } )
42+ sinon . stub ( fs , 'delete' ) . callsFake ( async ( filePath : any ) => {
43+ createdFiles . delete ( filePath . toString ( ) )
44+ } )
45+
46+ return { createdFiles, createdDirs }
47+ }
48+
2849 afterEach ( function ( ) {
2950 sinon . restore ( )
3051 } )
@@ -86,7 +107,7 @@ describe('Transformation History Handler', function () {
86107 assert ( fileContent . includes ( 'date\tproject_name\tstatus\tduration\tdiff_patch\tsummary\tjob_id\n' ) )
87108 assert (
88109 fileContent . includes (
89- ' 01/01/25, 10:00 AM\ttest-project\tCOMPLETED\t5 min\t/job/path/ diff.patch\t /job/path/ summary/ summary.md\tjob-123\n'
110+ ` 01/01/25, 10:00 AM\ttest-project\tCOMPLETED\t5 min\t${ path . join ( ' /job/path' , ' diff.patch' ) } \t ${ path . join ( ' /job/path' , ' summary' , ' summary.md' ) } \tjob-123\n`
90111 )
91112 )
92113 } )
@@ -157,22 +178,9 @@ describe('Transformation History Handler', function () {
157178 }
158179
159180 beforeEach ( function ( ) {
160- createdFiles = new Map ( )
161- createdDirs = new Set ( )
162-
163- // Mock file operations to track what gets created
164- sinon . stub ( fs , 'mkdir' ) . callsFake ( async ( dirPath : any ) => {
165- createdDirs . add ( dirPath . toString ( ) )
166- } )
167- sinon . stub ( fs , 'copy' ) . callsFake ( async ( src : any , dest : any ) => {
168- createdFiles . set ( dest . toString ( ) , `copied from ${ src . toString ( ) } ` )
169- } )
170- sinon . stub ( fs , 'writeFile' ) . callsFake ( async ( filePath : any , content : any ) => {
171- createdFiles . set ( filePath . toString ( ) , content . toString ( ) )
172- } )
173- sinon . stub ( fs , 'delete' ) . callsFake ( async ( filePath : any ) => {
174- createdFiles . delete ( filePath . toString ( ) )
175- } )
181+ const mocks = setupFileSystemMocks ( )
182+ createdFiles = mocks . createdFiles
183+ createdDirs = mocks . createdDirs
176184 } )
177185
178186 it ( 'Creates job history directory and metadata files' , async function ( ) {
@@ -199,28 +207,28 @@ describe('Transformation History Handler', function () {
199207 // Pre-populate files that would exist
200208 createdFiles . set ( '/payload.zip' , 'payload content' )
201209 createdFiles . set ( path . join ( os . tmpdir ( ) , 'build-logs.txt' ) , 'build logs' )
202- createdFiles . set ( '/job/path/ metadata.json' , 'metadata' )
203- createdFiles . set ( '/job/path/ zipped-code.zip' , 'zip content' )
210+ createdFiles . set ( path . join ( '/job/path' , ' metadata.json') , 'metadata' )
211+ createdFiles . set ( path . join ( '/job/path' , ' zipped-code.zip') , 'zip content' )
204212
205213 await cleanupTempJobFiles ( '/job/path' , 'COMPLETED' , '/payload.zip' )
206214
207215 // Verify files were deleted (no longer exist in createdFiles)
208216 assert ( ! createdFiles . has ( '/payload.zip' ) )
209217 assert ( ! createdFiles . has ( path . join ( os . tmpdir ( ) , 'build-logs.txt' ) ) )
210- assert ( ! createdFiles . has ( '/job/path/ metadata.json' ) )
211- assert ( ! createdFiles . has ( '/job/path/ zipped-code.zip' ) )
218+ assert ( ! createdFiles . has ( path . join ( '/job/path' , ' metadata.json') ) )
219+ assert ( ! createdFiles . has ( path . join ( '/job/path' , ' zipped-code.zip') ) )
212220 } )
213221
214222 it ( 'Preserves metadata for failed jobs' , async function ( ) {
215223 // Pre-populate files that would exist
216- createdFiles . set ( '/job/path/ metadata.json' , 'metadata' )
217- createdFiles . set ( '/job/path/ zipped-code.zip' , 'zip content' )
224+ createdFiles . set ( path . join ( '/job/path' , ' metadata.json') , 'metadata' )
225+ createdFiles . set ( path . join ( '/job/path' , ' zipped-code.zip') , 'zip content' )
218226
219227 await cleanupTempJobFiles ( '/job/path' , 'FAILED' )
220228
221229 // Verify metadata files still exist (were NOT deleted)
222- assert ( createdFiles . has ( '/job/path/ metadata.json' ) )
223- assert ( createdFiles . has ( '/job/path/ zipped-code.zip' ) )
230+ assert ( createdFiles . has ( path . join ( '/job/path' , ' metadata.json') ) )
231+ assert ( createdFiles . has ( path . join ( '/job/path' , ' zipped-code.zip') ) )
224232 } )
225233 } )
226234
@@ -229,32 +237,25 @@ describe('Transformation History Handler', function () {
229237 let createdDirs : Set < string >
230238
231239 beforeEach ( function ( ) {
232- createdFiles = new Map ( )
233- createdDirs = new Set ( )
234-
235- // Mock file operations to track what gets created
236- sinon . stub ( fs , 'mkdir' ) . callsFake ( async ( dirPath : any ) => {
237- createdDirs . add ( dirPath . toString ( ) )
238- } )
239- sinon . stub ( fs , 'copy' ) . callsFake ( async ( src : any , dest : any ) => {
240- createdFiles . set ( dest . toString ( ) , `copied from ${ src . toString ( ) } ` )
241- } )
240+ const mocks = setupFileSystemMocks ( )
241+ createdFiles = mocks . createdFiles
242+ createdDirs = mocks . createdDirs
242243 } )
243244
244245 it ( 'Copies diff patch and summary files to destination' , async function ( ) {
245- await copyArtifacts ( '/ archive/ path', '/ destination/ path')
246+ await copyArtifacts ( path . join ( ' archive' , ' path') , path . join ( ' destination' , ' path') )
246247
247248 // Verify directories were created
248- assert ( createdDirs . has ( '/ destination/ path') )
249- assert ( createdDirs . has ( '/ destination/ path/ summary') )
249+ assert ( createdDirs . has ( path . join ( ' destination' , ' path') ) )
250+ assert ( createdDirs . has ( path . join ( ' destination' , ' path' , ' summary') ) )
250251
251252 // Verify files were copied to correct locations
252- assert ( createdFiles . has ( '/ destination/ path/ diff.patch') )
253- assert ( createdFiles . has ( '/ destination/ path/ summary/ summary.md') )
253+ assert ( createdFiles . has ( path . join ( ' destination' , ' path' , ' diff.patch') ) )
254+ assert ( createdFiles . has ( path . join ( ' destination' , ' path' , ' summary' , ' summary.md') ) )
254255
255256 // Verify source paths are correct
256- const diffSource = createdFiles . get ( '/ destination/ path/ diff.patch')
257- const summarySource = createdFiles . get ( '/ destination/ path/ summary/ summary.md')
257+ const diffSource = createdFiles . get ( path . join ( ' destination' , ' path' , ' diff.patch') )
258+ const summarySource = createdFiles . get ( path . join ( ' destination' , ' path' , ' summary' , ' summary.md') )
258259 assert ( diffSource ?. includes ( ExportResultArchiveStructure . PathToDiffPatch ) )
259260 assert ( summarySource ?. includes ( ExportResultArchiveStructure . PathToSummary ) )
260261 } )
0 commit comments