Skip to content

Commit d8b34f1

Browse files
siakmun-awskaranA-aws
authored andcommitted
test(amazonq): messages at different remaining iteration counts aws#6381
## Problem Previously the logic of showing different messages at different remaining iteration counts are tested manually. ## Solution Adding tests to automate the process.
1 parent 755368f commit d8b34f1

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ export class FeatureDevController {
619619
if (isStoppedGeneration) {
620620
this.messenger.sendAnswer({
621621
message: ((remainingIterations) => {
622-
if (remainingIterations && totalIterations) {
622+
if (totalIterations !== undefined) {
623623
if (remainingIterations <= 0) {
624624
return "I stopped generating your code. You don't have more iterations left, however, you can start a new session."
625625
} else if (remainingIterations <= 2) {

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

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { featureDevScheme, featureName, messageWithConversationId } from '../../
4343
import { i18n } from '../../../../shared/i18n-helper'
4444
import { FollowUpTypes } from '../../../../amazonq/commons/types'
4545
import { ToolkitError } from '../../../../shared'
46+
import { MessengerTypes } from '../../../../amazonqFeatureDev/controllers/chat/messenger/constants'
4647

4748
let mockGetCodeGeneration: sinon.SinonStub
4849
describe('Controller', () => {
@@ -531,10 +532,11 @@ describe('Controller', () => {
531532
await waitUntil(() => Promise.resolve(sendMetricDataTelemetrySpy.callCount >= 2), {})
532533
}
533534

534-
async function verifyAddCodeMessage(
535-
remainingIterations: number,
536-
totalIterations: number,
537-
expectedMessage: string
535+
async function verifyMessage(
536+
expectedMessage: string,
537+
type: MessengerTypes,
538+
remainingIterations?: number,
539+
totalIterations?: number
538540
) {
539541
sinon.stub(session, 'send').resolves()
540542
sinon.stub(session, 'sendLinesOfCodeGeneratedTelemetry').resolves() // Avoid sending extra telemetry
@@ -547,7 +549,7 @@ describe('Controller', () => {
547549

548550
assert.ok(
549551
sendAnswerSpy.calledWith({
550-
type: 'answer',
552+
type,
551553
tabID,
552554
message: expectedMessage,
553555
})
@@ -600,7 +602,33 @@ describe('Controller', () => {
600602
return 'Would you like me to add this code to your project?'
601603
}
602604
})()
603-
await verifyAddCodeMessage(remainingIterations, totalIterations, expectedMessage)
605+
await verifyMessage(expectedMessage, 'answer', remainingIterations, totalIterations)
606+
})
607+
}
608+
609+
for (let remainingIterations = -1; remainingIterations <= 3; remainingIterations++) {
610+
let remaining: number | undefined = remainingIterations
611+
if (remainingIterations < 0) {
612+
remaining = undefined
613+
}
614+
it(`verifies messages after cancellation for remaining iterations at ${remaining !== undefined ? remaining : 'undefined'}`, async () => {
615+
const totalIterations = 10
616+
const expectedMessage = (() => {
617+
if (remaining === undefined || remaining > 2) {
618+
return 'I stopped generating your code. If you want to continue working on this task, provide another description.'
619+
} else if (remaining > 0) {
620+
return `I stopped generating your code. If you want to continue working on this task, provide another description. You have ${remaining} out of ${totalIterations} code generations left.`
621+
} else {
622+
return "I stopped generating your code. You don't have more iterations left, however, you can start a new session."
623+
}
624+
})()
625+
session.state.tokenSource.cancel()
626+
await verifyMessage(
627+
expectedMessage,
628+
'answer-part',
629+
remaining,
630+
remaining === undefined ? undefined : totalIterations
631+
)
604632
})
605633
}
606634
})

0 commit comments

Comments
 (0)