@@ -194,6 +194,87 @@ def test_sarif_file_output(self, tmp_path):
194194 with open (sarif_path ) as f :
195195 sarif_data = json .load (f )
196196 assert sarif_data ["version" ] == "2.1.0"
197+
198+ def test_sarif_reachable_only_filters_non_blocking (self , tmp_path ):
199+ """Test that --sarif-reachable-only excludes non-blocking (unreachable) alerts"""
200+ from socketsecurity .config import CliConfig
201+ from unittest .mock import Mock
202+
203+ sarif_path = tmp_path / "report.sarif"
204+
205+ config = Mock (spec = CliConfig )
206+ config .sarif_file = str (sarif_path )
207+ config .sarif_reachable_only = True
208+ config .sbom_file = None
209+
210+ handler = OutputHandler (config , Mock ())
211+
212+ def make_issue (name , error ):
213+ return Issue (
214+ pkg_name = name ,
215+ pkg_version = "1.0.0" ,
216+ severity = "high" ,
217+ title = f"Vuln in { name } " ,
218+ description = "test" ,
219+ type = "vulnerability" ,
220+ manifests = "package.json" ,
221+ pkg_type = "npm" ,
222+ key = f"key-{ name } " ,
223+ purl = f"pkg:npm/{ name } @1.0.0" ,
224+ error = error ,
225+ )
226+
227+ diff = Diff ()
228+ diff .id = "test-scan-id"
229+ diff .new_alerts = [
230+ make_issue ("reachable-pkg" , error = True ),
231+ make_issue ("unreachable-pkg" , error = False ),
232+ ]
233+
234+ handler .output_console_sarif (diff )
235+
236+ with open (sarif_path ) as f :
237+ sarif_data = json .load (f )
238+
239+ rule_ids = [r ["ruleId" ] for r in sarif_data ["runs" ][0 ]["results" ]]
240+ assert any ("reachable-pkg" in r for r in rule_ids )
241+ assert not any ("unreachable-pkg" in r for r in rule_ids )
242+
243+ def test_sarif_reachable_only_false_includes_all (self , tmp_path ):
244+ """Test that without --sarif-reachable-only all alerts are included"""
245+ from socketsecurity .config import CliConfig
246+ from unittest .mock import Mock
247+
248+ sarif_path = tmp_path / "report.sarif"
249+
250+ config = Mock (spec = CliConfig )
251+ config .sarif_file = str (sarif_path )
252+ config .sarif_reachable_only = False
253+ config .sbom_file = None
254+
255+ handler = OutputHandler (config , Mock ())
256+
257+ diff = Diff ()
258+ diff .id = "test-scan-id"
259+ diff .new_alerts = [
260+ Issue (pkg_name = "blocking-pkg" , pkg_version = "1.0.0" , severity = "high" ,
261+ title = "Vuln" , description = "test" , type = "vulnerability" ,
262+ manifests = "package.json" , pkg_type = "npm" , key = "k1" ,
263+ purl = "pkg:npm/blocking-pkg@1.0.0" , error = True ),
264+ Issue (pkg_name = "non-blocking-pkg" , pkg_version = "1.0.0" , severity = "low" ,
265+ title = "Vuln" , description = "test" , type = "vulnerability" ,
266+ manifests = "package.json" , pkg_type = "npm" , key = "k2" ,
267+ purl = "pkg:npm/non-blocking-pkg@1.0.0" , error = False ),
268+ ]
269+
270+ handler .output_console_sarif (diff )
271+
272+ with open (sarif_path ) as f :
273+ sarif_data = json .load (f )
274+
275+ rule_ids = [r ["ruleId" ] for r in sarif_data ["runs" ][0 ]["results" ]]
276+ assert any ("blocking-pkg" in r for r in rule_ids )
277+ assert any ("non-blocking-pkg" in r for r in rule_ids )
197278 assert "$schema" in sarif_data
198279 assert len (sarif_data ["runs" ]) == 1
199280
0 commit comments