@@ -123,6 +123,111 @@ def test_sbom_file_saving(self, handler, tmp_path):
123123 handler .save_sbom_file (diff , str (sbom_path ))
124124 assert sbom_path .exists ()
125125
126+ def test_json_file_saving (self , tmp_path ):
127+ from socketsecurity .config import CliConfig
128+ from unittest .mock import Mock
129+
130+ json_path = tmp_path / "report.json"
131+
132+ config = Mock (spec = CliConfig )
133+ config .disable_blocking = False
134+ config .strict_blocking = False
135+ config .json_file = str (json_path )
136+ config .summary_file = None
137+ config .report_link_file = None
138+ config .sbom_file = None
139+ config .legal = True
140+ config .repo = "owner/repo"
141+ config .branch = "main"
142+ config .commit_sha = "abc123"
143+ config .enable_json = False
144+ config .enable_sarif = False
145+ config .enable_gitlab_security = False
146+ config .enable_debug = False
147+
148+ handler = OutputHandler (config , Mock ())
149+
150+ diff = Diff ()
151+ diff .id = "scan-123"
152+ diff .diff_url = "https://socket.dev/diff/123"
153+ diff .report_url = "https://socket.dev/report/123"
154+ diff .new_alerts = [
155+ Issue (
156+ title = "Test" ,
157+ severity = "high" ,
158+ description = "desc" ,
159+ error = True ,
160+ key = "test-key" ,
161+ type = "vulnerability" ,
162+ pkg_type = "npm" ,
163+ pkg_name = "test-package" ,
164+ pkg_version = "1.0.0" ,
165+ purl = "pkg:npm/test-package@1.0.0" ,
166+ url = "https://socket.dev/npm/package/test-package/alerts/1.0.0" ,
167+ )
168+ ]
169+
170+ handler .save_json_file (diff , str (json_path ))
171+
172+ saved = json .loads (json_path .read_text ())
173+ assert saved ["full_scan_id" ] == "scan-123"
174+ assert saved ["report_url" ] == "https://socket.dev/report/123"
175+ assert saved ["repo" ] == "owner/repo"
176+ assert saved ["branch" ] == "main"
177+ assert saved ["commit_sha" ] == "abc123"
178+ assert saved ["legal_mode" ] is True
179+
180+ def test_summary_and_report_link_files_are_written (self , tmp_path ):
181+ from socketsecurity .config import CliConfig
182+ from unittest .mock import Mock
183+
184+ summary_path = tmp_path / "summary.txt"
185+ report_link_path = tmp_path / "report-link.txt"
186+
187+ config = Mock (spec = CliConfig )
188+ config .disable_blocking = False
189+ config .strict_blocking = False
190+ config .json_file = None
191+ config .summary_file = str (summary_path )
192+ config .report_link_file = str (report_link_path )
193+ config .sbom_file = None
194+ config .legal = False
195+ config .repo = None
196+ config .branch = ""
197+ config .commit_sha = ""
198+ config .enable_json = False
199+ config .enable_sarif = False
200+ config .enable_gitlab_security = False
201+ config .enable_debug = False
202+
203+ handler = OutputHandler (config , Mock ())
204+
205+ diff = Diff ()
206+ diff .id = "scan-123"
207+ diff .diff_url = "https://socket.dev/diff/123"
208+ diff .report_url = "https://socket.dev/report/123"
209+ diff .new_alerts = [
210+ Issue (
211+ title = "Test" ,
212+ severity = "high" ,
213+ description = "desc" ,
214+ error = True ,
215+ key = "test-key" ,
216+ type = "vulnerability" ,
217+ pkg_type = "npm" ,
218+ pkg_name = "test-package" ,
219+ pkg_version = "1.0.0" ,
220+ purl = "pkg:npm/test-package@1.0.0" ,
221+ url = "https://socket.dev/npm/package/test-package/alerts/1.0.0" ,
222+ )
223+ ]
224+
225+ handler .save_summary_file (diff , str (summary_path ))
226+ handler .save_report_link_file (diff , str (report_link_path ))
227+
228+ assert "Security issues detected by Socket Security:" in summary_path .read_text ()
229+ assert report_link_path .read_text ().strip () == "https://socket.dev/report/123"
230+
126231 def test_report_pass_with_strict_blocking_new_alerts (self ):
127232 """Test that strict-blocking fails on new blocking alerts"""
128233 from socketsecurity .config import CliConfig
0 commit comments