@@ -354,9 +354,25 @@ VERSION_ID="22.04"
354354 } )
355355
356356 it ( 'isCloudDesktop' , async function ( ) {
357+ // Mock fs module for isAmazonLinux2() calls
358+ const fsMock = {
359+ existsSync : sandbox . stub ( ) . returns ( false ) ,
360+ readFileSync : sandbox . stub ( ) . returns ( '' ) ,
361+ }
362+ const fsExistsStub = fsMock . existsSync
363+
364+ // Stub Module._load to intercept require calls
365+ const Module = require ( 'module' )
366+ const moduleLoadStub = sandbox . stub ( Module , '_load' ) . callThrough ( )
367+ moduleLoadStub . withArgs ( 'fs' ) . returns ( fsMock )
368+
357369 sandbox . stub ( process , 'platform' ) . value ( 'linux' )
370+ sandbox . stub ( globals , 'isWeb' ) . returns ( false )
358371 stubOsVersion ( '5.10.220-188.869.amzn2int.x86_64' )
359372
373+ // Mock fs to return false so it falls back to kernel check (which should return true for AL2)
374+ fsExistsStub . returns ( false )
375+
360376 const runStub = sandbox . stub ( ChildProcess . prototype , 'run' ) . resolves ( { exitCode : 0 } as any )
361377 assert . strictEqual ( await isCloudDesktop ( ) , true )
362378
@@ -365,29 +381,58 @@ VERSION_ID="22.04"
365381 } )
366382
367383 describe ( 'getComputeEnvType' , async function ( ) {
384+ let fsExistsStub : sinon . SinonStub
385+ let moduleLoadStub : sinon . SinonStub
386+
387+ beforeEach ( function ( ) {
388+ // Mock fs module for isAmazonLinux2() calls
389+ const fsMock = {
390+ existsSync : sandbox . stub ( ) . returns ( false ) ,
391+ readFileSync : sandbox . stub ( ) . returns ( '' ) ,
392+ }
393+ fsExistsStub = fsMock . existsSync
394+
395+ // Stub Module._load to intercept require calls
396+ const Module = require ( 'module' )
397+ moduleLoadStub = sandbox . stub ( Module , '_load' ) . callThrough ( )
398+ moduleLoadStub . withArgs ( 'fs' ) . returns ( fsMock )
399+ } )
400+
368401 it ( 'cloudDesktop' , async function ( ) {
369402 sandbox . stub ( process , 'platform' ) . value ( 'linux' )
370403 sandbox . stub ( vscode . env , 'remoteName' ) . value ( 'ssh-remote' )
404+ sandbox . stub ( globals , 'isWeb' ) . returns ( false )
371405 stubOsVersion ( '5.10.220-188.869.amzn2int.x86_64' )
372406 sandbox . stub ( ChildProcess . prototype , 'run' ) . resolves ( { exitCode : 0 } as any )
373407
408+ // Mock fs to return false so it falls back to kernel check (which should return true for AL2)
409+ fsExistsStub . returns ( false )
410+
374411 assert . deepStrictEqual ( await getComputeEnvType ( ) , 'cloudDesktop-amzn' )
375412 } )
376413
377414 it ( 'ec2-internal' , async function ( ) {
378415 sandbox . stub ( process , 'platform' ) . value ( 'linux' )
379416 sandbox . stub ( vscode . env , 'remoteName' ) . value ( 'ssh-remote' )
417+ sandbox . stub ( globals , 'isWeb' ) . returns ( false )
380418 stubOsVersion ( '5.10.220-188.869.amzn2int.x86_64' )
381419 sandbox . stub ( ChildProcess . prototype , 'run' ) . resolves ( { exitCode : 1 } as any )
382420
421+ // Mock fs to return false so it falls back to kernel check (which should return true for AL2)
422+ fsExistsStub . returns ( false )
423+
383424 assert . deepStrictEqual ( await getComputeEnvType ( ) , 'ec2-amzn' )
384425 } )
385426
386427 it ( 'ec2' , async function ( ) {
387428 sandbox . stub ( process , 'platform' ) . value ( 'linux' )
388429 sandbox . stub ( vscode . env , 'remoteName' ) . value ( 'ssh-remote' )
430+ sandbox . stub ( globals , 'isWeb' ) . returns ( false )
389431 stubOsVersion ( '5.10.220-188.869.NOT_INTERNAL.x86_64' )
390432
433+ // Mock fs to return false so it falls back to kernel check (which should return false for non-AL2)
434+ fsExistsStub . returns ( false )
435+
391436 assert . deepStrictEqual ( await getComputeEnvType ( ) , 'ec2' )
392437 } )
393438 } )
0 commit comments