Skip to content

Commit 69a7754

Browse files
authored
Merge pull request #4405 from jpinkney-aws/jpinkney-aws/sso-testing
tests: Allow Amazon Q e2e tests to call the backend
2 parents eb1d9e7 + a613d51 commit 69a7754

File tree

4 files changed

+53
-33
lines changed

4 files changed

+53
-33
lines changed

CONTRIBUTING.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ Unlike the user setting overrides, not all of these environment variables have t
420420

421421
#### Lambda
422422

423-
- `AUTH_UTIL_LAMBDA_ARN`: The Amazon Resource Name (ARN) of the lambda function
423+
- `AUTH_UTIL_LAMBDA_ARN`: The Auth Util Lambda is used to log into using Builder ID/IdC automatically when running e2e tests. This is the arn that points to the auth util lambda.
424424

425425
#### ECS
426426

@@ -436,8 +436,10 @@ Unlike the user setting overrides, not all of these environment variables have t
436436
- `GITHUB_ACTION`: The name of the current GitHub Action workflow step that is running
437437
- `CODEBUILD_BUILD_ID`: The unique ID of the current CodeBuild build that is executing
438438
- `AWS_TOOLKIT_AUTOMATION`: If tests are currently being ran
439-
- `DEVELOPMENT_PATH`: The path to the aws toolkit vscode project
439+
- `TEST_SSO_STARTURL`: The start url you want to use on E2E tests
440+
- `TEST_SSO_REGION`: The region for the start url you want to use on E2E tests
440441
- `AWS_TOOLKIT_TEST_NO_COLOR`: If the tests should include colour in their output
442+
- `DEVELOPMENT_PATH`: The path to the aws toolkit vscode project
441443
- `TEST_DIR` - The directory where the test runner should find the tests
442444

443445
### SAM/CFN ("goformation") JSON schema

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

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,22 @@ import assert from 'assert'
77
import { qTestingFramework } from './framework/framework'
88
import { FollowUpTypes } from '../../amazonqFeatureDev/types'
99
import sinon from 'sinon'
10-
import { FeatureDevClient } from '../../amazonqFeatureDev/client/featureDev'
1110
import { verifyTextOrder } from './framework/text'
1211
import { examples } from '../../amazonqFeatureDev/userFacingText'
13-
import * as authUtil from '../../codewhisperer/util/authUtil'
14-
import request from '../../common/request'
12+
import { registerAuthHook, using } from '../../test/setupUtil'
13+
import { loginToIdC } from './utils/setup'
1514

1615
describe('Amazon Q Feature Dev', function () {
1716
let framework: qTestingFramework
1817

19-
const samplePlanResponse = 'sample plan response'
18+
before(async function () {
19+
await using(registerAuthHook('amazonq-test-account'), async () => {
20+
await loginToIdC()
21+
})
22+
})
2023

2124
beforeEach(() => {
22-
/**
23-
* TODO remove these stubs when we know the backend can handle all the test load + when we know the tests
24-
* are working without any flakiness
25-
*/
26-
sinon.stub(authUtil, 'getChatAuthState').resolves({
27-
amazonQ: 'connected',
28-
codewhispererChat: 'connected',
29-
codewhispererCore: 'connected',
30-
})
31-
sinon.stub(FeatureDevClient.prototype, 'createConversation').resolves('1234')
32-
sinon.stub(FeatureDevClient.prototype, 'createUploadUrl').resolves({
33-
uploadId: '5678',
34-
uploadUrl: 'foo',
35-
$response: sinon.mock() as any,
36-
})
37-
sinon.stub(FeatureDevClient.prototype, 'generatePlan').resolves(samplePlanResponse)
38-
sinon.stub(request, 'fetch').resolves({
39-
response: {
40-
status: 200,
41-
},
42-
})
25+
registerAuthHook('amazonq-test-account')
4326
framework = new qTestingFramework('featuredev', true, true)
4427
})
4528

@@ -85,8 +68,12 @@ describe('Amazon Q Feature Dev', function () {
8568

8669
const chatItems = q.getChatItems()
8770

88-
// Verify that all the responses come back in the correct order
89-
verifyTextOrder(chatItems, ['Welcome to /dev', prompt, samplePlanResponse])
71+
/**
72+
* Verify that all the responses come back in the correct order and that a response
73+
* after the prompt is non empty (represents a response from the backend, since the same response isn't
74+
* guarenteed we can't verify direct responses)
75+
*/
76+
verifyTextOrder(chatItems, [/Welcome to \/dev/, new RegExp(prompt), /.\S/])
9077

9178
// Check that the last UI message has the two buttons
9279
assert.notStrictEqual(chatItems.pop()?.followUp?.options, [
@@ -123,8 +110,12 @@ describe('Amazon Q Feature Dev', function () {
123110

124111
const chatItems = q.getChatItems()
125112

126-
// Verify that all the responses come back in the correct order
127-
verifyTextOrder(chatItems, [prompt, samplePlanResponse])
113+
/**
114+
* Verify that all the responses come back in the correct order and that a response
115+
* after the prompt is non empty (represents a response from the backend, since the same response isn't
116+
* guarenteed we can't verify direct responses)
117+
*/
118+
verifyTextOrder(chatItems, [/Welcome to \/dev/, new RegExp(prompt), /.\S/])
128119

129120
// Check that the UI has the two buttons
130121
assert.notStrictEqual(chatItems.pop()?.followUp?.options, [

packages/toolkit/src/testE2E/amazonq/framework/text.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import { ChatItem } from '@aws/mynah-ui'
1212
* @param expectedText An array of expected text items in order
1313
* @returns true if the items in expectedText are found in the correct order in chatItems otherwise false
1414
*/
15-
export function verifyTextOrder(chatItems: ChatItem[], expectedText: string[]) {
15+
export function verifyTextOrder(chatItems: ChatItem[], expectedText: RegExp[]) {
1616
let currInd = 0
1717
for (const item of chatItems) {
18-
if (item.body?.includes(expectedText[currInd])) {
18+
const currentExpected = expectedText[currInd]
19+
if (currentExpected && item.body?.match(currentExpected)) {
1920
currInd++
2021
}
2122
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import { AuthUtil, getChatAuthState } from '../../../codewhisperer/util/authUtil'
6+
7+
export async function loginToIdC() {
8+
const authState = await getChatAuthState()
9+
if (process.env['AWS_TOOLKIT_AUTOMATION'] === 'local') {
10+
if (authState.amazonQ !== 'connected') {
11+
throw new Error('You will need to login manually before running tests.')
12+
}
13+
return
14+
}
15+
16+
const startUrl = process.env['TEST_SSO_STARTURL']
17+
const region = process.env['TEST_SSO_REGION']
18+
19+
if (!startUrl || !region) {
20+
throw new Error(
21+
'TEST_SSO_STARTURL and TEST_SSO_REGION are required environment variables when running Amazon Q E2E tests'
22+
)
23+
}
24+
25+
await AuthUtil.instance.connectToEnterpriseSso(startUrl, region)
26+
}

0 commit comments

Comments
 (0)