11/** Tests for retry orchestration logic */
22
3+ import { join } from 'path' ;
4+
35import * as compile from '../../../../src/cds/compiler/compile' ;
46import { orchestrateRetryAttempts } from '../../../../src/cds/compiler/retry' ;
57import type { CompilationTask } from '../../../../src/cds/compiler/types' ;
@@ -453,10 +455,12 @@ describe('retry.ts', () => {
453455 // Execute
454456 orchestrateRetryAttempts ( mockDependencyGraph , codeqlExePath ) ;
455457
456- // Verify diagnostics are added for failed tasks
458+ // Verify a single project-level diagnostic is added (attached to the project's
459+ // package.json) rather than one per source file.
460+ expect ( mockDiagnostics . addCompilationDiagnostic ) . toHaveBeenCalledTimes ( 1 ) ;
457461 expect ( mockDiagnostics . addCompilationDiagnostic ) . toHaveBeenCalledWith (
458- '/ test/ project/db/schema.cds' ,
459- expect . any ( String ) ,
462+ join ( ' test- project' , 'package.json' ) ,
463+ expect . stringContaining ( '1 CDS file in this project was not extracted.' ) ,
460464 codeqlExePath ,
461465 '/test' ,
462466 ) ;
@@ -482,9 +486,74 @@ describe('retry.ts', () => {
482486
483487 orchestrateRetryAttempts ( mockDependencyGraph , codeqlExePath ) ;
484488
485- // Verify diagnostics are added for tasks that were never retried (retryInfo is undefined)
489+ // Verify a single project-level diagnostic is added for tasks that were never
490+ // retried (retryInfo is undefined), rather than one per source file.
491+ expect ( mockDiagnostics . addCompilationDiagnostic ) . toHaveBeenCalledTimes ( 1 ) ;
492+ expect ( mockDiagnostics . addCompilationDiagnostic ) . toHaveBeenCalledWith (
493+ join ( 'test-project' , 'package.json' ) ,
494+ expect . stringContaining ( '1 CDS file in this project was not extracted.' ) ,
495+ codeqlExePath ,
496+ '/test' ,
497+ ) ;
498+ } ) ;
499+
500+ it ( 'should emit a single diagnostic per failed task regardless of source file count' , ( ) => {
501+ // Setup: A single failed task with many source files (simulating a large project).
502+ const manyFiles = Array . from ( { length : 250 } , ( _ , i ) => `/test/project/db/file${ i } .cds` ) ;
503+ const failedTask : CompilationTask = {
504+ ...mockFailedTask ,
505+ sourceFiles : manyFiles ,
506+ retryInfo : { hasBeenRetried : true , retryReason : 'Test retry' } ,
507+ status : 'failed' ,
508+ } ;
509+ mockProject . compilationTasks = [ failedTask ] ;
510+ mockProject . cdsFiles = manyFiles ;
511+
512+ const tasksRequiringRetry = new Map ( [ [ 'test-project' , [ failedTask ] ] ] ) ;
513+ mockValidator . identifyTasksRequiringRetry . mockReturnValue ( tasksRequiringRetry ) ;
514+ mockPackageManager . needsFullDependencyInstallation . mockReturnValue ( false ) ;
515+
516+ mockCompile . compileCdsToJson . mockReturnValue ( {
517+ success : false ,
518+ message : 'Compilation failed' ,
519+ durationMs : 500 ,
520+ } ) ;
521+
522+ orchestrateRetryAttempts ( mockDependencyGraph , codeqlExePath ) ;
523+
524+ // One diagnostic per failed task — not one per source file.
525+ expect ( mockDiagnostics . addCompilationDiagnostic ) . toHaveBeenCalledTimes ( 1 ) ;
526+ expect ( mockDiagnostics . addCompilationDiagnostic ) . toHaveBeenCalledWith (
527+ join ( 'test-project' , 'package.json' ) ,
528+ expect . stringContaining ( '250 CDS files in this project were not extracted.' ) ,
529+ codeqlExePath ,
530+ '/test' ,
531+ ) ;
532+ } ) ;
533+
534+ it ( 'should attach the diagnostic to the project directory when no package.json exists' , ( ) => {
535+ // Setup: A failed task on a project that has no package.json.
536+ const failedTask = { ...mockFailedTask } ;
537+ failedTask . retryInfo = { hasBeenRetried : true , retryReason : 'Test retry' } ;
538+ failedTask . status = 'failed' ;
539+ mockProject . compilationTasks = [ failedTask ] ;
540+ mockProject . packageJson = undefined ;
541+
542+ const tasksRequiringRetry = new Map ( [ [ 'test-project' , [ failedTask ] ] ] ) ;
543+ mockValidator . identifyTasksRequiringRetry . mockReturnValue ( tasksRequiringRetry ) ;
544+ mockPackageManager . needsFullDependencyInstallation . mockReturnValue ( false ) ;
545+
546+ mockCompile . compileCdsToJson . mockReturnValue ( {
547+ success : false ,
548+ message : 'Compilation failed' ,
549+ durationMs : 500 ,
550+ } ) ;
551+
552+ orchestrateRetryAttempts ( mockDependencyGraph , codeqlExePath ) ;
553+
554+ expect ( mockDiagnostics . addCompilationDiagnostic ) . toHaveBeenCalledTimes ( 1 ) ;
486555 expect ( mockDiagnostics . addCompilationDiagnostic ) . toHaveBeenCalledWith (
487- '/ test/ project/db/schema.cds ' ,
556+ 'test- project' ,
488557 expect . any ( String ) ,
489558 codeqlExePath ,
490559 '/test' ,
0 commit comments