Skip to content

Commit 8a496b9

Browse files
siakmun-awskevluu-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 d15b125 commit 8a496b9

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
@@ -566,7 +566,7 @@ export class FeatureDevController {
566566
if (isStoppedGeneration) {
567567
this.messenger.sendAnswer({
568568
message: ((remainingIterations) => {
569-
if (remainingIterations && totalIterations) {
569+
if (totalIterations !== undefined) {
570570
if (remainingIterations <= 0) {
571571
return "I stopped generating your code. You don't have more iterations left, however, you can start a new session."
572572
} 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', () => {
@@ -526,10 +527,11 @@ describe('Controller', () => {
526527
await waitUntil(() => Promise.resolve(sendMetricDataTelemetrySpy.callCount >= 2), {})
527528
}
528529

529-
async function verifyAddCodeMessage(
530-
remainingIterations: number,
531-
totalIterations: number,
532-
expectedMessage: string
530+
async function verifyMessage(
531+
expectedMessage: string,
532+
type: MessengerTypes,
533+
remainingIterations?: number,
534+
totalIterations?: number
533535
) {
534536
sinon.stub(session, 'send').resolves()
535537
sinon.stub(session, 'sendLinesOfCodeGeneratedTelemetry').resolves() // Avoid sending extra telemetry
@@ -542,7 +544,7 @@ describe('Controller', () => {
542544

543545
assert.ok(
544546
sendAnswerSpy.calledWith({
545-
type: 'answer',
547+
type,
546548
tabID,
547549
message: expectedMessage,
548550
})
@@ -595,7 +597,33 @@ describe('Controller', () => {
595597
return 'Would you like me to add this code to your project?'
596598
}
597599
})()
598-
await verifyAddCodeMessage(remainingIterations, totalIterations, expectedMessage)
600+
await verifyMessage(expectedMessage, 'answer', remainingIterations, totalIterations)
601+
})
602+
}
603+
604+
for (let remainingIterations = -1; remainingIterations <= 3; remainingIterations++) {
605+
let remaining: number | undefined = remainingIterations
606+
if (remainingIterations < 0) {
607+
remaining = undefined
608+
}
609+
it(`verifies messages after cancellation for remaining iterations at ${remaining !== undefined ? remaining : 'undefined'}`, async () => {
610+
const totalIterations = 10
611+
const expectedMessage = (() => {
612+
if (remaining === undefined || remaining > 2) {
613+
return 'I stopped generating your code. If you want to continue working on this task, provide another description.'
614+
} else if (remaining > 0) {
615+
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.`
616+
} else {
617+
return "I stopped generating your code. You don't have more iterations left, however, you can start a new session."
618+
}
619+
})()
620+
session.state.tokenSource.cancel()
621+
await verifyMessage(
622+
expectedMessage,
623+
'answer-part',
624+
remaining,
625+
remaining === undefined ? undefined : totalIterations
626+
)
599627
})
600628
}
601629
})

0 commit comments

Comments
 (0)