-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathcli.e2e.ts
More file actions
328 lines (272 loc) · 10.8 KB
/
cli.e2e.ts
File metadata and controls
328 lines (272 loc) · 10.8 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
import { existsSync, readFileSync } from 'fs';
import { join } from 'path';
import { run, createTempProject, cleanupTempProject, writeConfigFile } from './helpers';
describe('CLI basics', () => {
it('should print version', () => {
const result = run('--version');
expect(result.exitCode).toBe(0);
expect(result.stdout.trim()).toMatch(/^\d+\.\d+\.\d+$/);
});
it('should print help', () => {
const result = run('--help');
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain('ai-devkit');
expect(result.stdout).toContain('init');
expect(result.stdout).toContain('lint');
expect(result.stdout).toContain('memory');
expect(result.stdout).toContain('skill');
expect(result.stdout).toContain('phase');
});
it('should exit with error for unknown command', () => {
const result = run('nonexistent-command');
expect(result.exitCode).not.toBe(0);
});
});
describe('init command', () => {
let projectDir: string;
beforeEach(() => {
projectDir = createTempProject();
});
afterEach(() => {
cleanupTempProject(projectDir);
});
it('should initialize with environment and all phases', () => {
const result = run('init -e claude --all', { cwd: projectDir });
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain('AI DevKit initialized successfully');
// Config file should exist
const configPath = join(projectDir, '.ai-devkit.json');
expect(existsSync(configPath)).toBe(true);
const config = JSON.parse(readFileSync(configPath, 'utf-8'));
expect(config.environments).toContain('claude');
expect(config.phases).toEqual(
expect.arrayContaining(['requirements', 'design', 'planning', 'implementation', 'testing', 'deployment', 'monitoring'])
);
});
it('should initialize with specific phases', () => {
const result = run('init -e cursor -p requirements,design', { cwd: projectDir });
expect(result.exitCode).toBe(0);
const config = JSON.parse(readFileSync(join(projectDir, '.ai-devkit.json'), 'utf-8'));
expect(config.environments).toContain('cursor');
expect(config.phases).toContain('requirements');
expect(config.phases).toContain('design');
expect(config.phases).not.toContain('monitoring');
});
it('should create phase template files in docs/ai', () => {
run('init -e claude -p requirements,planning', { cwd: projectDir });
expect(existsSync(join(projectDir, 'docs', 'ai', 'requirements', 'README.md'))).toBe(true);
expect(existsSync(join(projectDir, 'docs', 'ai', 'planning', 'README.md'))).toBe(true);
});
it('should support custom docs directory', () => {
run('init -e claude -p requirements -d custom/docs', { cwd: projectDir });
expect(existsSync(join(projectDir, 'custom', 'docs', 'requirements', 'README.md'))).toBe(true);
});
it('should create environment config files', () => {
run('init -e claude --all', { cwd: projectDir });
// Claude environment creates .claude/commands/ directory
expect(existsSync(join(projectDir, '.claude', 'commands'))).toBe(true);
});
it('should initialize with template file', () => {
const templatePath = join(projectDir, 'template.yaml');
const templateContent = `environments:
- claude
phases:
- requirements
- design
paths:
docs: docs/ai
`;
require('fs').writeFileSync(templatePath, templateContent);
const result = run(`init -t "${templatePath}"`, { cwd: projectDir });
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain('AI DevKit initialized successfully');
});
});
describe('lint command', () => {
let projectDir: string;
beforeEach(() => {
projectDir = createTempProject();
});
afterEach(() => {
cleanupTempProject(projectDir);
});
it('should run lint on uninitialized project', () => {
const result = run('lint', { cwd: projectDir });
// Should complete (may have failures but shouldn't crash)
expect(result.stdout).toBeDefined();
});
it('should run lint with --json flag', () => {
const result = run('lint --json', { cwd: projectDir });
const output = result.stdout.trim();
const json = JSON.parse(output);
expect(json).toHaveProperty('checks');
expect(json).toHaveProperty('summary');
expect(json).toHaveProperty('pass');
});
it('should lint initialized project', () => {
run('init -e claude --all', { cwd: projectDir });
const result = run('lint --json', { cwd: projectDir });
const json = JSON.parse(result.stdout.trim());
expect(json).toHaveProperty('checks');
expect(Array.isArray(json.checks)).toBe(true);
});
it('should lint with feature flag', () => {
run('init -e claude --all', { cwd: projectDir });
const result = run('lint -f my-feature --json', { cwd: projectDir });
const json = JSON.parse(result.stdout.trim());
expect(json).toHaveProperty('feature');
expect(json.feature.normalizedName).toBe('my-feature');
});
});
describe('memory commands', () => {
let projectDir: string;
let uid: string;
let projectMemoryDbPath: string;
beforeEach(() => {
projectDir = createTempProject();
uid = `${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
projectMemoryDbPath = join(projectDir, '.ai-devkit', 'memory.db');
writeConfigFile(projectDir, {
version: '1.0.0',
environments: [],
phases: [],
memory: {
path: '.ai-devkit/memory.db'
},
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
});
});
afterEach(() => {
cleanupTempProject(projectDir);
});
it('should store and search knowledge', () => {
const title = `E2E API Design Practices ${uid}`;
const storeResult = run(
`memory store -t "${title}" -c "When building REST APIs always use Response DTOs instead of returning domain entities directly ref ${uid}."`,
{ cwd: projectDir }
);
expect(storeResult.exitCode).toBe(0);
const stored = JSON.parse(storeResult.stdout.trim());
expect(stored.success).toBe(true);
expect(stored.id).toBeDefined();
expect(existsSync(projectMemoryDbPath)).toBe(true);
const searchResult = run(`memory search -q "${title}"`, { cwd: projectDir });
expect(searchResult.exitCode).toBe(0);
const searched = JSON.parse(searchResult.stdout.trim());
expect(searched.results).toBeDefined();
expect(searched.results.length).toBeGreaterThan(0);
});
it('should store with tags and scope', () => {
const result = run(
`memory store -t "E2E Backend Testing Strategy ${uid}" -c "Integration tests should always hit a real database rather than mocks ensuring migration issues are caught ref ${uid}." --tags "testing,backend" -s "project:e2e-${uid}"`,
{ cwd: projectDir }
);
expect(result.exitCode).toBe(0);
const stored = JSON.parse(result.stdout.trim());
expect(stored.success).toBe(true);
});
it('should update stored knowledge', () => {
const storeResult = run(
`memory store -t "E2E Deployment Checklist ${uid}" -c "Before deploying to production ensure all tests pass and database migrations are reviewed and documented ref ${uid}."`,
{ cwd: projectDir }
);
expect(storeResult.exitCode).toBe(0);
const stored = JSON.parse(storeResult.stdout.trim());
const updateResult = run(
`memory update --id ${stored.id} -t "E2E Updated Deployment Checklist ${uid}"`,
{ cwd: projectDir }
);
expect(updateResult.exitCode).toBe(0);
const updated = JSON.parse(updateResult.stdout.trim());
expect(updated.success).toBe(true);
});
it('should search with --table flag', () => {
run(
`memory store -t "E2E Component Architecture ${uid}" -c "Use compound components pattern for complex UI elements providing better composition and reducing prop drilling ref ${uid}."`,
{ cwd: projectDir }
);
const result = run(`memory search -q "E2E Component Architecture ${uid}" --table`, { cwd: projectDir });
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain('id');
expect(result.stdout).toContain('title');
expect(result.stdout).toContain('scope');
});
it('should reject invalid store input', () => {
const result = run('memory store -t "Short" -c "Too short"', { cwd: projectDir });
expect(result.exitCode).not.toBe(0);
});
it('should search with limit', () => {
for (let i = 1; i <= 3; i++) {
run(
`memory store -t "E2E Knowledge item ${i} ${uid}" -c "This is detailed content for knowledge item number ${i} with unique identifier ${uid} to meet the minimum length."`,
{ cwd: projectDir }
);
}
const result = run(`memory search -q "E2E Knowledge item ${uid}" -l 2`, { cwd: projectDir });
expect(result.exitCode).toBe(0);
const searched = JSON.parse(result.stdout.trim());
expect(searched.results.length).toBeLessThanOrEqual(2);
});
});
describe('phase command', () => {
let projectDir: string;
beforeEach(() => {
projectDir = createTempProject();
// Initialize first
run('init -e claude -p requirements', { cwd: projectDir });
});
afterEach(() => {
cleanupTempProject(projectDir);
});
it('should add a new phase', () => {
const result = run('phase testing', { cwd: projectDir });
expect(result.exitCode).toBe(0);
expect(existsSync(join(projectDir, 'docs', 'ai', 'testing', 'README.md'))).toBe(true);
const config = JSON.parse(readFileSync(join(projectDir, '.ai-devkit.json'), 'utf-8'));
expect(config.phases).toContain('testing');
});
});
describe('install command', () => {
let projectDir: string;
beforeEach(() => {
projectDir = createTempProject();
});
afterEach(() => {
cleanupTempProject(projectDir);
});
it('should install from config file', () => {
writeConfigFile(projectDir, {
version: '1.0.0',
environments: ['claude'],
phases: ['requirements', 'design'],
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
});
const result = run('install', { cwd: projectDir });
expect(result.exitCode).toBe(0);
});
it('should fail with missing config file', () => {
const result = run('install -c nonexistent.json', { cwd: projectDir });
expect(result.exitCode).not.toBe(0);
});
});
describe('skill command', () => {
it('should list skills (empty)', () => {
const projectDir = createTempProject();
run('init -e claude -p requirements', { cwd: projectDir });
const result = run('skill list', { cwd: projectDir });
expect(result.exitCode).toBe(0);
cleanupTempProject(projectDir);
});
});
describe('Node.js compatibility', () => {
it('should report correct Node.js version range support', () => {
const nodeVersion = process.version;
const major = parseInt(nodeVersion.slice(1).split('.')[0], 10);
expect(major).toBeGreaterThanOrEqual(20);
// CLI should work on this Node version
const result = run('--version');
expect(result.exitCode).toBe(0);
});
});