Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions integ-tests/validate.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* eslint-disable security/detect-non-literal-fs-filename */
import { createTestProject, runCLI } from '../src/test-utils/index.js';
import { createTelemetryHelper, 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';
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';

describe('integration: validate command', () => {
let project: TestProject;
const telemetry = createTelemetryHelper();

beforeAll(async () => {
project = await createTestProject({
Expand All @@ -19,16 +20,22 @@ describe('integration: validate command', () => {
});
});

afterEach(() => {
telemetry.clearEntries();
});

afterAll(async () => {
telemetry.destroy();
await project.cleanup();
});

it('validates a valid project successfully', async () => {
const result = await runCLI(['validate'], project.projectPath);
const result = await runCLI(['validate'], project.projectPath, { env: telemetry.env });

expect(result.exitCode, `stderr: ${result.stderr}`).toBe(0);
// validate outputs "Valid" on success (Ink text render)
expect(result.stdout.toLowerCase()).toContain('valid');
telemetry.assertMetricEmitted({ command: 'validate', exit_reason: 'success' });
});

it('reports error for corrupted agentcore.json', async () => {
Expand All @@ -39,12 +46,13 @@ describe('integration: validate command', () => {
try {
await writeFile(configPath, '{invalid json!!!', 'utf-8');

const result = await runCLI(['validate'], project.projectPath);
const result = await runCLI(['validate'], project.projectPath, { env: telemetry.env });

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);
telemetry.assertMetricEmitted({ command: 'validate', exit_reason: 'failure' });
} finally {
// Restore original config so other tests aren't affected
await writeFile(configPath, originalContent, 'utf-8');
Expand All @@ -56,12 +64,13 @@ describe('integration: validate command', () => {
await mkdir(emptyDir, { recursive: true });

try {
const result = await runCLI(['validate'], emptyDir);
const result = await runCLI(['validate'], emptyDir, { env: telemetry.env });

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);
telemetry.assertMetricEmitted({ command: 'validate', exit_reason: 'failure' });
} finally {
await rm(emptyDir, { recursive: true, force: true });
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/commands/validate/command.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { withCommandRunTelemetry } from '../../telemetry/cli-command-run.js';
import { COMMAND_DESCRIPTIONS } from '../../tui/copy';
import { handleValidate } from './action';
import type { Command } from '@commander-js/extra-typings';
Expand All @@ -9,8 +10,7 @@ export const registerValidate = (program: Command) => {
.option('-d, --directory <path>', 'Project directory containing agentcore config')
.description(COMMAND_DESCRIPTIONS.validate)
.action(async options => {
const result = await handleValidate(options);

const result = await withCommandRunTelemetry('validate', {}, async () => handleValidate(options));
if (result.success) {
render(<Text color="green">Valid</Text>);
process.exit(0);
Expand Down
Loading