@@ -133,6 +133,37 @@ describe('SfgeEngine', () => {
133133 expect ( progressEvents . map ( e => e . percentComplete ) ) . toEqual ( [ 2 , 100 ] ) ;
134134 } ) ;
135135
136+ it ( 'When targets are empty, no violations are returned and SFGE is not invoked' , async ( ) => {
137+ // This test verifies that when the workspace contains .cls files but targets are empty
138+ // (e.g., after being filtered out by ignores), SFGE returns early without invoking
139+ // the Java process. This prevents SFGE from scanning all workspace files when
140+ // no targets are provided.
141+ const engine : SfgeEngine = new SfgeEngine ( DEFAULT_SFGE_ENGINE_CONFIG , fixedClock ) ;
142+ // Workspace folder has .cls files, but we pass empty targets
143+ const workspace : Workspace = new Workspace (
144+ 'id' ,
145+ [ path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace' ) ] ,
146+ [ ] // Empty targets - simulates all targets being filtered out by ignores
147+ ) ;
148+ const logEvents : LogEvent [ ] = [ ] ;
149+ engine . onEvent ( EventType . LogEvent , ( e : LogEvent ) => logEvents . push ( e ) ) ;
150+ const progressEvents : RunRulesProgressEvent [ ] = [ ] ;
151+ engine . onEvent ( EventType . RunRulesProgressEvent , ( e : RunRulesProgressEvent ) => progressEvents . push ( e ) ) ;
152+ const ruleNames : string [ ] = [ 'ApexFlsViolation' ] ;
153+
154+ // ====== TESTED BEHAVIOR ======
155+ const results : EngineRunResults = await engine . runRules ( ruleNames , createRunOptions ( workspace ) ) ;
156+
157+ // ====== ASSERTIONS ======
158+ // No violations should be returned
159+ expect ( results . violations ) . toHaveLength ( 0 ) ;
160+ // SFGE should not be invoked, so no log events about calling Java commands
161+ expect ( logEvents ) . toHaveLength ( 0 ) ;
162+ // The progress events should skip from the very first one (2%) to the very last one (100%)
163+ // This confirms we returned early without running SFGE
164+ expect ( progressEvents . map ( e => e . percentComplete ) ) . toEqual ( [ 2 , 100 ] ) ;
165+ } ) ;
166+
136167 it . each ( [
137168 { case : 'a folder with relevant files that do not violate the selected rules' , workspacePaths : [ path . join ( TEST_DATA_FOLDER , 'sampleRelevantWorkspace' ) ] } ,
138169 {
0 commit comments