Skip to content

Commit 46e1837

Browse files
authored
Merge pull request #4530 from jpinkney-aws/fix-amazonq-e2e-test
chore: Re-enable amazon q e2e tests
2 parents 4b09775 + abd2ab7 commit 46e1837

File tree

1 file changed

+69
-21
lines changed

1 file changed

+69
-21
lines changed

packages/core/src/testE2E/amazonq/featureDev.test.ts

Lines changed: 69 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,28 @@ import { Messenger } from './framework/messenger'
1313
import { FollowUpTypes } from '../../amazonqFeatureDev/types'
1414
import { examples, newTaskChanges, sessionClosed } from '../../amazonqFeatureDev/userFacingText'
1515
import { ChatItem } from '@aws/mynah-ui'
16+
import { sleep } from '../../shared/utilities/timeoutUtils'
1617

17-
describe.skip('Amazon Q Feature Dev', function () {
18+
describe('Amazon Q Feature Dev', function () {
1819
let framework: qTestingFramework
1920
let tab: Messenger
2021

2122
const maxTestDuration = 600000
22-
const prompt = 'Implement twosum in typescript'
23+
const prompt = 'Implement fibonacci in typescript'
2324
const iterateApproachPrompt = prompt + ' and add tests'
2425
const codegenApproachPrompt = prompt + ' and add even more tests'
26+
const tooManyRequestsWaitTime = 100000
2527

2628
before(async function () {
29+
/**
30+
* The tests are getting throttled, only run them on stable for now
31+
*
32+
* TODO: Re-enable for all versions once the backend can handle them
33+
*/
34+
if (process.env['VSCODE_TEST_VERSION'] !== 'stable') {
35+
this.skip()
36+
}
37+
2738
await using(registerAuthHook('amazonq-test-account'), async () => {
2839
await loginToIdC()
2940
})
@@ -99,24 +110,51 @@ describe.skip('Amazon Q Feature Dev', function () {
99110
async function iterate(prompt: string) {
100111
tab.addChatMessage({ prompt })
101112

102-
await retryIfRequired(async () => {
103-
// Wait for a backend response
104-
await tab.waitForChatFinishesLoading()
105-
})
113+
await retryIfRequired(
114+
async () => {
115+
// Wait for a backend response
116+
await tab.waitForChatFinishesLoading()
117+
},
118+
() => {
119+
tab.addChatMessage({ prompt })
120+
}
121+
)
106122
}
107123

108124
/**
109-
* Make the initial request and if the response has a retry button, click it until either
110-
* we can no longer retry or the tests recover.
125+
* Wait for the original request to finish.
126+
* If the response has a retry button or encountered a guardrails error, continue retrying
111127
*
112-
* This allows the e2e tests to recover from potential one off backend problems
128+
* This allows the e2e tests to recover from potential one off backend problems/random guardrails
113129
*/
114-
async function retryIfRequired(request: () => Promise<void>) {
115-
await request()
116-
while (tab.hasButton(FollowUpTypes.Retry)) {
117-
console.log('Retrying request')
118-
tab.clickButton(FollowUpTypes.Retry)
119-
await request()
130+
async function retryIfRequired(waitUntilReady: () => Promise<void>, request?: () => void) {
131+
await waitUntilReady()
132+
133+
const findAnotherTopic = 'find another topic to discuss'
134+
const tooManyRequests = 'Too many requests'
135+
const failureState = (message: string) => {
136+
return (
137+
tab.getChatItems().pop()?.body?.includes(message) ||
138+
tab.getChatItems().slice(-2).shift()?.body?.includes(message)
139+
)
140+
}
141+
while (
142+
tab.hasButton(FollowUpTypes.Retry) ||
143+
(request && (failureState(findAnotherTopic) || failureState(tooManyRequests)))
144+
) {
145+
if (tab.hasButton(FollowUpTypes.Retry)) {
146+
console.log('Retrying request')
147+
tab.clickButton(FollowUpTypes.Retry)
148+
await waitUntilReady()
149+
} else if (failureState(tooManyRequests)) {
150+
// 3 versions of the e2e tests are running at the same time in the ci so we occassionally need to wait before continuing
151+
request && request()
152+
await sleep(tooManyRequestsWaitTime)
153+
} else {
154+
// We've hit guardrails, re-make the request and wait again
155+
request && request()
156+
await waitUntilReady()
157+
}
120158
}
121159

122160
// The backend never recovered
@@ -217,9 +255,14 @@ describe.skip('Amazon Q Feature Dev', function () {
217255
beforeEach(async function () {
218256
this.timeout(maxTestDuration)
219257
tab.addChatMessage({ command: '/dev', prompt })
220-
await retryIfRequired(async () => {
221-
await tab.waitForChatFinishesLoading()
222-
})
258+
await retryIfRequired(
259+
async () => {
260+
await tab.waitForChatFinishesLoading()
261+
},
262+
() => {
263+
tab.addChatMessage({ prompt })
264+
}
265+
)
223266
})
224267

225268
functionalTests()
@@ -230,9 +273,14 @@ describe.skip('Amazon Q Feature Dev', function () {
230273
this.timeout(maxTestDuration)
231274
tab.addChatMessage({ command: '/dev' })
232275
tab.addChatMessage({ prompt })
233-
await retryIfRequired(async () => {
234-
await tab.waitForChatFinishesLoading()
235-
})
276+
await retryIfRequired(
277+
async () => {
278+
await tab.waitForChatFinishesLoading()
279+
},
280+
() => {
281+
tab.addChatMessage({ prompt })
282+
}
283+
)
236284
})
237285

238286
it('Clicks examples', async () => {

0 commit comments

Comments
 (0)