@@ -130,53 +130,5 @@ await test("measurePayloadShape handles empty response (SSE skipped)", async ()
130130 assert . ok ( s . bytes_in > 0 ) ;
131131} ) ;
132132
133- // ─── measureResponseShape — guards against the prod bug the agent caught ──
134-
135- const { measureResponseShape } = await import ( compiledPath ) ;
136-
137- await test ( "measureResponseShape measures application/json responses" , async ( ) => {
138- const body = JSON . stringify ( { jsonrpc : "2.0" , id : 1 , result : { ok : true } } ) ;
139- const res = new Response ( body , { headers : { "Content-Type" : "application/json" } } ) ;
140- const s = await measureResponseShape ( "req" , res ) ;
141- assert . ok ( s . bytes_out > 0 , `bytes_out should be > 0, got ${ s . bytes_out } ` ) ;
142- assert . ok ( s . tokens_out > 0 , `tokens_out should be > 0, got ${ s . tokens_out } ` ) ;
143- } ) ;
144-
145- await test ( "measureResponseShape ALSO measures text/event-stream (the smoke-test bug)" , async ( ) => {
146- // This is the case that the prior implementation got wrong:
147- // MCP Streamable HTTP transport returns text/event-stream by default,
148- // and the prior Content-Type filter recorded zeros for every such response.
149- const sseBody = `data: ${ JSON . stringify ( { jsonrpc : "2.0" , id : 1 , result : { content : [ { type : "text" , text : "hello world" } ] } } ) } \n\n` ;
150- const res = new Response ( sseBody , { headers : { "Content-Type" : "text/event-stream" } } ) ;
151- const s = await measureResponseShape ( "req" , res ) ;
152- assert . ok ( s . bytes_out > 50 , `bytes_out should reflect SSE body (~80 bytes), got ${ s . bytes_out } ` ) ;
153- assert . ok ( s . tokens_out > 5 , `tokens_out should be > 5, got ${ s . tokens_out } ` ) ;
154- console . log ( ` SSE response: bytes_out=${ s . bytes_out } tokens_out=${ s . tokens_out } ` ) ;
155- } ) ;
156-
157- await test ( "measureResponseShape leaves the original response body intact (clone)" , async ( ) => {
158- const body = JSON . stringify ( { jsonrpc : "2.0" , id : 1 , result : { x : 42 } } ) ;
159- const res = new Response ( body , { headers : { "Content-Type" : "application/json" } } ) ;
160-
161- // Measure first
162- await measureResponseShape ( "req" , res ) ;
163-
164- // The original response body MUST still be readable — measurement uses a clone
165- const originalText = await res . text ( ) ;
166- assert . equal ( originalText , body , "original response body should be intact after measurement" ) ;
167- } ) ;
168-
169- await test ( "measureResponseShape handles already-consumed body without throwing" , async ( ) => {
170- const body = JSON . stringify ( { ok : true } ) ;
171- const res = new Response ( body ) ;
172- // Drain the original first — this will make .clone() succeed but the cloned body
173- // won't have data flowing if it was a stream. For a static body this still works,
174- // but the test ensures no throw under unusual conditions.
175- await res . text ( ) ;
176- // Now ask measureResponseShape to handle this — it must not throw
177- const s = await measureResponseShape ( "req" , res ) ;
178- assert . ok ( typeof s . bytes_out === "number" , "must return a numeric bytes_out" ) ;
179- } ) ;
180-
181133console . log ( `\n${ pass } passed, ${ fail } failed` ) ;
182134process . exit ( fail > 0 ? 1 : 0 ) ;
0 commit comments