Skip to content

Commit e124837

Browse files
committed
trying to invoke the lambda before the test suite starts
1 parent 8987bf5 commit e124837

File tree

7 files changed

+125
-5
lines changed

7 files changed

+125
-5
lines changed

.github/workflows/node.js.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,23 @@ jobs:
214214
verbose: true
215215
file: ./coverage/${{ matrix.package }}/lcov.info
216216
token: ${{ secrets.CODECOV_TOKEN }}
217+
e2e:
218+
needs: lint-commits
219+
name: test E2E
220+
runs-on: ubuntu-latest
221+
strategy:
222+
matrix:
223+
node-version: [18.x]
224+
env:
225+
NODE_OPTIONS: '--max-old-space-size=8192'
226+
steps:
227+
- uses: actions/checkout@v4
228+
- name: Use Node.js ${{ matrix.node-version }}
229+
uses: actions/setup-node@v4
230+
with:
231+
node-version: ${{ matrix.node-version }}
232+
- run: npm ci
233+
- name: E2E Tests
234+
uses: coactions/setup-xvfb@v1
235+
with:
236+
run: npm run test:ui

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"testE2E": "npm run testE2E -w packages/ --if-present",
3131
"test:ui:prepare": "./node_modules/.bin/extest get-vscode -s ~/.vscode-test-resources -n && extest get-chromedriver -s ~/.vscode-test-resources -n",
3232
"test:ui:install": "cd packages/amazonq && npm run package 2>&1 | grep -o 'VSIX Version: [^ ]*' | cut -d' ' -f3 | xargs -I{} bash -c 'cd ../../ && ./node_modules/.bin/extest install-vsix -f amazon-q-vscode-{}.vsix -e packages/amazonq/test/e2e_new/amazonq/resources -s ~/.vscode-test-resources'",
33-
"test:ui:run": "npm run testCompile && ./node_modules/.bin/extest run-tests -s ~/.vscode-test-resources -e packages/amazonq/test/e2e_new/amazonq/resources packages/amazonq/dist/test/e2e_new/amazonq/tests/*.test.js 2>&1 | tee packages/amazonq/test/e2e_new/amazonq/logs/ui_e2e_testlog_$(date +%Y%m%d_%H%M%S).log",
33+
"test:ui:run": "npm run testCompile && ./node_modules/.bin/extest run-tests -s ~/.vscode-test-resources -e packages/amazonq/test/e2e_new/amazonq/resources packages/amazonq/dist/test/e2e_new/amazonq/tests/*.test.js",
3434
"test:ui": "npm run test:ui:prepare && npm run test:ui:install && npm run test:ui:run",
3535
"testInteg": "npm run testInteg -w packages/ --if-present",
3636
"package": "npm run package -w packages/toolkit -w packages/amazonq",

packages/amazonq/test/e2e_new/amazonq/utils/authUtils.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import { Workbench, By, WebviewView } from 'vscode-extension-tester'
66
import { findItemByText, sleep, waitForElements } from './generalUtils'
77
import { testContext } from './testContext'
8+
import { isRunningInGitHubActionsE2E } from './ciUtils'
9+
import { authenticateForCI } from './ciOidcClient'
810

911
/* Completes the entire Amazon Q login flow
1012
@@ -16,6 +18,18 @@ Currently, the function will
1618
1719
TO-DO: Currently this signInToAmazonQ is not fully autonomous as we ran into a blocker when the browser window pops up */
1820
export async function signInToAmazonQ(): Promise<void> {
21+
if (isRunningInGitHubActionsE2E()) {
22+
console.log('CI Environment detected: Using automated authentication')
23+
await authenticateForCI()
24+
25+
// Set up minimal test context for CI
26+
const workbench = new Workbench()
27+
testContext.workbench = workbench
28+
// Skip webview setup for CI as authentication is handled by Lambda
29+
return
30+
}
31+
32+
// Normal manual authentication flow for local development
1933
const workbench = new Workbench()
2034
await workbench.executeCommand('Amazon Q: Open Chat')
2135

@@ -45,6 +59,7 @@ export async function signInToAmazonQ(): Promise<void> {
4559
console.log('Waiting for manual authentication...')
4660
await sleep(12000)
4761
console.log('Manual authentication should be done')
62+
4863
await webviewView.switchBack()
4964

5065
const editorView = workbench.getEditorView()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { isRunningInGitHubActionsE2E, invokeAuthLambda } from './ciUtils'
7+
8+
/**
9+
* CI-specific authentication that bypasses browser interaction
10+
*/
11+
export async function authenticateForCI(): Promise<void> {
12+
if (!isRunningInGitHubActionsE2E()) {
13+
throw new Error('This function should only be called in CI environments')
14+
}
15+
16+
// Mock the device authorization flow for CI
17+
const mockUserCode = 'CI_AUTO_CODE'
18+
const mockVerificationUri = 'https://amzn.awsapps.com/start'
19+
20+
console.log('CI Authentication: Invoking Lambda with mock device authorization')
21+
await invokeAuthLambda(mockUserCode, mockVerificationUri)
22+
23+
// Give the Lambda time to complete the authentication
24+
await new Promise((resolve) => setTimeout(resolve, 10000))
25+
26+
console.log('CI Authentication: Lambda invocation completed')
27+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
interface AuthorizeRequest {
7+
readonly secret: string
8+
readonly userCode: string
9+
readonly verificationUri: string
10+
}
11+
12+
/**
13+
* Checks if the current environment is running in GitHub Actions CI for e2e tests
14+
*/
15+
export function isRunningInGitHubActionsE2E(): boolean {
16+
return (
17+
process.env.GITHUB_ACTIONS === 'true' &&
18+
process.env.CI === 'true' &&
19+
(process.env.GITHUB_JOB?.includes('e2e') === true ||
20+
process.env.GITHUB_WORKFLOW?.toLowerCase().includes('e2e') === true)
21+
)
22+
}
23+
24+
/**
25+
* Invokes the auth Lambda function for CI automation
26+
*/
27+
export async function invokeAuthLambda(userCode: string, verificationUri: string): Promise<void> {
28+
const lambdaArn = process.env.AUTH_UTIL_LAMBDA_ARN
29+
if (!lambdaArn) {
30+
throw new Error('AUTH_UTIL_LAMBDA_ARN environment variable is required for CI authentication')
31+
}
32+
33+
const AWS = require('aws-sdk')
34+
const lambda = new AWS.Lambda()
35+
36+
const request: AuthorizeRequest = {
37+
secret: 'GitHubBot/AuthSecret', // Default secret name
38+
userCode,
39+
verificationUri,
40+
}
41+
42+
await lambda
43+
.invoke({
44+
FunctionName: lambdaArn,
45+
Payload: JSON.stringify(request),
46+
})
47+
.promise()
48+
}

packages/amazonq/test/e2e_new/amazonq/utils/setup.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,21 @@
55
import { signInToAmazonQ } from './authUtils'
66
import { testContext } from './testContext'
77
import { closeAllTabs } from './cleanupUtils'
8+
import { isRunningInGitHubActionsE2E } from './ciUtils'
89

910
before(async function () {
1011
this.timeout(60000)
11-
console.log('\n\n*** MANUAL INTERVENTION REQUIRED ***')
12-
console.log('When prompted, you must manually click to open the browser and complete authentication')
13-
console.log('You have 60 seconds to complete this step\n\n')
12+
13+
if (isRunningInGitHubActionsE2E()) {
14+
console.log('\n\n*** CI AUTHENTICATION MODE ***')
15+
console.log('Using Lambda function for automated authentication\n\n')
16+
// CI authentication will be handled during the auth flow
17+
} else {
18+
console.log('\n\n*** MANUAL INTERVENTION REQUIRED ***')
19+
console.log('When prompted, you must manually click to open the browser and complete authentication')
20+
console.log('You have 60 seconds to complete this step\n\n')
21+
}
22+
1423
await signInToAmazonQ()
1524
const webviewView = testContext.webviewView
1625
await closeAllTabs(webviewView)

packages/core/src/shared/settings-amazonq.gen.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export const amazonqSettings = {
3636
"amazonQ.workspaceIndexMaxFileSize": {},
3737
"amazonQ.workspaceIndexCacheDirPath": {},
3838
"amazonQ.workspaceIndexIgnoreFilePatterns": {},
39-
"amazonQ.ignoredSecurityIssues": {}
39+
"amazonQ.ignoredSecurityIssues": {},
40+
"amazonQ.proxy.certificateAuthority": {}
4041
}
4142

4243
export default amazonqSettings

0 commit comments

Comments
 (0)