@@ -3,6 +3,7 @@ import * as assert from 'assert';
33import * as path from 'path' ;
44import * as sinon from 'sinon' ;
55import { ConfigurationTarget , Uri , WorkspaceFolder } from 'vscode' ;
6+ import * as logging from '../../../common/logging' ;
67import * as workspaceApis from '../../../common/workspace.apis' ;
78import {
89 addPythonProjectSetting ,
@@ -22,20 +23,16 @@ function getTestWorkspacePath(): string {
2223}
2324
2425/**
25- * These tests verify that settings ARE written when the value changes,
26- * regardless of whether it's the default/system manager or not.
27- *
28- * Note: These tests focus on the global settings path (project=undefined) because
29- * workspace-scoped tests would require mocking workspace.getWorkspaceFolder which
30- * cannot be easily stubbed in unit tests.
26+ * These tests verify that manager edits without a project do not write settings
27+ * and are logged explicitly as ignored global edits.
3128 */
3229suite ( 'Setting Helpers - Settings Write Behavior' , ( ) => {
3330 const SYSTEM_MANAGER_ID = 'ms-python.python:system' ;
3431 const VENV_MANAGER_ID = 'ms-python.python:venv' ;
3532 const PIP_MANAGER_ID = 'ms-python.python:pip' ;
3633 const CONDA_MANAGER_ID = 'ms-python.python:conda' ;
3734
38- let updateCalls : Array < { key : string ; value : unknown ; target : ConfigurationTarget } > ;
35+ let updateCalls : Array < { key : string ; value : unknown ; target : boolean | ConfigurationTarget | undefined } > ;
3936
4037 setup ( ( ) => {
4138 updateCalls = [ ] ;
@@ -46,7 +43,7 @@ suite('Setting Helpers - Settings Write Behavior', () => {
4643 } ) ;
4744
4845 /**
49- * Creates a mock WorkspaceConfiguration that tracks update calls
46+ * Creates a mock WorkspaceConfiguration that tracks update calls.
5047 */
5148 function createMockConfig ( options : {
5249 defaultEnvManagerGlobalValue ?: string ;
@@ -99,7 +96,7 @@ suite('Setting Helpers - Settings Write Behavior', () => {
9996 updateCalls . push ( {
10097 key : section ,
10198 value,
102- target : configurationTarget as ConfigurationTarget ,
99+ target : configurationTarget ,
103100 } ) ;
104101 return Promise . resolve ( ) ;
105102 } ;
@@ -113,6 +110,7 @@ suite('Setting Helpers - Settings Write Behavior', () => {
113110 currentEnvManager : VENV_MANAGER_ID ,
114111 } ) ;
115112 sinon . stub ( workspaceApis , 'getConfiguration' ) . returns ( mockConfig ) ;
113+ const traceVerboseStub = sinon . stub ( logging , 'traceVerbose' ) ;
116114
117115 await setAllManagerSettings ( [
118116 {
@@ -122,10 +120,12 @@ suite('Setting Helpers - Settings Write Behavior', () => {
122120 } ,
123121 ] ) ;
124122
125- const envManagerUpdates = updateCalls . filter (
126- ( c ) => c . key === 'defaultEnvManager' && c . target === ConfigurationTarget . Global ,
123+ const envManagerUpdates = updateCalls . filter ( ( c ) => c . key === 'defaultEnvManager' ) ;
124+ assert . strictEqual ( envManagerUpdates . length , 0 , 'Should never write defaultEnvManager for global edits' ) ;
125+ sinon . assert . calledWithMatch (
126+ traceVerboseStub ,
127+ '[setAllManagerSettings] Ignoring 1 edit(s) without a project because python-envs does not persist manager defaults to User/global settings.' ,
127128 ) ;
128- assert . strictEqual ( envManagerUpdates . length , 0 , 'Should never write to user/global settings' ) ;
129129 } ) ;
130130
131131 test ( 'should NOT write global defaultPackageManager even when value differs from current' , async ( ) => {
@@ -143,10 +143,12 @@ suite('Setting Helpers - Settings Write Behavior', () => {
143143 } ,
144144 ] ) ;
145145
146- const pkgManagerUpdates = updateCalls . filter (
147- ( c ) => c . key === 'defaultPackageManager' && c . target === ConfigurationTarget . Global ,
146+ const pkgManagerUpdates = updateCalls . filter ( ( c ) => c . key === 'defaultPackageManager' ) ;
147+ assert . strictEqual (
148+ pkgManagerUpdates . length ,
149+ 0 ,
150+ 'Should never write defaultPackageManager for global edits' ,
148151 ) ;
149- assert . strictEqual ( pkgManagerUpdates . length , 0 , 'Should never write to user/global settings' ) ;
150152 } ) ;
151153 } ) ;
152154
@@ -156,6 +158,7 @@ suite('Setting Helpers - Settings Write Behavior', () => {
156158 currentEnvManager : VENV_MANAGER_ID ,
157159 } ) ;
158160 sinon . stub ( workspaceApis , 'getConfiguration' ) . returns ( mockConfig ) ;
161+ const traceVerboseStub = sinon . stub ( logging , 'traceVerbose' ) ;
159162
160163 await setEnvironmentManager ( [
161164 {
@@ -164,10 +167,12 @@ suite('Setting Helpers - Settings Write Behavior', () => {
164167 } ,
165168 ] ) ;
166169
167- const envManagerUpdates = updateCalls . filter (
168- ( c ) => c . key === 'defaultEnvManager' && c . target === ConfigurationTarget . Global ,
170+ const envManagerUpdates = updateCalls . filter ( ( c ) => c . key === 'defaultEnvManager' ) ;
171+ assert . strictEqual ( envManagerUpdates . length , 0 , 'Should never write defaultEnvManager for global edits' ) ;
172+ sinon . assert . calledWithMatch (
173+ traceVerboseStub ,
174+ '[setEnvironmentManager] Ignoring 1 edit(s) without a project because python-envs does not persist manager defaults to User/global settings.' ,
169175 ) ;
170- assert . strictEqual ( envManagerUpdates . length , 0 , 'Should never write to user/global settings' ) ;
171176 } ) ;
172177 } ) ;
173178
@@ -177,6 +182,7 @@ suite('Setting Helpers - Settings Write Behavior', () => {
177182 currentPkgManager : PIP_MANAGER_ID ,
178183 } ) ;
179184 sinon . stub ( workspaceApis , 'getConfiguration' ) . returns ( mockConfig ) ;
185+ const traceVerboseStub = sinon . stub ( logging , 'traceVerbose' ) ;
180186
181187 await setPackageManager ( [
182188 {
@@ -185,10 +191,16 @@ suite('Setting Helpers - Settings Write Behavior', () => {
185191 } ,
186192 ] ) ;
187193
188- const pkgManagerUpdates = updateCalls . filter (
189- ( c ) => c . key === 'defaultPackageManager' && c . target === ConfigurationTarget . Global ,
194+ const pkgManagerUpdates = updateCalls . filter ( ( c ) => c . key === 'defaultPackageManager' ) ;
195+ assert . strictEqual (
196+ pkgManagerUpdates . length ,
197+ 0 ,
198+ 'Should never write defaultPackageManager for global edits' ,
199+ ) ;
200+ sinon . assert . calledWithMatch (
201+ traceVerboseStub ,
202+ '[setPackageManager] Ignoring 1 edit(s) without a project because python-envs does not persist manager defaults to User/global settings.' ,
190203 ) ;
191- assert . strictEqual ( pkgManagerUpdates . length , 0 , 'Should never write to user/global settings' ) ;
192204 } ) ;
193205 } ) ;
194206} ) ;
@@ -210,7 +222,7 @@ suite('Setting Helpers - Empty Path Bug Fix', () => {
210222 index : 0 ,
211223 } ;
212224
213- let updateCalls : Array < { key : string ; value : unknown ; target : ConfigurationTarget } > ;
225+ let updateCalls : Array < { key : string ; value : unknown ; target : boolean | ConfigurationTarget | undefined } > ;
214226
215227 setup ( ( ) => {
216228 updateCalls = [ ] ;
@@ -248,7 +260,7 @@ suite('Setting Helpers - Empty Path Bug Fix', () => {
248260 updateCalls . push ( {
249261 key : section ,
250262 value,
251- target : configurationTarget as ConfigurationTarget ,
263+ target : configurationTarget ,
252264 } ) ;
253265 return Promise . resolve ( ) ;
254266 } ;
0 commit comments