@@ -341,99 +341,60 @@ for i in range(3):
341341 // ============================================================================
342342
343343 test ( 'context isolation and concurrency: isolation, many contexts, mutex' , async ( ) => {
344- console . log ( '[isolation] Starting test' ) ;
345-
346344 // Test basic isolation between two contexts
347- console . log ( '[isolation] Creating ctx1 (python)' ) ;
348345 const ctx1 = await createContext ( 'python' ) ;
349- console . log ( '[isolation] Created ctx1:' , ctx1 . id ) ;
350-
351- console . log ( '[isolation] Creating ctx2 (python)' ) ;
352346 const ctx2 = await createContext ( 'python' ) ;
353- console . log ( '[isolation] Created ctx2:' , ctx2 . id ) ;
354347
355- console . log ( '[isolation] Executing secret assignment in ctx1' ) ;
356348 await executeCode ( ctx1 , 'secret = "context1"' ) ;
357- console . log ( '[isolation] Checking isolation in ctx2' ) ;
358349 const isolationCheck = await executeCode ( ctx2 , 'print(secret)' ) ;
359- console . log (
360- '[isolation] Isolation check result:' ,
361- isolationCheck . error ?. name
362- ) ;
363350 expect ( isolationCheck . error ) . toBeDefined ( ) ;
364351 expect ( isolationCheck . error ! . name || isolationCheck . error ! . message ) . toMatch (
365352 / N a m e E r r o r | n o t d e f i n e d / i
366353 ) ;
367354
368- // Cleanup basic isolation contexts - SEQUENTIAL to avoid hanging
369- console . log ( '[isolation] Deleting ctx1' ) ;
355+ // Cleanup basic isolation contexts sequentially
370356 await deleteContext ( ctx1 . id ) ;
371- console . log ( '[isolation] Deleting ctx2' ) ;
372357 await deleteContext ( ctx2 . id ) ;
373- console . log ( '[isolation] Cleanup done' ) ;
374358
375- // Test isolation across 3 contexts - create sequentially
376- console . log ( '[isolation] Creating 3 JS contexts' ) ;
359+ // Test isolation across 3 contexts
377360 const manyContexts : CodeContext [ ] = [ ] ;
378361 for ( let i = 0 ; i < 3 ; i ++ ) {
379- console . log ( `[isolation] Creating context ${ i } ` ) ;
380- const ctx = await createContext ( 'javascript' ) ;
381- console . log ( `[isolation] Created context ${ i } :` , ctx . id ) ;
382- manyContexts . push ( ctx ) ;
362+ manyContexts . push ( await createContext ( 'javascript' ) ) ;
383363 }
384364
385- // Set unique values in each context sequentially
386- console . log ( '[isolation] Setting values in 3 contexts' ) ;
365+ // Set unique values in each context
387366 for ( let i = 0 ; i < manyContexts . length ; i ++ ) {
388- console . log ( `[isolation] Setting value in context ${ i } ` ) ;
389367 const exec = await executeCode (
390368 manyContexts [ i ] ,
391369 `const contextValue = ${ i } ; contextValue;`
392370 ) ;
393- console . log ( `[isolation] Context ${ i } set complete` ) ;
394371 expect ( exec . error , `Context ${ i } set error` ) . toBeUndefined ( ) ;
395372 expect ( exec . results ! [ 0 ] . text ) . toContain ( String ( i ) ) ;
396373 }
397- console . log ( '[isolation] All values set' ) ;
398374
399- // Verify isolated state sequentially
400- console . log ( '[isolation] Verifying isolated state' ) ;
375+ // Verify isolated state
401376 for ( let i = 0 ; i < manyContexts . length ; i ++ ) {
402- console . log ( `[isolation] Reading context ${ i } ` ) ;
403377 const exec = await executeCode ( manyContexts [ i ] , 'contextValue;' ) ;
404- console . log ( `[isolation] Context ${ i } read complete` ) ;
405378 expect ( exec . error , `Context ${ i } read error` ) . toBeUndefined ( ) ;
406379 expect ( exec . results ! [ 0 ] . text ) . toContain ( String ( i ) ) ;
407380 }
408- console . log ( '[isolation] Verification done' ) ;
409381
410- // Cleanup many contexts
411- console . log ( '[isolation] Cleaning up 3 contexts' ) ;
412- for ( let i = 0 ; i < manyContexts . length ; i ++ ) {
413- console . log ( `[isolation] Deleting context ${ i } :` , manyContexts [ i ] . id ) ;
414- await deleteContext ( manyContexts [ i ] . id ) ;
415- console . log ( `[isolation] Deleted context ${ i } ` ) ;
382+ // Cleanup contexts sequentially
383+ for ( const ctx of manyContexts ) {
384+ await deleteContext ( ctx . id ) ;
416385 }
417- console . log ( '[isolation] Cleanup done' ) ;
418386
419387 // Test concurrent execution on same context (mutex test)
420- console . log ( '[isolation] Creating mutex context' ) ;
421388 const mutexCtx = await createContext ( 'javascript' ) ;
422- console . log ( '[isolation] Mutex context created:' , mutexCtx . id ) ;
423-
424- console . log ( '[isolation] Initializing counter' ) ;
425389 await executeCode ( mutexCtx , 'let counter = 0;' ) ;
426- console . log ( '[isolation] Counter initialized' ) ;
427390
428391 // Launch 5 concurrent increments
429- console . log ( '[isolation] Launching 5 concurrent increments' ) ;
430392 const concurrentRequests = 5 ;
431393 const results = await Promise . allSettled (
432394 Array . from ( { length : concurrentRequests } , ( ) =>
433395 executeCode ( mutexCtx , 'counter++; counter;' )
434396 )
435397 ) ;
436- console . log ( '[isolation] Concurrent increments done' ) ;
437398
438399 // Collect counter values
439400 const counterValues : number [ ] = [ ] ;
@@ -445,37 +406,29 @@ for i in range(3):
445406 if ( match ) counterValues . push ( parseInt ( match [ 0 ] , 10 ) ) ;
446407 }
447408 }
448- console . log ( '[isolation] Counter values:' , counterValues ) ;
449409
450410 // All 5 should succeed with values 1-5 (serial execution via mutex)
451411 expect ( counterValues . length ) . toBe ( concurrentRequests ) ;
452412 counterValues . sort ( ( a , b ) => a - b ) ;
453413 expect ( counterValues ) . toEqual ( Array . from ( { length : 5 } , ( _ , i ) => i + 1 ) ) ;
454414
455415 // Verify final counter state
456- console . log ( '[isolation] Verifying final counter' ) ;
457416 const finalExec = await executeCode ( mutexCtx , 'counter;' ) ;
458417 const finalValue = parseInt (
459418 finalExec . results ?. [ 0 ] ?. text ?. match ( / \d + / ) ?. [ 0 ] || '0' ,
460419 10
461420 ) ;
462- console . log ( '[isolation] Final counter value:' , finalValue ) ;
463421 expect ( finalValue ) . toBe ( 5 ) ;
464422
465- console . log ( '[isolation] Cleaning up mutex context' ) ;
466423 await deleteContext ( mutexCtx . id ) ;
467- console . log ( '[isolation] Test complete' ) ;
468424 } , 30000 ) ;
469425
470426 // ============================================================================
471427 // Test 6: Error Handling
472428 // ============================================================================
473429
474430 test ( 'error handling: invalid language, non-existent context, Python unavailable' , async ( ) => {
475- console . log ( '[errors] Starting test' ) ;
476-
477431 // Invalid language
478- console . log ( '[errors] Testing invalid language' ) ;
479432 const invalidLangResponse = await fetch (
480433 `${ workerUrl } /api/code/context/create` ,
481434 {
@@ -484,17 +437,12 @@ for i in range(3):
484437 body : JSON . stringify ( { language : 'invalid-lang' } )
485438 }
486439 ) ;
487- console . log (
488- '[errors] Invalid language response:' ,
489- invalidLangResponse . status
490- ) ;
491440 expect ( invalidLangResponse . status ) . toBeGreaterThanOrEqual ( 400 ) ;
492441 const invalidLangError =
493442 ( await invalidLangResponse . json ( ) ) as ErrorResponse ;
494443 expect ( invalidLangError . error ) . toBeTruthy ( ) ;
495444
496445 // Non-existent context execution
497- console . log ( '[errors] Testing non-existent context execution' ) ;
498446 const fakeContextExec = await fetch ( `${ workerUrl } /api/code/execute` , {
499447 method : 'POST' ,
500448 headers,
@@ -505,34 +453,27 @@ for i in range(3):
505453 }
506454 } )
507455 } ) ;
508- console . log ( '[errors] Fake context exec response:' , fakeContextExec . status ) ;
509456 expect ( fakeContextExec . status ) . toBeGreaterThanOrEqual ( 400 ) ;
510457 const fakeContextError = ( await fakeContextExec . json ( ) ) as ErrorResponse ;
511458 expect ( fakeContextError . error ) . toBeTruthy ( ) ;
512459
513460 // Delete non-existent context
514- console . log ( '[errors] Testing delete non-existent context' ) ;
515461 await fetch ( `${ workerUrl } /api/execute` , {
516462 method : 'POST' ,
517463 headers,
518464 body : JSON . stringify ( { command : 'echo "init"' } )
519465 } ) ;
520- console . log ( '[errors] Init command done' ) ;
521466 const deleteFakeResponse = await fetch (
522467 `${ workerUrl } /api/code/context/fake-id-99999` ,
523468 { method : 'DELETE' , headers }
524469 ) ;
525- console . log ( '[errors] Delete fake response:' , deleteFakeResponse . status ) ;
526470 expect ( deleteFakeResponse . status ) . toBeGreaterThanOrEqual ( 400 ) ;
527471 const deleteFakeError = ( await deleteFakeResponse . json ( ) ) as ErrorResponse ;
528472 expect ( deleteFakeError . error ) . toBeTruthy ( ) ;
529473
530474 // Python unavailable on base image
531- console . log ( '[errors] Testing Python unavailable on base image' ) ;
532475 const sandbox = await getSharedSandbox ( ) ;
533- console . log ( '[errors] Got sandbox' ) ;
534476 const baseImageHeaders = sandbox . createHeaders ( createUniqueSession ( ) ) ;
535- console . log ( '[errors] Created base image headers' ) ;
536477 const pythonUnavailableResponse = await fetch (
537478 `${ workerUrl } /api/code/context/create` ,
538479 {
@@ -541,17 +482,12 @@ for i in range(3):
541482 body : JSON . stringify ( { language : 'python' } )
542483 }
543484 ) ;
544- console . log (
545- '[errors] Python unavailable response:' ,
546- pythonUnavailableResponse . status
547- ) ;
548485 expect ( pythonUnavailableResponse . status ) . toBe ( 500 ) ;
549486 const pythonUnavailableError =
550487 ( await pythonUnavailableResponse . json ( ) ) as ErrorResponse ;
551488 expect ( pythonUnavailableError . error ) . toContain (
552489 'Python interpreter not available'
553490 ) ;
554491 expect ( pythonUnavailableError . error ) . toMatch ( / - p y t h o n / ) ;
555- console . log ( '[errors] Test complete' ) ;
556492 } , 30000 ) ;
557493} ) ;
0 commit comments