@@ -19,7 +19,7 @@ describe('Amazon Q Feature Dev', function () {
19
19
let tab : Messenger
20
20
21
21
const maxTestDuration = 600000
22
- const prompt = 'Implement twosum in typescript'
22
+ const prompt = 'Implement fibonacci in typescript'
23
23
const iterateApproachPrompt = prompt + ' and add tests'
24
24
const codegenApproachPrompt = prompt + ' and add even more tests'
25
25
@@ -99,24 +99,42 @@ describe('Amazon Q Feature Dev', function () {
99
99
async function iterate ( prompt : string ) {
100
100
tab . addChatMessage ( { prompt } )
101
101
102
- await retryIfRequired ( async ( ) => {
103
- // Wait for a backend response
104
- await tab . waitForChatFinishesLoading ( )
105
- } )
102
+ await retryIfRequired (
103
+ async ( ) => {
104
+ // Wait for a backend response
105
+ await tab . waitForChatFinishesLoading ( )
106
+ } ,
107
+ ( ) => {
108
+ tab . addChatMessage ( { prompt } )
109
+ }
110
+ )
106
111
}
107
112
108
113
/**
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.
114
+ * Wait for the original request to finish.
115
+ * If the response has a retry button or encountered a guardrails error, continue retrying
111
116
*
112
- * This allows the e2e tests to recover from potential one off backend problems
117
+ * This allows the e2e tests to recover from potential one off backend problems/random guardrails
113
118
*/
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 ( )
119
+ async function retryIfRequired ( waitUntilReady : ( ) = > Promise < void > , request ?: ( ) = > void ) {
120
+ await waitUntilReady ( )
121
+
122
+ const findAnotherTopic = 'find another topic to discuss'
123
+ while (
124
+ tab . hasButton ( FollowUpTypes . Retry ) ||
125
+ ( request &&
126
+ ( tab . getChatItems ( ) . pop ( ) ?. body ?. includes ( findAnotherTopic ) ||
127
+ tab . getChatItems ( ) . slice ( - 2 ) . shift ( ) ?. body ?. includes ( findAnotherTopic ) ) )
128
+ ) {
129
+ if ( tab . hasButton ( FollowUpTypes . Retry ) ) {
130
+ console . log ( 'Retrying request' )
131
+ tab . clickButton ( FollowUpTypes . Retry )
132
+ await waitUntilReady ( )
133
+ } else {
134
+ // We've hit guardrails, re-make the request and wait again
135
+ request && request ( )
136
+ await waitUntilReady ( )
137
+ }
120
138
}
121
139
122
140
// The backend never recovered
@@ -217,9 +235,14 @@ describe('Amazon Q Feature Dev', function () {
217
235
beforeEach ( async function ( ) {
218
236
this . timeout ( maxTestDuration )
219
237
tab . addChatMessage ( { command : '/dev' , prompt } )
220
- await retryIfRequired ( async ( ) => {
221
- await tab . waitForChatFinishesLoading ( )
222
- } )
238
+ await retryIfRequired (
239
+ async ( ) => {
240
+ await tab . waitForChatFinishesLoading ( )
241
+ } ,
242
+ ( ) => {
243
+ tab . addChatMessage ( { prompt } )
244
+ }
245
+ )
223
246
} )
224
247
225
248
functionalTests ( )
@@ -230,9 +253,14 @@ describe('Amazon Q Feature Dev', function () {
230
253
this . timeout ( maxTestDuration )
231
254
tab . addChatMessage ( { command : '/dev' } )
232
255
tab . addChatMessage ( { prompt } )
233
- await retryIfRequired ( async ( ) => {
234
- await tab . waitForChatFinishesLoading ( )
235
- } )
256
+ await retryIfRequired (
257
+ async ( ) => {
258
+ await tab . waitForChatFinishesLoading ( )
259
+ } ,
260
+ ( ) => {
261
+ tab . addChatMessage ( { prompt } )
262
+ }
263
+ )
236
264
} )
237
265
238
266
it ( 'Clicks examples' , async ( ) => {
0 commit comments