forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-edge-cases.test.ts
More file actions
195 lines (171 loc) · 5.87 KB
/
Copy pathcreate-edge-cases.test.ts
File metadata and controls
195 lines (171 loc) · 5.87 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
/* eslint-disable security/detect-non-literal-fs-filename */
import { exists, prereqs, runCLI } from '../src/test-utils/index.js';
import { createTelemetryHelper } from '../src/test-utils/telemetry-helper.js';
import { randomUUID } from 'node:crypto';
import { mkdir, 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 edge cases', () => {
let testDir: string;
const telemetry = createTelemetryHelper();
beforeAll(async () => {
testDir = join(tmpdir(), `agentcore-integ-edge-${randomUUID()}`);
await mkdir(testDir, { recursive: true });
});
afterAll(async () => {
telemetry.destroy();
await rm(testDir, { recursive: true, force: true });
});
describe('reserved names', () => {
it('rejects reserved name "Test"', async () => {
const result = await runCLI(['create', '--name', 'Test', '--json'], testDir, { env: telemetry.env });
expect(result.exitCode).toBe(1);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(false);
expect(typeof json.error).toBe('string');
expect(
json.error.toLowerCase().includes('reserved') || json.error.toLowerCase().includes('conflict'),
`Error should mention reserved/conflict: ${json.error}`
).toBeTruthy();
telemetry.assertMetricEmitted({
command: 'create',
exit_reason: 'failure',
language: 'python',
has_agent: 'true',
});
});
it('rejects reserved name "bedrock"', async () => {
const result = await runCLI(['create', '--name', 'bedrock', '--json'], testDir);
expect(result.exitCode).toBe(1);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(false);
expect(typeof json.error).toBe('string');
});
});
describe('invalid framework/provider combos', () => {
it('rejects GoogleADK with Bedrock provider', async () => {
const result = await runCLI(
[
'create',
'--name',
`GadkBr${Date.now().toString().slice(-6)}`,
'--language',
'Python',
'--framework',
'GoogleADK',
'--model-provider',
'Bedrock',
'--memory',
'none',
'--json',
],
testDir
);
expect(result.exitCode).toBe(1);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(false);
expect(typeof json.error).toBe('string');
});
it('rejects OpenAIAgents with Anthropic provider', async () => {
const result = await runCLI(
[
'create',
'--name',
`OaiAn${Date.now().toString().slice(-6)}`,
'--language',
'Python',
'--framework',
'OpenAIAgents',
'--model-provider',
'Anthropic',
'--memory',
'none',
'--json',
],
testDir
);
expect(result.exitCode).toBe(1);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(false);
expect(typeof json.error).toBe('string');
});
it('rejects invalid framework name', async () => {
const result = await runCLI(
[
'create',
'--name',
`BadFw${Date.now().toString().slice(-6)}`,
'--language',
'Python',
'--framework',
'InvalidFramework',
'--model-provider',
'Bedrock',
'--memory',
'none',
'--json',
],
testDir
);
expect(result.exitCode).toBe(1);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(false);
});
});
describe('flag interactions', () => {
it('--defaults creates project with default settings', async () => {
const name = `Def${Date.now().toString().slice(-6)}`;
const result = await runCLI(['create', '--name', name, '--defaults', '--json'], testDir, { env: telemetry.env });
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(true);
expect(json.projectPath).toBeTruthy();
telemetry.assertMetricEmitted({
command: 'create',
exit_reason: 'success',
language: 'python',
framework: 'strands',
model_provider: 'bedrock',
has_agent: 'true',
});
});
it('--dry-run shows what would be created without writing files', async () => {
const name = `DryRun${Date.now().toString().slice(-6)}`;
const result = await runCLI(['create', '--name', name, '--defaults', '--dry-run', '--json'], testDir);
expect(result.exitCode).toBe(0);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(true);
expect(json.dryRun).toBe(true);
// Project directory should NOT exist
const projectExists = await exists(join(testDir, name));
expect(projectExists, 'Dry run should not create project directory').toBe(false);
});
it('--skip-git creates project without .git directory', async () => {
const name = `NoGit${Date.now().toString().slice(-6)}`;
const result = await runCLI(
[
'create',
'--name',
name,
'--language',
'Python',
'--framework',
'Strands',
'--model-provider',
'Bedrock',
'--memory',
'none',
'--skip-git',
'--json',
],
testDir
);
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
const json = JSON.parse(result.stdout);
expect(json.success).toBe(true);
const gitExists = await exists(join(json.projectPath, '.git'));
expect(gitExists, '.git should not exist when --skip-git is used').toBe(false);
});
});
});