@@ -172,6 +172,24 @@ function extractEventNames(calls: typeof fetchCalls): Array<string> {
172172 } )
173173}
174174
175+ function findTelemetryEnvelope (
176+ eventName : string ,
177+ requestId : string ,
178+ ) : TelemetryEnvelope {
179+ for ( const call of fetchCalls ) {
180+ const body = JSON . parse ( call . options . body ) as Array < TelemetryEnvelope >
181+ const match = body . find ( ( env ) => {
182+ return (
183+ env . data . baseData . name === eventName
184+ && env . data . baseData . properties . requestId === requestId
185+ )
186+ } )
187+ if ( match ) return match
188+ }
189+
190+ throw new TypeError ( `${ eventName } envelope not found for ${ requestId } ` )
191+ }
192+
175193/** Wait for fire-and-forget microtasks to settle */
176194async function flushMicrotasks ( ) : Promise < void > {
177195 await new Promise ( ( resolve ) => setTimeout ( resolve , 20 ) )
@@ -471,8 +489,10 @@ describe("telemetry: feedback wrappers", () => {
471489 Math . random = origRandom
472490 await flushMicrotasks ( )
473491
474- expect ( fetchCalls . length ) . toBe ( 1 )
475- const env = getFirstEnvelopeFromCall ( )
492+ const env = findTelemetryEnvelope (
493+ "copilot-chat/panel.edit.feedback" ,
494+ "req-feedback-001" ,
495+ )
476496 expect ( env . data . baseData . name ) . toBe ( "copilot-chat/panel.edit.feedback" )
477497 const props = env . data . baseData . properties
478498 expect ( props . requestId ) . toBe ( "req-feedback-001" )
@@ -501,8 +521,10 @@ describe("telemetry: feedback wrappers", () => {
501521 Math . random = origRandom
502522 await flushMicrotasks ( )
503523
504- expect ( fetchCalls . length ) . toBe ( 1 )
505- const env = getFirstEnvelopeFromCall ( )
524+ const env = findTelemetryEnvelope (
525+ "copilot-chat/edit.hunk.action" ,
526+ "req-hunk-002" ,
527+ )
506528 expect ( env . data . baseData . name ) . toBe ( "copilot-chat/edit.hunk.action" )
507529 const props = env . data . baseData . properties
508530 expect ( props . requestId ) . toBe ( "req-hunk-002" )
0 commit comments