Skip to content

Commit 4302345

Browse files
committed
fix(amazonq): remove hard-coded limits and instead rely server-side data to communicate number of code generations remaining
1 parent 420d9da commit 4302345

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

packages/amazonq/.changes/next-release/Feature-f03a4f2f-5819-4276-b914-be0b1a4ecedf.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/core/src/amazonqFeatureDev/controllers/chat/controller.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,12 +460,17 @@ export class FeatureDevController {
460460

461461
if (remainingIterations !== undefined && totalIterations !== undefined) {
462462
this.messenger.sendAnswer({
463-
type: 'answer',
463+
type: 'answer' as const,
464464
tabID: tabID,
465-
message:
466-
remainingIterations > 2 || remainingIterations <= 0
467-
? 'Would you like me to add this code to your project?'
468-
: `Would you like me to add this code to your project, or provide feedback for new code? You have ${remainingIterations} out of ${totalIterations} code generations left.`,
465+
message: (() => {
466+
if (remainingIterations > 2) {
467+
return 'Would you like me to add this code to your project, or provide feedback for new code?'
468+
} else if (remainingIterations > 0) {
469+
return `Would you like me to add this code to your project, or provide feedback for new code? You have ${remainingIterations} out of ${totalIterations} code generations left.`
470+
} else {
471+
return 'Would you like me to add this code to your project?'
472+
}
473+
})(),
469474
})
470475
}
471476

packages/core/src/test/amazonqFeatureDev/controllers/chat/controller.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -586,10 +586,15 @@ describe('Controller', () => {
586586
for (let remainingIterations = 0; remainingIterations <= 3; remainingIterations++) {
587587
it(`verifies add code messages for remaining iterations at ${remainingIterations}`, async () => {
588588
const totalIterations = 10
589-
const expectedMessage =
590-
remainingIterations > 2 || remainingIterations <= 0
591-
? 'Would you like me to add this code to your project?'
592-
: `Would you like me to add this code to your project, or provide feedback for new code? You have ${remainingIterations} out of ${totalIterations} code generations left.`
589+
const expectedMessage = (() => {
590+
if (remainingIterations > 2) {
591+
return 'Would you like me to add this code to your project, or provide feedback for new code?'
592+
} else if (remainingIterations > 0) {
593+
return `Would you like me to add this code to your project, or provide feedback for new code? You have ${remainingIterations} out of ${totalIterations} code generations left.`
594+
} else {
595+
return 'Would you like me to add this code to your project?'
596+
}
597+
})()
593598
await verifyAddCodeMessage(remainingIterations, totalIterations, expectedMessage)
594599
})
595600
}

packages/core/src/test/amazonqFeatureDev/session/sessionState.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,17 @@ describe('sessionState', () => {
111111
it('transitions to PrepareCodeGenState when codeGenerationStatus ready ', async () => {
112112
mockGetCodeGeneration = sinon.stub().resolves({
113113
codeGenerationStatus: { status: 'Complete' },
114-
codeGenerationRemainingIterationCount: 9,
115-
codeGenerationTotalIterationCount: 10,
114+
codeGenerationRemainingIterationCount: 2,
115+
codeGenerationTotalIterationCount: 3,
116116
})
117117

118118
mockExportResultArchive = sinon.stub().resolves({ newFileContents: [], deletedFiles: [], references: [] })
119119

120120
const testAction = mockSessionStateAction()
121-
const state = new CodeGenState(testConfig, [], [], [], tabId, 0, {}, 9, 10)
121+
const state = new CodeGenState(testConfig, [], [], [], tabId, 0, {}, 2, 3)
122122
const result = await state.interact(testAction)
123123

124-
const nextState = new PrepareCodeGenState(testConfig, [], [], [], tabId, 1, 9, 10, undefined)
124+
const nextState = new PrepareCodeGenState(testConfig, [], [], [], tabId, 1, 2, 3, undefined)
125125

126126
assert.deepStrictEqual(result.nextState?.deletedFiles, nextState.deletedFiles)
127127
assert.deepStrictEqual(result.nextState?.filePaths, result.nextState?.filePaths)

0 commit comments

Comments
 (0)