@@ -16,6 +16,8 @@ export interface TelemetryHelper {
1616 env : { AGENTCORE_TELEMETRY_AUDIT : '1' ; AGENTCORE_CONFIG_DIR : string } ;
1717 /** Read all JSONL entries from the audit telemetry directory */
1818 readEntries : ( ) => TelemetryEntry [ ] ;
19+ /** Assert a metric was emitted with attrs matching the given subset */
20+ assertMetricEmitted : ( expected : Record < string , string | number | boolean > ) => void ;
1921 /** Delete telemetry entries only (keeps the config dir) */
2022 clearEntries : ( ) => void ;
2123 /** Delete the entire config directory — call in afterAll */
@@ -24,7 +26,7 @@ export interface TelemetryHelper {
2426
2527export function createTelemetryHelper ( ) : TelemetryHelper {
2628 const dir = mkdtempSync ( join ( tmpdir ( ) , 'agentcore-audit-' ) ) ;
27- return {
29+ const helper : TelemetryHelper = {
2830 dir,
2931 env : { AGENTCORE_TELEMETRY_AUDIT : '1' , AGENTCORE_CONFIG_DIR : dir } ,
3032 readEntries ( ) {
@@ -35,17 +37,17 @@ export function createTelemetryHelper(): TelemetryHelper {
3537 . map ( line => JSON . parse ( line ) as TelemetryEntry )
3638 ) ;
3739 } ,
40+ assertMetricEmitted ( expected ) {
41+ const entries = helper . readEntries ( ) ;
42+ const match = entries . find ( e => Object . entries ( expected ) . every ( ( [ k , v ] ) => String ( e . attrs [ k ] ) === String ( v ) ) ) ;
43+ expect ( match , `No telemetry entry matching ${ JSON . stringify ( expected ) } ` ) . toBeDefined ( ) ;
44+ } ,
3845 clearEntries ( ) {
3946 rmSync ( join ( dir , 'telemetry' ) , { recursive : true , force : true } ) ;
4047 } ,
4148 destroy ( ) {
4249 rmSync ( dir , { recursive : true , force : true } ) ;
4350 } ,
4451 } ;
45- }
46-
47- /** Assert that at least one telemetry entry was emitted matching the given attrs. */
48- export function assertTelemetry ( entries : TelemetryEntry [ ] , expected : Record < string , string | number | boolean > ) : void {
49- const match = entries . find ( e => Object . entries ( expected ) . every ( ( [ k , v ] ) => String ( e . attrs [ k ] ) === String ( v ) ) ) ;
50- expect ( match , `No telemetry entry matching ${ JSON . stringify ( expected ) } ` ) . toBeDefined ( ) ;
52+ return helper ;
5153}
0 commit comments