@@ -17,6 +17,7 @@ import {
1717 ISourceMapSupportService ,
1818} from '../../../client/application/diagnostics/types' ;
1919import { IApplicationDiagnostics } from '../../../client/application/types' ;
20+ import { IWorkspaceService } from '../../../client/common/application/types' ;
2021import { STANDARD_OUTPUT_CHANNEL } from '../../../client/common/constants' ;
2122import { IOutputChannel } from '../../../client/common/types' ;
2223import { createDeferred , createDeferredFromPromise } from '../../../client/common/utils/async' ;
@@ -30,6 +31,7 @@ suite('Application Diagnostics - ApplicationDiagnostics', () => {
3031 let lsNotSupportedCheck : typemoq . IMock < IDiagnosticsService > ;
3132 let pythonInterpreterCheck : typemoq . IMock < IDiagnosticsService > ;
3233 let outputChannel : typemoq . IMock < IOutputChannel > ;
34+ let workspaceService : typemoq . IMock < IWorkspaceService > ;
3335 let appDiagnostics : IApplicationDiagnostics ;
3436 const oldValueOfVSC_PYTHON_UNIT_TEST = process . env . VSC_PYTHON_UNIT_TEST ;
3537 const oldValueOfVSC_PYTHON_CI_TEST = process . env . VSC_PYTHON_CI_TEST ;
@@ -44,14 +46,20 @@ suite('Application Diagnostics - ApplicationDiagnostics', () => {
4446 lsNotSupportedCheck . setup ( ( service ) => service . runInBackground ) . returns ( ( ) => false ) ;
4547 pythonInterpreterCheck = typemoq . Mock . ofType < IDiagnosticsService > ( ) ;
4648 pythonInterpreterCheck . setup ( ( service ) => service . runInBackground ) . returns ( ( ) => false ) ;
49+ pythonInterpreterCheck . setup ( ( service ) => service . runInUntrustedWorkspace ) . returns ( ( ) => false ) ;
4750 outputChannel = typemoq . Mock . ofType < IOutputChannel > ( ) ;
51+ workspaceService = typemoq . Mock . ofType < IWorkspaceService > ( ) ;
52+ workspaceService . setup ( ( w ) => w . isTrusted ) . returns ( ( ) => true ) ;
4853
4954 serviceContainer
5055 . setup ( ( d ) => d . getAll ( typemoq . It . isValue ( IDiagnosticsService ) ) )
5156 . returns ( ( ) => [ envHealthCheck . object , lsNotSupportedCheck . object , pythonInterpreterCheck . object ] ) ;
5257 serviceContainer
5358 . setup ( ( d ) => d . get ( typemoq . It . isValue ( IOutputChannel ) , typemoq . It . isValue ( STANDARD_OUTPUT_CHANNEL ) ) )
5459 . returns ( ( ) => outputChannel . object ) ;
60+ serviceContainer
61+ . setup ( ( d ) => d . get ( typemoq . It . isValue ( IWorkspaceService ) ) )
62+ . returns ( ( ) => workspaceService . object ) ;
5563
5664 appDiagnostics = new ApplicationDiagnostics ( serviceContainer . object , outputChannel . object ) ;
5765 } ) ;
@@ -95,6 +103,29 @@ suite('Application Diagnostics - ApplicationDiagnostics', () => {
95103 pythonInterpreterCheck . verifyAll ( ) ;
96104 } ) ;
97105
106+ test ( 'When running in a untrusted workspace skip diagnosing validation checks which do not support it' , async ( ) => {
107+ workspaceService . reset ( ) ;
108+ workspaceService . setup ( ( w ) => w . isTrusted ) . returns ( ( ) => false ) ;
109+ envHealthCheck
110+ . setup ( ( e ) => e . diagnose ( typemoq . It . isAny ( ) ) )
111+ . returns ( ( ) => Promise . resolve ( [ ] ) )
112+ . verifiable ( typemoq . Times . once ( ) ) ;
113+ lsNotSupportedCheck
114+ . setup ( ( p ) => p . diagnose ( typemoq . It . isAny ( ) ) )
115+ . returns ( ( ) => Promise . resolve ( [ ] ) )
116+ . verifiable ( typemoq . Times . once ( ) ) ;
117+ pythonInterpreterCheck
118+ . setup ( ( p ) => p . diagnose ( typemoq . It . isAny ( ) ) )
119+ . returns ( ( ) => Promise . resolve ( [ ] ) )
120+ . verifiable ( typemoq . Times . never ( ) ) ;
121+
122+ await appDiagnostics . performPreStartupHealthCheck ( undefined ) ;
123+
124+ envHealthCheck . verifyAll ( ) ;
125+ lsNotSupportedCheck . verifyAll ( ) ;
126+ pythonInterpreterCheck . verifyAll ( ) ;
127+ } ) ;
128+
98129 test ( 'Performing Pre Startup Health Check must handles all validation checks only once either in background or foreground' , async ( ) => {
99130 const diagnostic : IDiagnostic = {
100131 code : 'Error' as any ,
@@ -215,9 +246,12 @@ suite('Application Diagnostics - ApplicationDiagnostics', () => {
215246 const foreGroundService = mock ( InvalidPythonInterpreterService ) ;
216247 const backGroundService = mock ( EnvironmentPathVariableDiagnosticsService ) ;
217248 const svcContainer = mock ( ServiceContainer ) ;
249+ const workspaceService = mock < IWorkspaceService > ( ) ;
218250 const foreGroundDeferred = createDeferred < IDiagnostic [ ] > ( ) ;
219251 const backgroundGroundDeferred = createDeferred < IDiagnostic [ ] > ( ) ;
220252
253+ when ( svcContainer . get < IWorkspaceService > ( IWorkspaceService ) ) . thenReturn ( workspaceService ) ;
254+ when ( workspaceService . isTrusted ) . thenReturn ( true ) ;
221255 when ( svcContainer . getAll < IDiagnosticsService > ( IDiagnosticsService ) ) . thenReturn ( [
222256 instance ( foreGroundService ) ,
223257 instance ( backGroundService ) ,
0 commit comments