@@ -194,15 +194,12 @@ describe('ClearcutSender', () => {
194194 } ) ;
195195 let resolveRequest : ( value : Response ) => void ;
196196
197- // We want the flush to start and hang
198197 fetchStub . onFirstCall ( ) . returns ( new Promise < Response > ( resolve => {
199198 resolveRequest = resolve ;
200199 } ) ) ;
201200
202- // Start flush via timer synchronously
203201 clock . tick ( FLUSH_INTERVAL_MS ) ;
204202
205- // Enqueue more events triggering overflow logic
206203 for ( let i = 0 ; i < 1100 ; i ++ ) {
207204 sender . enqueueEvent ( {
208205 tool_invocation : {
@@ -233,13 +230,10 @@ describe('ClearcutSender', () => {
233230 resolveFirstRequest = resolve ;
234231 } ) ) ;
235232
236- // Start flush via timer synchronously
237233 clock . tick ( FLUSH_INTERVAL_MS ) ;
238234
239- // Call shutdown while flush is pending
240235 const shutdownPromise = sender . sendShutdownEvent ( ) ;
241236
242- // Resolve first request to allow flush to complete
243237 resolveFirstRequest ! ( new Response ( JSON . stringify ( { } ) , { status : 200 } ) ) ;
244238 await shutdownPromise ;
245239
@@ -254,11 +248,9 @@ describe('ClearcutSender', () => {
254248 JSON . parse ( e . source_extension_json ) ,
255249 ) ;
256250
257- // First flush should have the event
258251 assert . strictEqual ( firstEvents . length , 1 ) ;
259252 assert . strictEqual ( firstEvents [ 0 ] . tool_invocation ?. tool_name , 'test-event' ) ;
260253
261- // Shutdown flush (second) should NOT duplicate it
262254 assert . strictEqual (
263255 secondEvents . length ,
264256 1 ,
@@ -287,14 +279,11 @@ describe('ClearcutSender', () => {
287279 const firstSessionId = firstEvent . session_id ;
288280
289281 const SESSION_ROTATION_INTERVAL_MS = 24 * 60 * 60 * 1000 ;
290- // Advance time past rotation interval
291- // We already moved FLUSH_INTERVAL_MS. Move the rest + buffer.
292282 await clock . tickAsync ( SESSION_ROTATION_INTERVAL_MS - FLUSH_INTERVAL_MS + 1000 ) ;
293283
294284 sender . enqueueEvent ( {
295285 tool_invocation : { tool_name : 'test2' , success : true , latency_ms : 10 } ,
296286 } ) ;
297- // Trigger second flush
298287 await clock . tickAsync ( FLUSH_INTERVAL_MS ) ;
299288
300289 const secondCallBody = JSON . parse (
@@ -311,26 +300,20 @@ describe('ClearcutSender', () => {
311300 it ( 'respects next_request_wait_millis from server' , async ( ) => {
312301 const sender = new ClearcutSender ( '1.0.0' , OsType . OS_TYPE_MACOS ) ;
313302
314- // Configure server to request 45s wait
315303 fetchStub . resolves ( new Response ( JSON . stringify ( {
316304 next_request_wait_millis : 45000 ,
317305 } ) , { status : 200 } ) ) ;
318306
319307 sender . enqueueEvent ( { } ) ;
320- // Initial flush
321308 await clock . tickAsync ( FLUSH_INTERVAL_MS ) ;
322309
323- // Reset stub history to track next calls
324310 fetchStub . resetHistory ( ) ;
325311
326- // Enqueue another event
327312 sender . enqueueEvent ( { } ) ;
328313
329- // Advance time by 44s - should NOT flush yet
330314 await clock . tickAsync ( 44000 ) ;
331315 assert . strictEqual ( fetchStub . callCount , 0 , 'Should not flush before wait time' ) ;
332316
333- // Advance time by 1s (total 45s) - SHOULD flush now
334317 await clock . tickAsync ( 1000 ) ;
335318 assert . strictEqual ( fetchStub . callCount , 1 , 'Should flush after wait time' ) ;
336319
@@ -344,15 +327,14 @@ describe('ClearcutSender', () => {
344327 let fetchSignal : AbortSignal | undefined ;
345328 fetchStub . callsFake ( ( _url , options ) => {
346329 fetchSignal = options . signal ;
347- return new Promise ( ( ) => { } ) ; // Never resolves
330+ return new Promise ( ( ) => {
331+ // Hangs forever
332+ } ) ;
348333 } ) ;
349334
350335 sender . enqueueEvent ( { } ) ;
351336
352- // Trigger flush
353337 await clock . tickAsync ( FLUSH_INTERVAL_MS ) ;
354-
355- // Advance time for timeout
356338 await clock . tickAsync ( REQUEST_TIMEOUT_MS ) ;
357339
358340 assert . ok ( fetchSignal , 'Fetch should have been called with a signal' ) ;
@@ -363,14 +345,14 @@ describe('ClearcutSender', () => {
363345
364346 it ( 'resolves sendShutdownEvent after timeout if flush hangs' , async ( ) => {
365347 const sender = new ClearcutSender ( '1.0.0' , OsType . OS_TYPE_MACOS ) ;
366- fetchStub . returns ( new Promise ( ( ) => { } ) ) ; // Hangs forever
348+ fetchStub . returns ( new Promise ( ( ) => {
349+ // Hangs forever
350+ } ) ) ;
367351
368352 const shutdownPromise = sender . sendShutdownEvent ( ) ;
369353
370- // Advance time by 5000ms (SHUTDOWN_TIMEOUT_MS)
371354 await clock . tickAsync ( 5000 ) ;
372355
373- // The promise should resolve now
374356 await shutdownPromise ;
375357 } ) ;
376358} ) ;
0 commit comments