@@ -31,7 +31,7 @@ interface FastPathTestOptions {
3131
3232function createOpts ( overrides ?: Partial < FastPathOptions > ) : FastPathTestOptions {
3333 const setInitialized = sinon . stub ( ) ;
34- const persistedPath = path . resolve ( 'persisted' , 'path' ) ;
34+ const persistedPath = __filename ;
3535 return {
3636 opts : {
3737 initialized : undefined ,
@@ -77,7 +77,7 @@ suite('tryFastPathGet', () => {
7777 } ) ;
7878
7979 test ( 'returns resolved env for global scope when getGlobalPersistedPath returns a path' , async ( ) => {
80- const globalPath = path . resolve ( 'usr' , 'bin' , 'python3' ) ;
80+ const globalPath = __filename ;
8181 const resolve = sinon . stub ( ) . resolves ( createMockEnv ( globalPath ) ) ;
8282 const { opts } = createOpts ( {
8383 scope : undefined ,
@@ -116,7 +116,7 @@ suite('tryFastPathGet', () => {
116116 } ) ;
117117
118118 test ( 'reports stale when global cached path resolves to undefined' , async ( ) => {
119- const globalPath = path . resolve ( 'usr' , 'bin' , 'python3' ) ;
119+ const globalPath = __filename ;
120120 const { opts } = createOpts ( {
121121 scope : undefined ,
122122 getGlobalPersistedPath : sinon . stub ( ) . resolves ( globalPath ) ,
@@ -132,7 +132,7 @@ suite('tryFastPathGet', () => {
132132 } ) ;
133133
134134 test ( 'returns undefined for global scope when cached path resolve fails' , async ( ) => {
135- const globalPath = path . resolve ( 'usr' , 'bin' , 'python3' ) ;
135+ const globalPath = __filename ;
136136 const { opts } = createOpts ( {
137137 scope : undefined ,
138138 getGlobalPersistedPath : sinon . stub ( ) . resolves ( globalPath ) ,
@@ -150,7 +150,7 @@ suite('tryFastPathGet', () => {
150150 } ) ;
151151
152152 test ( 'global scope fast path starts background init when initialized is undefined' , async ( ) => {
153- const globalPath = path . resolve ( 'usr' , 'bin' , 'python3' ) ;
153+ const globalPath = __filename ;
154154 const startBackgroundInit = sinon . stub ( ) . resolves ( ) ;
155155 const { opts, setInitialized } = createOpts ( {
156156 scope : undefined ,
@@ -201,6 +201,37 @@ suite('tryFastPathGet', () => {
201201 assert . strictEqual ( result , undefined ) ;
202202 } ) ;
203203
204+ test ( 'skips resolve and falls through when workspace persisted path no longer exists on disk' , async ( ) => {
205+ const missingPath = path . resolve ( 'does' , 'not' , 'exist' , 'python-missing' ) ;
206+ const resolve = sinon . stub ( ) . resolves ( createMockEnv ( missingPath ) ) ;
207+ const { opts } = createOpts ( {
208+ getPersistedPath : sinon . stub ( ) . resolves ( missingPath ) ,
209+ resolve,
210+ } ) ;
211+ const result = await tryFastPathGet ( opts ) ;
212+
213+ assert . strictEqual ( result , undefined , 'Should fall through when cached path is missing' ) ;
214+ assert . ok ( resolve . notCalled , 'Should not invoke resolve (and thus PET) when path is missing' ) ;
215+ } ) ;
216+
217+ test ( 'skips resolve and reports stale when global persisted path no longer exists on disk' , async ( ) => {
218+ const missingPath = path . resolve ( 'does' , 'not' , 'exist' , 'python-missing' ) ;
219+ const resolve = sinon . stub ( ) . resolves ( createMockEnv ( missingPath ) ) ;
220+ const { opts } = createOpts ( {
221+ scope : undefined ,
222+ getGlobalPersistedPath : sinon . stub ( ) . resolves ( missingPath ) ,
223+ resolve,
224+ } ) ;
225+ const result = await tryFastPathGet ( opts ) ;
226+
227+ assert . strictEqual ( result , undefined , 'Should fall through when cached global path is missing' ) ;
228+ assert . ok ( resolve . notCalled , 'Should not invoke resolve (and thus PET) when path is missing' ) ;
229+ assert . ok ( sendTelemetryStub . calledOnce , 'Should send telemetry for stale global cache' ) ;
230+ const [ eventName , , props ] = sendTelemetryStub . firstCall . args ;
231+ assert . strictEqual ( eventName , EventNames . GLOBAL_ENV_CACHE ) ;
232+ assert . strictEqual ( props . result , 'stale' ) ;
233+ } ) ;
234+
204235 test ( 'calls getProjectFsPath with the scope Uri' , async ( ) => {
205236 const scope = Uri . file ( path . resolve ( 'my' , 'project' ) ) ;
206237 const getProjectFsPath = sinon . stub ( ) . returns ( scope . fsPath ) ;
@@ -214,7 +245,7 @@ suite('tryFastPathGet', () => {
214245 test ( 'passes project fsPath to getPersistedPath' , async ( ) => {
215246 const projectPath = path . resolve ( 'project' , 'path' ) ;
216247 const getProjectFsPath = sinon . stub ( ) . returns ( projectPath ) ;
217- const getPersistedPath = sinon . stub ( ) . resolves ( path . resolve ( 'persisted' ) ) ;
248+ const getPersistedPath = sinon . stub ( ) . resolves ( __filename ) ;
218249 const { opts } = createOpts ( {
219250 getProjectFsPath,
220251 getPersistedPath,
@@ -266,7 +297,7 @@ suite('tryFastPathGet', () => {
266297 const getPersistedPath = sinon . stub ( ) . callsFake (
267298 ( ) =>
268299 new Promise < string | undefined > ( ( resolve ) => {
269- releasePersistedRead = ( ) => resolve ( path . resolve ( 'persisted' , 'path' ) ) ;
300+ releasePersistedRead = ( ) => resolve ( __filename ) ;
270301 } ) ,
271302 ) ;
272303 const { opts, setInitialized } = createOpts ( { getPersistedPath } ) ;
0 commit comments