@@ -41,6 +41,25 @@ suite('CondaPackageManager', () => {
4141 assert . ok ( showErrorMessageWithLogs . notCalled ) ;
4242 } ) ;
4343
44+ test ( 'does not fail a successful mutation when follow-up list output is malformed' , async ( ) => {
45+ const environment = {
46+ envId : { id : 'test-environment' , managerId : 'test-manager' } ,
47+ environmentPath : Uri . file ( '.' ) ,
48+ } as PythonEnvironment ;
49+ const logError = sinon . stub ( ) ;
50+ const manager = new CondaPackageManager (
51+ { createPackageItem : sinon . stub ( ) } as unknown as PythonEnvironmentApi ,
52+ { error : logError } as unknown as LogOutputChannel ,
53+ ) ;
54+ sinon . stub ( CondaInstallCommand . prototype , 'execute' ) . resolves ( ) ;
55+ const parseError = new CondaListOutputError ( 'Failed to parse conda list output' ) ;
56+ sinon . stub ( CondaListCommand . prototype , 'execute' ) . rejects ( parseError ) ;
57+
58+ await manager . manage ( environment , { install : [ 'requests' ] , runHeadless : true } ) ;
59+
60+ assert . ok ( logError . calledOnceWithExactly ( 'Error parsing installed Conda packages' , parseError ) ) ;
61+ } ) ;
62+
4463 test ( 'propagates package version lookup failures' , async ( ) => {
4564 const environment = {
4665 envId : { id : 'test-environment' , managerId : 'test-manager' } ,
@@ -105,4 +124,35 @@ suite('CondaPackageManager', () => {
105124
106125 await assert . rejects ( manager . getPackages ( environment ) , ( error : unknown ) => error === processError ) ;
107126 } ) ;
127+
128+ test ( 'does not report removals or replace the cache when refresh output is malformed' , async ( ) => {
129+ const environment = {
130+ envId : { id : 'test-environment' , managerId : 'test-manager' } ,
131+ environmentPath : Uri . file ( '.' ) ,
132+ } as PythonEnvironment ;
133+ const cachedPackage = {
134+ name : 'requests' ,
135+ displayName : 'requests' ,
136+ version : '2.32.0' ,
137+ description : '2.32.0' ,
138+ } ;
139+ const api = {
140+ createPackageItem : sinon . stub ( ) . callsFake ( ( pkg ) => pkg ) ,
141+ } as unknown as PythonEnvironmentApi ;
142+ const manager = new CondaPackageManager ( api , { error : sinon . stub ( ) } as unknown as LogOutputChannel ) ;
143+ const execute = sinon . stub ( CondaListCommand . prototype , 'execute' ) ;
144+ execute . onFirstCall ( ) . resolves ( [ cachedPackage ] ) ;
145+ execute . onSecondCall ( ) . rejects ( new CondaListOutputError ( 'Failed to parse conda list output' ) ) ;
146+ sinon . stub ( windowApis , 'withProgress' ) . callsFake ( async ( _options , task ) => task ( { } as never , { } as never ) ) ;
147+ const onDidChangePackages = sinon . stub ( ) ;
148+ manager . onDidChangePackages ( onDidChangePackages ) ;
149+
150+ await manager . getPackages ( environment ) ;
151+ await manager . refresh ( environment ) ;
152+ const packages = await manager . getPackages ( environment ) ;
153+
154+ assert . deepStrictEqual ( packages ?. map ( ( pkg ) => pkg . name ) , [ 'requests' ] ) ;
155+ assert . ok ( onDidChangePackages . notCalled ) ;
156+ assert . strictEqual ( execute . callCount , 2 ) ;
157+ } ) ;
108158} ) ;
0 commit comments