@@ -18,6 +18,8 @@ import globals from '../../shared/extensionGlobals'
18
18
import { maybeShowMinVscodeWarning } from '../../shared/extensionStartup'
19
19
import { getTestWindow } from './vscode/window'
20
20
import { assertTelemetry } from '../testUtil'
21
+ import { isSageMaker } from '../../shared/extensionUtilities'
22
+ import { hasSageMakerEnvVars } from '../../shared/vscode/env'
21
23
22
24
describe ( 'extensionUtilities' , function ( ) {
23
25
it ( 'maybeShowMinVscodeWarning' , async ( ) => {
@@ -361,3 +363,143 @@ describe('UserActivity', function () {
361
363
return event . event
362
364
}
363
365
} )
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
+ } )
380
+
381
+ describe ( 'SMAI detection' , function ( ) {
382
+ it ( 'returns true when both app name and env vars match' , function ( ) {
383
+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
384
+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
385
+
386
+ assert . strictEqual ( isSageMaker ( 'SMAI' ) , true )
387
+ } )
388
+
389
+ it ( 'returns false when app name is different' , function ( ) {
390
+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'Visual Studio Code' )
391
+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
392
+
393
+ assert . strictEqual ( isSageMaker ( 'SMAI' ) , false )
394
+ } )
395
+
396
+ it ( 'returns false when env vars are missing' , function ( ) {
397
+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
398
+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( false )
399
+
400
+ assert . strictEqual ( isSageMaker ( 'SMAI' ) , false )
401
+ } )
402
+
403
+ it ( 'defaults to SMAI when no parameter provided' , function ( ) {
404
+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
405
+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
406
+
407
+ assert . strictEqual ( isSageMaker ( ) , true )
408
+ } )
409
+ } )
410
+
411
+ describe ( 'SMUS detection' , function ( ) {
412
+ it ( 'returns true when all conditions are met' , function ( ) {
413
+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
414
+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
415
+ sandbox . stub ( process , 'env' ) . value ( { SERVICE_NAME : 'SageMakerUnifiedStudio' } )
416
+ utils . resetSageMakerState ( )
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
+ sandbox . stub ( process , 'env' ) . value ( { SERVICE_NAME : 'SomeOtherService' } )
425
+ utils . resetSageMakerState ( )
426
+
427
+ assert . strictEqual ( isSageMaker ( 'SMUS' ) , false )
428
+ } )
429
+
430
+ it ( 'returns false when env vars are missing' , function ( ) {
431
+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
432
+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( false )
433
+ sandbox . stub ( process , 'env' ) . value ( { SERVICE_NAME : 'SageMakerUnifiedStudio' } )
434
+ utils . resetSageMakerState ( )
435
+
436
+ assert . strictEqual ( isSageMaker ( 'SMUS' ) , false )
437
+ } )
438
+
439
+ it ( 'returns false when app name is different' , function ( ) {
440
+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'Visual Studio Code' )
441
+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
442
+ sandbox . stub ( process , 'env' ) . value ( { SERVICE_NAME : 'SageMakerUnifiedStudio' } )
443
+ utils . resetSageMakerState ( )
444
+
445
+ assert . strictEqual ( isSageMaker ( 'SMUS' ) , false )
446
+ } )
447
+ } )
448
+
449
+ it ( 'returns false for invalid appName parameter' , function ( ) {
450
+ sandbox . stub ( vscode . env , 'appName' ) . value ( 'SageMaker Code Editor' )
451
+ sandbox . stub ( env , 'hasSageMakerEnvVars' ) . returns ( true )
452
+
453
+ // @ts -ignore - Testing invalid input
454
+ assert . strictEqual ( isSageMaker ( 'INVALID' ) , false )
455
+ } )
456
+ } )
457
+
458
+ describe ( 'hasSageMakerEnvVars' , function ( ) {
459
+ let sandbox : sinon . SinonSandbox
460
+
461
+ beforeEach ( function ( ) {
462
+ sandbox = sinon . createSandbox ( )
463
+ } )
464
+
465
+ afterEach ( function ( ) {
466
+ sandbox . restore ( )
467
+ } )
468
+
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 )
473
+
474
+ // Test SM_ prefix
475
+ sandbox . stub ( process , 'env' ) . value ( { SM_APP_TYPE : 'CodeEditor' } )
476
+ assert . strictEqual ( hasSageMakerEnvVars ( ) , true )
477
+
478
+ // Test SERVICE_NAME with correct value
479
+ sandbox . stub ( process , 'env' ) . value ( { SERVICE_NAME : 'SageMakerUnifiedStudio' } )
480
+ assert . strictEqual ( hasSageMakerEnvVars ( ) , true )
481
+
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 )
485
+
486
+ // Test invalid SERVICE_NAME
487
+ sandbox . stub ( process , 'env' ) . value ( { SERVICE_NAME : 'SomeOtherService' } )
488
+ assert . strictEqual ( hasSageMakerEnvVars ( ) , false )
489
+
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 )
493
+
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 )
500
+
501
+ // Test no env vars
502
+ sandbox . stub ( process , 'env' ) . value ( { } )
503
+ assert . strictEqual ( hasSageMakerEnvVars ( ) , false )
504
+ } )
505
+ } )
0 commit comments