Skip to content

Commit cfa51f8

Browse files
committed
feat: instrument telemetry for status command
Wrap status command execution paths with withCommandRunTelemetry: - Validation errors (invalid --type/--state) - Runtime lookup by ID (--runtime-id) - Default project status Schema changes: - Add runtime-endpoint, config-bundle, ab-test to FilterType enum Error typing: - Use ValidationError for invalid --type/--state input Tests: - Integration tests verifying telemetry emission for all paths
1 parent fc135b0 commit cfa51f8

3 files changed

Lines changed: 321 additions & 196 deletions

File tree

integ-tests/status.test.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { createTelemetryHelper, runCLI } from '../src/test-utils/index.js';
2+
import { randomUUID } from 'node:crypto';
3+
import { mkdir, rm } from 'node:fs/promises';
4+
import { tmpdir } from 'node:os';
5+
import { join } from 'node:path';
6+
import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';
7+
8+
describe('status command', () => {
9+
let testDir: string;
10+
let projectDir: string;
11+
const telemetry = createTelemetryHelper();
12+
13+
beforeAll(async () => {
14+
testDir = join(tmpdir(), `agentcore-status-telemetry-${randomUUID()}`);
15+
await mkdir(testDir, { recursive: true });
16+
17+
const projectName = 'StatusTelemetryProj';
18+
const result = await runCLI(['create', '--name', projectName, '--no-agent'], testDir);
19+
if (result.exitCode !== 0) {
20+
throw new Error(`Failed to create project: ${result.stdout} ${result.stderr}`);
21+
}
22+
projectDir = join(testDir, projectName);
23+
});
24+
25+
afterEach(() => {
26+
telemetry.clearEntries();
27+
});
28+
29+
afterAll(async () => {
30+
telemetry.destroy();
31+
await rm(testDir, { recursive: true, force: true });
32+
});
33+
34+
it('emits success telemetry for basic status', async () => {
35+
const result = await runCLI(['status', '--json'], projectDir, { env: telemetry.env });
36+
expect(result.exitCode).toBe(0);
37+
telemetry.assertMetricEmitted({
38+
command: 'status',
39+
exit_reason: 'success',
40+
filter_type: 'none',
41+
filter_state: 'none',
42+
});
43+
});
44+
45+
it('emits success telemetry with filter attrs', async () => {
46+
const result = await runCLI(['status', '--type', 'agent', '--state', 'deployed', '--json'], projectDir, {
47+
env: telemetry.env,
48+
});
49+
expect(result.exitCode).toBe(0);
50+
telemetry.assertMetricEmitted({
51+
command: 'status',
52+
exit_reason: 'success',
53+
filter_type: 'agent',
54+
filter_state: 'deployed',
55+
});
56+
});
57+
58+
it('emits success telemetry for runtime-endpoint filter', async () => {
59+
const result = await runCLI(['status', '--type', 'runtime-endpoint', '--json'], projectDir, {
60+
env: telemetry.env,
61+
});
62+
expect(result.exitCode).toBe(0);
63+
telemetry.assertMetricEmitted({
64+
command: 'status',
65+
exit_reason: 'success',
66+
filter_type: 'runtime-endpoint',
67+
});
68+
});
69+
70+
it('emits failure telemetry for invalid --type', async () => {
71+
const result = await runCLI(['status', '--type', 'bogus'], projectDir, { env: telemetry.env });
72+
expect(result.exitCode).toBe(0);
73+
telemetry.assertMetricEmitted({
74+
command: 'status',
75+
exit_reason: 'failure',
76+
filter_type: 'unknown',
77+
filter_state: 'none',
78+
});
79+
});
80+
81+
it('emits failure telemetry for invalid --state', async () => {
82+
const result = await runCLI(['status', '--state', 'bogus'], projectDir, { env: telemetry.env });
83+
expect(result.exitCode).toBe(0);
84+
telemetry.assertMetricEmitted({
85+
command: 'status',
86+
exit_reason: 'failure',
87+
filter_type: 'none',
88+
filter_state: 'unknown',
89+
});
90+
});
91+
92+
it('emits failure telemetry for nonexistent target', async () => {
93+
const result = await runCLI(['status', '--target', 'nonexistent', '--json'], projectDir, {
94+
env: telemetry.env,
95+
});
96+
expect(result.exitCode).toBe(0);
97+
telemetry.assertMetricEmitted({
98+
command: 'status',
99+
exit_reason: 'failure',
100+
filter_type: 'none',
101+
filter_state: 'none',
102+
});
103+
});
104+
105+
it('emits failure telemetry for --runtime-id lookup', async () => {
106+
const result = await runCLI(['status', '--runtime-id', 'fake-id', '--json'], projectDir, {
107+
env: telemetry.env,
108+
});
109+
expect(result.exitCode).toBe(0);
110+
telemetry.assertMetricEmitted({
111+
command: 'status',
112+
exit_reason: 'failure',
113+
});
114+
});
115+
});

0 commit comments

Comments
 (0)