@@ -171,6 +171,48 @@ suite('runAsTask Tests', () => {
171171 ) ;
172172 } ) ;
173173
174+ test ( 'should quote uv executable when needed' , async ( ) => {
175+ const environment : PythonEnvironment = {
176+ envId : { id : 'test-env' , managerId : 'test-manager' } ,
177+ name : 'Test Environment' ,
178+ displayName : 'Test Environment' ,
179+ displayPath : '/path/to/env' ,
180+ version : '3.9.0' ,
181+ environmentPath : Uri . file ( '/path/to/env' ) ,
182+ execInfo : {
183+ run : {
184+ executable : '/path/to/python' ,
185+ args : [ ] ,
186+ } ,
187+ } ,
188+ sysPrefix : '/path/to/env' ,
189+ } ;
190+
191+ const options : PythonTaskExecutionOptions = {
192+ name : 'Quoted UV Task' ,
193+ args : [ 'script.py' ] ,
194+ } ;
195+
196+ const mockTaskExecution = { } as TaskExecution ;
197+
198+ mockGetWorkspaceFolder . returns ( undefined ) ;
199+ mockShouldUseUv . withArgs ( undefined , environment . environmentPath . fsPath , undefined ) . resolves ( true ) ;
200+ mockQuoteStringIfNecessary . withArgs ( 'uv' ) . returns ( '"uv"' ) ;
201+ mockExecuteTask . resolves ( mockTaskExecution ) ;
202+
203+ await runAsTask ( environment , options ) ;
204+
205+ const taskArg = mockExecuteTask . firstCall . args [ 0 ] as Task ;
206+ const execution = taskArg . execution as ShellExecution ;
207+
208+ assert . strictEqual ( execution . command , '"uv"' , 'Should quote the uv executable when required' ) ;
209+ assert . deepStrictEqual (
210+ execution . args ,
211+ [ 'run' , '--python' , '/path/to/python' , 'script.py' ] ,
212+ 'Should preserve uv arguments when quoting the executable' ,
213+ ) ;
214+ } ) ;
215+
174216 test ( 'should create and execute task with regular run configuration when no activatedRun' , async ( ) => {
175217 // Mock - Environment without activatedRun
176218 const environment : PythonEnvironment = {
@@ -197,6 +239,7 @@ suite('runAsTask Tests', () => {
197239 const mockTaskExecution = { } as TaskExecution ;
198240
199241 mockGetWorkspaceFolder . withArgs ( undefined ) . returns ( undefined ) ;
242+ mockShouldUseUv . withArgs ( undefined , environment . environmentPath . fsPath , undefined ) . resolves ( false ) ;
200243 mockQuoteStringIfNecessary . withArgs ( '/path/to/python' ) . returns ( '/path/to/python' ) ;
201244 mockExecuteTask . resolves ( mockTaskExecution ) ;
202245
@@ -214,6 +257,10 @@ suite('runAsTask Tests', () => {
214257 mockTraceInfo . calledWith ( sinon . match ( / R u n n i n g a s t a s k : \/ p a t h \/ t o \/ p y t h o n - - d e f a u l t - a r g t e s t \. p y / ) ) ,
215258 'Should log execution with run args' ,
216259 ) ;
260+ const taskArg = mockExecuteTask . firstCall . args [ 0 ] as Task ;
261+ const execution = taskArg . execution as ShellExecution ;
262+ assert . strictEqual ( execution . command , '/path/to/python' , 'Should keep the python executable when uv is off' ) ;
263+ assert . deepStrictEqual ( execution . args , [ '--default-arg' , 'test.py' ] , 'Should keep the non-uv arguments' ) ;
217264 } ) ;
218265
219266 test ( 'should handle custom reveal option' , async ( ) => {
0 commit comments