11import { createTestProject , readProjectConfig , runCLI } from '../src/test-utils/index.js' ;
22import type { TestProject } from '../src/test-utils/index.js' ;
3+ import { createTelemetryHelper } from '../src/test-utils/telemetry-helper.js' ;
34import { afterAll , beforeAll , describe , expect , it } from 'vitest' ;
45
6+ const telemetry = createTelemetryHelper ( ) ;
7+
58describe ( 'integration: add and remove resources' , ( ) => {
69 let project : TestProject ;
710
@@ -16,13 +19,16 @@ describe('integration: add and remove resources', () => {
1619
1720 afterAll ( async ( ) => {
1821 await project . cleanup ( ) ;
22+ telemetry . destroy ( ) ;
1923 } ) ;
2024
2125 describe ( 'memory lifecycle' , ( ) => {
2226 const memoryName = `IntegMem${ Date . now ( ) . toString ( ) . slice ( - 6 ) } ` ;
2327
2428 it ( 'adds a memory resource' , async ( ) => {
25- const result = await runCLI ( [ 'add' , 'memory' , '--name' , memoryName , '--json' ] , project . projectPath ) ;
29+ const result = await runCLI ( [ 'add' , 'memory' , '--name' , memoryName , '--json' ] , project . projectPath , {
30+ env : telemetry . env ,
31+ } ) ;
2632
2733 expect ( result . exitCode , `stdout: ${ result . stdout } , stderr: ${ result . stderr } ` ) . toBe ( 0 ) ;
2834 const json = JSON . parse ( result . stdout ) ;
@@ -34,13 +40,17 @@ describe('integration: add and remove resources', () => {
3440 expect ( memories , 'memories should exist' ) . toBeDefined ( ) ;
3541 const found = memories ! . some ( ( m : Record < string , unknown > ) => m . name === memoryName ) ;
3642 expect ( found , `Memory "${ memoryName } " should be in config` ) . toBe ( true ) ;
43+
44+ // Verify telemetry
45+ telemetry . assertMetricEmitted ( { command : 'add.memory' , exit_reason : 'success' } ) ;
3746 } ) ;
3847
3948 it ( 'adds a memory with EPISODIC strategy and verifies reflectionNamespaces' , async ( ) => {
4049 const episodicMemName = `EpiMem${ Date . now ( ) . toString ( ) . slice ( - 6 ) } ` ;
4150 const result = await runCLI (
4251 [ 'add' , 'memory' , '--name' , episodicMemName , '--strategies' , 'EPISODIC' , '--json' ] ,
43- project . projectPath
52+ project . projectPath ,
53+ { env : telemetry . env }
4454 ) ;
4555
4656 expect ( result . exitCode , `stdout: ${ result . stdout } , stderr: ${ result . stderr } ` ) . toBe ( 0 ) ;
@@ -61,6 +71,14 @@ describe('integration: add and remove resources', () => {
6171 expect ( episodic ! . reflectionNamespaces , 'Should have reflectionNamespaces' ) . toBeDefined ( ) ;
6272 expect ( episodic ! . reflectionNamespaces ! . length ) . toBeGreaterThan ( 0 ) ;
6373
74+ // Verify telemetry
75+ telemetry . assertMetricEmitted ( {
76+ command : 'add.memory' ,
77+ exit_reason : 'success' ,
78+ strategy_count : '1' ,
79+ strategy_episodic : 'true' ,
80+ } ) ;
81+
6482 // Clean up
6583 await runCLI ( [ 'remove' , 'memory' , '--name' , episodicMemName , '--json' ] , project . projectPath ) ;
6684 } ) ;
@@ -86,7 +104,8 @@ describe('integration: add and remove resources', () => {
86104 it ( 'adds a credential resource' , async ( ) => {
87105 const result = await runCLI (
88106 [ 'add' , 'credential' , '--name' , credentialName , '--api-key' , 'test-key-integ-123' , '--json' ] ,
89- project . projectPath
107+ project . projectPath ,
108+ { env : telemetry . env }
90109 ) ;
91110
92111 expect ( result . exitCode , `stdout: ${ result . stdout } , stderr: ${ result . stderr } ` ) . toBe ( 0 ) ;
@@ -99,6 +118,13 @@ describe('integration: add and remove resources', () => {
99118 expect ( credentials , 'credentials should exist' ) . toBeDefined ( ) ;
100119 const found = credentials ! . some ( ( c : Record < string , unknown > ) => c . name === credentialName ) ;
101120 expect ( found , `Credential "${ credentialName } " should be in config` ) . toBe ( true ) ;
121+
122+ // Verify telemetry
123+ telemetry . assertMetricEmitted ( {
124+ command : 'add.credential' ,
125+ exit_reason : 'success' ,
126+ credential_type : 'api-key' ,
127+ } ) ;
102128 } ) ;
103129
104130 it ( 'removes the credential resource' , async ( ) => {
@@ -115,4 +141,30 @@ describe('integration: add and remove resources', () => {
115141 expect ( found , `Credential "${ credentialName } " should be removed from config` ) . toBe ( false ) ;
116142 } ) ;
117143 } ) ;
144+
145+ describe ( 'policy-engine' , ( ) => {
146+ const engineName = `TestEngine${ Date . now ( ) . toString ( ) . slice ( - 6 ) } ` ;
147+
148+ it ( 'adds a policy engine resource' , async ( ) => {
149+ const result = await runCLI ( [ 'add' , 'policy-engine' , '--name' , engineName , '--json' ] , project . projectPath , {
150+ env : telemetry . env ,
151+ } ) ;
152+
153+ expect ( result . exitCode , `stdout: ${ result . stdout } , stderr: ${ result . stderr } ` ) . toBe ( 0 ) ;
154+ const json = JSON . parse ( result . stdout ) ;
155+ expect ( json . success ) . toBe ( true ) ;
156+
157+ telemetry . assertMetricEmitted ( {
158+ command : 'add.policy-engine' ,
159+ exit_reason : 'success' ,
160+ attach_gateway_count : '0' ,
161+ } ) ;
162+ } ) ;
163+
164+ it ( 'removes the policy engine resource' , async ( ) => {
165+ const result = await runCLI ( [ 'remove' , 'policy-engine' , '--name' , engineName , '--json' ] , project . projectPath ) ;
166+
167+ expect ( result . exitCode , `stdout: ${ result . stdout } , stderr: ${ result . stderr } ` ) . toBe ( 0 ) ;
168+ } ) ;
169+ } ) ;
118170} ) ;
0 commit comments