Skip to content

Commit 0f46ad1

Browse files
committed
tests: Allow feature dev e2e tests to recover from guardrails
1 parent b0da0a2 commit 0f46ad1

File tree

1 file changed

+48
-20
lines changed

1 file changed

+48
-20
lines changed

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

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Amazon Q Feature Dev', function () {
1919
let tab: Messenger
2020

2121
const maxTestDuration = 600000
22-
const prompt = 'Implement twosum in typescript'
22+
const prompt = 'Implement fibonacci in typescript'
2323
const iterateApproachPrompt = prompt + ' and add tests'
2424
const codegenApproachPrompt = prompt + ' and add even more tests'
2525

@@ -99,24 +99,42 @@ describe('Amazon Q Feature Dev', function () {
9999
async function iterate(prompt: string) {
100100
tab.addChatMessage({ prompt })
101101

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+
)
106111
}
107112

108113
/**
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
111116
*
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
113118
*/
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+
}
120138
}
121139

122140
// The backend never recovered
@@ -217,9 +235,14 @@ describe('Amazon Q Feature Dev', function () {
217235
beforeEach(async function () {
218236
this.timeout(maxTestDuration)
219237
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+
)
223246
})
224247

225248
functionalTests()
@@ -230,9 +253,14 @@ describe('Amazon Q Feature Dev', function () {
230253
this.timeout(maxTestDuration)
231254
tab.addChatMessage({ command: '/dev' })
232255
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+
)
236264
})
237265

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

0 commit comments

Comments
 (0)