Skip to content

Commit 2e29b54

Browse files
committed
Minor fixes and PR fixes
1 parent ba771da commit 2e29b54

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

packages/core/src/codewhisperer/service/transformByQ/transformationHistoryHandler.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import * as CodeWhispererConstants from '../../models/constants'
1111
import { JDKVersion, TransformationType, transformByQState } from '../../models/model'
1212
import { getLogger } from '../../../shared/logger/logger'
1313
import { codeWhispererClient } from '../../../codewhisperer/client/codewhisperer'
14-
import { pollTransformationStatusUntilComplete } from '../../commands/startTransformByQ'
15-
import { downloadAndExtractResultArchive } from './transformApiHandler'
14+
import { downloadAndExtractResultArchive, pollTransformationJob } from './transformApiHandler'
1615
import { ChatSessionManager } from '../../../amazonqGumby/chat/storages/chatSession'
1716
import { AuthUtil } from '../../util/authUtil'
1817
import { setMaven } from './transformFileHandler'
@@ -134,7 +133,7 @@ export async function copyArtifacts(pathToArchiveDir: string, pathToDestinationD
134133
getLogger().error('Code Transformation: Error saving local copy of artifacts: %s', (error as Error).message)
135134
}
136135

137-
const buildLogsPath = path.join(summaryPath, 'buildCommandOutput.log')
136+
const buildLogsPath = path.join(path.dirname(summaryPath), 'buildCommandOutput.log')
138137
try {
139138
await fs.copy(buildLogsPath, path.join(pathToDestinationDir, 'summary', 'buildCommandOutput.log'))
140139
} catch (error) {
@@ -248,7 +247,7 @@ export async function refreshJob(jobId: string, currentStatus: string, projectNa
248247
getLogger().error('Code Transformation: Error fetching status (job id: %s): %s', jobId, errorMessage)
249248
if (errorMessage.includes('not authorized to make this call')) {
250249
// job not available on backend
251-
status = 'FAILED'
250+
status = 'FAILED' // won't allow retries for this job
252251
} else {
253252
// some other error (e.g. network error)
254253
return
@@ -418,8 +417,9 @@ async function setupTransformationState(jobId: string, projectName: string, stat
418417
}
419418

420419
async function pollAndCompleteTransformation(jobId: string) {
421-
const status = await pollTransformationStatusUntilComplete(
420+
const status = await pollTransformationJob(
422421
jobId,
422+
CodeWhispererConstants.validStatesForCheckingDownloadUrl,
423423
AuthUtil.instance.regionProfileManager.activeRegionProfile
424424
)
425425
await cleanupTempJobFiles(transformByQState.getJobHistoryPath(), status, transformByQState.getPayloadFilePath())

packages/core/src/test/amazonqGumby/transformationJobHistory.test.ts

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@ import { ExportResultArchiveStructure } from '../../shared/utilities/download'
2525
import { JDKVersion, TransformationType } from '../../codewhisperer'
2626

2727
describe('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
})
@@ -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 () {
@@ -229,16 +237,9 @@ 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 () {

0 commit comments

Comments
 (0)