@@ -220,13 +220,31 @@ describe('SolutionConverter', () => {
220220 expect ( completedListener ) . toHaveBeenCalledTimes ( 1 ) ;
221221 } ) ;
222222
223- it ( 'prints an error message to the output channel if the solution could not be converted ' , async ( ) => {
223+ it ( 'prints an error message when ListMissingPacks fails and ConvertSolution is skipped ' , async ( ) => {
224224 mockCsolutionService . listMissingPacks . mockResolvedValue ( { success : false } ) ;
225225 mockCsolutionService . convertSolution . mockResolvedValue ( { success : false } ) ;
226226 await fireAndWaitForConversion ( ) ;
227227
228228 const outputChannel = outputChannelProvider . mockGetCreatedChannelByName ( manifest . CMSIS_SOLUTION_OUTPUT_CHANNEL ) ;
229229
230+ // When listMissingPacks fails, ConvertSolution is skipped
231+ expect ( outputChannel ! . mockAppendedStrings ) . toEqual ( [
232+ expect . stringContaining ( '⚙️ Converting solution...' ) ,
233+ expect . stringContaining ( 'Check for missing packs...' ) ,
234+ expect . stringContaining ( 'Get log messages...' ) ,
235+ expect . stringContaining ( '🟥 Convert solution failed' ) ,
236+ ] ) ;
237+
238+ expect ( completedListener ) . toHaveBeenCalledTimes ( 1 ) ;
239+ } ) ;
240+
241+ it ( 'prints an error when convert solution fails' , async ( ) => {
242+ mockCsolutionService . listMissingPacks . mockResolvedValue ( { success : true } ) ;
243+ mockCsolutionService . convertSolution . mockResolvedValue ( { success : false } ) ;
244+ await fireAndWaitForConversion ( ) ;
245+
246+ const outputChannel = outputChannelProvider . mockGetCreatedChannelByName ( manifest . CMSIS_SOLUTION_OUTPUT_CHANNEL ) ;
247+
230248 expect ( outputChannel ! . mockAppendedStrings ) . toEqual ( [
231249 expect . stringContaining ( '⚙️ Converting solution...' ) ,
232250 expect . stringContaining ( 'Check for missing packs...' ) ,
@@ -303,7 +321,7 @@ describe('SolutionConverter', () => {
303321 expect ( completedListener ) . toHaveBeenCalledTimes ( 1 ) ;
304322 } ) ;
305323
306- it ( 'get cbuild output and set diagnostics accordingly' , async ( ) => {
324+ it ( 'get cbuild west output and set diagnostics accordingly' , async ( ) => {
307325 const mockDiagnosticsCollectionSet = jest . spyOn ( vscode . languages . createDiagnosticCollection ( ) , 'set' ) ;
308326 mockCsolutionService . convertSolution . mockResolvedValue ( { success : true } ) ;
309327 mockCsolutionService . getLogMessages . mockResolvedValue ( { success : true } ) ;
@@ -406,4 +424,40 @@ describe('SolutionConverter', () => {
406424 ) ;
407425 } ) ;
408426 } ) ;
427+
428+ it ( 'creates diagnostic when cpackget fails to download a pack' , async ( ) => {
429+ const diagnosticCollection = vscode . languages . createDiagnosticCollection ( ) ;
430+ const mockDiagnosticsCollectionSet = jest . spyOn ( diagnosticCollection , 'set' ) as unknown as jest . MockedFunction <
431+ ( uri : vscode . Uri , diagnostics : readonly vscode . Diagnostic [ ] | undefined ) => void
432+ > ;
433+ jest . spyOn ( cmsisToolboxManager , 'runCmsisTool' ) . mockImplementation ( async ( _t , _a , onOutput ) => {
434+ onOutput ( 'W: retry failed' ) ;
435+ onOutput ( 'E: network timeout' ) ;
436+ return [ 1 , undefined ] ;
437+ } ) ;
438+ mockCsolutionService . listMissingPacks . mockResolvedValue ( { success : true , packs : [ 'VendorA::PackA@1.0.0' ] } ) ;
439+ mockCsolutionService . getLogMessages . mockResolvedValue ( { success : true } ) ;
440+
441+ await fireAndWaitForConversion ( ) ;
442+
443+ expect ( mockDiagnosticsCollectionSet ) . toHaveBeenCalledTimes ( 1 ) ;
444+ const [ [ , diagnostics ] ] = mockDiagnosticsCollectionSet . mock . calls ;
445+ expect ( diagnostics ?. [ 0 ] ?. message ) . toContain ( 'network timeout' ) ;
446+ expect ( diagnostics ?. [ 0 ] ?. message ) . toContain ( 'retry failed' ) ;
447+ } ) ;
448+
449+ it ( 'extracts warnings from cbuild2cmake and csolution tool output' , async ( ) => {
450+ const mockDiagnosticsCollectionSet = jest . spyOn ( vscode . languages . createDiagnosticCollection ( ) , 'set' ) ;
451+ mockCsolutionService . convertSolution . mockResolvedValue ( { success : true } ) ;
452+ mockCsolutionService . getLogMessages . mockResolvedValue ( { success : true } ) ;
453+ jest . spyOn ( compileCommandsGenerator , 'runCbuildSetup' ) . mockResolvedValue ( [ true , [
454+ 'warning cbuild2cmake: some warning' ,
455+ 'error csolution: some error' ,
456+ ] ] ) ;
457+
458+ await fireAndWaitForConversion ( ) ;
459+
460+ // Expect two calls: one for cbuild2cmake warning, one for csolution error
461+ expect ( mockDiagnosticsCollectionSet ) . toHaveBeenCalledTimes ( 2 ) ;
462+ } ) ;
409463} ) ;
0 commit comments