@@ -212,18 +212,57 @@ def cmd_adaptive(args: argparse.Namespace) -> None:
212212
213213
214214def cmd_suite (args : argparse .Namespace ) -> None :
215+ statuses = {
216+ "data" : None ,
217+ "tests" : None ,
218+ "api" : None ,
219+ "export" : None ,
220+ "rate" : None ,
221+ "adaptive" : None ,
222+ }
223+
224+ def _safe (run_fn , key ):
225+ try :
226+ run_fn (args )
227+ statuses [key ] = True
228+ except SystemExit :
229+ statuses [key ] = False
230+
215231 # Always run data + tests
216- cmd_data ( args )
217- cmd_tests ( args )
232+ _safe ( cmd_data , "data" )
233+ _safe ( cmd_tests , "tests" )
218234 # Optionally run API-related checks
219235 if args .with_api :
220- cmd_api ( args )
236+ _safe ( cmd_api , "api" )
221237 if args .with_export :
222- cmd_export ( args )
238+ _safe ( cmd_export , "export" )
223239 if args .with_rate :
224- cmd_rate ( args )
240+ _safe ( cmd_rate , "rate" )
225241 if args .with_adaptive :
226- cmd_adaptive (args )
242+ _safe (cmd_adaptive , "adaptive" )
243+
244+ # Optional JSON report
245+ if getattr (args , "report_json" , None ):
246+ import json , datetime
247+ report = {
248+ "timestamp" : datetime .datetime .utcnow ().isoformat () + "Z" ,
249+ "config" : {
250+ "with_api" : bool (args .with_api ),
251+ "with_export" : bool (args .with_export ),
252+ "with_rate" : bool (args .with_rate ),
253+ "with_adaptive" : bool (args .with_adaptive ),
254+ },
255+ "statuses" : statuses ,
256+ }
257+ out_path = Path (args .report_json )
258+ out_path .parent .mkdir (parents = True , exist_ok = True )
259+ out_path .write_text (json .dumps (report , indent = 2 ), encoding = "utf-8" )
260+ print (f"Wrote sanity report to { out_path } " )
261+
262+ # Exit non-zero if any selected check failed
263+ failures = [k for k , v in statuses .items () if v is False ]
264+ if failures :
265+ raise SystemExit (1 )
227266
228267
229268def build_parser () -> argparse .ArgumentParser :
@@ -268,6 +307,7 @@ def add_api_opts(sp):
268307 sp_suite .add_argument ("--with-export" , action = "store_true" )
269308 sp_suite .add_argument ("--with-rate" , action = "store_true" )
270309 sp_suite .add_argument ("--with-adaptive" , action = "store_true" )
310+ sp_suite .add_argument ("--report-json" , default = None , help = "Write JSON summary to this path" )
271311 sp_suite .set_defaults (func = cmd_suite )
272312
273313 return p
0 commit comments