@@ -13,17 +13,28 @@ import { Messenger } from './framework/messenger'
13
13
import { FollowUpTypes } from '../../amazonqFeatureDev/types'
14
14
import { examples , newTaskChanges , sessionClosed } from '../../amazonqFeatureDev/userFacingText'
15
15
import { ChatItem } from '@aws/mynah-ui'
16
+ import { sleep } from '../../shared/utilities/timeoutUtils'
16
17
17
- describe . skip ( 'Amazon Q Feature Dev' , function ( ) {
18
+ describe ( 'Amazon Q Feature Dev' , function ( ) {
18
19
let framework : qTestingFramework
19
20
let tab : Messenger
20
21
21
22
const maxTestDuration = 600000
22
- const prompt = 'Implement twosum in typescript'
23
+ const prompt = 'Implement fibonacci in typescript'
23
24
const iterateApproachPrompt = prompt + ' and add tests'
24
25
const codegenApproachPrompt = prompt + ' and add even more tests'
26
+ const tooManyRequestsWaitTime = 100000
25
27
26
28
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
+
27
38
await using( registerAuthHook ( 'amazonq-test-account' ) , async ( ) => {
28
39
await loginToIdC ( )
29
40
} )
@@ -99,24 +110,51 @@ describe.skip('Amazon Q Feature Dev', function () {
99
110
async function iterate ( prompt : string ) {
100
111
tab . addChatMessage ( { prompt } )
101
112
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
+ )
106
122
}
107
123
108
124
/**
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
111
127
*
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
113
129
*/
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
+ }
120
158
}
121
159
122
160
// The backend never recovered
@@ -217,9 +255,14 @@ describe.skip('Amazon Q Feature Dev', function () {
217
255
beforeEach ( async function ( ) {
218
256
this . timeout ( maxTestDuration )
219
257
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
+ )
223
266
} )
224
267
225
268
functionalTests ( )
@@ -230,9 +273,14 @@ describe.skip('Amazon Q Feature Dev', function () {
230
273
this . timeout ( maxTestDuration )
231
274
tab . addChatMessage ( { command : '/dev' } )
232
275
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
+ )
236
284
} )
237
285
238
286
it ( 'Clicks examples' , async ( ) => {
0 commit comments