forked from aws/agentcore-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidate.test.ts
More file actions
69 lines (57 loc) · 2.42 KB
/
Copy pathvalidate.test.ts
File metadata and controls
69 lines (57 loc) · 2.42 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
/* eslint-disable security/detect-non-literal-fs-filename */
import { createTestProject, runCLI } from '../src/test-utils/index.js';
import type { TestProject } from '../src/test-utils/index.js';
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';
describe('integration: validate command', () => {
let project: TestProject;
beforeAll(async () => {
project = await createTestProject({
language: 'Python',
framework: 'Strands',
modelProvider: 'Bedrock',
memory: 'none',
});
});
afterAll(async () => {
await project.cleanup();
});
it('validates a valid project successfully', async () => {
const result = await runCLI(['validate'], project.projectPath);
expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
// validate outputs "Valid" on success (Ink text render)
expect(result.stdout.toLowerCase()).toContain('valid');
});
it('reports error for corrupted agentcore.json', async () => {
const configPath = join(project.projectPath, 'agentcore', 'agentcore.json');
const { readFile } = await import('node:fs/promises');
const originalContent = await readFile(configPath, 'utf-8');
try {
await writeFile(configPath, '{invalid json!!!', 'utf-8');
const result = await runCLI(['validate'], project.projectPath);
expect(result.exitCode).toBe(1);
// Error message should appear in stdout (Ink render) or stderr
const output = result.stdout + result.stderr;
expect(output.length, 'Should produce error output').toBeGreaterThan(0);
} finally {
// Restore original config so other tests aren't affected
await writeFile(configPath, originalContent, 'utf-8');
}
});
it('reports error when run outside a project', async () => {
const emptyDir = join(tmpdir(), `agentcore-no-project-${randomUUID()}`);
await mkdir(emptyDir, { recursive: true });
try {
const result = await runCLI(['validate'], emptyDir);
expect(result.exitCode).toBe(1);
// Error message should appear somewhere in output
const output = result.stdout + result.stderr;
expect(output.length, 'Should produce error output').toBeGreaterThan(0);
} finally {
await rm(emptyDir, { recursive: true, force: true });
}
});
});