-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathcreate-protocols.test.ts
More file actions
249 lines (214 loc) · 7.89 KB
/
create-protocols.test.ts
File metadata and controls
249 lines (214 loc) · 7.89 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/* eslint-disable security/detect-non-literal-fs-filename */
import { exists, prereqs, readProjectConfig, runCLI } from '../src/test-utils/index.js';
import { randomUUID } from 'node:crypto';
import { mkdir, readFile, rm } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { afterAll, beforeAll, describe, expect, it } from 'vitest';
describe.skipIf(!prereqs.npm || !prereqs.git)('integration: create with protocol modes', () => {
let testDir: string;
beforeAll(async () => {
testDir = join(tmpdir(), `agentcore-integ-protocols-${randomUUID()}`);
await mkdir(testDir, { recursive: true });
});
afterAll(async () => {
await rm(testDir, { recursive: true, force: true });
});
it('creates MCP standalone project (no framework, no model provider)', async () => {
const name = `Mcp${Date.now().toString().slice(-6)}`;
const result = await runCLI(
['create', '--name', name, '--language', 'Python', '--protocol', 'MCP', '--json'],
testDir
);
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(true);
const agentName = json.agentName || name;
const agentDir = join(json.projectPath, 'app', agentName);
expect(await exists(agentDir), 'Agent directory should exist').toBe(true);
expect(await exists(join(agentDir, 'main.py')), 'main.py should exist').toBe(true);
expect(await exists(join(agentDir, 'pyproject.toml')), 'pyproject.toml should exist').toBe(true);
// Verify pyproject.toml references mcp (FastMCP)
const pyproject = await readFile(join(agentDir, 'pyproject.toml'), 'utf-8');
expect(pyproject.toLowerCase().includes('mcp'), 'pyproject.toml should reference mcp').toBe(true);
// Verify config has protocol set to MCP
const config = await readProjectConfig(json.projectPath);
const agents = config.runtimes as Record<string, unknown>[];
expect(agents).toBeDefined();
expect(agents.length).toBe(1);
expect(agents[0]!.name).toBe(agentName);
expect(agents[0]!.protocol).toBe('MCP');
// MCP agents should have no credentials
const credentials = (config.credentials as Record<string, unknown>[]) ?? [];
expect(credentials.length).toBe(0);
});
it('creates A2A project with Strands framework', async () => {
const name = `A2a${Date.now().toString().slice(-6)}`;
const result = await runCLI(
[
'create',
'--name',
name,
'--language',
'Python',
'--protocol',
'A2A',
'--framework',
'Strands',
'--model-provider',
'Bedrock',
'--memory',
'none',
'--json',
],
testDir
);
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(true);
const agentName = json.agentName || name;
const agentDir = join(json.projectPath, 'app', agentName);
expect(await exists(agentDir), 'Agent directory should exist').toBe(true);
expect(await exists(join(agentDir, 'main.py')), 'main.py should exist').toBe(true);
// Verify config has protocol set to A2A
const config = await readProjectConfig(json.projectPath);
const agents = config.runtimes as Record<string, unknown>[];
expect(agents.length).toBe(1);
expect(agents[0]!.protocol).toBe('A2A');
});
it('creates HTTP project with explicit protocol HTTP', async () => {
const name = `Http${Date.now().toString().slice(-6)}`;
const result = await runCLI(
[
'create',
'--name',
name,
'--language',
'Python',
'--framework',
'Strands',
'--model-provider',
'Bedrock',
'--memory',
'none',
'--json',
],
testDir
);
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(true);
// Verify config has explicit protocol: HTTP
const config = await readProjectConfig(json.projectPath);
const agents = config.runtimes as Record<string, unknown>[];
expect(agents.length).toBe(1);
expect(agents[0]!.protocol).toBe('HTTP');
});
it('rejects invalid protocol', async () => {
const name = `Bad${Date.now().toString().slice(-6)}`;
const result = await runCLI(
['create', '--name', name, '--language', 'Python', '--protocol', 'INVALID', '--json'],
testDir
);
expect(result.exitCode).not.toBe(0);
});
it('rejects MCP with --framework flag', async () => {
const name = `McpFw${Date.now().toString().slice(-6)}`;
const result = await runCLI(
['create', '--name', name, '--language', 'Python', '--protocol', 'MCP', '--framework', 'Strands', '--json'],
testDir
);
expect(result.exitCode).not.toBe(0);
});
});
describe.skipIf(!prereqs.npm || !prereqs.git)('integration: add agent with protocol modes', () => {
let testDir: string;
let projectPath: string;
beforeAll(async () => {
testDir = join(tmpdir(), `agentcore-integ-add-protocol-${randomUUID()}`);
await mkdir(testDir, { recursive: true });
// Create a base project first (HTTP, no agent)
const result = await runCLI(['create', '--name', 'ProtoTest', '--no-agent', '--json'], testDir);
expect(result.exitCode, `setup stderr: ${result.stderr}`).toBe(0);
const json = JSON.parse(result.stdout);
projectPath = json.projectPath;
});
afterAll(async () => {
await rm(testDir, { recursive: true, force: true });
});
it('adds MCP agent to existing project', async () => {
const name = `McpAgent${Date.now().toString().slice(-6)}`;
const result = await runCLI(
['add', 'agent', '--name', name, '--protocol', 'MCP', '--language', 'Python', '--json'],
projectPath
);
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(true);
const config = await readProjectConfig(projectPath);
const agents = config.runtimes as Record<string, unknown>[];
const mcpAgent = agents.find(a => a.name === name);
expect(mcpAgent).toBeDefined();
expect(mcpAgent!.protocol).toBe('MCP');
});
it('adds A2A agent to existing project', async () => {
const name = `A2aAgent${Date.now().toString().slice(-6)}`;
const result = await runCLI(
[
'add',
'agent',
'--name',
name,
'--protocol',
'A2A',
'--framework',
'Strands',
'--model-provider',
'Bedrock',
'--memory',
'none',
'--language',
'Python',
'--json',
],
projectPath
);
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(true);
const config = await readProjectConfig(projectPath);
const agents = config.runtimes as Record<string, unknown>[];
const a2aAgent = agents.find(a => a.name === name);
expect(a2aAgent).toBeDefined();
expect(a2aAgent!.protocol).toBe('A2A');
});
it('adds BYO agent with MCP protocol', async () => {
const name = `ByoMcp${Date.now().toString().slice(-6)}`;
const result = await runCLI(
[
'add',
'agent',
'--name',
name,
'--type',
'byo',
'--protocol',
'MCP',
'--language',
'Python',
'--code-location',
`app/${name}/`,
'--json',
],
projectPath
);
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(true);
const config = await readProjectConfig(projectPath);
const agents = config.runtimes as Record<string, unknown>[];
const byoAgent = agents.find(a => a.name === name);
expect(byoAgent).toBeDefined();
expect(byoAgent!.protocol).toBe('MCP');
});
});