@@ -18,6 +18,8 @@ import globals from '../../shared/extensionGlobals'
1818import { maybeShowMinVscodeWarning } from '../../shared/extensionStartup'
1919import { getTestWindow } from './vscode/window'
2020import { assertTelemetry } from '../testUtil'
21+ import { isSageMaker } from '../../shared/extensionUtilities'
22+ import { hasSageMakerEnvVars } from '../../shared/vscode/env'
2123
2224describe ( 'extensionUtilities' , function ( ) {
2325 it ( 'maybeShowMinVscodeWarning' , async ( ) => {
@@ -361,3 +363,146 @@ describe('UserActivity', function () {
361363 return event . event
362364 }
363365} )
366+
367+ describe ( 'isSageMaker' , function ( ) {
368+ let sandbox : sinon . SinonSandbox
369+ const env = require ( '../../shared/vscode/env' )
370+ const utils = require ( '../../shared/extensionUtilities' )
371+
372+ beforeEach ( function ( ) {
373+ sandbox = sinon . createSandbox ( )
374+ utils . resetSageMakerState ( )
375+ } )
376+
377+ afterEach ( function ( ) {
378+ sandbox . restore ( )
379+ delete process . env . SERVICE_NAME
380+ } )
381+
382+ describe ( 'SMAI detection' , function ( ) {
383+ it ( 'returns true when both app name and env vars match' , function ( ) {
384+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
385+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
386+
387+ assert . strictEqual ( isSageMaker ( 'SMAI' ) , true )
388+ } )
389+
390+ it ( 'returns false when app name is different' , function ( ) {
391+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'Visual Studio Code' )
392+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
393+
394+ assert . strictEqual ( isSageMaker ( 'SMAI' ) , false )
395+ } )
396+
397+ it ( 'returns false when env vars are missing' , function ( ) {
398+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
399+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( false )
400+
401+ assert . strictEqual ( isSageMaker ( 'SMAI' ) , false )
402+ } )
403+
404+ it ( 'defaults to SMAI when no parameter provided' , function ( ) {
405+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
406+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
407+
408+ assert . strictEqual ( isSageMaker ( ) , true )
409+ } )
410+ } )
411+
412+ describe ( 'SMUS detection' , function ( ) {
413+ it ( 'returns true when all conditions are met' , function ( ) {
414+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
415+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
416+ process . env . SERVICE_NAME = 'SageMakerUnifiedStudio'
417+
418+ assert . strictEqual ( isSageMaker ( 'SMUS' ) , true )
419+ } )
420+
421+ it ( 'returns false when unified studio is missing' , function ( ) {
422+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
423+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
424+ process . env . SERVICE_NAME = 'SomeOtherService'
425+
426+ assert . strictEqual ( isSageMaker ( 'SMUS' ) , false )
427+ } )
428+
429+ it ( 'returns false when env vars are missing' , function ( ) {
430+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
431+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( false )
432+ process . env . SERVICE_NAME = 'SageMakerUnifiedStudio'
433+
434+ assert . strictEqual ( isSageMaker ( 'SMUS' ) , false )
435+ } )
436+
437+ it ( 'returns false when app name is different' , function ( ) {
438+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'Visual Studio Code' )
439+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
440+ process . env . SERVICE_NAME = 'SageMakerUnifiedStudio'
441+
442+ assert . strictEqual ( isSageMaker ( 'SMUS' ) , false )
443+ } )
444+ } )
445+
446+ it ( 'returns false for invalid appName parameter' , function ( ) {
447+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
448+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
449+
450+ // @ts -ignore - Testing invalid input
451+ assert . strictEqual ( isSageMaker ( 'INVALID' ) , false )
452+ } )
453+ } )
454+
455+ describe ( 'hasSageMakerEnvVars' , function ( ) {
456+ let originalEnv : NodeJS . ProcessEnv
457+
458+ 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
467+ } )
468+
469+ afterEach ( function ( ) {
470+ process . env = originalEnv
471+ } )
472+
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
487+
488+ const result = hasSageMakerEnvVars ( )
489+
490+ assert . strictEqual ( result , expected )
491+ } )
492+ }
493+
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'
497+
498+ const result = hasSageMakerEnvVars ( )
499+
500+ assert . strictEqual ( result , true )
501+ } )
502+
503+ it ( 'returns false when no SageMaker env vars are set' , function ( ) {
504+ const result = hasSageMakerEnvVars ( )
505+
506+ assert . strictEqual ( result , false )
507+ } )
508+ } )
0 commit comments