generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 4
add end to end tests #322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+517
−393
Merged
add end to end tests #322
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| name: E2E Tests | ||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| aws_region: | ||
| description: 'AWS region for deployment' | ||
| default: 'us-east-1' | ||
|
|
||
| permissions: | ||
| id-token: write # OIDC — lets GitHub assume an AWS IAM role via short-lived token (no stored keys) | ||
| contents: read | ||
|
|
||
| jobs: | ||
| e2e: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 30 | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
| - uses: actions/setup-node@v6 | ||
| with: | ||
| node-version: '20.x' | ||
| cache: 'npm' | ||
| - name: Configure git | ||
| run: | | ||
| git config --global user.email "ci@amazon.com" | ||
| git config --global user.name "CI" | ||
| - uses: astral-sh/setup-uv@v5 | ||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@v4 | ||
| with: | ||
| role-to-assume: ${{ secrets.E2E_AWS_ROLE_ARN }} | ||
| aws-region: ${{ inputs.aws_region }} | ||
| - name: Get AWS Account ID | ||
| id: aws | ||
| run: echo "account_id=$(aws sts get-caller-identity --query Account --output text)" >> "$GITHUB_OUTPUT" | ||
| - run: npm ci | ||
| - run: npm run build | ||
| - name: Run E2E tests | ||
| env: | ||
| AWS_ACCOUNT_ID: ${{ steps.aws.outputs.account_id }} | ||
| AWS_REGION: ${{ inputs.aws_region }} | ||
| run: npm run test:e2e |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import { hasAwsCredentials, parseJsonOutput, prereqs, runCLI } from '../src/test-utils/index.js'; | ||
| import { execSync } from 'node:child_process'; | ||
| import { randomUUID } from 'node:crypto'; | ||
| import { mkdir, rm, writeFile } from 'node:fs/promises'; | ||
| import { tmpdir } from 'node:os'; | ||
| import { join } from 'node:path'; | ||
| import { afterAll, beforeAll, describe, expect, it } from 'vitest'; | ||
|
|
||
| const hasAws = hasAwsCredentials(); | ||
| const canRun = prereqs.npm && prereqs.git && prereqs.uv && hasAws; | ||
|
|
||
| describe.sequential('e2e: create → deploy → invoke', () => { | ||
| let testDir: string; | ||
| let projectPath: string; | ||
| let agentName: string; | ||
|
|
||
| beforeAll(async () => { | ||
| if (!canRun) return; | ||
|
|
||
| testDir = join(tmpdir(), `agentcore-e2e-${randomUUID()}`); | ||
| await mkdir(testDir, { recursive: true }); | ||
|
|
||
| agentName = `E2e${Date.now()}`; | ||
| const result = await runCLI( | ||
| [ | ||
| 'create', | ||
| '--name', | ||
| agentName, | ||
| '--language', | ||
| 'Python', | ||
| '--framework', | ||
| 'Strands', | ||
| '--model-provider', | ||
| 'Bedrock', | ||
| '--memory', | ||
| 'none', | ||
| '--json', | ||
| ], | ||
| testDir, | ||
| false | ||
| ); | ||
|
|
||
| expect(result.exitCode, `Create failed: ${result.stderr}`).toBe(0); | ||
| const json = parseJsonOutput(result.stdout) as { projectPath: string }; | ||
| projectPath = json.projectPath; | ||
|
|
||
| // TODO: Replace with `agentcore add target` once the CLI command is re-introduced | ||
| const account = | ||
| process.env.AWS_ACCOUNT_ID || | ||
| execSync('aws sts get-caller-identity --query Account --output text').toString().trim(); | ||
| const region = process.env.AWS_REGION || 'us-east-1'; | ||
| const awsTargetsPath = join(projectPath, 'agentcore', 'aws-targets.json'); | ||
| await writeFile(awsTargetsPath, JSON.stringify([{ name: 'default', account, region }])); | ||
| }, 120000); | ||
|
|
||
| afterAll(async () => { | ||
| if (projectPath && hasAws) { | ||
| await runCLI(['remove', 'all', '--json'], projectPath, false); | ||
| const result = await runCLI(['deploy', '--yes', '--json'], projectPath, false); | ||
|
|
||
| if (result.exitCode !== 0) { | ||
| console.log('Teardown stdout:', result.stdout); | ||
| console.log('Teardown stderr:', result.stderr); | ||
| } | ||
| } | ||
| if (testDir) await rm(testDir, { recursive: true, force: true }); | ||
| }, 600000); | ||
|
|
||
| it.skipIf(!canRun)( | ||
| 'deploys to AWS successfully', | ||
| async () => { | ||
| expect(projectPath, 'Project should have been created').toBeTruthy(); | ||
|
|
||
| const result = await runCLI(['deploy', '--yes', '--json'], projectPath, false); | ||
|
|
||
| if (result.exitCode !== 0) { | ||
| console.log('Deploy stdout:', result.stdout); | ||
| console.log('Deploy stderr:', result.stderr); | ||
| } | ||
|
|
||
| expect(result.exitCode, `Deploy failed: ${result.stderr}`).toBe(0); | ||
|
|
||
| const json = parseJsonOutput(result.stdout) as { success: boolean }; | ||
| expect(json.success, 'Deploy should report success').toBe(true); | ||
| }, | ||
| 300000 | ||
| ); | ||
|
|
||
| it.skipIf(!canRun)( | ||
| 'invokes the deployed agent', | ||
| async () => { | ||
| expect(projectPath, 'Project should have been created').toBeTruthy(); | ||
jesseturner21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const result = await runCLI( | ||
| ['invoke', '--prompt', 'Say hello', '--agent', agentName, '--json'], | ||
| projectPath, | ||
| false | ||
| ); | ||
|
|
||
| if (result.exitCode !== 0) { | ||
| console.log('Invoke stdout:', result.stdout); | ||
| console.log('Invoke stderr:', result.stderr); | ||
| } | ||
|
|
||
| expect(result.exitCode, `Invoke failed: ${result.stderr}`).toBe(0); | ||
|
|
||
| const json = parseJsonOutput(result.stdout) as { success: boolean }; | ||
| expect(json.success, 'Invoke should report success').toBe(true); | ||
| }, | ||
| 120000 | ||
| ); | ||
| }); | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.