@@ -376,7 +376,6 @@ describe('isSageMaker', function () {
376376
377377 afterEach ( function ( ) {
378378 sandbox . restore ( )
379- delete process . env . SERVICE_NAME
380379 } )
381380
382381 describe ( 'SMAI detection' , function ( ) {
@@ -413,31 +412,35 @@ describe('isSageMaker', function () {
413412 it ( 'returns true when all conditions are met' , function ( ) {
414413 sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
415414 sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
416- process . env . SERVICE_NAME = 'SageMakerUnifiedStudio'
415+ sandbox . stub ( process , 'env' ) . value ( { SERVICE_NAME : 'SageMakerUnifiedStudio' } )
416+ utils . resetSageMakerState ( )
417417
418418 assert . strictEqual ( isSageMaker ( 'SMUS' ) , true )
419419 } )
420420
421421 it ( 'returns false when unified studio is missing' , function ( ) {
422422 sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
423423 sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
424- process . env . SERVICE_NAME = 'SomeOtherService'
424+ sandbox . stub ( process , 'env' ) . value ( { SERVICE_NAME : 'SomeOtherService' } )
425+ utils . resetSageMakerState ( )
425426
426427 assert . strictEqual ( isSageMaker ( 'SMUS' ) , false )
427428 } )
428429
429430 it ( 'returns false when env vars are missing' , function ( ) {
430431 sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
431432 sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( false )
432- process . env . SERVICE_NAME = 'SageMakerUnifiedStudio'
433+ sandbox . stub ( process , 'env' ) . value ( { SERVICE_NAME : 'SageMakerUnifiedStudio' } )
434+ utils . resetSageMakerState ( )
433435
434436 assert . strictEqual ( isSageMaker ( 'SMUS' ) , false )
435437 } )
436438
437439 it ( 'returns false when app name is different' , function ( ) {
438440 sandbox . stub ( vscode . env , 'appName' ) . value ( 'Visual Studio Code' )
439441 sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
440- process . env . SERVICE_NAME = 'SageMakerUnifiedStudio'
442+ sandbox . stub ( process , 'env' ) . value ( { SERVICE_NAME : 'SageMakerUnifiedStudio' } )
443+ utils . resetSageMakerState ( )
441444
442445 assert . strictEqual ( isSageMaker ( 'SMUS' ) , false )
443446 } )
@@ -453,56 +456,50 @@ describe('isSageMaker', function () {
453456} )
454457
455458describe ( 'hasSageMakerEnvVars' , function ( ) {
456- let originalEnv : NodeJS . ProcessEnv
459+ let sandbox : sinon . SinonSandbox
457460
458461 beforeEach ( function ( ) {
459- originalEnv = { ...process . env }
460- // Clear all SageMaker-related env vars
461- delete process . env . SAGEMAKER_APP_TYPE
462- delete process . env . SAGEMAKER_INTERNAL_IMAGE_URI
463- delete process . env . STUDIO_LOGGING_DIR
464- delete process . env . SM_APP_TYPE
465- delete process . env . SM_INTERNAL_IMAGE_URI
466- delete process . env . SERVICE_NAME
462+ sandbox = sinon . createSandbox ( )
467463 } )
468464
469465 afterEach ( function ( ) {
470- process . env = originalEnv
466+ sandbox . restore ( )
471467 } )
472468
473- const testCases = [
474- { env : 'SAGEMAKER_APP_TYPE' , value : 'JupyterServer' , expected : true } ,
475- { env : 'SAGEMAKER_INTERNAL_IMAGE_URI' , value : 'some-uri' , expected : true } ,
476- { env : 'STUDIO_LOGGING_DIR' , value : '/var/log/studio/app.log' , expected : true } ,
477- { env : 'STUDIO_LOGGING_DIR' , value : '/var/log/other/app.log' , expected : false } ,
478- { env : 'SM_APP_TYPE' , value : 'JupyterServer' , expected : true } ,
479- { env : 'SM_INTERNAL_IMAGE_URI' , value : 'some-uri' , expected : true } ,
480- { env : 'SERVICE_NAME' , value : 'SageMakerUnifiedStudio' , expected : true } ,
481- { env : 'SERVICE_NAME' , value : 'SomeOtherService' , expected : false } ,
482- ]
483-
484- for ( const { env, value, expected } of testCases ) {
485- it ( `returns ${ expected } when ${ env } is set to "${ value } "` , function ( ) {
486- process . env [ env ] = value
469+ it ( 'detects SageMaker environment variables' , function ( ) {
470+ // Test SAGEMAKER_ prefix
471+ sandbox . stub ( process , 'env' ) . value ( { SAGEMAKER_APP_TYPE : 'JupyterServer' } )
472+ assert . strictEqual ( hasSageMakerEnvVars ( ) , true )
487473
488- const result = hasSageMakerEnvVars ( )
474+ // Test SM_ prefix
475+ sandbox . stub ( process , 'env' ) . value ( { SM_APP_TYPE : 'CodeEditor' } )
476+ assert . strictEqual ( hasSageMakerEnvVars ( ) , true )
489477
490- assert . strictEqual ( result , expected )
491- } )
492- }
478+ // Test SERVICE_NAME with correct value
479+ sandbox . stub ( process , 'env' ) . value ( { SERVICE_NAME : 'SageMakerUnifiedStudio' } )
480+ assert . strictEqual ( hasSageMakerEnvVars ( ) , true )
493481
494- it ( 'returns true when multiple SageMaker env vars are set' , function ( ) {
495- process . env . SAGEMAKER_APP_TYPE = 'JupyterServer'
496- process . env . SM_APP_TYPE = 'CodeEditor'
482+ // Test STUDIO_LOGGING_DIR with correct path
483+ sandbox . stub ( process , ' env' ) . value ( { STUDIO_LOGGING_DIR : '/var/log/studio/app.log' } )
484+ assert . strictEqual ( hasSageMakerEnvVars ( ) , true )
497485
498- const result = hasSageMakerEnvVars ( )
486+ // Test invalid SERVICE_NAME
487+ sandbox . stub ( process , 'env' ) . value ( { SERVICE_NAME : 'SomeOtherService' } )
488+ assert . strictEqual ( hasSageMakerEnvVars ( ) , false )
499489
500- assert . strictEqual ( result , true )
501- } )
490+ // Test invalid STUDIO_LOGGING_DIR
491+ sandbox . stub ( process , 'env' ) . value ( { STUDIO_LOGGING_DIR : '/var/log/other/app.log' } )
492+ assert . strictEqual ( hasSageMakerEnvVars ( ) , false )
502493
503- it ( 'returns false when no SageMaker env vars are set' , function ( ) {
504- const result = hasSageMakerEnvVars ( )
494+ // Test multiple env vars
495+ sandbox . stub ( process , 'env' ) . value ( {
496+ SAGEMAKER_APP_TYPE : 'JupyterServer' ,
497+ SM_APP_TYPE : 'CodeEditor' ,
498+ } )
499+ assert . strictEqual ( hasSageMakerEnvVars ( ) , true )
505500
506- assert . strictEqual ( result , false )
501+ // Test no env vars
502+ sandbox . stub ( process , 'env' ) . value ( { } )
503+ assert . strictEqual ( hasSageMakerEnvVars ( ) , false )
507504 } )
508505} )
0 commit comments