-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathcli.e2e.ts
More file actions
663 lines (553 loc) · 22.7 KB
/
Copy pathcli.e2e.ts
File metadata and controls
663 lines (553 loc) · 22.7 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
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'fs';
import { tmpdir } from 'os';
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');
expect(result.stdout).not.toContain('setup');
});
it('should not expose removed workflow command setup', () => {
const result = run('setup');
expect(result.exitCode).not.toBe(0);
});
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 not create workflow slash command directories', () => {
run('init -e claude --all', { cwd: projectDir });
expect(existsSync(join(projectDir, '.claude', 'commands'))).toBe(false);
expect(existsSync(join(projectDir, '.cursor', 'commands'))).toBe(false);
expect(existsSync(join(projectDir, '.codex', 'commands'))).toBe(false);
});
it('should initialize Cursor without workflow slash command directories', () => {
run('init -e cursor -p requirements', { cwd: projectDir });
expect(existsSync(join(projectDir, 'docs', 'ai', 'requirements', 'README.md'))).toBe(true);
expect(existsSync(join(projectDir, '.cursor', 'commands'))).toBe(false);
});
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');
});
it('should save template registries to config', () => {
const templatePath = join(projectDir, 'template.yaml');
const templateContent = `environments:
- claude
phases:
- requirements
registries:
my-org/skills: https://github.com/my-org/skills.git
`;
require('fs').writeFileSync(templatePath, templateContent);
const result = run(`init -t "${templatePath}"`, { cwd: projectDir });
expect(result.exitCode).toBe(0);
const config = JSON.parse(readFileSync(join(projectDir, '.ai-devkit.json'), 'utf-8'));
expect(config.registries).toEqual({
'my-org/skills': 'https://github.com/my-org/skills.git'
});
});
});
describe('CLI build artifacts', () => {
it('should not include removed workflow command templates in dist', () => {
const commandsDir = join(__dirname, '..', 'packages', 'cli', 'dist', 'templates', 'commands');
const commandFiles = existsSync(commandsDir)
? readdirSync(commandsDir).filter((file) => file.endsWith('.md'))
: [];
expect(commandFiles).toEqual([]);
});
});
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()
});
});
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()
});
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);
});
it('should install when config has registries and skills', () => {
writeConfigFile(projectDir, {
version: '1.0.0',
environments: ['claude'],
phases: ['requirements'],
registries: {
'codeaholicguy/ai-devkit': 'https://github.com/codeaholicguy/ai-devkit.git'
},
skills: [
{ registry: 'codeaholicguy/ai-devkit', name: 'dev-lifecycle' }
],
createdAt: new Date().toISOString()
});
const result = run('install', { cwd: projectDir });
expect(result.exitCode).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('skill remove (issue #63)', () => {
let projectDir: string;
beforeEach(() => {
projectDir = createTempProject();
});
afterEach(() => {
cleanupTempProject(projectDir);
});
it('should remove the skill entry from .ai-devkit.json after removal', () => {
writeConfigFile(projectDir, {
version: '1.0.0',
environments: ['claude'],
phases: [],
skills: [
{ registry: 'codeaholicguy/ai-devkit', name: 'dev-lifecycle' }
],
createdAt: new Date().toISOString()
});
// Create the skill directory so the remove command finds it
const skillDir = join(projectDir, '.claude', 'skills', 'dev-lifecycle');
mkdirSync(skillDir, { recursive: true });
const result = run('skill remove dev-lifecycle', { cwd: projectDir });
expect(result.exitCode).toBe(0);
// Skill directory should be gone
expect(existsSync(skillDir)).toBe(false);
// .ai-devkit.json should no longer list the skill
const config = JSON.parse(readFileSync(join(projectDir, '.ai-devkit.json'), 'utf-8'));
const skills = (config.skills ?? []) as Array<{ name: string }>;
expect(skills.some((s) => s.name === 'dev-lifecycle')).toBe(false);
});
it('should preserve remaining skills in .ai-devkit.json when removing one', () => {
writeConfigFile(projectDir, {
version: '1.0.0',
environments: ['claude'],
phases: [],
skills: [
{ registry: 'codeaholicguy/ai-devkit', name: 'dev-lifecycle' },
{ registry: 'codeaholicguy/ai-devkit', name: 'memory' }
],
createdAt: new Date().toISOString()
});
const skillDir = join(projectDir, '.claude', 'skills', 'dev-lifecycle');
mkdirSync(skillDir, { recursive: true });
run('skill remove dev-lifecycle', { cwd: projectDir });
const config = JSON.parse(readFileSync(join(projectDir, '.ai-devkit.json'), 'utf-8'));
const skills = (config.skills ?? []) as Array<{ name: string }>;
expect(skills.some((s) => s.name === 'dev-lifecycle')).toBe(false);
expect(skills.some((s) => s.name === 'memory')).toBe(true);
});
});
});
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);
});
});
describe('agent sessions command', () => {
interface ClaudeJsonlEntry {
type: string;
timestamp?: string;
cwd?: string;
message?: { content?: string };
}
interface CodexLine {
type: string;
timestamp?: string;
payload?: { id?: string; cwd?: string; timestamp?: string; type?: string; message?: string };
}
function writeClaudeSession(home: string, recordedCwd: string, sessionId: string, firstUserMessage: string): string {
return writeClaudeSessionInLaunchDir(home, recordedCwd, recordedCwd, sessionId, firstUserMessage);
}
/**
* Write a Claude session under one launch dir's encoded path while the
* session content records a different cwd. Lets us simulate the worktree
* case (user cd'd into a subdir/worktree after launching Claude) by
* passing different launch and recorded cwds.
*/
function writeClaudeSessionInLaunchDir(
home: string,
launchCwd: string,
recordedCwd: string,
sessionId: string,
firstUserMessage: string,
): string {
const encoded = launchCwd.replace(/\//g, '-');
const projectDir = join(home, '.claude', 'projects', encoded);
mkdirSync(projectDir, { recursive: true });
const filePath = join(projectDir, `${sessionId}.jsonl`);
const entries: ClaudeJsonlEntry[] = [
{
type: 'user',
timestamp: '2025-01-01T00:00:00Z',
cwd: recordedCwd,
message: { content: firstUserMessage },
},
];
writeFileSync(filePath, entries.map((e) => JSON.stringify(e)).join('\n'));
return filePath;
}
function writeCodexSession(home: string, cwd: string, sessionId: string, firstUserMessage: string): string {
const dayDir = join(home, '.codex', 'sessions', '2025', '01', '01');
mkdirSync(dayDir, { recursive: true });
const filePath = join(dayDir, `${sessionId}.jsonl`);
const lines: CodexLine[] = [
{ type: 'session_meta', payload: { id: sessionId, cwd, timestamp: '2025-01-01T00:00:00Z' } },
{
type: 'event',
timestamp: '2025-01-01T00:00:01Z',
payload: { type: 'user_message', message: firstUserMessage },
},
];
writeFileSync(filePath, lines.map((l) => JSON.stringify(l)).join('\n'));
return filePath;
}
let home: string;
beforeEach(() => {
home = mkdtempSync(join(tmpdir(), 'ai-devkit-sessions-e2e-'));
});
afterEach(() => {
rmSync(home, { recursive: true, force: true });
});
it('lists the sessions subcommand in agent --help', () => {
const result = run('agent --help', { env: { HOME: home } });
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain('sessions');
});
it('shows the --all hint when default-cwd lookup is empty', () => {
const projectDir = createTempProject();
try {
const result = run('agent sessions', { cwd: projectDir, env: { HOME: home } });
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain('--all');
} finally {
cleanupTempProject(projectDir);
}
});
it('finds a Claude session recorded for the current cwd', () => {
const projectDir = createTempProject();
// macOS symlinks /var → /private/var; the spawned CLI's process.cwd()
// returns the canonical path. Use realpath here so the recorded cwd in
// the fake session matches what the CLI computes from process.cwd().
const canonical = realpathSync(projectDir);
try {
writeClaudeSession(home, canonical, 'claude-here', 'hello from project');
const result = run('agent sessions --json', { cwd: projectDir, env: { HOME: home } });
expect(result.exitCode).toBe(0);
const sessions = JSON.parse(result.stdout) as Array<{
type: string;
sessionId: string;
cwd: string;
firstUserMessage: string;
}>;
expect(sessions).toHaveLength(1);
expect(sessions[0]).toMatchObject({
type: 'claude',
sessionId: 'claude-here',
cwd: canonical,
firstUserMessage: 'hello from project',
});
} finally {
cleanupTempProject(projectDir);
}
});
it('finds a session whose recorded cwd lives in a different launch dir (worktree case)', () => {
const launchCwd = '/repo';
const worktreeCwd = '/repo/.worktrees/feature';
writeClaudeSessionInLaunchDir(home, launchCwd, worktreeCwd, 'wt-session', 'in worktree');
const result = run(`agent sessions --cwd "${worktreeCwd}" --json`, { env: { HOME: home } });
expect(result.exitCode).toBe(0);
const sessions = JSON.parse(result.stdout) as Array<{ sessionId: string; cwd: string }>;
expect(sessions).toHaveLength(1);
expect(sessions[0]).toMatchObject({ sessionId: 'wt-session', cwd: worktreeCwd });
});
it('lists sessions across every cwd with --all', () => {
writeClaudeSession(home, '/repo-a', 'claude-a', 'a');
writeClaudeSession(home, '/repo-b', 'claude-b', 'b');
writeCodexSession(home, '/repo-codex', 'codex-1', 'codex hi');
const result = run('agent sessions --all --json', { env: { HOME: home } });
expect(result.exitCode).toBe(0);
const sessions = JSON.parse(result.stdout) as Array<{ type: string; sessionId: string }>;
expect(sessions).toHaveLength(3);
expect(sessions.map((s) => s.sessionId).sort()).toEqual(['claude-a', 'claude-b', 'codex-1']);
});
it('filters to one tool with --type', () => {
writeClaudeSession(home, '/repo-claude', 'claude-1', 'c');
writeCodexSession(home, '/repo-codex', 'codex-1', 'cx');
const result = run('agent sessions --all --type codex --json', { env: { HOME: home } });
expect(result.exitCode).toBe(0);
const sessions = JSON.parse(result.stdout) as Array<{ type: string; sessionId: string }>;
expect(sessions).toHaveLength(1);
expect(sessions[0].type).toBe('codex');
expect(sessions[0].sessionId).toBe('codex-1');
});
it('rejects an invalid --type with a clear error', () => {
const result = run('agent sessions --all --type wrong', { env: { HOME: home } });
expect(result.exitCode).not.toBe(0);
expect(result.stderr + result.stdout).toMatch(/Invalid --type "wrong"/);
});
it('caps rows with --limit', () => {
writeClaudeSession(home, '/r1', 's1', 'one');
writeClaudeSession(home, '/r2', 's2', 'two');
writeClaudeSession(home, '/r3', 's3', 'three');
const result = run('agent sessions --all --limit 2 --json', { env: { HOME: home } });
expect(result.exitCode).toBe(0);
const sessions = JSON.parse(result.stdout) as Array<{ sessionId: string }>;
expect(sessions).toHaveLength(2);
});
it('treats --limit 0 as unlimited', () => {
for (let i = 0; i < 3; i++) {
writeClaudeSession(home, `/r${i}`, `s${i}`, `msg-${i}`);
}
const result = run('agent sessions --all --limit 0 --json', { env: { HOME: home } });
expect(result.exitCode).toBe(0);
const sessions = JSON.parse(result.stdout) as Array<unknown>;
expect(sessions).toHaveLength(3);
});
it('emits a JSON schema with expected fields and ISO date strings', () => {
writeClaudeSession(home, '/repo', 'claude-z', 'hello');
const result = run('agent sessions --all --json', { env: { HOME: home } });
expect(result.exitCode).toBe(0);
const sessions = JSON.parse(result.stdout);
expect(Array.isArray(sessions)).toBe(true);
expect(sessions[0]).toEqual(
expect.objectContaining({
type: 'claude',
sessionId: 'claude-z',
cwd: '/repo',
firstUserMessage: 'hello',
sessionFilePath: expect.any(String),
}),
);
expect(sessions[0].lastActive).toMatch(/^\d{4}-\d{2}-\d{2}T/);
expect(sessions[0].startedAt).toMatch(/^\d{4}-\d{2}-\d{2}T/);
});
});