@@ -535,6 +535,107 @@ suite('PythonEnvironmentManagers getLastKnownEnvironment', () => {
535535 assert . strictEqual ( envManagers . getLastKnownEnvironment ( script ) , selectedEnvironment ) ;
536536 } ) ;
537537
538+ test ( 'publishes through the inline manager after an explicit override is cleared' , async ( ) => {
539+ const script = Uri . file ( '/workspace/project/script.py' ) ;
540+ projectsByUri . set ( script . toString ( ) , { name : 'project' , uri : Uri . file ( '/workspace/project' ) } ) ;
541+ const selectedSet = sinon . stub ( ) . resolves ( ) ;
542+ let selectedEnvironment : PythonEnvironment ;
543+ const selectedId = registerManager ( async ( ) => selectedEnvironment , selectedSet , 'venv' ) ;
544+ let inlineEnvironment : PythonEnvironment ;
545+ const inlineGet = sinon . stub ( ) . callsFake ( async ( ) => inlineEnvironment ) ;
546+ const inlineId = registerManager ( inlineGet , async ( ) => undefined , 'inline-script' ) ;
547+ selectedEnvironment = { ...makeEnv ( 'selected' ) , envId : { id : 'selected' , managerId : selectedId } } ;
548+ inlineEnvironment = { ...makeEnv ( 'inline' ) , envId : { id : 'inline' , managerId : inlineId } } ;
549+ defaultManagerId = selectedId ;
550+ markInlineScript ( script ) ;
551+ await envManagers . setEnvironment ( script , inlineEnvironment , false ) ;
552+ await envManagers . setEnvironment ( script , selectedEnvironment , false ) ;
553+ await new Promise ( ( resolve ) => setImmediate ( resolve ) ) ;
554+ selectedSet . resetHistory ( ) ;
555+ inlineGet . resetHistory ( ) ;
556+ const events : DidChangeEnvironmentEventArgs [ ] = [ ] ;
557+ envManagers . onDidChangeActiveEnvironment ( ( event ) => events . push ( event ) ) ;
558+
559+ await envManagers . setEnvironment ( script , undefined , false ) ;
560+
561+ sinon . assert . calledOnceWithExactly ( selectedSet , script , undefined ) ;
562+ sinon . assert . calledOnceWithExactly ( inlineGet , script ) ;
563+ assert . strictEqual ( envManagers . getEnvironmentManager ( script ) ?. id , inlineId ) ;
564+ assert . strictEqual ( envManagers . getLastKnownEnvironment ( script ) , inlineEnvironment ) ;
565+ assert . deepStrictEqual ( events , [
566+ {
567+ uri : script ,
568+ old : selectedEnvironment ,
569+ new : inlineEnvironment ,
570+ } ,
571+ ] ) ;
572+ } ) ;
573+
574+ test ( 'does not let override clearing overwrite a newer inline selection' , async ( ) => {
575+ const script = Uri . file ( '/workspace/project/script.py' ) ;
576+ projectsByUri . set ( script . toString ( ) , { name : 'project' , uri : Uri . file ( '/workspace/project' ) } ) ;
577+ let releaseOverrideClear : ( ( ) => void ) | undefined ;
578+ let signalOverrideClear : ( ( ) => void ) | undefined ;
579+ const overrideClearStarted = new Promise < void > ( ( resolve ) => {
580+ signalOverrideClear = resolve ;
581+ } ) ;
582+ const overrideClearGate = new Promise < void > ( ( resolve ) => {
583+ releaseOverrideClear = resolve ;
584+ } ) ;
585+ const selectedSet = sinon . stub ( ) ;
586+ selectedSet . onFirstCall ( ) . resolves ( ) ;
587+ selectedSet . onSecondCall ( ) . callsFake ( async ( ) => {
588+ signalOverrideClear ! ( ) ;
589+ await overrideClearGate ;
590+ } ) ;
591+ let selectedEnvironment : PythonEnvironment ;
592+ const selectedId = registerManager ( async ( ) => selectedEnvironment , selectedSet , 'venv' ) ;
593+
594+ let releaseNewInline : ( ( ) => void ) | undefined ;
595+ let signalNewInline : ( ( ) => void ) | undefined ;
596+ const newInlineStarted = new Promise < void > ( ( resolve ) => {
597+ signalNewInline = resolve ;
598+ } ) ;
599+ const newInlineGate = new Promise < void > ( ( resolve ) => {
600+ releaseNewInline = resolve ;
601+ } ) ;
602+ const inlineSet = sinon . stub ( ) ;
603+ inlineSet . onFirstCall ( ) . resolves ( ) ;
604+ inlineSet . onSecondCall ( ) . callsFake ( async ( ) => {
605+ signalNewInline ! ( ) ;
606+ await newInlineGate ;
607+ } ) ;
608+ let inlineEnvironment : PythonEnvironment ;
609+ const inlineId = registerManager ( async ( ) => inlineEnvironment , inlineSet , 'inline-script' ) ;
610+ const oldInline = {
611+ ...makeEnv ( 'old-inline' ) ,
612+ envId : { id : 'old-inline' , managerId : inlineId } ,
613+ } ;
614+ const newInline = {
615+ ...makeEnv ( 'new-inline' ) ,
616+ envId : { id : 'new-inline' , managerId : inlineId } ,
617+ } ;
618+ inlineEnvironment = oldInline ;
619+ selectedEnvironment = { ...makeEnv ( 'selected' ) , envId : { id : 'selected' , managerId : selectedId } } ;
620+ defaultManagerId = selectedId ;
621+ markInlineScript ( script ) ;
622+ await envManagers . setEnvironment ( script , oldInline , false ) ;
623+ await envManagers . setEnvironment ( script , selectedEnvironment , false ) ;
624+
625+ const clearOverride = envManagers . setEnvironment ( script , undefined , false ) ;
626+ await overrideClearStarted ;
627+ inlineEnvironment = newInline ;
628+ const newerSelection = envManagers . setEnvironment ( script , newInline , false ) ;
629+ await newInlineStarted ;
630+ releaseOverrideClear ! ( ) ;
631+ await clearOverride ;
632+ releaseNewInline ! ( ) ;
633+ await newerSelection ;
634+
635+ assert . strictEqual ( envManagers . getEnvironmentManager ( script ) ?. id , inlineId ) ;
636+ assert . strictEqual ( envManagers . getLastKnownEnvironment ( script ) , newInline ) ;
637+ } ) ;
638+
538639 test ( 'clears inline routing after a no-op inline refresh during settings persistence' , async ( ) => {
539640 const script = Uri . file ( '/workspace/project/script.py' ) ;
540641 projectsByUri . set ( script . toString ( ) , { name : 'project' , uri : Uri . file ( '/workspace/project' ) } ) ;
0 commit comments