-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathcreate-deploy-invoke.test.ts
More file actions
112 lines (93 loc) · 3.54 KB
/
create-deploy-invoke.test.ts
File metadata and controls
112 lines (93 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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();
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
);
});